Return-Path: Received: by yocto-www.yoctoproject.org (Postfix, from userid 118) id 37912E00C91; Mon, 22 Feb 2016 03:31:31 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on yocto-www.yoctoproject.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-HAM-Report: * -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low * trust * [209.85.192.170 listed in list.dnswl.org] * -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% * [score: 0.0000] * 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily * valid * -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Received: from mail-pf0-f170.google.com (mail-pf0-f170.google.com [209.85.192.170]) by yocto-www.yoctoproject.org (Postfix) with ESMTP id 87CECE00C3B for ; Mon, 22 Feb 2016 03:31:23 -0800 (PST) Received: by mail-pf0-f170.google.com with SMTP id x65so91516833pfb.1 for ; Mon, 22 Feb 2016 03:31:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+k3sxT5t3oIp/FfY5l2E7oAjA3qD9D1cRpdLEdpjNCM=; b=R6SGGVMMBsULIIFGVUr7X0HxLUPqtlHuM4HARaPQsKjUYLpu3OCmgeXnpBJ8f4tL+l RoUQdRLDOXd+8eKift4liEIJBpO9JrbGXZPKnH4HxaeavD6gi6hdN1rULm6iGHlvxCnL dUmBooP0OvaTo4UXEBUPkPmOilEt3BUh9hOGAsXli2JBiO75K/skCv7Li9JOh6idnc+3 Bwe0s94oC04mOoGeiuAvQmtlwT8TsOYQrFigC5Y/UWvrT0J46UjYT2+EjktFjPX6sCjc qlC7419zpMxvyQcKHfKptrKPc08YgHVM5jsjhKe0lnqbifaj+U3C0XRNnxdnSAMJwrKC ANxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+k3sxT5t3oIp/FfY5l2E7oAjA3qD9D1cRpdLEdpjNCM=; b=Bn+FBzgm5r6xE4R5bXWeCaPO2LRf/0dLWQ2i/jUynDMUZIVaLV4c5mMH3XYnEnPlea aX3lseeXtlV0V/jdtRv4UPWgAgn9ufWjASQbwU0tVjN6o8999rYdllB3kD8jaO/VXyAe 3MCSTx/y11sT6hwU7lmN7B4FhFgdUtd1T8wKFTce7vK7CoGXg+jYbPBHoYf782xP9OW3 7urKeSXaqyNoc4l3nfFBMaZfDSukOcXFgSen7im9AsjLgxBHKKwhtun1RHV6PhYLVT54 W7X5uARtJpKH9xV+RBJ8iRhjOBvJvPDoFSKDiscBTXnmsLYnUIoTjlhBVX/GcoUx8sS2 0T7A== X-Gm-Message-State: AG10YORO4xywaf0lPavg1QtpHVzHDNPBhqIM3M1+QPMsHuMGQ1ZQYOtFnzC5G/s6wDf3tEN4 X-Received: by 10.98.93.211 with SMTP id n80mr37643482pfj.61.1456140682885; Mon, 22 Feb 2016 03:31:22 -0800 (PST) Received: from dorado.ger.corp.intel.com (fmdmzpr01-ext.fm.intel.com. [192.55.54.36]) by smtp.gmail.com with ESMTPSA id n78sm36216801pfb.53.2016.02.22.03.31.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 22 Feb 2016 03:31:22 -0800 (PST) From: Michael Wood To: toaster@yoctoproject.org Date: Mon, 22 Feb 2016 11:31:00 +0000 Message-Id: <1456140666-5344-5-git-send-email-michael.g.wood@intel.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1456140666-5344-1-git-send-email-michael.g.wood@intel.com> References: <1456140666-5344-1-git-send-email-michael.g.wood@intel.com> Subject: [PATCH 04/10] toaster: libtoaster Update implementation of startABuild and cancelABuild X-BeenThere: toaster@yoctoproject.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Web based interface for BitBake List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Feb 2016 11:31:31 -0000 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 --- .../toaster/toastergui/static/js/customrecipe.js | 4 +-- .../lib/toaster/toastergui/static/js/layerBtn.js | 3 +- .../lib/toaster/toastergui/static/js/libtoaster.js | 41 ++++++++++++++-------- .../toaster/toastergui/static/js/projectpage.js | 4 +-- .../toaster/toastergui/static/js/projecttopbar.js | 6 ++-- .../toaster/toastergui/static/js/recipedetails.js | 4 +-- bitbake/lib/toaster/toastergui/templates/base.html | 1 + 7 files changed, 34 insertions(+), 29 deletions(-) diff --git a/bitbake/lib/toaster/toastergui/static/js/customrecipe.js b/bitbake/lib/toaster/toastergui/static/js/customrecipe.js index a1fe486..93f1000 100644 --- a/bitbake/lib/toaster/toastergui/static/js/customrecipe.js +++ b/bitbake/lib/toaster/toastergui/static/js/customrecipe.js @@ -204,9 +204,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/bitbake/lib/toaster/toastergui/static/js/layerBtn.js b/bitbake/lib/toaster/toastergui/static/js/layerBtn.js index 7318b3f..025f9d9 100644 --- a/bitbake/lib/toaster/toastergui/static/js/layerBtn.js +++ b/bitbake/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/bitbake/lib/toaster/toastergui/static/js/libtoaster.js b/bitbake/lib/toaster/toastergui/static/js/libtoaster.js index a3858ec..3b9b72f 100644 --- a/bitbake/lib/toaster/toastergui/static/js/libtoaster.js +++ b/bitbake/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/bitbake/lib/toaster/toastergui/static/js/projectpage.js b/bitbake/lib/toaster/toastergui/static/js/projectpage.js index 4a482d7..413714a 100644 --- a/bitbake/lib/toaster/toastergui/static/js/projectpage.js +++ b/bitbake/lib/toaster/toastergui/static/js/projectpage.js @@ -230,9 +230,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/bitbake/lib/toaster/toastergui/static/js/projecttopbar.js b/bitbake/lib/toaster/toastergui/static/js/projecttopbar.js index 58a32a0..b09f974 100644 --- a/bitbake/lib/toaster/toastergui/static/js/projecttopbar.js +++ b/bitbake/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/bitbake/lib/toaster/toastergui/static/js/recipedetails.js b/bitbake/lib/toaster/toastergui/static/js/recipedetails.js index 2bfd0a4..d5f9eac 100644 --- a/bitbake/lib/toaster/toastergui/static/js/recipedetails.js +++ b/bitbake/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/bitbake/lib/toaster/toastergui/templates/base.html b/bitbake/lib/toaster/toastergui/templates/base.html index 6994bcc..ed15c59 100644 --- a/bitbake/lib/toaster/toastergui/templates/base.html +++ b/bitbake/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, -- 2.5.0