summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/toastergui
diff options
context:
space:
mode:
authorAlexandru DAMIAN <alexandru.damian@intel.com>2015-06-05 12:30:12 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-06-12 00:01:48 +0100
commitc941743c9a1310c1b5ef942fa6e6d1ed31a7faa7 (patch)
tree19a7e7c37848359f98f50fb260fe1b45be8ceb56 /bitbake/lib/toaster/toastergui
parent58600cf8e76f270969ded6ec63ac0908f39dae09 (diff)
downloadpoky-c941743c9a1310c1b5ef942fa6e6d1ed31a7faa7.tar.gz
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>
Diffstat (limited to 'bitbake/lib/toaster/toastergui')
-rw-r--r--bitbake/lib/toaster/toastergui/static/js/table.js13
-rw-r--r--bitbake/lib/toaster/toastergui/tables.py8
-rwxr-xr-xbitbake/lib/toaster/toastergui/views.py3
-rw-r--r--bitbake/lib/toaster/toastergui/widgets.py19
4 files changed, 38 insertions, 5 deletions
diff --git a/bitbake/lib/toaster/toastergui/static/js/table.js b/bitbake/lib/toaster/toastergui/static/js/table.js
index 80e9ec2392..45c61848da 100644
--- a/bitbake/lib/toaster/toastergui/static/js/table.js
+++ b/bitbake/lib/toaster/toastergui/static/js/table.js
@@ -110,9 +110,13 @@ function tableInit(ctx){
110 setupTableChrome(tableData); 110 setupTableChrome(tableData);
111 111
112 /* Add table data rows */ 112 /* Add table data rows */
113 var column_index;
113 for (var i in tableData.rows){ 114 for (var i in tableData.rows){
115 /* only display if the column is display-able */
114 var row = $("<tr></tr>"); 116 var row = $("<tr></tr>");
117 column_index = -1;
115 for (var key_j in tableData.rows[i]){ 118 for (var key_j in tableData.rows[i]){
119
116 /* if we have a static: version of a key, prefer the static: version for rendering */ 120 /* if we have a static: version of a key, prefer the static: version for rendering */
117 var orig_key_j = key_j; 121 var orig_key_j = key_j;
118 122
@@ -125,6 +129,12 @@ function tableInit(ctx){
125 key_j = "static:" + key_j; 129 key_j = "static:" + key_j;
126 } 130 }
127 131
132 /* we skip over un-displayable column entries */
133 column_index += 1;
134 if (! tableData.columns[column_index].displayable) {
135 continue;
136 }
137
128 var td = $("<td></td>"); 138 var td = $("<td></td>");
129 td.prop("class", orig_key_j); 139 td.prop("class", orig_key_j);
130 if (tableData.rows[i][key_j]){ 140 if (tableData.rows[i][key_j]){
@@ -206,6 +216,9 @@ function tableInit(ctx){
206 /* Add table header and column toggle menu */ 216 /* Add table header and column toggle menu */
207 for (var i in tableData.columns){ 217 for (var i in tableData.columns){
208 var col = tableData.columns[i]; 218 var col = tableData.columns[i];
219 if (col.displayable === false) {
220 continue;
221 }
209 var header = $("<th></th>"); 222 var header = $("<th></th>");
210 header.prop("class", col.field_name); 223 header.prop("class", col.field_name);
211 224
diff --git a/bitbake/lib/toaster/toastergui/tables.py b/bitbake/lib/toaster/toastergui/tables.py
index b75e565246..e540b91499 100644
--- a/bitbake/lib/toaster/toastergui/tables.py
+++ b/bitbake/lib/toaster/toastergui/tables.py
@@ -79,7 +79,7 @@ class LayersTable(ToasterTable):
79 self.add_column(title="Git repository URL", 79 self.add_column(title="Git repository URL",
80 help_text="The Git repository for the layer source code", 80 help_text="The Git repository for the layer source code",
81 hidden=True, 81 hidden=True,
82 static_data_name="git_url", 82 static_data_name="layer__vcs_url",
83 static_data_template=git_url_template) 83 static_data_template=git_url_template)
84 84
85 git_dir_template = ''' 85 git_dir_template = '''
@@ -328,13 +328,17 @@ class RecipesTable(ToasterTable):
328 self.add_column(title="Revision", 328 self.add_column(title="Revision",
329 field_name="layer_version__get_vcs_reference") 329 field_name="layer_version__get_vcs_reference")
330 330
331
332 self.add_column(title="Build", 331 self.add_column(title="Build",
333 help_text="Add or delete recipes to and from your project", 332 help_text="Add or delete recipes to and from your project",
334 hideable=False, 333 hideable=False,
335 static_data_name="add-del-layers", 334 static_data_name="add-del-layers",
336 static_data_template='{% include "recipe_btn.html" %}') 335 static_data_template='{% include "recipe_btn.html" %}')
337 336
337 self.add_column(title="Project compatible Layer ID",
338 displayable = False,
339 field_name = "projectcompatible_layer",
340 computation = lambda x: (x.layer_version.get_equivalents_wpriority(Project.objects.get(pk=kwargs['pid']))[0]))
341
338class LayerRecipesTable(RecipesTable): 342class LayerRecipesTable(RecipesTable):
339 """ Smaller version of the Recipes table for use in layer details """ 343 """ Smaller version of the Recipes table for use in layer details """
340 344
diff --git a/bitbake/lib/toaster/toastergui/views.py b/bitbake/lib/toaster/toastergui/views.py
index 280159ad2c..c25c512a84 100755
--- a/bitbake/lib/toaster/toastergui/views.py
+++ b/bitbake/lib/toaster/toastergui/views.py
@@ -112,6 +112,9 @@ def objtojson(obj):
112 elif isinstance(d[di], int) and hasattr(obj, "get_%s_display" % di): 112 elif isinstance(d[di], int) and hasattr(obj, "get_%s_display" % di):
113 nd[di] = getattr(obj, "get_%s_display" % di)() 113 nd[di] = getattr(obj, "get_%s_display" % di)()
114 return nd 114 return nd
115 elif isinstance( obj, type(lambda x:x)):
116 import inspect
117 return inspect.getsourcelines(obj)[0]
115 else: 118 else:
116 raise TypeError("Unserializable object %s (%s) of type %s" % ( obj, dir(obj), type(obj))) 119 raise TypeError("Unserializable object %s (%s) of type %s" % ( obj, dir(obj), type(obj)))
117 120
diff --git a/bitbake/lib/toaster/toastergui/widgets.py b/bitbake/lib/toaster/toastergui/widgets.py
index 82b7514bd8..407a0fbe15 100644
--- a/bitbake/lib/toaster/toastergui/widgets.py
+++ b/bitbake/lib/toaster/toastergui/widgets.py
@@ -54,6 +54,13 @@ class ToasterTable(TemplateView):
54 self.empty_state = "Sorry - no data found" 54 self.empty_state = "Sorry - no data found"
55 self.default_orderby = "" 55 self.default_orderby = ""
56 56
57 # add the "id" column, undisplayable, by default
58 self.add_column(title="Id",
59 displayable=False,
60 orderable=True,
61 field_name="id")
62
63
57 def get(self, request, *args, **kwargs): 64 def get(self, request, *args, **kwargs):
58 if request.GET.get('format', None) == 'json': 65 if request.GET.get('format', None) == 'json':
59 66
@@ -142,6 +149,7 @@ class ToasterTable(TemplateView):
142 def add_column(self, title="", help_text="", 149 def add_column(self, title="", help_text="",
143 orderable=False, hideable=True, hidden=False, 150 orderable=False, hideable=True, hidden=False,
144 field_name="", filter_name=None, static_data_name=None, 151 field_name="", filter_name=None, static_data_name=None,
152 displayable=True, computation=None,
145 static_data_template=None): 153 static_data_template=None):
146 """Add a column to the table. 154 """Add a column to the table.
147 155
@@ -168,6 +176,8 @@ class ToasterTable(TemplateView):
168 'filter_name' : filter_name, 176 'filter_name' : filter_name,
169 'static_data_name': static_data_name, 177 'static_data_name': static_data_name,
170 'static_data_template': static_data_template, 178 'static_data_template': static_data_template,
179 'displayable': displayable,
180 'computation': computation,
171 }) 181 })
172 182
173 def render_static_data(self, template, row): 183 def render_static_data(self, template, row):
@@ -289,8 +299,11 @@ class ToasterTable(TemplateView):
289 299
290 col['field_name'] = col['static_data_name'] 300 col['field_name'] = col['static_data_name']
291 301
292 if True: # we add the raw model data at all times 302 # compute the computation on the raw data if needed
293 model_data = row 303 model_data = row
304 if col['computation']:
305 model_data = col['computation'](row)
306 else:
294 # Traverse to any foriegn key in the object hierachy 307 # Traverse to any foriegn key in the object hierachy
295 for subfield in field.split("__"): 308 for subfield in field.split("__"):
296 if hasattr(model_data, subfield): 309 if hasattr(model_data, subfield):
@@ -300,7 +313,7 @@ class ToasterTable(TemplateView):
300 if isinstance(model_data, types.MethodType): 313 if isinstance(model_data, types.MethodType):
301 model_data = model_data() 314 model_data = model_data()
302 315
303 required_data[field] = model_data 316 required_data[col['field_name']] = model_data
304 317
305 data['rows'].append(required_data) 318 data['rows'].append(required_data)
306 319