Return-Path: Received: by yocto-www.yoctoproject.org (Postfix, from userid 118) id 7D0BEE00C41; Thu, 22 Sep 2016 09:56:18 -0700 (PDT) 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,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-HAM-Report: * -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no * trust * [209.85.220.41 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-pa0-f41.google.com (mail-pa0-f41.google.com [209.85.220.41]) by yocto-www.yoctoproject.org (Postfix) with ESMTP id E6175E00C0F for ; Thu, 22 Sep 2016 09:56:11 -0700 (PDT) Received: by mail-pa0-f41.google.com with SMTP id wk8so30989908pab.1 for ; Thu, 22 Sep 2016 09:56:11 -0700 (PDT) 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=KF3FUVaBQb7ok4LGBfCf0tvQIAp4Dl+i90gRg8NpFMQ=; b=IWVDDYU1w/wzMpKVpBSFXyZUAHnlXi79PAO8uKDEsocvFKI+inraQrVu1I2AeKqU1F u7Fehe7Se60SMqZg5NC5LLIVf8+MzYBZxc3J90mKtVm11cMKG/oAPjzIMj4PnaF2HFFy Ab+rNOIgE4kCVk1rauy7+5SIwKJfu9thOJMYrpN4oQIFsumaLgi4Lv2mVPqmIzunLw6C 1ptUwt5WLXBuHiB5ELvVS7PSIo459z7BBz/otW/f+AdVp21UHICPCWGNDJ4sWfcXp4LF kgT13064bja/82asSjgzrRfzGn4VZb2gpmT3VhzI0ag5S/FbiINgvayGfIfsxvhYmEj2 lp1w== 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=KF3FUVaBQb7ok4LGBfCf0tvQIAp4Dl+i90gRg8NpFMQ=; b=mikuzcidVcV4QzA9I0BYFnmdLj6t2qg2T6e6CDdD/EHmwxiC/k3zLgVeED9EIkUxzJ mG4JsBmpL9sh+0GxL+9MJBN/14dCpRM64sFsv3CABbXkv4vKhtxlyQ+luFH6gZr7gEU3 KRzAWz1HrQqncgvAMA0sx8TKysa1dAG3Uhpsfo+Yu2IssoiZhtZQHDsMVg3VmvD0yLnS ehwHbmNZ1sBFc5BZ3zEiuYep1A2mvVwBwsJUZtHm0/M0vmGmkYU2vu4fmAL3pXAx8bQO E1FxFcsX315fF67E+VlpzUJWuaKKZAyM8e9A9Sy19NtrQgU2S16pZacf69eL3YB8o/p6 KTMQ== X-Gm-Message-State: AE9vXwO1qmPaDOoXLNi+BNVyFx5TUCXvMLeiZa6Ov9SEjyIRxIN5jdohJKStL5pVzHA23Ntb X-Received: by 10.66.11.167 with SMTP id r7mr4959423pab.136.1474563371147; Thu, 22 Sep 2016 09:56:11 -0700 (PDT) Received: from orion.ger.corp.intel.com ([192.55.55.41]) by smtp.gmail.com with ESMTPSA id uj8sm5458889pab.5.2016.09.22.09.56.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 22 Sep 2016 09:56:10 -0700 (PDT) From: Michael Wood To: toaster@yoctoproject.org Date: Thu, 22 Sep 2016 17:55:48 +0100 Message-Id: <1474563354-11878-5-git-send-email-michael.g.wood@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1474563354-11878-1-git-send-email-michael.g.wood@intel.com> References: <1474563354-11878-1-git-send-email-michael.g.wood@intel.com> Subject: [PATCH 04/10] toaster: project page Implement front end feature to delete project 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, 22 Sep 2016 16:56:18 -0000 Add confirm modal and api calls to delete a project from the project dashboard. [YOCTO #6238] Signed-off-by: Michael Wood --- bitbake/lib/toaster/toastergui/api.py | 15 +++++++--- .../toaster/toastergui/static/js/projectpage.js | 30 ++++++++++++++++++- .../toaster/toastergui/static/js/projecttopbar.js | 6 ++-- .../toastergui/templates/baseprojectpage.html | 6 ++++ .../lib/toaster/toastergui/templates/project.html | 35 +++++++++++++--------- .../toastergui/templates/projecttopbar.html | 2 +- 6 files changed, 71 insertions(+), 23 deletions(-) diff --git a/bitbake/lib/toaster/toastergui/api.py b/bitbake/lib/toaster/toastergui/api.py index 5589118..856918b 100644 --- a/bitbake/lib/toaster/toastergui/api.py +++ b/bitbake/lib/toaster/toastergui/api.py @@ -393,7 +393,7 @@ class XhrCustomRecipeId(View): """ Get Custom Image recipe or return an error response""" try: custom_recipe = \ - CustomImageRecipe.objects.get(pk=recipe_id) + CustomImageRecipe.objects.get(pk=recipe_id) return custom_recipe, None except CustomImageRecipe.DoesNotExist: @@ -418,8 +418,12 @@ class XhrCustomRecipeId(View): if error: return error + project = custom_recipe.project + custom_recipe.delete() - return JsonResponse({"error": "ok"}) + return JsonResponse({"error": "ok", + "gotoUrl": reverse("projectcustomimages", + args=(project.pk,))}) class XhrCustomRecipePackages(View): @@ -820,8 +824,11 @@ class XhrProject(View): def delete(self, request, *args, **kwargs): try: - Project.objects.get(kwargs['project_id']).delete() + Project.objects.get(pk=kwargs['project_id']).delete() except Project.DoesNotExist: return error_response("Project %s does not exist" % kwargs['project_id']) - return JsonResponse({"error": "ok"}) + return JsonResponse({ + "error": "ok", + "gotoUrl": reverse("all-projects", args=[]) + }) diff --git a/bitbake/lib/toaster/toastergui/static/js/projectpage.js b/bitbake/lib/toaster/toastergui/static/js/projectpage.js index 3bf3cba..7f19c0d 100644 --- a/bitbake/lib/toaster/toastergui/static/js/projectpage.js +++ b/bitbake/lib/toaster/toastergui/static/js/projectpage.js @@ -45,6 +45,9 @@ function projectPageInit(ctx) { /* Now we're really ready show the page */ $("#project-page").show(); + + /* Set the project name in the delete modal */ + $("#delete-project-modal .project-name").text(prjInfo.name); }); (function notificationRequest(){ @@ -328,7 +331,32 @@ function projectPageInit(ctx) { $("#delete-project-confirmed").click(function(e){ e.preventDefault(); - + libtoaster.disableAjaxLoadingTimer(); + $(this).find('[data-role="submit-state"]').hide(); + $(this).find('[data-role="loading-state"]').show(); + $(this).attr("disabled", "disabled"); + $('#delete-project-modal [data-dismiss="modal"]').hide(); + + $.ajax({ + type: 'DELETE', + url: libtoaster.ctx.xhrProjectUrl, + headers: { 'X-CSRFToken' : $.cookie('csrftoken')}, + success: function (data) { + if (data.error !== "ok") { + console.warn(data.error); + } else { + var msg = $('You have deleted 1 project: '); + + msg.find("#project-deleted").text(libtoaster.ctx.projectName); + libtoaster.setNotification("project-deleted", msg.html()); + + window.location.replace(data.gotoUrl); + } + }, + error: function (data) { + console.warn(data); + } + }); }); } diff --git a/bitbake/lib/toaster/toastergui/static/js/projecttopbar.js b/bitbake/lib/toaster/toastergui/static/js/projecttopbar.js index f0cd18b..92ab2d6 100644 --- a/bitbake/lib/toaster/toastergui/static/js/projecttopbar.js +++ b/bitbake/lib/toaster/toastergui/static/js/projecttopbar.js @@ -4,7 +4,7 @@ function projectTopBarInit(ctx) { var projectNameForm = $("#project-name-change-form"); var projectNameContainer = $("#project-name-container"); - var projectName = $("#project-name"); + var projectName = $(".project-name"); var projectNameFormToggle = $("#project-change-form-toggle"); var projectNameChangeCancel = $("#project-name-change-cancel"); @@ -25,14 +25,14 @@ function projectTopBarInit(ctx) { e.preventDefault(); projectNameForm.hide(); projectNameContainer.fadeIn(); - $("#project-name-change-input").val(projectName.text()); + $("#project-name-change-input").val(projectName.first().text()); }); $("#project-name-change-btn").click(function(){ var newProjectName = $("#project-name-change-input").val(); libtoaster.editCurrentProject({ projectName: newProjectName }, function (){ - projectName.html(newProjectName); + projectName.text(newProjectName); libtoaster.ctx.projectName = newProjectName; projectNameChangeCancel.click(); }); diff --git a/bitbake/lib/toaster/toastergui/templates/baseprojectpage.html b/bitbake/lib/toaster/toastergui/templates/baseprojectpage.html index b3b6f1c..8427d25 100644 --- a/bitbake/lib/toaster/toastergui/templates/baseprojectpage.html +++ b/bitbake/lib/toaster/toastergui/templates/baseprojectpage.html @@ -34,6 +34,12 @@ $(document).ready(function(){
  • Layers
  • BitBake variables
  • + + +
  • + + Delete project +
  • diff --git a/bitbake/lib/toaster/toastergui/templates/project.html b/bitbake/lib/toaster/toastergui/templates/project.html index 30ee93a..7644dad 100644 --- a/bitbake/lib/toaster/toastergui/templates/project.html +++ b/bitbake/lib/toaster/toastergui/templates/project.html @@ -24,30 +24,37 @@ }); -{% comment %} - - +