Skip to contentSkip to conversation

UI fixes michaelw/toaster/table-ui-fixes

PATCH In review Michael Wood 2 participants 8 messages Oct 8, 2015 – Oct 9, 2015

lore
Share & tools
lore
#0 lore raw

cover UI fixes michaelw/toaster/table-ui-fixes

A number of UI fixes:
Add/Rm layer button not updated in some cases [YOCTO #8294]
Updates to the JS unit tests
A fix for the project layers returned
And a bug noticed in the layer details page where the button class names were
incorrect meaning the toggle of the add/remove layer didn't enable/disable the buttons to trigger recipe builds.

Michael Wood (5):
toaster: layerdetails update build recipe button class name
toaster: Fix typo in returning pk list of layer versions in current
project
toaster: tables Add the recipe filter back into the Recipe table
toaster: Fix stale layer state buttons
toaster: Update JS unit tests

 bitbake/lib/toaster/orm/models.py                  |  2 +-
 .../lib/toaster/toastergui/static/js/layerBtn.js   |  9 +-----
 .../toaster/toastergui/static/js/layerdetails.js   |  4 +--
 bitbake/lib/toaster/toastergui/static/js/table.js  |  2 +-
 .../lib/toaster/toastergui/static/js/tests/test.js | 34 +++++++++++-----------
 bitbake/lib/toaster/toastergui/tables.py           | 20 +++++++++++--
 .../toastergui/templates/js-unit-tests.html        | 16 +++++++---
 .../toaster/toastergui/templates/layer_btn.html    | 12 ++++++--
 .../toaster/toastergui/templates/recipe_btn.html   | 12 ++++++--
 .../toaster/toastergui/templates/toastertable.html |  1 -
 10 files changed, 71 insertions(+), 41 deletions(-)
Signature · 1 line
2.1.4
#1 lore raw

PATCH 1/5 toaster: layerdetails update build recipe button class name

Update the class name which we are using for the recipe build button. This fixes a regression in the buttons being enabled/disabled when adding and removing the layer being viewed from the project.

---
 bitbake/lib/toaster/toastergui/static/js/layerdetails.js | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
bitbake/lib/toaster/toastergui/static/js/layerdetails.js +2 -2
index 8817b47..8c2ec4c 100644
@@ -254,7 +254,7 @@ function layerDetailsPageInit (ctx) {
 
     if (added){
       /* enable and switch all the button states */
-      $(".build-target-btn").removeAttr("disabled");
+      $(".build-recipe-btn").removeAttr("disabled");
       $(".select-machine-btn").removeAttr("disabled");
       addRmLayerBtn.addClass("btn-danger");
       addRmLayerBtn.data('directive', "remove");
@@ -263,7 +263,7 @@ function layerDetailsPageInit (ctx) {
 
     } else {
       /* disable and switch all the button states */
-      $(".build-target-btn").attr("disabled","disabled");
+      $(".build-recipe-btn").attr("disabled","disabled");
       $(".select-machine-btn").attr("disabled", "disabled");
       addRmLayerBtn.removeClass("btn-danger");
       addRmLayerBtn.data('directive', "add");
Signature · 1 line
2.1.4
#2 lore raw

PATCH 2/5 toaster: Fix typo in returning pk list of layer versions in current project

In reply to Michael Wood

This was accidentally returning the primary key of the ProjectLayer rather than the ProjectLayer.Layer_Version.pk

---
 bitbake/lib/toaster/orm/models.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
bitbake/lib/toaster/orm/models.py +1 -1
index 375985e..1cbf480 100644
@@ -222,7 +222,7 @@ class Project(models.Model):
         if pk is False:
             return layer_versions
         else:
-            return layer_versions.values_list('pk', flat=True)
+            return layer_versions.values_list('layercommit__pk', flat=True)
 
 
     def get_available_machines(self):
Signature · 1 line
2.1.4
#3 lore raw

PATCH 3/5 toaster: tables Add the recipe filter back into the Recipe table

In reply to Michael Wood

Add the "Is recipe currently available in the project" filter back to the Recipe table which was removed when we had intermediate AvailableRecipe tables.

---
 bitbake/lib/toaster/toastergui/tables.py | 13 +++++++++++++
 1 file changed, 13 insertions(+)
bitbake/lib/toaster/toastergui/tables.py +13 -0
index a676ffa..4f24772 100644
@@ -335,10 +335,23 @@ class RecipesTable(ToasterTable, ProjectFiltersMixin):
 
         return context
 
+    def setup_filters(self, *args, **kwargs):
+        self.add_filter(title="Filter by project recipes",
+                        name="in_current_project",
+                        filter_actions=[
+                            self.make_filter_action("in_project", "Recipes provided by layers added to this project", self.filter_in_project),
+                            self.make_filter_action("not_in_project", "Recipes provided by layers not added to this project", self.filter_not_in_project)
+                        ])
 
     def setup_queryset(self, *args, **kwargs):
         prj = Project.objects.get(pk = kwargs['pid'])
 
+        # Project layers used by the filters
+        self.project_layers = prj.get_project_layer_versions(pk=True)
+
+        # Project layers used to switch the button states
+        self.static_context_extra['current_layers'] = self.project_layers
+
         self.queryset = prj.get_all_compatible_recipes()
         self.queryset = self.queryset.order_by(self.default_orderby)
 
Signature · 1 line
2.1.4
#4 lore raw

PATCH 4/5 toaster: Fix stale layer state buttons

In reply to Michael Wood

Move the "is available to the project" state computation to the template for the Layer add/remove buttons, Recipe build/Add layer as done for the Package add/remove. This is more reliable as we can get an inconsistent state on the front end JS as there are many opportunities for hitting out of date project information.

[YOCTO #8294]

---
 bitbake/lib/toaster/toastergui/static/js/layerBtn.js       |  9 +--------
 bitbake/lib/toaster/toastergui/static/js/table.js          |  2 +-
 bitbake/lib/toaster/toastergui/static/js/tests/test.js     |  2 +-
 bitbake/lib/toaster/toastergui/tables.py                   |  7 ++++---
 bitbake/lib/toaster/toastergui/templates/layer_btn.html    | 12 ++++++++++--
 bitbake/lib/toaster/toastergui/templates/recipe_btn.html   | 12 ++++++++++--
 bitbake/lib/toaster/toastergui/templates/toastertable.html |  1 -
 7 files changed, 27 insertions(+), 18 deletions(-)
bitbake/lib/toaster/toastergui/static/js/layerBtn.js +1 -8
index da0241c..7318b3f 100644
@@ -1,6 +1,6 @@
 "use strict";
 
-function layerBtnsInit(ctx) {
+function layerBtnsInit() {
 
   /* Remove any current bindings to avoid duplicated binds */
   $(".layerbtn").unbind('click');
@@ -80,11 +80,4 @@ function layerBtnsInit(ctx) {
     imgCustomModal.data('recipe', $(this).data('recipe'));
     imgCustomModal.modal('show');
   });
-
-  /* Setup the initial state of the buttons */
-
-  for (var i in ctx.projectLayers){
-      $(".layer-exists-" + ctx.projectLayers[i]).show();
-      $(".layer-add-" + ctx.projectLayers[i]).hide();
-  }
 }
bitbake/lib/toaster/toastergui/static/js/table.js +1 -1
index bc81e67..40b5022 100644
@@ -130,7 +130,7 @@ function tableInit(ctx){
       tableBody.append(row);
 
       /* If we have layerbtns then initialise them */
-      layerBtnsInit(ctx);
+      layerBtnsInit();
 
       /* If we have popovers initialise them now */
       $('td > a.btn').popover({
bitbake/lib/toaster/toastergui/static/js/tests/test.js +1 -1
index d610113..f0df6e4 100644
@@ -152,7 +152,7 @@ QUnit.test("Layer details page init", function(assert){
 });
 
 QUnit.test("Layer btns init", function(assert){
-  assert.throws(layerBtnsInit({ projectLayers : [] }));
+  assert.throws(layerBtnsInit());
 });
 
 QUnit.test("Table init", function(assert){
bitbake/lib/toaster/toastergui/tables.py +4 -3
index 4f24772..b10445b 100644
@@ -57,9 +57,7 @@ class LayersTable(ToasterTable):
         context = super(LayersTable, self).get_context_data(**kwargs)
 
         project = Project.objects.get(pk=kwargs['pid'])
-
         context['project'] = project
-        context['projectlayers'] = map(lambda prjlayer: prjlayer.layercommit.id, ProjectLayer.objects.filter(project=project))
 
         return context
 
@@ -93,7 +91,10 @@ class LayersTable(ToasterTable):
 
     def setup_queryset(self, *args, **kwargs):
         prj = Project.objects.get(pk = kwargs['pid'])
-        compatible_layers = prj.compatible_layerversions()
+        compatible_layers = prj.get_all_compatible_layer_versions()
+
+        self.static_context_extra['current_layers'] = \
+                prj.get_project_layer_versions(pk=True)
 
         self.queryset = compatible_layers.order_by(self.default_orderby)
 
bitbake/lib/toaster/toastergui/templates/layer_btn.html +10 -2
index a2e9393..314eec7 100644
@@ -1,8 +1,16 @@
-<button class="btn btn-danger btn-block layer-exists-{{data.pk}} layerbtn" style="display:none;" data-layer='{ "id": {{data.pk}}, "name":  "{{data.layer.name}}", "layerdetailurl": "{%url 'layerdetails' extra.pid data.pk%}"}' data-directive="remove" >
+<button class="btn btn-danger btn-block layer-exists-{{data.pk}} layerbtn"  data-layer='{ "id": {{data.pk}}, "name":  "{{data.layer.name}}", "layerdetailurl": "{%url 'layerdetails' extra.pid data.pk%}"}' data-directive="remove"
+    {% if data.pk not in extra.current_layers %}
+    style="display:none;"
+    {% endif %}
+  >
   <i class="icon-trash"></i>
   Delete layer
 </button>
-<button class="btn btn-block layer-add-{{data.pk}} layerbtn" data-layer='{ "id": {{data.pk}}, "name":  "{{data.layer.name}}", "layerdetailurl": "{%url 'layerdetails' extra.pid data.pk%}"}' data-directive="add">
+<button class="btn btn-block layer-add-{{data.pk}} layerbtn" data-layer='{ "id": {{data.pk}}, "name":  "{{data.layer.name}}", "layerdetailurl": "{%url 'layerdetails' extra.pid data.pk%}"}' data-directive="add"
+    {% if data.pk in extra.current_layers %}
+    style="display:none;"
+    {% endif %}
+  >
   <i class="icon-plus"></i>
   Add layer
 </button>
bitbake/lib/toaster/toastergui/templates/recipe_btn.html +10 -2
index 77c1b23..baab06e 100644
@@ -1,7 +1,15 @@
-<button data-recipe-name="{{data.name}}" class="btn btn-block layer-exists-{{data.layer_version.pk}} build-recipe-btn" style="display:none; margin-top: 5px;" >
+<button data-recipe-name="{{data.name}}" class="btn btn-block layer-exists-{{data.layer_version.pk}} build-recipe-btn" style="margin-top: 5px;
+  {% if data.layer_version.pk not in extra.current_layers %}
+    display:none;
+  {% endif %}"
+ >
   Build recipe
 </button>
-<button class="btn btn-block layerbtn layer-add-{{data.layer_version.pk}}" data-layer='{ "id": {{data.layer_version.pk}}, "name":  "{{data.layer_version.layer.name}}", "layerdetailurl": "{%url 'layerdetails' extra.pid data.layer_version.pk%}"}' data-directive="add">
+<button class="btn btn-block layerbtn layer-add-{{data.layer_version.pk}}" data-layer='{ "id": {{data.layer_version.pk}}, "name":  "{{data.layer_version.layer.name}}", "layerdetailurl": "{%url 'layerdetails' extra.pid data.layer_version.pk%}"}' data-directive="add"
+    {% if data.layer_version.pk in extra.current_layers %}
+     style="display:none;"
+    {% endif %}
+>
   <i class="icon-plus"></i>
   Add layer
   <i title="" class="icon-question-sign get-help" data-original-title="To build this target, you must first add the {{data.layer_version.layer.name}} layer to your project"></i>
bitbake/lib/toaster/toastergui/templates/toastertable.html +0 -1
index 9ef4c6f..98a715f 100644
@@ -12,7 +12,6 @@
       tableName : "{{table_name}}",
       url : "{{ xhr_table_url }}?format=json",
       title : "{{title}}",
-      projectLayers : {{projectlayers|json}},
     };
 
     try {
Signature · 1 line
2.1.4
#5 lore raw

PATCH 5/5 toaster: Update JS unit tests

In reply to Michael Wood

Update JS unit tests.
- Expand the add remove layer check to make sure that the layer is actually added to the project.
- Remove some unused vars
- Make sure that the layers/project ids will always exist at the point of running the test.
- Add the missing typeahead input fields to the dom to fix the failing typeahead test.

---
 .../lib/toaster/toastergui/static/js/tests/test.js | 32 +++++++++++-----------
 .../toastergui/templates/js-unit-tests.html        | 16 ++++++++---
 2 files changed, 28 insertions(+), 20 deletions(-)
bitbake/lib/toaster/toastergui/static/js/tests/test.js +16 -16
index f0df6e4..aac0ba6 100644
@@ -13,8 +13,6 @@ QUnit.test("Layer alert notification", function(assert) {
     "name":"meta-example"
   };
 
-  var correctResponse = "You have added <strong>3</strong> layers to your project: <a id=\"layer-affected-name\" href=\"/toastergui/project/1/layer/22\">meta-example</a> and its dependencies <a href=\"/toastergui/project/1/layer/9\" data-original-title=\"\" title=\"\">meta-example-two</a>, <a href=\"/toastergui/project/1/layer/9\" data-original-title=\"\" title=\"\">meta-example-three</a>";
-
   var layerDepsList = [
     {
     "layerdetailurl":"/toastergui/project/1/layer/9",
@@ -68,9 +66,9 @@ QUnit.test("Show notification", function(assert){
 });
 
 var layer = {
-  "id": 91,
-  "name":  "meta-crystalforest",
-  "layerdetailurl": "/toastergui/project/4/layer/91"
+  "id": 1,
+  "name":  "meta-testing",
+  "layerdetailurl": "/toastergui/project/1/layer/1"
 };
 
 QUnit.test("Add layer", function(assert){
@@ -84,11 +82,19 @@ QUnit.test("Add layer", function(assert){
     }
   }, 200);
 
-  libtoaster.addRmLayer(layer, true, function(deps){
-    assert.equal(deps.length, 1);
-    done();
+  /* Compare the number of layers before and after the add in the project */
+  libtoaster.getProjectInfo(libtoaster.ctx.projectPageUrl, function(prjInfo){
+    var origNumLayers = prjInfo.layers.length;
+
+    libtoaster.addRmLayer(layer, true, function(deps){
+      libtoaster.getProjectInfo(libtoaster.ctx.projectPageUrl,
+        function(prjInfo){
+        assert.ok(prjInfo.layers.length > origNumLayers,
+          "Layer not added to project");
+        done();
+      });
+    });
   });
-
 });
 
 QUnit.test("Rm layer", function(assert){
@@ -156,7 +162,7 @@ QUnit.test("Layer btns init", function(assert){
 });
 
 QUnit.test("Table init", function(assert){
-  assert.throws(tableInit({ url : tableUrl }));
+  assert.throws(tableInit({ url : ctx.tableUrl }));
 });
 
 $(document).ajaxError(function(event, jqxhr, settings, errMsg){
@@ -167,9 +173,3 @@ $(document).ajaxError(function(event, jqxhr, settings, errMsg){
     assert.notOk(jqxhr.responseText);
   });
 });
-
-
-
-
-
-
bitbake/lib/toaster/toastergui/templates/js-unit-tests.html +12 -4
index 5b8fd84..8d65f33 100644
@@ -22,9 +22,11 @@
 <script src="{% static 'js/table.js' %}"></script>
 
 <script>
-  var tableUrl = '{% url 'projectlayers' project.pk %}';
+  var ctx = {
+    tableUrl : '{% url 'projectlayers' project.pk %}',
+    projectId : {{project.pk}},
+  }
 </script>
-
 <script src="{% static 'js/tests/test.js' %}"></script>
 
 <div id="qunit"></div>
@@ -34,6 +36,12 @@
 <input type="text" id="projects" placeholder="projects"></input>
 <input type="text" id="machines" placeholder="machines"></input>
 
-{% endblock %}
-
+<!-- import layer dependency input typeahead -->
+<input type="text" id="layer-dependency" style="display:none"></input>
+<!-- project page input typeaheads -->
+<input type="text" id="layer-add-input" style="display:none"></input>
+<input type="text" id="machine-change-input" style="display:none"></input>
+<!-- import layer dependency input typeahead on layer details edit layer -->
+<input type="text" id="layer-dep-input" style="display:none"></input>
 
+{% endblock %}
Signature · 1 line
2.1.4
#6 lore raw
In reply to Michael Wood
Quoted 9 lines · Michael Wood

A number of UI fixes:
Add/Rm layer button not updated in some cases [YOCTO #8294] Updates to the JS unit tests
A fix for the project layers returned
And a bug noticed in the layer details page where the button class names were
incorrect meaning the toggle of the add/remove layer didn't enable/disable the buttons to trigger recipe builds.

I'll review this morning.

Elliot

Quoted 31 lines

Michael Wood (5):
toaster: layerdetails update build recipe button class name
toaster: Fix typo in returning pk list of layer versions in current
project
toaster: tables Add the recipe filter back into the Recipe table
toaster: Fix stale layer state buttons
toaster: Update JS unit tests

 bitbake/lib/toaster/orm/models.py                  |  2 +-
 .../lib/toaster/toastergui/static/js/layerBtn.js   |  9 +-----
 .../toaster/toastergui/static/js/layerdetails.js   |  4 +--
 bitbake/lib/toaster/toastergui/static/js/table.js  |  2 +-
 .../lib/toaster/toastergui/static/js/tests/test.js | 34
+++++++++++-----------
 bitbake/lib/toaster/toastergui/tables.py           | 20 +++++++++++--
 .../toastergui/templates/js-unit-tests.html        | 16 +++++++---
 .../toaster/toastergui/templates/layer_btn.html    | 12 ++++++--
 .../toaster/toastergui/templates/recipe_btn.html   | 12 ++++++--
 .../toaster/toastergui/templates/toastertable.html |  1 -
 10 files changed, 71 insertions(+), 41 deletions(-)

--
2.1.4

--
_______________________________________________
toaster mailing list
[email protected]
https://lists.yoctoproject.org/listinfo/toaster

Signature · 3 lines
Elliot Smith
Software Engineer
Intel Open Source Technology Centre
#7 lore raw
Quoted 12 lines · Elliot
Quoted 9 lines · Michael Wood

A number of UI fixes:
Add/Rm layer button not updated in some cases [YOCTO #8294] Updates to the JS unit tests
A fix for the project layers returned
And a bug noticed in the layer details page where the button class names were
incorrect meaning the toggle of the add/remove layer didn't enable/disable the buttons to trigger recipe builds.

Quoted 2 lines

I'll review this morning.

Reviewed and submitted upstream to bitbake-devel.

Elliot

Signature · 3 lines
Elliot Smith
Software Engineer
Intel Open Source Technology Centre