Return-Path: Received: by yocto-www.yoctoproject.org (Postfix, from userid 118) id 84DEDE00D20; Thu, 25 Feb 2016 10:21:37 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 X-Spam-HAM-Report: * -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% * [score: 0.0000] * -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature * 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily * valid Received: from mail-wm0-f48.google.com (mail-wm0-f48.google.com [74.125.82.48]) by yocto-www.yoctoproject.org (Postfix) with ESMTP id 6A004E00D12 for ; Thu, 25 Feb 2016 10:21:34 -0800 (PST) Received: by mail-wm0-f48.google.com with SMTP id b205so43145872wmb.1 for ; Thu, 25 Feb 2016 10:21:33 -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=B4SMohp9eWjqJUTOrb9Dxd2YqxgdDwuAcL9lNM5OI2U=; b=g2n6HcizQUxmGDcILEIb5TzgfMNpGX24XPn2ChF92g/Jj4kTJaqSrjySTLfi+QNswL bGwOQ4shRrtE1qACuOjCHs5oe4NqVbVIR+QNGexYQpwV6tZtahbpXq5Ncl3Z6hMhyscE TuqMkw79rkjw7rIeEbZAtXbPTut795HqcliZihNQEllNHTBqhCyI04Hnnt3RQ8x46WVz EVCHEKSo5GNWPse5JyJAR4SLhGpNb1Fe5S+be6zVn6mXT+Ce4dL/VGYNtANxjY58+AGv ZEpXU8zhH56Rhs+flhZ4+A0GHGb/FsYNIMy82Vo3/+RUvdEpt/yOHGaz8EC+IuV5fieS rTow== 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=B4SMohp9eWjqJUTOrb9Dxd2YqxgdDwuAcL9lNM5OI2U=; b=jMXk86KXjIH8l2ZV94bl3L9QXYnT9C52gaK0wjkY7X3DWGu4VN6M7zaxctZ59b9QIm QM1vzpMyY6BzFSFmI36YTHIdUeXwzZLsRG47Dk/HgjQSyKAEAxyRweOJNzxB5MZOuEP8 EcT31e1ts+26+GwJHE1QX+i4hEtq0AjhiUCJJIxMleTvW3xlVJ5s9vOo4FBwXbnLQjTG 8xAatg3cMjGXcy6StRjOhZ/9adgpmpBnQNaolm8rWPh7Oz/SgSgW1yA8NWI1n2ZS1zuo SpVgeUr23wZ/W4WShLg+FFtzh6zwnn+mm1LoLl/bITiar+F2wD0N+Prw9gXLuU46aoIE vBOQ== X-Gm-Message-State: AG10YOTfcyip/4hOwSSDtzt6vwSrea2GR9EQEFbvBrM3aOEUlYVP0/jAiS0+iSk+0+h3j241 X-Received: by 10.28.144.195 with SMTP id s186mr46587wmd.9.1456424493429; Thu, 25 Feb 2016 10:21:33 -0800 (PST) Received: from draco.icx.intel.com ([83.217.123.106]) by smtp.gmail.com with ESMTPSA id az8sm3084010wjc.17.2016.02.25.10.21.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 25 Feb 2016 10:21:32 -0800 (PST) From: Michael Wood To: toaster@yoctoproject.org Date: Thu, 25 Feb 2016 18:21:18 +0000 Message-Id: <1456424485-6566-5-git-send-email-michael.g.wood@intel.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1456424485-6566-1-git-send-email-michael.g.wood@intel.com> References: <1456424485-6566-1-git-send-email-michael.g.wood@intel.com> Subject: [PATCH 04/11] 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: Thu, 25 Feb 2016 18:21:37 -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 3c57899..131ac2a 100644 --- a/bitbake/lib/toaster/toastergui/static/js/customrecipe.js +++ b/bitbake/lib/toaster/toastergui/static/js/customrecipe.js @@ -207,9 +207,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 b2666ab..aa43284 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 b6b49b6..8d1d20f 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 292ceb7..78a9506 100644 --- a/bitbake/lib/toaster/toastergui/static/js/projectpage.js +++ b/bitbake/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/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.1.4