From 4a2a057130e877eae96d726bc86c6b9f48ed1ca3 Mon Sep 17 00:00:00 2001 From: Alexandru DAMIAN Date: Mon, 8 Jun 2015 18:41:46 +0100 Subject: [PATCH] bitbake: toastergui: remove xhr_projectedit and xhr_projectinfo URLs This patch removes the xhr_projectedit and xhr_projectinfo URLs in favour of REST calls to the Project page. The project page takes now the POST requests to modify project settings. All usages of removed URLs are now changed to point to the project page, using the json format. The interface call specs have not modified. (Bitbake rev: 6ad3078bd2be1a8cda99040acaa9bb81d77f0013) Signed-off-by: Alexandru DAMIAN Signed-off-by: Richard Purdie --- bitbake/lib/toaster/contrib/tts/urllist.py | 3 - .../lib/toaster/toastergui/static/js/base.js | 3 +- .../toastergui/static/js/libtoaster.js | 8 +- .../toastergui/static/js/projectapp.js | 73 ++++++++++-- .../toaster/toastergui/templates/base.html | 3 - .../toaster/toastergui/templates/project.html | 2 +- bitbake/lib/toaster/toastergui/tests.py | 1 - bitbake/lib/toaster/toastergui/urls.py | 2 - bitbake/lib/toaster/toastergui/views.py | 110 +++++++----------- 9 files changed, 108 insertions(+), 97 deletions(-) diff --git a/bitbake/lib/toaster/contrib/tts/urllist.py b/bitbake/lib/toaster/contrib/tts/urllist.py index a7d6d6ec4e9..433ac9fe85d 100644 --- a/bitbake/lib/toaster/contrib/tts/urllist.py +++ b/bitbake/lib/toaster/contrib/tts/urllist.py @@ -40,10 +40,7 @@ URLS = [ 'toastergui/project/1/importlayer', 'toastergui/project/1/targets/', 'toastergui/project/1/machines/', -'toastergui/xhr_build/', 'toastergui/xhr_projectbuild/1/', -'toastergui/xhr_projectinfo/', -'toastergui/xhr_projectedit/1', 'toastergui/xhr_configvaredit/1', 'toastergui/xhr_datatypeahead/1', 'toastergui/xhr_importlayer/', diff --git a/bitbake/lib/toaster/toastergui/static/js/base.js b/bitbake/lib/toaster/toastergui/static/js/base.js index 9424b6c3284..9c8d01ef5a9 100644 --- a/bitbake/lib/toaster/toastergui/static/js/base.js +++ b/bitbake/lib/toaster/toastergui/static/js/base.js @@ -29,7 +29,7 @@ function basePageInit (ctx) { if (libtoaster.ctx.projectId == undefined) return; - libtoaster.getProjectInfo(ctx.projectInfoUrl, libtoaster.ctx.projectId, + libtoaster.getProjectInfo(libtoaster.ctx.projectPageUrl, function(data){ if (data.machine.name == undefined || data.layers.length == 0) { /* we can't build anything with out a machine and some layers */ @@ -102,7 +102,6 @@ function basePageInit (ctx) { /* TBD: do we override even if we already have a context project ?? */ /* TODO: replace global library context with references to the "selected" project */ libtoaster.ctx.projectPageUrl = selectedProject.projectPageUrl; - libtoaster.ctx.xhrProjectEditUrl = selectedProject.xhrProjectEditUrl; libtoaster.ctx.projectName = selectedProject.name; libtoaster.ctx.projectId = selectedProject.id; diff --git a/bitbake/lib/toaster/toastergui/static/js/libtoaster.js b/bitbake/lib/toaster/toastergui/static/js/libtoaster.js index 72fb0a93f53..87910299a5d 100644 --- a/bitbake/lib/toaster/toastergui/static/js/libtoaster.js +++ b/bitbake/lib/toaster/toastergui/static/js/libtoaster.js @@ -120,11 +120,11 @@ var libtoaster = (function (){ } /* Get a project's configuration info */ - function _getProjectInfo(url, projectId, onsuccess, onfail){ + function _getProjectInfo(url, onsuccess, onfail){ $.ajax({ - type: "POST", + type: "GET", + data : { format: "json" }, url: url, - data: { project_id : projectId }, headers: { 'X-CSRFToken' : $.cookie('csrftoken')}, success: function (_data) { if (_data.error !== "ok") { @@ -150,7 +150,7 @@ var libtoaster = (function (){ function _editCurrentProject(data, onSuccess, onFail){ $.ajax({ type: "POST", - url: libtoaster.ctx.xhrProjectEditUrl, + url: libtoaster.ctx.projectPageUrl + "?format=json", data: data, headers: { 'X-CSRFToken' : $.cookie('csrftoken')}, success: function (data) { diff --git a/bitbake/lib/toaster/toastergui/static/js/projectapp.js b/bitbake/lib/toaster/toastergui/static/js/projectapp.js index a3309c76af0..36c942fa298 100644 --- a/bitbake/lib/toaster/toastergui/static/js/projectapp.js +++ b/bitbake/lib/toaster/toastergui/static/js/projectapp.js @@ -156,6 +156,62 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc * Retrieves text suggestions for text-edit drop down autocomplete boxes */ + $scope.getLayersAutocompleteSuggestions = function(currentValue) { + var deffered = $q.defer(); + + $http({method:"GET", url: $scope.urls.layers, params : { search: currentValue, format: "json" }}) + .success(function (_data) { + if (_data.error != "ok") { + console.warn("error on data", _data.error); + deffered.reject(_data.error); + } + deffered.resolve(_data.rows); + }); + + return deffered.promise; + } + + $scope.filterProjectLayerIds = function () { + return $scope.layers.map(function (e) { return e.id; }); + } + + $scope.getMachinesAutocompleteSuggestions = function(currentValue) { + var deffered = $q.defer(); + + $http({method:"GET", url: $scope.urls.machines, params : { search: currentValue, format: "json" }}) + .success(function (_data) { + if (_data.error != "ok") { + console.warn("error on data", _data.error); + deffered.reject(_data.error); + } + deffered.resolve(_data.rows); + }); + + return deffered.promise; + } + + $scope.getRecipesAutocompleteSuggestions = function(currentValue) { + var deffered = $q.defer(); + + $http({method:"GET", url: $scope.urls.targets, params : { search: currentValue, format: "json" }}) + .success(function (_data) { + if (_data.error != "ok") { + console.warn("error on data", _data.error); + deffered.reject(_data.error); + } + deffered.resolve(_data.rows); + }); + return deffered.promise; + } + + $scope.values = function() { + var deffered = $q.defer(); + + deffered.resolve(["mama", "tata"]); + + return deffered.promise; + }; + $scope.getAutocompleteSuggestions = function(type, currentValue) { var deffered = $q.defer(); @@ -421,7 +477,7 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc $scope.onLayerSelect = function (item) { - $scope.layerAddId = item.id; + $scope.layerToAdd = item; }; $scope.machineSelect = function (machineName) { @@ -443,14 +499,9 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc }; - $scope.layerAddById = function (id) { - $scope.layerAddId = id; - $scope.layerAdd(); - }; - $scope.layerAdd = function() { - $http({method:"GET", url: $scope.urls.xhr_datatypeahead, params : { type: "layerdeps", value: $scope.layerAddId }}) + $http({method:"GET", url: $scope.layerToAdd.layerdict.layerdetailurl, params : {}}) .success(function (_data) { if (_data.error != "ok") { console.warn(_data.error); @@ -493,7 +544,7 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc }); modalInstance.result.then(function (selectedArray) { - selectedArray.push($scope.layerAddId); + selectedArray.push($scope.layerToAdd.layerversion.id); console.warn("TRC6: selected", selectedArray); $scope._makeXHRCall({ @@ -512,7 +563,7 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc $scope._makeXHRCall({ method: "POST", url: $scope.urls.xhr_edit, data: { - layerAdd: $scope.layerAddId, + layerAdd: $scope.layerToAdd.layerversion.id, } }).then(function () { $scope.layerAddName = undefined; @@ -768,10 +819,8 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc _cmdExecuteWithParam("/layeradd=", function (layer) { - angular.forEach(layer.split(","), function (l) { - $scope.layerAddId = l; + $scope.layerToAdd = layer; $scope.layerAdd(); - }); }); }; diff --git a/bitbake/lib/toaster/toastergui/templates/base.html b/bitbake/lib/toaster/toastergui/templates/base.html index e10dc116736..5d51bc3c957 100644 --- a/bitbake/lib/toaster/toastergui/templates/base.html +++ b/bitbake/lib/toaster/toastergui/templates/base.html @@ -34,13 +34,11 @@ projectsUrl : "{% url 'all-projects' %}", {% if project.id %} xhrProjectDataTypeaheadUrl : "{% url 'xhr_datatypeahead' project.id %}", - xhrProjectEditUrl : "{% url 'xhr_projectedit' project.id %}", projectPageUrl : "{% url 'project' project.id %}", projectName : "{{project.name}}", projectId : {{project.id}}, {% else %} xhrProjectDataTypeaheadUrl : undefined, - xhrProjectEditUrl : undefined, projectPageUrl : undefined, projectName : undefined, projectId : undefined, @@ -53,7 +51,6 @@ $(document).ready(function () { /* Vars needed for base.js */ var ctx = {}; - ctx.projectInfoUrl = "{% url 'xhr_projectinfo' %}"; ctx.numProjects = {{projects|length}}; ctx.currentUrl = "{{request.path|escapejs}}"; diff --git a/bitbake/lib/toaster/toastergui/templates/project.html b/bitbake/lib/toaster/toastergui/templates/project.html index 933da4f7daa..e5986313048 100644 --- a/bitbake/lib/toaster/toastergui/templates/project.html +++ b/bitbake/lib/toaster/toastergui/templates/project.html @@ -430,7 +430,7 @@ angular.element(document).ready(function() { scope = angular.element("#main").scope(); scope.urls = {}; scope.urls.xhr_build = "{% url 'xhr_projectbuild' project.id %}"; - scope.urls.xhr_edit = "{% url 'xhr_projectedit' project.id %}"; + scope.urls.xhr_edit = "{% url 'project' project.id %}?format=json"; scope.urls.xhr_datatypeahead = "{% url 'xhr_datatypeahead' project.id %}"; scope.urls.layers = "{% url 'all-layers' project.id %}"; scope.urls.targets = "{% url 'all-targets' project.id %}"; diff --git a/bitbake/lib/toaster/toastergui/tests.py b/bitbake/lib/toaster/toastergui/tests.py index 0f100209404..c92c5feeb58 100644 --- a/bitbake/lib/toaster/toastergui/tests.py +++ b/bitbake/lib/toaster/toastergui/tests.py @@ -40,7 +40,6 @@ class AllProjectsViewTestCase(ProvisionedProjectTestCase): self.assertTrue("id" in data["list"][0]) self.assertTrue("xhrProjectDataTypeaheadUrl" in data["list"][0]) self.assertTrue("projectPageUrl" in data["list"][0]) - self.assertTrue("xhrProjectEditUrl" in data["list"][0]) self.assertTrue("projectBuildUrl" in data["list"][0]) class ProvisionedLayersProjectTestCase(ProvisionedProjectTestCase): diff --git a/bitbake/lib/toaster/toastergui/urls.py b/bitbake/lib/toaster/toastergui/urls.py index e10e0bb1596..d527be00176 100644 --- a/bitbake/lib/toaster/toastergui/urls.py +++ b/bitbake/lib/toaster/toastergui/urls.py @@ -122,8 +122,6 @@ urlpatterns = patterns('toastergui.views', name=tables.LayerMachinesTable.__name__.lower()), url(r'^xhr_projectbuild/(?P\d+)$', 'xhr_projectbuild', name='xhr_projectbuild'), - url(r'^xhr_projectinfo/$', 'xhr_projectinfo', name='xhr_projectinfo'), - url(r'^xhr_projectedit/(?P\d+)$', 'xhr_projectedit', name='xhr_projectedit'), url(r'^xhr_configvaredit/(?P\d+)$', 'xhr_configvaredit', name='xhr_configvaredit'), url(r'^xhr_datatypeahead/(?P\d+)$', 'xhr_datatypeahead', name='xhr_datatypeahead'), diff --git a/bitbake/lib/toaster/toastergui/views.py b/bitbake/lib/toaster/toastergui/views.py index 678e356e0d4..91c4fa25436 100755 --- a/bitbake/lib/toaster/toastergui/views.py +++ b/bitbake/lib/toaster/toastergui/views.py @@ -2210,6 +2210,45 @@ if toastermain.settings.MANAGED: except User.DoesNotExist: puser = None + # execute POST requests + if request.method == "POST": + # add layers + if 'layerAdd' in request.POST: + for lc in Layer_Version.objects.filter(pk__in=request.POST['layerAdd'].split(",")): + ProjectLayer.objects.get_or_create(project = prj, layercommit = lc) + + # remove layers + if 'layerDel' in request.POST: + for t in request.POST['layerDel'].strip().split(" "): + pt = ProjectLayer.objects.filter(project = prj, layercommit_id = int(t)).delete() + + if 'projectName' in request.POST: + prj.name = request.POST['projectName'] + prj.save(); + + if 'projectVersion' in request.POST: + prj.release = Release.objects.get(pk = request.POST['projectVersion']) + # we need to change the bitbake version + prj.bitbake_version = prj.release.bitbake_version + prj.save() + # we need to change the layers + for i in prj.projectlayer_set.all(): + # find and add a similarly-named layer on the new branch + try: + lv = prj.compatible_layerversions(layer_name = i.layercommit.layer.name)[0] + ProjectLayer.objects.get_or_create(project = prj, layercommit = lv) + except IndexError: + pass + finally: + # get rid of the old entry + i.delete() + + if 'machineName' in request.POST: + machinevar = prj.projectvariable_set.get(name="MACHINE") + machinevar.value=request.POST['machineName'] + machinevar.save() + + # we use implicit knowledge of the current user's project to filter layer information, e.g. pid = prj.id @@ -2241,10 +2280,12 @@ if toastermain.settings.MANAGED: "branch" : { "name" : x.layercommit.get_vcs_reference(), "layersource" : x.layercommit.up_branch.layer_source.name if x.layercommit.up_branch != None else None}}, prj.projectlayer_set.all().order_by("id")), "targets" : map(lambda x: {"target" : x.target, "task" : x.task, "pk": x.pk}, prj.projecttarget_set.all()), + "variables": map(lambda x: (x.name, x.value), prj.projectvariable_set.all()), "freqtargets": freqtargets[:5], "releases": map(lambda x: {"id": x.pk, "name": x.name, "description":x.description}, Release.objects.all()), "project_html": 1, } + try: context["machine"] = {"name": prj.projectvariable_set.get(name="MACHINE").value} except ProjectVariable.DoesNotExist: @@ -2300,66 +2341,6 @@ if toastermain.settings.MANAGED: except Exception as e: return HttpResponse(jsonfilter({"error":str(e) + "\n" + traceback.format_exc()}), content_type = "application/json") - # This is a wraper for xhr_projectedit which allows for a project id - # which only becomes known client side - def xhr_projectinfo(request): - if request.POST.has_key("project_id") == False: - raise BadParameterException("invalid project id") - - return xhr_projectedit(request, request.POST['project_id']) - - def xhr_projectedit(request, pid): - try: - prj = Project.objects.get(id = pid) - # add layers - if 'layerAdd' in request.POST: - for lc in Layer_Version.objects.filter(pk__in=request.POST['layerAdd'].split(",")): - ProjectLayer.objects.get_or_create(project = prj, layercommit = lc) - - # remove layers - if 'layerDel' in request.POST: - for t in request.POST['layerDel'].strip().split(" "): - pt = ProjectLayer.objects.filter(project = prj, layercommit_id = int(t)).delete() - - if 'projectName' in request.POST: - prj.name = request.POST['projectName'] - prj.save(); - - if 'projectVersion' in request.POST: - prj.release = Release.objects.get(pk = request.POST['projectVersion']) - # we need to change the bitbake version - prj.bitbake_version = prj.release.bitbake_version - prj.save() - # we need to change the layers - for i in prj.projectlayer_set.all(): - # find and add a similarly-named layer on the new branch - try: - lv = prj.compatible_layerversions(layer_name = i.layercommit.layer.name)[0] - ProjectLayer.objects.get_or_create(project = prj, layercommit = lv) - except IndexError: - pass - finally: - # get rid of the old entry - i.delete() - - if 'machineName' in request.POST: - machinevar = prj.projectvariable_set.get(name="MACHINE") - machinevar.value=request.POST['machineName'] - machinevar.save() - - # return all project settings - return HttpResponse(jsonfilter( { - "error": "ok", - "layers" : map(lambda x: {"id": x.layercommit.pk, "orderid" : x.pk, "name" : x.layercommit.layer.name, "giturl" : x.layercommit.layer.vcs_url, "url": x.layercommit.layer.layer_index_url, "layerdetailurl": reverse("layerdetails", args=(prj.id, x.layercommit.pk,)), "branch" : { "name" : x.layercommit.get_vcs_reference(), "layersource" : x.layercommit.up_branch.layer_source.name}}, prj.projectlayer_set.all().select_related("layer").order_by("id")), - "builds" : _project_recent_build_list(prj), - "variables": map(lambda x: (x.name, x.value), prj.projectvariable_set.all()), - "machine": {"name": prj.projectvariable_set.get(name="MACHINE").value}, - "prj": {"name": prj.name, "release": { "id": prj.release.pk, "name": prj.release.name, "desc": prj.release.description}}, - }), content_type = "application/json") - - except Exception as e: - return HttpResponse(jsonfilter({"error":str(e) + "\n" + traceback.format_exc()}), content_type = "application/json") - from django.views.decorators.csrf import csrf_exempt @csrf_exempt @@ -2929,7 +2910,6 @@ if toastermain.settings.MANAGED: p.id = p.pk p.xhrProjectDataTypeaheadUrl = reverse('xhr_datatypeahead', args=(p.id,)) p.projectPageUrl = reverse('project', args=(p.id,)) - p.xhrProjectEditUrl = reverse('xhr_projectedit', args=(p.id,)) p.projectBuildUrl = reverse('xhr_projectbuild', args=(p.id,)) # build view-specific information; this is rendered specifically in the builds page, at the top of the page (i.e. Recent builds) @@ -3233,14 +3213,6 @@ else: def xhr_projectbuild(request, pid): return {} - @_template_renderer('landing_not_managed.html') - def xhr_projectinfo(request): - return {} - - @_template_renderer('landing_not_managed.html') - def xhr_projectedit(request, pid): - return {} - @_template_renderer('landing_not_managed.html') def xhr_datatypeahead(request): return {} -- 2.47.2