From 27f5137cd6143b523e9aea8eeba406337aa935c4 Mon Sep 17 00:00:00 2001 From: Alexandru DAMIAN Date: Mon, 8 Jun 2015 15:22:01 +0100 Subject: bitbake: toastergui: remove xhr_datatypeahaed layerdeps call This patch removes the url-constructing calls to get the layer details in favor of embedding the look-up URL in the JSON data on the layer list page. This allows further removal of the XHR-specific code for layer dependencies in favor of REST calls to layer details data. (Bitbake rev: 33d2b87aca667d72262a3928deaf35414b46a7c1) Signed-off-by: Alexandru DAMIAN Signed-off-by: Richard Purdie --- .../toaster/toastergui/static/js/importlayer.js | 8 +-- .../toaster/toastergui/static/js/layerdetails.js | 2 +- .../lib/toaster/toastergui/static/js/libtoaster.js | 9 ++-- .../lib/toaster/toastergui/static/js/projectapp.js | 61 ++++++++++++++++------ bitbake/lib/toaster/toastergui/tables.py | 23 +++++--- .../toaster/toastergui/templates/importlayer.html | 1 - .../toaster/toastergui/templates/layerdetails.html | 1 - .../lib/toaster/toastergui/templates/project.html | 1 - bitbake/lib/toaster/toastergui/urls.py | 3 -- bitbake/lib/toaster/toastergui/views.py | 11 +--- 10 files changed, 73 insertions(+), 47 deletions(-) (limited to 'bitbake') diff --git a/bitbake/lib/toaster/toastergui/static/js/importlayer.js b/bitbake/lib/toaster/toastergui/static/js/importlayer.js index e1fc5c5187..e9d7ae8ef2 100644 --- a/bitbake/lib/toaster/toastergui/static/js/importlayer.js +++ b/bitbake/lib/toaster/toastergui/static/js/importlayer.js @@ -48,7 +48,7 @@ function importLayerPageInit (ctx) { newLayerDep.children("span").tooltip(); var link = newLayerDep.children("a"); - link.attr("href", ctx.layerDetailsUrl+String(currentLayerDepSelection.id)); + link.attr("href", currentLayerDepSelection.layerDetailsUrl); link.text(currentLayerDepSelection.name); link.tooltip({title: currentLayerDepSelection.tooltip, placement: "right"}); @@ -63,11 +63,11 @@ function importLayerPageInit (ctx) { $("#layer-deps-list").append(newLayerDep); - libtoaster.getLayerDepsForProject(libtoaster.ctx.projectId, currentLayerDepSelection.id, function (data){ + libtoaster.getLayerDepsForProject(currentLayerDepSelection.layerDetailsUrl, function (data){ /* These are the dependencies of the layer added as a dependency */ if (data.list.length > 0) { - currentLayerDepSelection.url = ctx.layerDetailsUrl+currentLayerDepSelection.id; - layerDeps[currentLayerDepSelection.id].deps = data.list + currentLayerDepSelection.url = currentLayerDepSelection.layerDetailsUrl; + layerDeps[currentLayerDepSelection.id].deps = data.list; } /* Clear the current selection */ diff --git a/bitbake/lib/toaster/toastergui/static/js/layerdetails.js b/bitbake/lib/toaster/toastergui/static/js/layerdetails.js index ab781829cd..0accd971d4 100644 --- a/bitbake/lib/toaster/toastergui/static/js/layerdetails.js +++ b/bitbake/lib/toaster/toastergui/static/js/layerdetails.js @@ -65,7 +65,7 @@ function layerDetailsPageInit (ctx) { newLayerDep.children("span").tooltip(); var link = newLayerDep.children("a"); - link.attr("href", ctx.layerDetailsUrl+String(currentLayerDepSelection.id)); + link.attr("href", currentLayerDepSelection.layerDetailsUrl); link.text(currentLayerDepSelection.name); link.tooltip({title: currentLayerDepSelection.tooltip, placement: "right"}); diff --git a/bitbake/lib/toaster/toastergui/static/js/libtoaster.js b/bitbake/lib/toaster/toastergui/static/js/libtoaster.js index 2a9a790693..b1038cf618 100644 --- a/bitbake/lib/toaster/toastergui/static/js/libtoaster.js +++ b/bitbake/lib/toaster/toastergui/static/js/libtoaster.js @@ -170,10 +170,10 @@ var libtoaster = (function (){ }); } - function _getLayerDepsForProject(projectId, layerId, onSuccess, onFail){ + function _getLayerDepsForProject(url, onSuccess, onFail){ /* Check for dependencies not in the current project */ - $.getJSON(libtoaster.ctx.projectLayersUrl, - { format: 'json', search: layerId }, + $.getJSON(url, + { format: 'json' }, function(data) { if (data.error != "ok") { console.log(data.error); @@ -225,8 +225,7 @@ var libtoaster = (function (){ function _addRmLayer(layerObj, add, doneCb){ if (add === true) { /* If adding get the deps for this layer */ - libtoaster.getLayerDepsForProject(libtoaster.ctx.projectId, - layerObj.id, + libtoaster.getLayerDepsForProject(layerObj.url, function (layers) { /* got result for dependencies */ diff --git a/bitbake/lib/toaster/toastergui/static/js/projectapp.js b/bitbake/lib/toaster/toastergui/static/js/projectapp.js index 36c942fa29..a915278444 100644 --- a/bitbake/lib/toaster/toastergui/static/js/projectapp.js +++ b/bitbake/lib/toaster/toastergui/static/js/projectapp.js @@ -16,7 +16,9 @@ // with this program; if not, write to the Free Software Foundation, Inc., // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -angular_formpost = function($httpProvider) { +'use strict'; + +var angular_formpost = function($httpProvider) { // Use x-www-form-urlencoded Content-Type // By Ezekiel Victor, http://victorblog.com/2012/12/20/make-angularjs-http-service-behave-like-jquery-ajax/, no license, with attribution $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8'; @@ -127,10 +129,10 @@ projectApp.filter('timediff', function() { if (parseInt(j) < 10) {return "0" + j;} return j; } - seconds = parseInt(input); - minutes = Math.floor(seconds / 60); + var seconds = parseInt(input); + var minutes = Math.floor(seconds / 60); seconds = seconds - minutes * 60; - hours = Math.floor(seconds / 3600); + var hours = Math.floor(seconds / 3600); seconds = seconds - hours * 3600; return pad(hours) + ":" + pad(minutes) + ":" + pad(seconds); }; @@ -250,6 +252,31 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc } var deffered = $q.defer(); + /* we only talk in JSON to the server */ + if (callparams.method == 'GET') { + if (callparams.data === undefined) { + callparams.data = {}; + } + callparams.data.format = "json"; + } else { + if (callparams.url.indexOf("?") > -1) { + callparams.url = callparams.url.split("?").map(function (element, index) { + if (index == 1) { + var elements = []; + if (element.indexOf("&")>-1) { + elements = element.split("&"); + } + elements.push("format=json"); + element = elements.join("&"); + } + return element; + }).join("?"); + } else { + callparams.url += "?format=json"; + } + } + + if (undefined === callparams.headers) { callparams.headers = {}; } callparams.headers['X-CSRFToken'] = $cookies.csrftoken; @@ -476,8 +503,9 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc }; - $scope.onLayerSelect = function (item) { + $scope.onLayerSelect = function (item, model, label) { $scope.layerToAdd = item; + $scope.layerAddName = item.layer__name; }; $scope.machineSelect = function (machineName) { @@ -501,20 +529,22 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc $scope.layerAdd = function() { - $http({method:"GET", url: $scope.layerToAdd.layerdict.layerdetailurl, params : {}}) + $http({method:"GET", url: $scope.layerToAdd.layerDetailsUrl, params : {format: "json"}}) .success(function (_data) { if (_data.error != "ok") { console.warn(_data.error); } else { - if (_data.list.length > 0) { + console.log("got layer deps", _data.layerdeps.list); + if (_data.layerdeps.list.length > 0) { // activate modal + console.log("listing modals"); var modalInstance = $modal.open({ templateUrl: 'dependencies_modal', controller: function ($scope, $modalInstance, items, layerAddName) { $scope.items = items; $scope.layerAddName = layerAddName; $scope.selectedItems = (function () { - s = {}; + var s = {}; for (var i = 0; i < items.length; i++) { s[items[i].id] = true; } return s; @@ -535,16 +565,18 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc }, resolve: { items: function () { - return _data.list; + return _data.layerdeps.list; }, layerAddName: function () { return $scope.layerAddName; }, } }); + console.log("built modal instance", modalInstance); modalInstance.result.then(function (selectedArray) { - selectedArray.push($scope.layerToAdd.layerversion.id); + console.log("layer to add", $scope.layerToAdd) + selectedArray.push($scope.layerToAdd.id); console.warn("TRC6: selected", selectedArray); $scope._makeXHRCall({ @@ -563,7 +595,7 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc $scope._makeXHRCall({ method: "POST", url: $scope.urls.xhr_edit, data: { - layerAdd: $scope.layerToAdd.layerversion.id, + layerAdd: $scope.layerToAdd.id, } }).then(function () { $scope.layerAddName = undefined; @@ -772,8 +804,7 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc return; if (imported.deps_added.length === 0) { - text = "You have imported "+imported.imported_layer.name+ + text = "You have imported "+imported.imported_layer.name+ " and added it to your project."; } else { var links = ", "; imported.deps_added.map (function(item, index){ - links +=""+item.name+ + links +=""+item.name+ ""; /*If we're at the last element we don't want the trailing comma */ if (imported.deps_added[index+1] !== undefined) @@ -832,7 +863,7 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc if (zone.maxid === undefined) { zone.maxid = 0; } var crtid = zone.maxid ++; angular.forEach(zone, function (o) { o.close(); }); - o = { + var o = { id: crtid, text: text, type: type, close: function() { zone.splice((function(id) { diff --git a/bitbake/lib/toaster/toastergui/tables.py b/bitbake/lib/toaster/toastergui/tables.py index e03aa768c9..003b924d00 100644 --- a/bitbake/lib/toaster/toastergui/tables.py +++ b/bitbake/lib/toaster/toastergui/tables.py @@ -23,6 +23,7 @@ from toastergui.widgets import ToasterTable, ToasterTemplateView from orm.models import Recipe, ProjectLayer, Layer_Version, Machine, Project from django.db.models import Q, Max from django.conf.urls import url +from django.core.urlresolvers import reverse from django.views.generic import TemplateView class LayersTable(ToasterTable): @@ -35,9 +36,9 @@ class LayersTable(ToasterTable): def get_context_data(self, **kwargs): context = super(LayersTable, self).get_context_data(**kwargs) - context['project'] = Project.objects.get(pk=kwargs['pid']) - - context['projectlayers'] = map(lambda prjlayer: prjlayer.layercommit.id, ProjectLayer.objects.filter(project=context['project'])) + 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 @@ -142,6 +143,13 @@ class LayersTable(ToasterTable): static_data_name="add-del-layers", static_data_template='{% include "layer_btn.html" %}') + project = Project.objects.get(pk=kwargs['pid']) + self.add_column(title="LayerDetailsUrl", + displayable = False, + field_name="layerDetailsUrl", + computation = lambda x: reverse('layerdetails', args=(project.id, x.id))) + + class LayerDetails(ToasterTemplateView): @@ -152,7 +160,8 @@ class LayerDetails(ToasterTemplateView): context['project'] = Project.objects.get(pk=kwargs['pid']) context['layerversion'] = Layer_Version.objects.get(pk=kwargs['layerid']) context['layerdict'] = _lv_to_dict(context['project'], context['layerversion']) - context['layerdeps'] = {"list": [x.depends_on.get_equivalents_wpriority(context['project'])[0] for x in context['layerversion'].dependencies.all()]} + context['layerdeps'] = {"list": [ + [{"id": y.id, "name": y.layer.name} for y in x.depends_on.get_equivalents_wpriority(context['project'])][0] for x in context['layerversion'].dependencies.all()]} context['projectlayers'] = map(lambda prjlayer: prjlayer.layercommit.id, ProjectLayer.objects.filter(project=context['project'])) self.context_entries = ['project', 'layerversion', 'projectlayers', 'layerdict', 'layerdeps'] @@ -265,9 +274,10 @@ class RecipesTable(ToasterTable): self.default_orderby = "name" def get_context_data(self, **kwargs): + project = Project.objects.get(pk=kwargs['pid']) context = super(RecipesTable, self).get_context_data(**kwargs) - context['project'] = Project.objects.get(pk=kwargs['pid']) + context['project'] = project context['projectlayers'] = map(lambda prjlayer: prjlayer.layercommit.id, ProjectLayer.objects.filter(project=context['project'])) @@ -342,10 +352,11 @@ class RecipesTable(ToasterTable): static_data_name="add-del-layers", static_data_template='{% include "recipe_btn.html" %}') + project = Project.objects.get(pk=kwargs['pid']) 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])) + computation = lambda x: (x.layer_version.get_equivalents_wpriority(project)[0])) class LayerRecipesTable(RecipesTable): """ Smaller version of the Recipes table for use in layer details """ diff --git a/bitbake/lib/toaster/toastergui/templates/importlayer.html b/bitbake/lib/toaster/toastergui/templates/importlayer.html index af8f4f985a..498a204aff 100644 --- a/bitbake/lib/toaster/toastergui/templates/importlayer.html +++ b/bitbake/lib/toaster/toastergui/templates/importlayer.html @@ -14,7 +14,6 @@