bitbake: toaster: ToasterTables add computational fields

This patch adds the ability to pass a function to be computed
for generating a field value in setting up a column in
ToasterTables.

Also adding "displayable" property that can be turned False for
columns that are present in JSON data but are not part of the UI.

Add the "id" column by default for all rows.

(Bitbake rev: fb683135348b074412da154585c75865aad1eab0)

Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Alexandru DAMIAN 2015-06-05 12:30:12 +01:00 committed by Richard Purdie
parent 58600cf8e7
commit c941743c9a
4 changed files with 38 additions and 5 deletions

View File

@ -110,9 +110,13 @@ function tableInit(ctx){
setupTableChrome(tableData);
/* Add table data rows */
var column_index;
for (var i in tableData.rows){
/* only display if the column is display-able */
var row = $("<tr></tr>");
column_index = -1;
for (var key_j in tableData.rows[i]){
/* if we have a static: version of a key, prefer the static: version for rendering */
var orig_key_j = key_j;
@ -125,6 +129,12 @@ function tableInit(ctx){
key_j = "static:" + key_j;
}
/* we skip over un-displayable column entries */
column_index += 1;
if (! tableData.columns[column_index].displayable) {
continue;
}
var td = $("<td></td>");
td.prop("class", orig_key_j);
if (tableData.rows[i][key_j]){
@ -206,6 +216,9 @@ function tableInit(ctx){
/* Add table header and column toggle menu */
for (var i in tableData.columns){
var col = tableData.columns[i];
if (col.displayable === false) {
continue;
}
var header = $("<th></th>");
header.prop("class", col.field_name);

View File

@ -79,7 +79,7 @@ class LayersTable(ToasterTable):
self.add_column(title="Git repository URL",
help_text="The Git repository for the layer source code",
hidden=True,
static_data_name="git_url",
static_data_name="layer__vcs_url",
static_data_template=git_url_template)
git_dir_template = '''
@ -328,13 +328,17 @@ class RecipesTable(ToasterTable):
self.add_column(title="Revision",
field_name="layer_version__get_vcs_reference")
self.add_column(title="Build",
help_text="Add or delete recipes to and from your project",
hideable=False,
static_data_name="add-del-layers",
static_data_template='{% include "recipe_btn.html" %}')
self.add_column(title="Project compatible Layer ID",
displayable = False,
field_name = "projectcompatible_layer",
computation = lambda x: (x.layer_version.get_equivalents_wpriority(Project.objects.get(pk=kwargs['pid']))[0]))
class LayerRecipesTable(RecipesTable):
""" Smaller version of the Recipes table for use in layer details """

View File

@ -112,6 +112,9 @@ def objtojson(obj):
elif isinstance(d[di], int) and hasattr(obj, "get_%s_display" % di):
nd[di] = getattr(obj, "get_%s_display" % di)()
return nd
elif isinstance( obj, type(lambda x:x)):
import inspect
return inspect.getsourcelines(obj)[0]
else:
raise TypeError("Unserializable object %s (%s) of type %s" % ( obj, dir(obj), type(obj)))

View File

@ -54,6 +54,13 @@ class ToasterTable(TemplateView):
self.empty_state = "Sorry - no data found"
self.default_orderby = ""
# add the "id" column, undisplayable, by default
self.add_column(title="Id",
displayable=False,
orderable=True,
field_name="id")
def get(self, request, *args, **kwargs):
if request.GET.get('format', None) == 'json':
@ -142,6 +149,7 @@ class ToasterTable(TemplateView):
def add_column(self, title="", help_text="",
orderable=False, hideable=True, hidden=False,
field_name="", filter_name=None, static_data_name=None,
displayable=True, computation=None,
static_data_template=None):
"""Add a column to the table.
@ -168,6 +176,8 @@ class ToasterTable(TemplateView):
'filter_name' : filter_name,
'static_data_name': static_data_name,
'static_data_template': static_data_template,
'displayable': displayable,
'computation': computation,
})
def render_static_data(self, template, row):
@ -289,8 +299,11 @@ class ToasterTable(TemplateView):
col['field_name'] = col['static_data_name']
if True: # we add the raw model data at all times
model_data = row
# compute the computation on the raw data if needed
model_data = row
if col['computation']:
model_data = col['computation'](row)
else:
# Traverse to any foriegn key in the object hierachy
for subfield in field.split("__"):
if hasattr(model_data, subfield):
@ -300,7 +313,7 @@ class ToasterTable(TemplateView):
if isinstance(model_data, types.MethodType):
model_data = model_data()
required_data[field] = model_data
required_data[col['field_name']] = model_data
data['rows'].append(required_data)