aboutsummaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/toastergui/static/js/customrecipe.js
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/toaster/toastergui/static/js/customrecipe.js')
-rw-r--r--bitbake/lib/toaster/toastergui/static/js/customrecipe.js98
1 files changed, 71 insertions, 27 deletions
diff --git a/bitbake/lib/toaster/toastergui/static/js/customrecipe.js b/bitbake/lib/toaster/toastergui/static/js/customrecipe.js
index 33fcb88e947..a1fe4862e5c 100644
--- a/bitbake/lib/toaster/toastergui/static/js/customrecipe.js
+++ b/bitbake/lib/toaster/toastergui/static/js/customrecipe.js
@@ -15,33 +15,33 @@ function customRecipePageInit(ctx) {
/* Table is done so now setup the click handler for the package buttons */
$(".add-rm-package-btn").click(function(e){
e.preventDefault();
- var pkgBtnData = $(this).data();
+ var targetPkg = $(this).data();
- checkPackageDeps(pkgBtnData, function(pkgData){
- if (pkgBtnData.directive === 'add'){
+ checkPackageDeps(targetPkg, function(pkgData){
+ if (targetPkg.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);
+ addRemovePackage(targetPkg);
} else {
- showPackageDepsModal(pkgBtnData, pkgData);
+ showPackageDepsModal(targetPkg, pkgData);
}
- } else if (pkgBtnData.directive === 'remove') {
+ } else if (targetPkg.directive === 'remove') {
if (pkgData.reverse_dependencies.length === 0){
- addRemovePackage(pkgBtnData);
+ addRemovePackage(targetPkg);
} else {
- showPackageReverseDepsModal(pkgBtnData, pkgData);
+ showPackageReverseDepsModal(targetPkg, pkgData);
}
}
});
});
});
- function checkPackageDeps(pkgBtnData, doneCb){
+ function checkPackageDeps(targetPkg, doneCb){
$.ajax({
type: 'GET',
- url: pkgBtnData.packageUrl,
+ url: targetPkg.packageUrl,
headers: { 'X-CSRFToken' : $.cookie('csrftoken')},
success: function(data){
if (data.error !== 'ok'){
@@ -53,12 +53,12 @@ function customRecipePageInit(ctx) {
});
}
- function showPackageDepsModal(pkgBtnData, pkgData){
+ function showPackageDepsModal(targetPkg, 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);
+ modal.find(".package-to-add-name").text(targetPkg.name);
depsList.text("");
@@ -72,7 +72,9 @@ function customRecipePageInit(ctx) {
modal.find("#package-deps-total-size").text(
pkgData.unsatisfied_dependencies_size_formatted);
- addPkgDepsModalBtn.data(pkgBtnData);
+ targetPkg.depsAdded = deps;
+
+ addPkgDepsModalBtn.data(targetPkg);
modal.modal('show');
}
@@ -82,12 +84,12 @@ function customRecipePageInit(ctx) {
addRemovePackage($(this).data(), null);
});
- function showPackageReverseDepsModal(pkgBtnData, pkgData){
+ function showPackageReverseDepsModal(targetPkg, 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);
+ modal.find(".package-to-rm-name").text(targetPkg.name);
depsList.text("");
@@ -101,7 +103,7 @@ function customRecipePageInit(ctx) {
modal.find("#package-reverse-deps-total-size").text(
pkgData.reverse_dependencies_size_formatted);
- rmdPkgReverseDepsModalBtn.data(pkgBtnData);
+ rmdPkgReverseDepsModalBtn.data(targetPkg);
modal.modal('show');
}
@@ -112,30 +114,58 @@ function customRecipePageInit(ctx) {
});
- function addRemovePackage(pkgBtnData, tableParams){
+ function addRemovePackage(targetPkg, tableParams){
var method;
var msg = "You have ";
- var btnCell = $("#package-btn-cell-"+pkgBtnData.package);
+ var btnCell = $("#package-btn-cell-" + targetPkg.id);
var inlineNotify = btnCell.children(".inline-notification");
- if (pkgBtnData.directive === 'add') {
+ if (targetPkg.directive === 'add') {
method = 'PUT';
- msg += "added 1 package to "+ctx.recipe.name+":";
- inlineNotify.text("1 package added");
- } else if (pkgBtnData.directive === 'remove') {
+ /* If the package had dependencies also notify that they were added */
+ if (targetPkg.hasOwnProperty('depsAdded') &&
+ targetPkg.depsAdded.length > 0) {
+
+ msg += "added " + (targetPkg.depsAdded.length + 1);
+ msg += " packages to " + ctx.recipe.name + ": ";
+ msg += "<strong>" + targetPkg.name + "</strong> and its dependencies";
+
+ for (var i in targetPkg.depsAdded){
+ var dep = targetPkg.depsAdded[i];
+
+ msg += " <strong>" + dep.name + "</strong>";
+
+ /* Add any cells currently in view to the list of cells which get
+ * an inline notification inside them and which change add/rm state
+ */
+ var depBtnCell = $("#package-btn-cell-" + dep.pk);
+ btnCell = btnCell.add(depBtnCell);
+
+ inlineNotify = inlineNotify.add(
+ depBtnCell.children(".inline-notification"));
+ }
+
+ inlineNotify.text(
+ (targetPkg.depsAdded.length + 1) + " packages added");
+
+ } else {
+ msg += ' <strong>' + targetPkg.name + '<strong>';
+ inlineNotify.text("1 package added");
+ }
+
+ } else if (targetPkg.directive === 'remove') {
method = 'DELETE';
msg += "removed 1 package from "+ctx.recipe.name+":";
+ msg += ' <strong>' + targetPkg.name + '<strong>';
inlineNotify.text("1 package removed");
} else {
throw("Unknown package directive: should be add or remove");
}
- msg += ' <strong>' + pkgBtnData.name + '<strong>';
-
$.ajax({
type: method,
- url: pkgBtnData.packageUrl,
+ url: targetPkg.packageUrl,
headers: { 'X-CSRFToken' : $.cookie('csrftoken')},
success: function(data){
if (data.error !== 'ok'){
@@ -145,15 +175,29 @@ function customRecipePageInit(ctx) {
libtoaster.showChangeNotification(msg);
- /* Also do the in-cell notification */
+ /* do the in-cell/inline notification to swap buttoms from add to
+ * remove
+ */
btnCell.children("button").fadeOut().promise().done(function(){
inlineNotify.fadeIn().delay(500).fadeOut(function(){
- if (pkgBtnData.directive === 'add')
+ if (targetPkg.directive === 'add')
btnCell.children("button[data-directive=remove]").fadeIn();
else
btnCell.children("button[data-directive=add]").fadeIn();
});
});
+
+ /* Update the total num packages */
+ $.ajax({
+ type: "GET",
+ url: ctx.recipe.xhrPackageListUrl,
+ headers: { 'X-CSRFToken' : $.cookie('csrftoken')},
+ success: function(data){
+ console.log(data);
+ $("#total-num-packages").text(data.total);
+ $("#total-size-packages").text(data.total_size_formatted);
+ }
+ });
}
});
}