From: Michael Wood
Date: Mon, 26 Sep 2016 10:59:35 +0000 (+0300)
Subject: bitbake: toaster: importlayer Convert success import to new notification system
X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5b23bf083b7adcd7884d58aaf26f23102e6e3f5a;p=thirdparty%2Fopenembedded%2Fopenembedded-core-contrib.git
bitbake: toaster: importlayer Convert success import to new notification system
Use the simpler libtoaster method of showing a notification about
successful import of a layer.
Also a number of whitespace clean ups.
(Bitbake rev: 89d3acbc32eadd2acf90030d8b9703ce193dff0c)
Signed-off-by: Michael Wood
Signed-off-by: Ed Bartosh
Signed-off-by: Richard Purdie
---
diff --git a/bitbake/lib/toaster/toastergui/static/js/importlayer.js b/bitbake/lib/toaster/toastergui/static/js/importlayer.js
index 191b30ffeeb..570ca3369bf 100644
--- a/bitbake/lib/toaster/toastergui/static/js/importlayer.js
+++ b/bitbake/lib/toaster/toastergui/static/js/importlayer.js
@@ -17,7 +17,9 @@ function importLayerPageInit (ctx) {
var currentLayerDepSelection;
var validLayerName = /^(\w|-)+$/;
- libtoaster.makeTypeahead(layerDepInput, libtoaster.ctx.layersTypeAheadUrl, { include_added: "true" }, function(item){
+ libtoaster.makeTypeahead(layerDepInput,
+ libtoaster.ctx.layersTypeAheadUrl,
+ { include_added: "true" }, function(item){
currentLayerDepSelection = item;
});
@@ -95,7 +97,8 @@ function importLayerPageInit (ctx) {
$("#layer-deps-list").append(newLayerDep);
- libtoaster.getLayerDepsForProject(currentLayerDepSelection.layerdetailurl, function (data){
+ libtoaster.getLayerDepsForProject(currentLayerDepSelection.layerdetailurl,
+ function (data){
/* These are the dependencies of the layer added as a dependency */
if (data.list.length > 0) {
currentLayerDepSelection.url = currentLayerDepSelection.layerdetailurl;
@@ -150,7 +153,9 @@ function importLayerPageInit (ctx) {
var body = ""+layer.name+"'s dependencies ("+
depNames.join(", ")+") require some layers that are not added to your project. Select the ones you want to add:
";
- showLayerDepsModal(layer, depDepsArray, title, body, false, function(layerObsList){
+ showLayerDepsModal(layer,
+ depDepsArray,
+ title, body, false, function(layerObsList){
/* Add the accepted layer dependencies' ids to the allDeps array */
for (var key in layerObsList){
allDeps.push(layerObsList[key].id);
@@ -191,9 +196,8 @@ function importLayerPageInit (ctx) {
if (data.error != "ok") {
console.log(data.error);
} else {
- /* Success layer import now go to the project page */
- $.cookie('layer-imported-alert', JSON.stringify(data), { path: '/'});
- window.location.replace(libtoaster.ctx.projectPageUrl+'?notify=layer-imported');
+ createImportedNotification(data);
+ window.location.replace(libtoaster.ctx.projectPageUrl);
}
},
error: function (data) {
@@ -204,6 +208,30 @@ function importLayerPageInit (ctx) {
}
});
+ /* Layer imported notification */
+ function createImportedNotification(imported){
+ var message = "Layer imported";
+
+ if (imported.deps_added.length === 0) {
+ message = "You have imported "+imported.imported_layer.name+" and added it to your project.";
+ } else {
+
+ var links = ""+imported.imported_layer.name+", ";
+
+ imported.deps_added.map (function(item, index){
+ links +=''+item.name+'';
+ /*If we're at the last element we don't want the trailing comma */
+ if (imported.deps_added[index+1] !== undefined)
+ links += ', ';
+ });
+
+ /* Length + 1 here to do deps + the imported layer */
+ message = 'You have imported '+imported.imported_layer.name+' and added '+(imported.deps_added.length+1)+' layers to your project: '+links+'';
+ }
+
+ libtoaster.setNotification("layer-imported", message);
+ }
+
function enable_import_btn(enabled) {
var importAndAddHint = $("#import-and-add-hint");
@@ -230,10 +258,13 @@ function importLayerPageInit (ctx) {
}
if (valid) {
- if ($("#local-dir-radio").prop("checked") && localDirPath.val().length > 0) {
+ if ($("#local-dir-radio").prop("checked") &&
+ localDirPath.val().length > 0) {
enable_import_btn(true);
}
- if ($("#git-repo-radio").prop("checked") && vcsURLInput.val().length > 0 && gitRefInput.val().length > 0) {
+
+ if ($("#git-repo-radio").prop("checked") &&
+ vcsURLInput.val().length > 0 && gitRefInput.val().length > 0) {
enable_import_btn(true);
}
}
@@ -266,13 +297,13 @@ function importLayerPageInit (ctx) {
}
layerNameInput.on('blur', function() {
- if (!$(this).val()){
- return;
- }
- var name = $(this).val();
+ if (!$(this).val()){
+ return;
+ }
+ var name = $(this).val();
- /* Check if the layer name exists */
- $.getJSON(libtoaster.ctx.layersTypeAheadUrl,
+ /* Check if the layer name exists */
+ $.getJSON(libtoaster.ctx.layersTypeAheadUrl,
{ include_added: "true" , search: name, format: "json" },
function(layer) {
if (layer.results.length > 0) {
diff --git a/bitbake/lib/toaster/toastergui/static/js/projectpage.js b/bitbake/lib/toaster/toastergui/static/js/projectpage.js
index 7f19c0d7aa4..45367036496 100644
--- a/bitbake/lib/toaster/toastergui/static/js/projectpage.js
+++ b/bitbake/lib/toaster/toastergui/static/js/projectpage.js
@@ -50,70 +50,8 @@ function projectPageInit(ctx) {
$("#delete-project-modal .project-name").text(prjInfo.name);
});
- (function notificationRequest(){
-
- if (urlParams.hasOwnProperty('notify')){
- switch (urlParams.notify){
- case 'new-project':
- $("#project-created-notification").show();
- break;
- 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 1 layer from your ";
- message += "project: " + layer + "";
-
- libtoaster.showChangeNotification(message);
-
- $.removeCookie("layer-deleted", { path: "/"});
- }
-
-
- /* Layer imported notification */
- function layerImportedNotification(){
- var imported = $.cookie("layer-imported-alert");
- var message = "Layer imported";
-
- if (!imported)
- return;
- else
- imported = JSON.parse(imported);
-
- if (imported.deps_added.length === 0) {
- message = "You have imported "+imported.imported_layer.name+" and added it to your project.";
- } else {
-
- var links = ""+imported.imported_layer.name+", ";
-
- imported.deps_added.map (function(item, index){
- links +=''+item.name+'';
- /*If we're at the last element we don't want the trailing comma */
- if (imported.deps_added[index+1] !== undefined)
- links += ', ';
- });
-
- /* Length + 1 here to do deps + the imported layer */
- message = 'You have imported '+imported.imported_layer.name+' and added '+(imported.deps_added.length+1)+' layers to your project: '+links+'';
- }
-
- libtoaster.showChangeNotification(message);
-
- $.removeCookie("layer-imported-alert", { path: "/"});
+ if (urlParams.hasOwnProperty('notify') && urlParams.notify === 'new-project'){
+ $("#project-created-notification").show();
}
/* Add/Rm layer functionality */