summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Wood <michael.g.wood@intel.com>2016-04-06 17:46:32 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-04-06 23:00:10 +0100
commit61a21d96abab113cbd13376cdb8b08a426b50538 (patch)
tree51d2e802f699f2c2ccc713dffc00ead929546325
parent0d76084f5d896e4199e1446e2d6d43190a4fcc3a (diff)
downloadopenembedded-core-contrib-61a21d96abab113cbd13376cdb8b08a426b50538.tar.gz
toaster: libtoaster Update implementation of startABuild and cancelABuild
Update the implementation of startABuild and cancelAbuild to reflect changes to the backend api. We now have a dedicated endpoint to make calls into so add this url to libtoaster.ctx and allow passing null in as a url value to indicate that we want to use the current project Also: - Fix some documentation comments - Add the convenience of passing in an array of targets to startABuild Signed-off-by: Michael Wood <michael.g.wood@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--lib/toaster/toastergui/static/js/customrecipe.js4
-rw-r--r--lib/toaster/toastergui/static/js/layerBtn.js3
-rw-r--r--lib/toaster/toastergui/static/js/libtoaster.js41
-rw-r--r--lib/toaster/toastergui/static/js/projectpage.js4
-rw-r--r--lib/toaster/toastergui/static/js/projecttopbar.js6
-rw-r--r--lib/toaster/toastergui/static/js/recipedetails.js4
-rw-r--r--lib/toaster/toastergui/templates/base.html1
7 files changed, 34 insertions, 29 deletions
diff --git a/lib/toaster/toastergui/static/js/customrecipe.js b/lib/toaster/toastergui/static/js/customrecipe.js
index f1b8afbf2f..a31c26834e 100644
--- a/lib/toaster/toastergui/static/js/customrecipe.js
+++ b/lib/toaster/toastergui/static/js/customrecipe.js
@@ -267,9 +267,7 @@ function customRecipePageInit(ctx) {
/* Trigger a build of your custom image */
$(".build-custom-image").click(function(){
- libtoaster.startABuild(libtoaster.ctx.projectBuildsUrl,
- libtoaster.ctx.projectId,
- ctx.recipe.name,
+ libtoaster.startABuild(null, ctx.recipe.name,
function(){
window.location.replace(libtoaster.ctx.projectBuildsUrl);
});
diff --git a/lib/toaster/toastergui/static/js/layerBtn.js b/lib/toaster/toastergui/static/js/layerBtn.js
index b2666ab92c..aa43284396 100644
--- a/lib/toaster/toastergui/static/js/layerBtn.js
+++ b/lib/toaster/toastergui/static/js/layerBtn.js
@@ -60,8 +60,7 @@ function layerBtnsInit() {
e.preventDefault();
var recipe = $(this).data('recipe-name');
- libtoaster.startABuild(libtoaster.ctx.projectBuildsUrl,
- libtoaster.ctx.projectId, recipe,
+ libtoaster.startABuild(null, recipe,
function(){
/* Success */
window.location.replace(libtoaster.ctx.projectBuildsUrl);
diff --git a/lib/toaster/toastergui/static/js/libtoaster.js b/lib/toaster/toastergui/static/js/libtoaster.js
index b6b49b6b4d..8d1d20f133 100644
--- a/lib/toaster/toastergui/static/js/libtoaster.js
+++ b/lib/toaster/toastergui/static/js/libtoaster.js
@@ -90,27 +90,35 @@ var libtoaster = (function (){
jQElement.data('typeahead').render = customRenderFunc;
}
- /*
- * url - the url of the xhr build */
- function _startABuild (url, project_id, targets, onsuccess, onfail) {
+ /* startABuild:
+ * url: xhr_buildrequest or null for current project
+ * targets: an array or space separated list of targets to build
+ * onsuccess: callback for successful execution
+ * onfail: callback for failed execution
+ */
+ function _startABuild (url, targets, onsuccess, onfail) {
- var data = {
- project_id : project_id,
- targets : targets,
+ if (!url)
+ url = libtoaster.ctx.xhrBuildRequestUrl;
+
+ /* Flatten the array of targets into a space spearated list */
+ if (targets instanceof Array){
+ targets = targets.reduce(function(prevV, nextV){
+ return prev + ' ' + next;
+ });
}
$.ajax( {
type: "POST",
url: url,
- data: data,
+ data: { 'targets' : targets },
headers: { 'X-CSRFToken' : $.cookie('csrftoken')},
success: function (_data) {
- /* No proper reponse YOCTO #7995
if (_data.error !== "ok") {
console.warn(_data.error);
- } else { */
+ } else {
if (onsuccess !== undefined) onsuccess(_data);
- // }
+ }
},
error: function (_data) {
console.warn("Call failed");
@@ -120,22 +128,25 @@ var libtoaster = (function (){
}
/* cancelABuild:
- * url: projectbuilds
- * builds_ids: space separated list of build request ids
+ * url: xhr_buildrequest url or null for current project
+ * buildRequestIds: space separated list of build request ids
* onsuccess: callback for successful execution
* onfail: callback for failed execution
*/
- function _cancelABuild(url, build_ids, onsuccess, onfail){
+ function _cancelABuild(url, buildRequestIds, onsuccess, onfail){
+ if (!url)
+ url = libtoaster.ctx.xhrBuildRequestUrl;
+
$.ajax( {
type: "POST",
url: url,
- data: { 'buildCancel': build_ids },
+ data: { 'buildCancel': buildRequestIds },
headers: { 'X-CSRFToken' : $.cookie('csrftoken')},
success: function (_data) {
if (_data.error !== "ok") {
console.warn(_data.error);
} else {
- if (onsuccess !== undefined) onsuccess(_data);
+ if (onsuccess) onsuccess(_data);
}
},
error: function (_data) {
diff --git a/lib/toaster/toastergui/static/js/projectpage.js b/lib/toaster/toastergui/static/js/projectpage.js
index 6655a189a1..3013416dd1 100644
--- a/lib/toaster/toastergui/static/js/projectpage.js
+++ b/lib/toaster/toastergui/static/js/projectpage.js
@@ -232,9 +232,7 @@ function projectPageInit(ctx) {
toBuild = toBuild.trim();
- libtoaster.startABuild(libtoaster.ctx.projectBuildsUrl,
- libtoaster.ctx.projectId,
- toBuild,
+ libtoaster.startABuild(null, toBuild,
function(){
/* Build request started */
window.location.replace(libtoaster.ctx.projectBuildsUrl);
diff --git a/lib/toaster/toastergui/static/js/projecttopbar.js b/lib/toaster/toastergui/static/js/projecttopbar.js
index 58a32a056e..b09f974e47 100644
--- a/lib/toaster/toastergui/static/js/projecttopbar.js
+++ b/lib/toaster/toastergui/static/js/projecttopbar.js
@@ -82,9 +82,9 @@ function projectTopBarInit(ctx) {
selectedTarget = { name: newBuildTargetInput.val() };
/* Fire off the build */
- libtoaster.startABuild(libtoaster.ctx.projectBuildsUrl,
- null, selectedTarget.name, function(){
- window.location.replace(libtoaster.ctx.projectBuildsUrl);
+ libtoaster.startABuild(null, selectedTarget.name,
+ function(){
+ window.location.replace(libtoaster.ctx.projectBuildsUrl);
}, null);
});
}
diff --git a/lib/toaster/toastergui/static/js/recipedetails.js b/lib/toaster/toastergui/static/js/recipedetails.js
index 2bfd0a4b2c..d5f9eacdce 100644
--- a/lib/toaster/toastergui/static/js/recipedetails.js
+++ b/lib/toaster/toastergui/static/js/recipedetails.js
@@ -42,9 +42,7 @@ function recipeDetailsPageInit(ctx){
/* Trigger a build of your custom image */
$(".build-recipe-btn").click(function(){
- libtoaster.startABuild(libtoaster.ctx.projectBuildsUrl,
- libtoaster.ctx.projectId,
- ctx.recipe.name,
+ libtoaster.startABuild(null, ctx.recipe.name,
function(){
window.location.replace(libtoaster.ctx.projectBuildsUrl);
});
diff --git a/lib/toaster/toastergui/templates/base.html b/lib/toaster/toastergui/templates/base.html
index 121a75c49a..192f9fb556 100644
--- a/lib/toaster/toastergui/templates/base.html
+++ b/lib/toaster/toastergui/templates/base.html
@@ -47,6 +47,7 @@
projectBuildsUrl: {% url 'projectbuilds' project.id as pburl %}{{pburl|json}},
xhrCustomRecipeUrl : "{% url 'xhr_customrecipe' %}",
projectId : {{project.id}},
+ xhrBuildRequestUrl: "{% url 'xhr_buildrequest' project.id %}",
{% else %}
projectId : undefined,
projectPageUrl : undefined,