From 4b3c9d61dc0c416d4d277de680604e2f6697e288 Mon Sep 17 00:00:00 2001 From: Michael Wood Date: Mon, 7 Dec 2015 18:42:16 +0000 Subject: bitbake: toaster: customrecipe Add further front end features using new API This adds some basic package dependency hint modals when you add and remove a package. It also makes sure that if the CustomImageRecipe has no current included packages that we go and check this with the server to see if a relevant build has taken place which will provide this information. [YOCTO #8082] (Bitbake rev: 418f5509e74d46d36a8eb966a245083006e5f4ba) Signed-off-by: Michael Wood Signed-off-by: brian avery Signed-off-by: Richard Purdie --- .../toaster/toastergui/static/js/customrecipe.js | 132 ++++++++++++++++++--- .../toaster/toastergui/templates/customrecipe.html | 46 ++++++- .../toastergui/templates/pkg_add_rm_btn.html | 35 +++--- 3 files changed, 180 insertions(+), 33 deletions(-) (limited to 'bitbake') diff --git a/bitbake/lib/toaster/toastergui/static/js/customrecipe.js b/bitbake/lib/toaster/toastergui/static/js/customrecipe.js index 4cd9382b49..33fcb88e94 100644 --- a/bitbake/lib/toaster/toastergui/static/js/customrecipe.js +++ b/bitbake/lib/toaster/toastergui/static/js/customrecipe.js @@ -4,32 +4,129 @@ function customRecipePageInit(ctx) { var urlParams = libtoaster.parseUrlParams(); var customiseTable = $("#selectpackagestable"); + var addPkgDepsModalBtn = $("#add-package-deps-modal-btn"); + var rmdPkgReverseDepsModalBtn = $("#rm-package-reverse-deps-modal-btn"); - (function notificationRequest(){ - if (urlParams.hasOwnProperty('notify') && urlParams.notify === 'new'){ - $("#image-created-notification").show(); - } - })(); + if (urlParams.hasOwnProperty('notify') && urlParams.notify === 'new'){ + $("#image-created-notification").show(); + } - customiseTable.on('table-done', function(e, total, tableParams){ + customiseTable.on('table-done', function(e, total){ /* Table is done so now setup the click handler for the package buttons */ $(".add-rm-package-btn").click(function(e){ e.preventDefault(); - addRemovePackage($(this), tableParams); + var pkgBtnData = $(this).data(); + + checkPackageDeps(pkgBtnData, function(pkgData){ + if (pkgBtnData.directive === 'add'){ + /* If we're adding a package we may need to show the modal to advise + * on dependencies for this package. + */ + if (pkgData.unsatisfied_dependencies.length === 0){ + addRemovePackage(pkgBtnData); + } else { + showPackageDepsModal(pkgBtnData, pkgData); + } + } else if (pkgBtnData.directive === 'remove') { + if (pkgData.reverse_dependencies.length === 0){ + addRemovePackage(pkgBtnData); + } else { + showPackageReverseDepsModal(pkgBtnData, pkgData); + } + } + }); + }); + }); + + function checkPackageDeps(pkgBtnData, doneCb){ + $.ajax({ + type: 'GET', + url: pkgBtnData.packageUrl, + headers: { 'X-CSRFToken' : $.cookie('csrftoken')}, + success: function(data){ + if (data.error !== 'ok'){ + console.warn(data.error); + return; + } + doneCb(data); + } }); + } + + function showPackageDepsModal(pkgBtnData, pkgData){ + var modal = $("#package-deps-modal"); + var depsList = modal.find("#package-add-dep-list"); + var deps = pkgData.unsatisfied_dependencies; + + modal.find(".package-to-add-name").text(pkgBtnData.name); + + depsList.text(""); + + for (var i in deps){ + var li = $('
  • ').text(deps[i].name); + li.append($('').text(" ("+ + deps[i].size_formatted+")")); + depsList.append(li); + } + + modal.find("#package-deps-total-size").text( + pkgData.unsatisfied_dependencies_size_formatted); + + addPkgDepsModalBtn.data(pkgBtnData); + modal.modal('show'); + } + + addPkgDepsModalBtn.click(function(e){ + e.preventDefault(); + + addRemovePackage($(this).data(), null); + }); + + function showPackageReverseDepsModal(pkgBtnData, pkgData){ + var modal = $("#package-reverse-deps-modal"); + var depsList = modal.find("#package-reverse-dep-list"); + var deps = pkgData.reverse_dependencies; + + modal.find(".package-to-rm-name").text(pkgBtnData.name); + + depsList.text(""); + + for (var i in deps){ + var li = $('
  • ').text(deps[i].name); + li.append($('').text(" ("+ + deps[i].size_formatted+")")); + depsList.append(li); + } + + modal.find("#package-reverse-deps-total-size").text( + pkgData.reverse_dependencies_size_formatted); + + rmdPkgReverseDepsModalBtn.data(pkgBtnData); + modal.modal('show'); + } + + rmdPkgReverseDepsModalBtn.click(function(e){ + e.preventDefault(); + + addRemovePackage($(this).data(), null); }); - function addRemovePackage(pkgBtn, tableParams){ - var pkgBtnData = pkgBtn.data(); + + function addRemovePackage(pkgBtnData, tableParams){ var method; var msg = "You have "; - if (pkgBtnData.directive == 'add') { + var btnCell = $("#package-btn-cell-"+pkgBtnData.package); + var inlineNotify = btnCell.children(".inline-notification"); + + if (pkgBtnData.directive === 'add') { method = 'PUT'; msg += "added 1 package to "+ctx.recipe.name+":"; - } else if (pkgBtnData.directive == 'remove') { + inlineNotify.text("1 package added"); + } else if (pkgBtnData.directive === 'remove') { method = 'DELETE'; msg += "removed 1 package from "+ctx.recipe.name+":"; + inlineNotify.text("1 package removed"); } else { throw("Unknown package directive: should be add or remove"); } @@ -45,11 +142,18 @@ function customRecipePageInit(ctx) { console.warn(data.error); return; } - /* Reload and Invalidate the Add | Rm package table's current data */ - tableParams.nocache = true; - customiseTable.trigger('reload', [tableParams]); libtoaster.showChangeNotification(msg); + + /* Also do the in-cell notification */ + btnCell.children("button").fadeOut().promise().done(function(){ + inlineNotify.fadeIn().delay(500).fadeOut(function(){ + if (pkgBtnData.directive === 'add') + btnCell.children("button[data-directive=remove]").fadeIn(); + else + btnCell.children("button[data-directive=add]").fadeIn(); + }); + }); } }); } diff --git a/bitbake/lib/toaster/toastergui/templates/customrecipe.html b/bitbake/lib/toaster/toastergui/templates/customrecipe.html index 2f3aee3686..4d88be054d 100644 --- a/bitbake/lib/toaster/toastergui/templates/customrecipe.html +++ b/bitbake/lib/toaster/toastergui/templates/customrecipe.html @@ -26,6 +26,8 @@ recipe : { id: {{recipe.pk}}, name: "{{recipe.name}}", + includedPackagesCount: {{recipe.includes_set.count}}, + baseRecipeId: {{recipe.base_recipe.pk}}, } }; @@ -37,6 +39,44 @@ } }); + + + + + + + +
    - {% if recipe.package_set.count == 0 and last_build == None %} + {% if recipe.get_all_packages.count == 0 and last_build == None %}

    Add | Remove packages

    Toaster has no package information for {{recipe.name}}. To generate package information, build {{recipe.name}}

    - +
    {% else %} {# ToasterTable for Adding remove packages #} @@ -103,7 +143,7 @@ Approx. packages included -
    {{recipe.package_set.all.count}}
    +
    {{recipe.get_all_packages.count}}
    Approx. package size diff --git a/bitbake/lib/toaster/toastergui/templates/pkg_add_rm_btn.html b/bitbake/lib/toaster/toastergui/templates/pkg_add_rm_btn.html index 8723d4ed56..493456f855 100644 --- a/bitbake/lib/toaster/toastergui/templates/pkg_add_rm_btn.html +++ b/bitbake/lib/toaster/toastergui/templates/pkg_add_rm_btn.html @@ -1,16 +1,19 @@ - +
    + + +
    -- cgit v1.2.3-54-g00ecf