Add the front end feature to delete a layer from the layer details page. [YOCO #9184]
Signed-off-by: Michael Wood <[email protected]> --- .../lib/toaster/toastergui/static/js/layerdetails.js | 20 ++++++++++++++++++++ .../lib/toaster/toastergui/static/js/projectpage.js | 18 ++++++++++++++++++ .../toaster/toastergui/templates/layerdetails.html | 20 +++++++++++++++++++- bitbake/lib/toaster/toastergui/urls.py | 2 +- 4 files changed, 58 insertions(+), 2 deletions(-) diff --git a/bitbake/lib/toaster/toastergui/static/js/layerdetails.js b/bitbake/lib/toaster/toastergui/static/js/layerdetails.js index a56087b..683486e 100644 --- a/bitbake/lib/toaster/toastergui/static/js/layerdetails.js +++ b/bitbake/lib/toaster/toastergui/static/js/layerdetails.js @@ -397,6 +397,26 @@ function layerDetailsPageInit (ctx) { $(this).parents("form").submit(); }); + $("#layer-delete-confirmed").click(function(){ + $.cookie("layer-deleted", ctx.layerVersion.name, { path: '/'}); + + $.ajax({ + type: "DELETE", + url: ctx.xhrUpdateLayerUrl, + headers: { 'X-CSRFToken' : $.cookie('csrftoken')}, + success: function(data) { + if (data.error != "ok") { + console.warn(data.error); + } else { + window.location = data.redirect + "?notify=layer-deleted"; + } + }, + error: function(data) { + console.warn("Call failed"); + console.warn(data); + } + }); + }); layerDepsList.find(".glyphicon-trash").click(layerDepRemoveClick); layerDepsList.find("a").tooltip(); diff --git a/bitbake/lib/toaster/toastergui/static/js/projectpage.js b/bitbake/lib/toaster/toastergui/static/js/projectpage.js index 6d92490..df79849 100644 --- a/bitbake/lib/toaster/toastergui/static/js/projectpage.js +++ b/bitbake/lib/toaster/toastergui/static/js/projectpage.js @@ -58,12 +58,30 @@ function projectPageInit(ctx) { case 'layer-imported': layerImportedNotification(); break; + case 'layer-deleted': + layerDeletedNotification(); default: break; } } })(); + /* Layer deleted notification */ + function layerDeletedNotification(){ + var layer = $.cookie("layer-deleted"); + + if (!layer) + return; + + var message = "You have deleted <strong>1</strong> layer from your "; + message += "project: <strong>" + layer + "</strong>"; + + libtoaster.showChangeNotification(message); + + $.removeCookie("layer-deleted", { path: "/"}); + } + + /* Layer imported notification */ function layerImportedNotification(){ var imported = $.cookie("layer-imported-alert"); diff --git a/bitbake/lib/toaster/toastergui/templates/layerdetails.html b/bitbake/lib/toaster/toastergui/templates/layerdetails.html index 143ec25..4b51d1a 100644 --- a/bitbake/lib/toaster/toastergui/templates/layerdetails.html +++ b/bitbake/lib/toaster/toastergui/templates/layerdetails.html @@ -6,6 +6,20 @@ {% block title %} {{layerversion.layer.name}} - {{project.name}} - Toaster {% endblock %} {% block pagecontent %} +<div id="delete-layer-modal" class="modal fade" tabindex="-1" role="dialog"> + <div class="modal-dialog" role="document"> + <div class="modal-content"> + <div class="modal-body"> + Are you sure you want to delete the <strong>{{layerversion.layer.name}}</strong> layer? + </div> + <div class="modal-footer"> + <button type="button" id="layer-delete-confirmed" class="btn btn-primary">Delete</button> + <button type="button" class="btn btn-default btn-link" data-dismiss="modal">Cancel</button> + </div> + </div> + </div> +</div> + <div class="row"> <div class="col-md-12"> <ul class="breadcrumb"> @@ -44,7 +58,7 @@ $(document).ready(function(){ var ctx = { - xhrUpdateLayerUrl : "{% url 'xhr_layer' layerversion.pk %}", + xhrUpdateLayerUrl : "{% url 'xhr_layer' project.id layerversion.pk %}", layerVersion : { name : "{{layerversion.layer.name}}", id : {{layerversion.id}}, @@ -271,6 +285,10 @@ </dd> {% endif %} </dl> + {% if layerversion.layer_source_id and layerversion.layer_source.sourcetype == layerversion.layer_source.TYPE_IMPORTED %} + <i class="icon-trash text-danger"></i> + <a href="#delete-layer-modal" role="button" class="text-danger" data-toggle="modal" data-target="#delete-layer-modal">Delete {{layerversion.layer.name}}</a> + {% endif %} </div> </div> </div> diff --git a/bitbake/lib/toaster/toastergui/urls.py b/bitbake/lib/toaster/toastergui/urls.py index 15b1063..1c0ccbb 100644 --- a/bitbake/lib/toaster/toastergui/urls.py +++ b/bitbake/lib/toaster/toastergui/urls.py @@ -191,7 +191,7 @@ urlpatterns = patterns('toastergui.views', url(r'^xhr_importlayer/$', 'xhr_importlayer', name='xhr_importlayer'), - url(r'^xhr_layer/(?P<layerversion_id>\d+)$', + url(r'^xhr_layer/(?P<pid>\d+)/(?P<layerversion_id>\d+)$', api.XhrLayer.as_view(), name='xhr_layer'), -- 2.7.4 -- _______________________________________________ toaster mailing list [email protected] https://lists.yoctoproject.org/listinfo/toaster
