]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
bitbake: toaster: project page Implement front end feature to delete project
authorMichael Wood <michael.g.wood@intel.com>
Mon, 26 Sep 2016 10:59:31 +0000 (13:59 +0300)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Fri, 30 Sep 2016 15:52:22 +0000 (16:52 +0100)
Add confirm modal and api calls to delete a project from the project
dashboard.

[YOCTO #6238]

(Bitbake rev: e1cca28826dfa66d905dd4daf9964564c355207e)

Signed-off-by: Michael Wood <michael.g.wood@intel.com>
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
bitbake/lib/toaster/toastergui/api.py
bitbake/lib/toaster/toastergui/static/js/projectpage.js
bitbake/lib/toaster/toastergui/static/js/projecttopbar.js
bitbake/lib/toaster/toastergui/templates/baseprojectpage.html
bitbake/lib/toaster/toastergui/templates/project.html
bitbake/lib/toaster/toastergui/templates/projecttopbar.html

index 5589118027afcfca381237c47a0906de04fb42e8..856918b6a34eb25dc228eb655b22e5c7c8647ab6 100644 (file)
@@ -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=[])
+        })
index 3bf3cbaf2b37516d09827ab53b5c74f0d6e14464..7f19c0d7aa4d7e07514b782d360d57b00873dd59 100644 (file)
@@ -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 =  $('<span>You have deleted <strong>1</strong> project: <strong id="project-deleted"></strong></span>');
+
+            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);
+        }
+    });
   });
 
 }
index f0cd18bf484ae13554e4788eb1fecd075bb31d4c..92ab2d67fd254971c93a01be363f515bea5b7c3c 100644 (file)
@@ -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();
     });
index b3b6f1caf8fd7d01a602d69357d555cc2072304c..8427d2521085d9b6ad9b0e5b2146b1ac3634f598 100644 (file)
@@ -34,6 +34,12 @@ $(document).ready(function(){
       <li><a href="{% url 'projectlayers' project.id %}">Layers</a></li>
       <li class="nav-header">Extra configuration</li>
       <li><a href="{% url 'projectconf' project.id %}">BitBake variables</a></li>
+
+      <li class="nav-header">Actions</li>
+      <li>
+        <a href="#delete-project-modal" role="button" class="text-danger" data-toggle="modal" data-target="#delete-project-modal">
+          <i class="icon-trash text-danger"></i> Delete project</a>
+      </li>
     </ul>
   </div>
   <div class="col-md-10">
index 30ee93a76fa99e33497cb51505ffabd5e32beca4..7644dad2f33b9bc996470528d424163bd02ae69e 100644 (file)
   });
 </script>
 
-{% comment %}
-<!-- Comment out the ability to change the project release, until we decide what to do this functionality -->
-<div id="change-release-modal" class="modal hide fade in" tabindex="-1" role="dialog" aria-labelledby="change-release-modal" aria-hidden="false">
+<div id="delete-project-modal" class="modal fade" tabindex="-1" role="dialog" data-backdrop="static" data-keyboard="false">
   <div class="modal-dialog">
     <div class="modal-content">
-
       <div class="modal-header">
-       <button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
-       <h3>Changing Yocto Project release to <span class="proposed-release-change-name"></span></h3>
+        <h4>Are you sure you want to delete this project?</h4>
       </div>
       <div class="modal-body">
-       <p>The following added layers do not exist for <span class="proposed-release-change-name"></span>: </p>
-       <ul id="layers-to-remove-list">
-       </ul>
-       <p>If you change the Yocto Project release to <span class="proposed-release-change-name"></span>, the above layers will be deleted from your added layers.</p>
+        <p>Deleting the <strong class="project-name"></strong> project will remove forever:</p>
+        <ul>
+          <li>Its configuration information</li>
+          <li>Its imported layers</li>
+          <li>Its custom images</li>
+          <li>All its build information</li>
+        </ul>
       </div>
       <div class="modal-footer">
-       <button id="change-release-and-rm-layers" data-dismiss="modal" type="submit" class="btn btn-primary">Change release and delete layers</button>
-       <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
+        <button type="button" class="btn btn-primary" id="delete-project-confirmed">
+          <span data-role="submit-state">Delete project</span>
+          <span data-role="loading-state" style="display:none">
+            <span class="fa-pulse">
+            <i class="fa-pulse icon-spinner"></i>
+          </span>
+            &nbsp;Deleting project...
+          </span>
+        </button>
+        <button type="button" class="btn btn-link" data-dismiss="modal">Cancel</button>
       </div>
     </div><!-- /.modal-content -->
   </div><!-- /.modal-dialog -->
-</div><!-- /.modal -->
-{% endcomment %}
+</div>
+
 
 <div class="row" id="project-page" style="display:none">
   <div class="col-md-6">
index 2734af0c9599c800a54d7d821f99b01546f8e601..768ca945541b9c6406b30ae1b4c2c6deb0c47cc5 100644 (file)
@@ -24,7 +24,7 @@
   <!-- project name -->
   <div class="page-header">
     <h1 id="project-name-container">
-      <span id="project-name">{{project.name}}</span>
+      <span class="project-name">{{project.name}}</span>
 
       <span class="glyphicon glyphicon-edit" id="project-change-form-toggle"></i>