From ab896df63ba058f535cb303611574f293c7c680b Mon Sep 17 00:00:00 2001 From: Michael Wood Date: Fri, 9 Oct 2015 10:32:42 +0100 Subject: bitbake: toaster: Fix stale layer state buttons 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 rev: 43469c3360566ad4897785f14f8717a9bc8b6078) Signed-off-by: Michael Wood Signed-off-by: Elliot Smith Signed-off-by: Richard Purdie --- 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(-) (limited to 'bitbake/lib/toaster/toastergui') diff --git a/bitbake/lib/toaster/toastergui/static/js/layerBtn.js b/bitbake/lib/toaster/toastergui/static/js/layerBtn.js index da0241c62b..7318b3f50e 100644 --- a/bitbake/lib/toaster/toastergui/static/js/layerBtn.js +++ b/bitbake/lib/toaster/toastergui/static/js/layerBtn.js @@ -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(); - } } diff --git a/bitbake/lib/toaster/toastergui/static/js/table.js b/bitbake/lib/toaster/toastergui/static/js/table.js index bc81e67a6a..40b5022deb 100644 --- a/bitbake/lib/toaster/toastergui/static/js/table.js +++ b/bitbake/lib/toaster/toastergui/static/js/table.js @@ -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({ diff --git a/bitbake/lib/toaster/toastergui/static/js/tests/test.js b/bitbake/lib/toaster/toastergui/static/js/tests/test.js index d610113029..f0df6e4ac1 100644 --- a/bitbake/lib/toaster/toastergui/static/js/tests/test.js +++ b/bitbake/lib/toaster/toastergui/static/js/tests/test.js @@ -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){ diff --git a/bitbake/lib/toaster/toastergui/tables.py b/bitbake/lib/toaster/toastergui/tables.py index 4f24772206..b10445b00f 100644 --- a/bitbake/lib/toaster/toastergui/tables.py +++ b/bitbake/lib/toaster/toastergui/tables.py @@ -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) diff --git a/bitbake/lib/toaster/toastergui/templates/layer_btn.html b/bitbake/lib/toaster/toastergui/templates/layer_btn.html index a2e93934de..314eec7cf2 100644 --- a/bitbake/lib/toaster/toastergui/templates/layer_btn.html +++ b/bitbake/lib/toaster/toastergui/templates/layer_btn.html @@ -1,8 +1,16 @@ - - diff --git a/bitbake/lib/toaster/toastergui/templates/recipe_btn.html b/bitbake/lib/toaster/toastergui/templates/recipe_btn.html index 77c1b235b9..baab06eb52 100644 --- a/bitbake/lib/toaster/toastergui/templates/recipe_btn.html +++ b/bitbake/lib/toaster/toastergui/templates/recipe_btn.html @@ -1,7 +1,15 @@ - -