aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Wood <michael.g.wood@intel.com>2015-04-10 18:15:03 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-05-08 17:42:05 +0100
commited26a06a07a75c8039f2a9b251b350331c7474aa (patch)
treeebb2d88d75b51a856322c0a26ab89570a9954276
parent4b59ba1bbb61fe60f500ad742a6515227b22397d (diff)
downloadopenembedded-core-contrib-ed26a06a07a75c8039f2a9b251b350331c7474aa.tar.gz
openembedded-core-contrib-ed26a06a07a75c8039f2a9b251b350331c7474aa.tar.bz2
openembedded-core-contrib-ed26a06a07a75c8039f2a9b251b350331c7474aa.zip
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 <michael.g.wood@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--bitbake/lib/toaster/toastergui/static/js/base.js39
-rw-r--r--bitbake/lib/toaster/toastergui/static/js/importlayer.js12
-rw-r--r--bitbake/lib/toaster/toastergui/static/js/layerdetails.js23
-rw-r--r--bitbake/lib/toaster/toastergui/static/js/libtoaster.js16
-rw-r--r--bitbake/lib/toaster/toastergui/static/js/machines.js12
-rw-r--r--bitbake/lib/toaster/toastergui/templates/base.html17
-rw-r--r--bitbake/lib/toaster/toastergui/templates/importlayer.html4
-rw-r--r--bitbake/lib/toaster/toastergui/templates/layerdetails.html5
-rw-r--r--bitbake/lib/toaster/toastergui/templates/layers_dep_modal.html2
-rw-r--r--bitbake/lib/toaster/toastergui/templates/machines.html5
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 667c5dff6c7..c4c96c80e6d 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 d14a8abcafa..ec1cc19e900 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 bac60c45120..3b6423f7f41 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 ae9e4556a17..9257f735dbc 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 $('<span></span>').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 973a037be70..fbcafc26b50 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 58392b36f5e..25933a1e90b 100644
--- a/bitbake/lib/toaster/toastergui/templates/base.html
+++ b/bitbake/lib/toaster/toastergui/templates/base.html
@@ -26,20 +26,27 @@
libtoaster.debug = true;
</script>
{% endif %}
+<script>
+ libtoaster.ctx = {
+ projectId : {{project.id|default:'undefined'}},
+ xhrDataTypeaheadUrl : "{% url 'xhr_datatypeahead' %}",
+ {% if project.id %}
+ xhrProjectEditUrl : "{% url 'xhr_projectedit' project.id %}",
+ projectPageUrl : "{% url 'project' project.id %}",
+ projectName : "{{project.name}}",
+ {% endif %}
+ };
+</script>
<script src="{% static 'js/base.js' %}"></script>
{%if MANAGED %}
<script>
$(document).ready(function () {
/* Vars needed for base.js */
var ctx = {};
- ctx.xhrDataTypeaheadUrl = "{% url 'xhr_datatypeahead' %}";
ctx.projectBuildUrl = "{% url 'xhr_build' %}";
- ctx.projectPageUrl = "{% url 'base_project' %}";
+ ctx.projectBasePageUrl = "{% url 'base_project' %}";
ctx.projectInfoUrl = "{% url 'xhr_projectinfo' %}";
ctx.numProjects = {{projects|length}};
- {% if project %}
- ctx.projectId = {{project.id}};
- {% endif %}
ctx.currentUrl = "{{request.path|escapejs}}";
basePageInit(ctx);
diff --git a/bitbake/lib/toaster/toastergui/templates/importlayer.html b/bitbake/lib/toaster/toastergui/templates/importlayer.html
index 5ef8a5786ca..c92b5d8b242 100644
--- a/bitbake/lib/toaster/toastergui/templates/importlayer.html
+++ b/bitbake/lib/toaster/toastergui/templates/importlayer.html
@@ -13,12 +13,8 @@
<script>
$(document).ready(function (){
var ctx = {
- xhrDataTypeaheadUrl : "{% url 'xhr_datatypeahead' %}",
layerDetailsUrl : "{% url 'base_layerdetails' %}",
xhrImportLayerUrl : "{% url 'xhr_importlayer' %}",
- xhrEditProjectUrl : "{% url 'xhr_projectedit' project.id %}",
- projectPageUrl : "{% url 'project' project.id %}",
- projectId : {{project.id}}
};
try {
diff --git a/bitbake/lib/toaster/toastergui/templates/layerdetails.html b/bitbake/lib/toaster/toastergui/templates/layerdetails.html
index 0d3aa15373d..435bf04e42d 100644
--- a/bitbake/lib/toaster/toastergui/templates/layerdetails.html
+++ b/bitbake/lib/toaster/toastergui/templates/layerdetails.html
@@ -18,12 +18,7 @@
var ctx = {
projectBuildUrl : "{% url 'xhr_build' %}",
layerDetailsUrl : "{% url 'base_layerdetails' %}",
- projectPageUrl : "{% url 'project' project.id %}",
- xhrEditProjectUrl : "{% url 'xhr_projectedit' project.id %}",
- xhrDataTypeaheadUrl : "{% url 'xhr_datatypeahead' %}",
xhrUpdateLayerUrl : "{% url 'xhr_updatelayer' %}",
- projectId : {{project.id}},
- projectName : "{{project.name}}",
numTargets : {{total_targets}},
numMachines: {{machines|length}},
layerVersion : {
diff --git a/bitbake/lib/toaster/toastergui/templates/layers_dep_modal.html b/bitbake/lib/toaster/toastergui/templates/layers_dep_modal.html
index 8222027d4f2..ea49af50d8e 100644
--- a/bitbake/lib/toaster/toastergui/templates/layers_dep_modal.html
+++ b/bitbake/lib/toaster/toastergui/templates/layers_dep_modal.html
@@ -18,7 +18,7 @@
</div>
<script>
- /* projectId: current project
+ /*
* layer: Object representing the parent layer { id: .. name: ... url }
* dependencies: array of dependency layer objects { id: .. name: ..}
* title: optional override for title
diff --git a/bitbake/lib/toaster/toastergui/templates/machines.html b/bitbake/lib/toaster/toastergui/templates/machines.html
index 2ac35378e0b..64db0f9ca7a 100644
--- a/bitbake/lib/toaster/toastergui/templates/machines.html
+++ b/bitbake/lib/toaster/toastergui/templates/machines.html
@@ -12,11 +12,6 @@
$(document).ready(function (){
var ctx = {
- projectPageUrl : "{% url 'project' project.id %}",
- projectName : "{{project.name}}",
- xhrEditProjectUrl : "{% url 'xhr_projectedit' project.id %}",
- projectId : {{project.id}},
- xhrDataTypeaheadUrl : "{% url 'xhr_datatypeahead' %}",
};
try {