From ed26a06a07a75c8039f2a9b251b350331c7474aa Mon Sep 17 00:00:00 2001 From: Michael Wood Date: Fri, 10 Apr 2015 18:15:03 +0100 Subject: bitbake: toaster: Move project context variables to common scope We have a bunch of context data which are used in multiple pages so it makes more sense to have this in a single place libtoaster.ctx that's accessible from each page rather than request it from every page. (Bitbake rev: 4ef2774a2f683929c700550a9acc7b8f6074195b) Signed-off-by: Michael Wood Signed-off-by: Richard Purdie --- bitbake/lib/toaster/toastergui/static/js/base.js | 39 ++++++++++++---------- .../toaster/toastergui/static/js/importlayer.js | 12 +++---- .../toaster/toastergui/static/js/layerdetails.js | 23 ++++++------- .../lib/toaster/toastergui/static/js/libtoaster.js | 16 ++++----- .../lib/toaster/toastergui/static/js/machines.js | 12 +++---- bitbake/lib/toaster/toastergui/templates/base.html | 17 +++++++--- .../toaster/toastergui/templates/importlayer.html | 4 --- .../toaster/toastergui/templates/layerdetails.html | 5 --- .../toastergui/templates/layers_dep_modal.html | 2 +- .../lib/toaster/toastergui/templates/machines.html | 5 --- 10 files changed, 63 insertions(+), 72 deletions(-) diff --git a/bitbake/lib/toaster/toastergui/static/js/base.js b/bitbake/lib/toaster/toastergui/static/js/base.js index 667c5dff6c..c4c96c80e6 100644 --- a/bitbake/lib/toaster/toastergui/static/js/base.js +++ b/bitbake/lib/toaster/toastergui/static/js/base.js @@ -6,7 +6,7 @@ function basePageInit (ctx) { /* Hide the button if we're on the project,newproject or importlyaer page * or if there are no projects yet defined */ - if (ctx.numProjects === 0 || ctx.currentUrl.search('newproject|project/\\d/$|importlayer/$') > 0){ + if (ctx.numProjects == 0 || ctx.currentUrl.search('newproject|project/\\d/$|importlayer/$') > 0){ newBuildButton.hide(); return; } @@ -18,17 +18,18 @@ function basePageInit (ctx) { newBuildButton.show().removeAttr("disabled"); - _checkProjectBuildable(); + _checkProjectBuildable() _setupNewBuildButton(); + var currentProjectId = libtoaster.ctx.projectId; function _checkProjectBuildable(){ - if (ctx.projectId === undefined) + if (currentProjectId == undefined) return; - libtoaster.getProjectInfo(ctx.projectInfoUrl, ctx.projectId, + libtoaster.getProjectInfo(ctx.projectInfoUrl, currentProjectId, function(data){ - if (data.machine.name === undefined || data.layers.length === 0) { + if (data.machine.name == undefined || data.layers.length == 0) { /* we can't build anything with out a machine and some layers */ $("#new-build-button #targets-form").hide(); $("#new-build-button .alert").show(); @@ -51,18 +52,18 @@ function basePageInit (ctx) { /* If we don't have a current project then present the set project * form. */ - if (ctx.projectId === undefined) { + if (currentProjectId == undefined) { $('#change-project-form').show(); $('#project .icon-pencil').hide(); } - libtoaster.makeTypeahead(newBuildTargetInput, ctx.xhrDataTypeaheadUrl, { type : "targets", project_id: ctx.projectId }, function(item){ + libtoaster.makeTypeahead(newBuildTargetInput, { type : "targets", project_id: currentProjectId }, function(item){ /* successfully selected a target */ selectedTarget = item; }); - libtoaster.makeTypeahead(newBuildProjectInput, ctx.xhrDataTypeaheadUrl, { type : "projects" }, function(item){ + libtoaster.makeTypeahead(newBuildProjectInput, { type : "projects" }, function(item){ /* successfully selected a project */ newBuildProjectSaveBtn.removeAttr("disabled"); selectedProject = item; @@ -72,13 +73,13 @@ function basePageInit (ctx) { * the value that has been set by selecting a suggestion from the typeahead */ newBuildProjectInput.on('input', function(event) { - if (event.keyCode === 13) + if (event.keyCode == 13) return; newBuildProjectSaveBtn.attr("disabled", "disabled"); }); newBuildTargetInput.on('input', function() { - if ($(this).val().length === 0) + if ($(this).val().length == 0) newBuildTargetBuildBtn.attr("disabled", "disabled"); else newBuildTargetBuildBtn.removeAttr("disabled"); @@ -88,21 +89,22 @@ function basePageInit (ctx) { if (!newBuildTargetInput.val()) return; - var selectedTargetName = newBuildTargetInput.val(); + if (!selectedTarget) + selectedTarget = { name: newBuildTargetInput.val() }; /* fire and forget */ - libtoaster.startABuild(ctx.projectBuildUrl, ctx.projectId, selectedTargetName, null, null); - window.location.replace(ctx.projectPageUrl+ctx.projectId); + libtoaster.startABuild(ctx.projectBuildUrl, currentProjectId, selectedTarget.name, null, null); + window.location.replace(ctx.projectBasePageUrl+currentProjectId); }); newBuildProjectSaveBtn.click(function() { - ctx.projectId = selectedProject.id; + currentProjectId = selectedProject.id /* Update the typeahead project_id paramater */ _checkProjectBuildable(); - newBuildTargetInput.data('typeahead').options.xhrParams.project_id = ctx.projectId; + newBuildTargetInput.data('typeahead').options.xhrParams.project_id = currentProjectId; newBuildTargetInput.val(""); - $("#new-build-button #project a").text(selectedProject.name).attr('href', ctx.projectPageUrl+ctx.projectId); - $("#new-build-button .alert a").attr('href', ctx.projectPageUrl+ctx.projectId); + $("#new-build-button #project a").text(selectedProject.name).attr('href', ctx.projectBasePageUrl+currentProjectId); + $("#new-build-button .alert a").attr('href', ctx.projectBasePageUrl+currentProjectId); $("#change-project-form").slideUp({ 'complete' : function() { @@ -130,5 +132,6 @@ function basePageInit (ctx) { $(".new-build").click (function(event) { event.stopPropagation(); }); - } + }; + } diff --git a/bitbake/lib/toaster/toastergui/static/js/importlayer.js b/bitbake/lib/toaster/toastergui/static/js/importlayer.js index d14a8abcaf..ec1cc19e90 100644 --- a/bitbake/lib/toaster/toastergui/static/js/importlayer.js +++ b/bitbake/lib/toaster/toastergui/static/js/importlayer.js @@ -18,7 +18,7 @@ function importLayerPageInit (ctx) { $("#new-project-button").hide(); - libtoaster.makeTypeahead(layerDepInput, ctx.xhrDataTypeaheadUrl, { type : "layers", project_id: ctx.projectId, include_added: "true" }, function(item){ + libtoaster.makeTypeahead(layerDepInput, { type : "layers", project_id: libtoaster.ctx.projectId, include_added: "true" }, function(item){ currentLayerDepSelection = item; layerDepBtn.removeAttr("disabled"); @@ -28,7 +28,7 @@ function importLayerPageInit (ctx) { /* We automatically add "openembedded-core" layer for convenience as a * dependency as pretty much all layers depend on this one */ - $.getJSON(ctx.xhrDataTypeaheadUrl, { type : "layers", project_id: ctx.projectId, include_added: "true" , value: "openembedded-core" }, function(layer) { + $.getJSON(libtoaster.ctx.xhrDataTypeaheadUrl, { type : "layers", project_id: libtoaster.ctx.projectId, include_added: "true" , value: "openembedded-core" }, function(layer) { if (layer.list.length == 1) { currentLayerDepSelection = layer.list[0]; layerDepBtn.click(); @@ -63,7 +63,7 @@ function importLayerPageInit (ctx) { $("#layer-deps-list").append(newLayerDep); - libtoaster.getLayerDepsForProject(ctx.xhrDataTypeaheadUrl, ctx.projectId, currentLayerDepSelection.id, function (data){ + libtoaster.getLayerDepsForProject(libtoaster.ctx.projectId, currentLayerDepSelection.id, function (data){ /* These are the dependencies of the layer added as a dependency */ if (data.list.length > 0) { currentLayerDepSelection.url = ctx.layerDetailsUrl+currentLayerDepSelection.id; @@ -137,7 +137,7 @@ function importLayerPageInit (ctx) { vcs_url: vcsURLInput.val(), git_ref: gitRefInput.val(), dir_path: $("#layer-subdir").val(), - project_id: ctx.projectId, + project_id: libtoaster.ctx.projectId, layer_deps: layerDepsCsv, }; @@ -152,7 +152,7 @@ function importLayerPageInit (ctx) { } else { /* Success layer import now go to the project page */ $.cookie('layer-imported-alert', JSON.stringify(data), { path: '/'}); - window.location.replace(ctx.projectPageUrl+'#/layerimported'); + window.location.replace(libtoaster.ctx.projectPageUrl+'#/layerimported'); } }, error: function (data) { @@ -211,7 +211,7 @@ function importLayerPageInit (ctx) { var name = $(this).val(); /* Check if the layer name exists */ - $.getJSON(ctx.xhrDataTypeaheadUrl, { type : "layers", project_id: ctx.projectId, include_added: "true" , value: name }, function(layer) { + $.getJSON(libtoaster.ctx.xhrDataTypeaheadUrl, { type : "layers", project_id: libtoaster.ctx.projectId, include_added: "true" , value: name }, function(layer) { if (layer.list.length > 0) { for (var i in layer.list){ if (layer.list[i].name == name) { diff --git a/bitbake/lib/toaster/toastergui/static/js/layerdetails.js b/bitbake/lib/toaster/toastergui/static/js/layerdetails.js index bac60c4512..3b6423f7f4 100644 --- a/bitbake/lib/toaster/toastergui/static/js/layerdetails.js +++ b/bitbake/lib/toaster/toastergui/static/js/layerdetails.js @@ -9,7 +9,7 @@ function layerDetailsPageInit (ctx) { var addRmLayerBtn = $("#add-remove-layer-btn"); /* setup the dependencies typeahead */ - libtoaster.makeTypeahead(layerDepInput, ctx.xhrDataTypeaheadUrl, { type : "layers", project_id: ctx.projectId, include_added: "true" }, function(item){ + libtoaster.makeTypeahead(layerDepInput, { type : "layers", project_id: libtoaster.ctx.projectId, include_added: "true" }, function(item){ currentLayerDepSelection = item; layerDepBtn.removeAttr("disabled"); @@ -125,15 +125,14 @@ function layerDetailsPageInit (ctx) { $(".build-target-btn").click(function(){ /* fire a build */ var target = $(this).data('target-name'); - libtoaster.startABuild(ctx.projectBuildUrl, ctx.projectId, target, null, null); - window.location.replace(ctx.projectPageUrl); + libtoaster.startABuild(ctx.projectBuildUrl, libtoaster.ctx.projectId, target, null, null); + window.location.replace(libtoaster.ctx.projectPageUrl); }); $(".select-machine-btn").click(function(){ var data = { machineName : $(this).data('machine-name') }; - libtoaster.editProject(ctx.xhrEditProjectUrl, ctx.projectId, data, - function (){ - window.location.replace(ctx.projectPageUrl+"#/machineselected"); + libtoaster.editCurrentProject(data, function (){ + window.location.replace(libtoaster.ctx.projectPageUrl+"#/machineselected"); }, null); }); @@ -256,8 +255,8 @@ function layerDetailsPageInit (ctx) { } alertMsg.children("#layer-affected-name").text(ctx.layerVersion.name); - alertMsg.children("#project-affected-name").text(ctx.projectName); - alertMsg.children("#project-affected-name").attr("href", ctx.projectPageUrl); + alertMsg.children("#project-affected-name").text(libtoaster.ctx.projectName); + alertMsg.children("#project-affected-name").attr("href", libtoaster.ctx.projectPageUrl); $("#alert-area").show(); } @@ -269,12 +268,11 @@ function layerDetailsPageInit (ctx) { if (directive == 'add') { /* If adding get the deps for this layer */ - libtoaster.getLayerDepsForProject(ctx.xhrDataTypeaheadUrl, ctx.projectId, ctx.layerVersion.id, function (data) { + libtoaster.getLayerDepsForProject(libtoaster.ctx.projectId, ctx.layerVersion.id, function (data) { /* got result for dependencies */ if (data.list.length == 0){ var editData = { layerAdd : ctx.layerVersion.id }; - libtoaster.editProject(ctx.xhrEditProjectUrl, ctx.projectId, editData, - function() { + libtoaster.editCurrentProject(editData, function() { setLayerInCurrentPrj(true); }); return; @@ -291,8 +289,7 @@ function layerDetailsPageInit (ctx) { } else if (directive == 'remove') { var editData = { layerDel : ctx.layerVersion.id }; - libtoaster.editProject(ctx.xhrEditProjectUrl, ctx.projectId, editData, - function () { + libtoaster.editCurrentProject(editData, function () { /* Success removed layer */ //window.location.reload(); setLayerInCurrentPrj(false); diff --git a/bitbake/lib/toaster/toastergui/static/js/libtoaster.js b/bitbake/lib/toaster/toastergui/static/js/libtoaster.js index ae9e4556a1..9257f735db 100644 --- a/bitbake/lib/toaster/toastergui/static/js/libtoaster.js +++ b/bitbake/lib/toaster/toastergui/static/js/libtoaster.js @@ -14,12 +14,12 @@ var libtoaster = (function (){ * selectedCB: function to call once an item has been selected one * arg of the item. */ - function _makeTypeahead (jQElement, xhrUrl, xhrParams, selectedCB) { + function _makeTypeahead (jQElement, xhrParams, selectedCB) { jQElement.typeahead({ source: function(query, process){ xhrParams.value = query; - $.getJSON(xhrUrl, this.options.xhrParams, function(data){ + $.getJSON(libtoaster.ctx.xhrDataTypeaheadUrl, this.options.xhrParams, function(data){ if (data.error !== "ok") { console.log("Error getting data from server "+data.error); return; @@ -41,7 +41,7 @@ var libtoaster = (function (){ return $('').text(item.name).get(0); }, sorter: function (items) { return items; }, - xhrUrl: xhrUrl, + xhrUrl: libtoaster.ctx.xhrDataTypeaheadUrl, xhrParams: xhrParams, }); @@ -147,10 +147,10 @@ var libtoaster = (function (){ * projectVersion * machineName */ - function _editProject(url, projectId, data, onSuccess, onFail){ + function _editCurrentProject(data, onSuccess, onFail){ $.ajax({ type: "POST", - url: url, + url: libtoaster.ctx.xhrProjectEditUrl, data: data, headers: { 'X-CSRFToken' : $.cookie('csrftoken')}, success: function (data) { @@ -170,9 +170,9 @@ var libtoaster = (function (){ }); } - function _getLayerDepsForProject(xhrDataTypeaheadUrl, projectId, layerId, onSuccess, onFail){ + function _getLayerDepsForProject(projectId, layerId, onSuccess, onFail){ /* Check for dependencies not in the current project */ - $.getJSON(xhrDataTypeaheadUrl, + $.getJSON(libtoaster.ctx.xhrDataTypeaheadUrl, { type: 'layerdeps', 'value': layerId , project_id: projectId }, function(data) { if (data.error != "ok") { @@ -227,7 +227,7 @@ var libtoaster = (function (){ makeTypeahead : _makeTypeahead, getProjectInfo: _getProjectInfo, getLayerDepsForProject : _getLayerDepsForProject, - editProject : _editProject, + editCurrentProject : _editCurrentProject, debug: false, parseUrlParams : _parseUrlParams, dumpsUrlParams : _dumpsUrlParams, diff --git a/bitbake/lib/toaster/toastergui/static/js/machines.js b/bitbake/lib/toaster/toastergui/static/js/machines.js index 973a037be7..fbcafc26b5 100644 --- a/bitbake/lib/toaster/toastergui/static/js/machines.js +++ b/bitbake/lib/toaster/toastergui/static/js/machines.js @@ -45,7 +45,7 @@ function machinesPageInit (ctx) { var layerName = addLayerBtn.data('layer-name'); alertMsg.children("#layer-affected-name").text(layerName); - alertMsg.children("#project-affected-name").text(ctx.projectName).attr('href', ctx.projectPageUrl); + alertMsg.children("#project-affected-name").text(libtoaster.ctx.projectName).attr('href', libtoaster.ctx.projectPageUrl); $("#alert-area").show(); } @@ -61,12 +61,11 @@ function machinesPageInit (ctx) { name : $(this).data('layer-name'), }; - libtoaster.getLayerDepsForProject(ctx.xhrDataTypeaheadUrl, ctx.projectId, layer.id, function (data) { + libtoaster.getLayerDepsForProject(libtoaster.ctx.projectId, layer.id, function (data) { /* got result for dependencies */ if (data.list.length == 0){ var editData = { layerAdd : layer.id }; - libtoaster.editProject(ctx.xhrEditProjectUrl, ctx.projectId, editData, - function() { + libtoaster.editCurrentProject(editData, function() { setLayerInCurrentPrj(btn); }); return; @@ -84,9 +83,8 @@ function machinesPageInit (ctx) { $(".select-machine-btn").click(function(){ var data = { machineName : $(this).data('machine-name') }; - libtoaster.editProject(ctx.xhrEditProjectUrl, ctx.projectId, data, - function (){ - window.location.replace(ctx.projectPageUrl+"#/machineselected"); + libtoaster.editCurrentProject(data, function (){ + window.location.replace(libtoaster.ctx.projectPageUrl+"#/machineselected"); }, null); }); diff --git a/bitbake/lib/toaster/toastergui/templates/base.html b/bitbake/lib/toaster/toastergui/templates/base.html index 58392b36f5..25933a1e90 100644 --- a/bitbake/lib/toaster/toastergui/templates/base.html +++ b/bitbake/lib/toaster/toastergui/templates/base.html @@ -26,20 +26,27 @@ libtoaster.debug = true; {% endif %} + {%if MANAGED %}