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 <michael.g.wood@intel.com>
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Michael Wood 2016-09-26 13:59:35 +03:00 committed by Richard Purdie
parent fbf7e14894
commit 5b23bf083b
2 changed files with 47 additions and 78 deletions

View File

@ -17,7 +17,9 @@ function importLayerPageInit (ctx) {
var currentLayerDepSelection; var currentLayerDepSelection;
var validLayerName = /^(\w|-)+$/; 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; currentLayerDepSelection = item;
}); });
@ -95,7 +97,8 @@ function importLayerPageInit (ctx) {
$("#layer-deps-list").append(newLayerDep); $("#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 */ /* These are the dependencies of the layer added as a dependency */
if (data.list.length > 0) { if (data.list.length > 0) {
currentLayerDepSelection.url = currentLayerDepSelection.layerdetailurl; currentLayerDepSelection.url = currentLayerDepSelection.layerdetailurl;
@ -150,7 +153,9 @@ function importLayerPageInit (ctx) {
var body = "<strong>"+layer.name+"</strong>'s dependencies ("+ var body = "<strong>"+layer.name+"</strong>'s dependencies ("+
depNames.join(", ")+"</span>) require some layers that are not added to your project. Select the ones you want to add:</p>"; depNames.join(", ")+"</span>) require some layers that are not added to your project. Select the ones you want to add:</p>";
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 */ /* Add the accepted layer dependencies' ids to the allDeps array */
for (var key in layerObsList){ for (var key in layerObsList){
allDeps.push(layerObsList[key].id); allDeps.push(layerObsList[key].id);
@ -191,9 +196,8 @@ function importLayerPageInit (ctx) {
if (data.error != "ok") { if (data.error != "ok") {
console.log(data.error); console.log(data.error);
} else { } else {
/* Success layer import now go to the project page */ createImportedNotification(data);
$.cookie('layer-imported-alert', JSON.stringify(data), { path: '/'}); window.location.replace(libtoaster.ctx.projectPageUrl);
window.location.replace(libtoaster.ctx.projectPageUrl+'?notify=layer-imported');
} }
}, },
error: function (data) { 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 <strong><a class=\"alert-link\" href=\""+imported.imported_layer.layerdetailurl+"\">"+imported.imported_layer.name+"</a></strong> and added it to your project.";
} else {
var links = "<a href=\""+imported.imported_layer.layerdetailurl+"\">"+imported.imported_layer.name+"</a>, ";
imported.deps_added.map (function(item, index){
links +='<a href="'+item.layerdetailurl+'">'+item.name+'</a>';
/*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 <strong><a href="'+imported.imported_layer.layerdetailurl+'">'+imported.imported_layer.name+'</a></strong> and added <strong>'+(imported.deps_added.length+1)+'</strong> layers to your project: <strong>'+links+'</strong>';
}
libtoaster.setNotification("layer-imported", message);
}
function enable_import_btn(enabled) { function enable_import_btn(enabled) {
var importAndAddHint = $("#import-and-add-hint"); var importAndAddHint = $("#import-and-add-hint");
@ -230,10 +258,13 @@ function importLayerPageInit (ctx) {
} }
if (valid) { 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); 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); enable_import_btn(true);
} }
} }
@ -266,13 +297,13 @@ function importLayerPageInit (ctx) {
} }
layerNameInput.on('blur', function() { layerNameInput.on('blur', function() {
if (!$(this).val()){ if (!$(this).val()){
return; return;
} }
var name = $(this).val(); var name = $(this).val();
/* Check if the layer name exists */ /* Check if the layer name exists */
$.getJSON(libtoaster.ctx.layersTypeAheadUrl, $.getJSON(libtoaster.ctx.layersTypeAheadUrl,
{ include_added: "true" , search: name, format: "json" }, { include_added: "true" , search: name, format: "json" },
function(layer) { function(layer) {
if (layer.results.length > 0) { if (layer.results.length > 0) {

View File

@ -50,70 +50,8 @@ function projectPageInit(ctx) {
$("#delete-project-modal .project-name").text(prjInfo.name); $("#delete-project-modal .project-name").text(prjInfo.name);
}); });
(function notificationRequest(){ if (urlParams.hasOwnProperty('notify') && urlParams.notify === 'new-project'){
$("#project-created-notification").show();
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 <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");
var message = "Layer imported";
if (!imported)
return;
else
imported = JSON.parse(imported);
if (imported.deps_added.length === 0) {
message = "You have imported <strong><a class=\"alert-link\" href=\""+imported.imported_layer.layerdetailurl+"\">"+imported.imported_layer.name+"</a></strong> and added it to your project.";
} else {
var links = "<a href=\""+imported.imported_layer.layerdetailurl+"\">"+imported.imported_layer.name+"</a>, ";
imported.deps_added.map (function(item, index){
links +='<a href="'+item.layerdetailurl+'">'+item.name+'</a>';
/*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 <strong><a href="'+imported.imported_layer.layerdetailurl+'">'+imported.imported_layer.name+'</a></strong> and added <strong>'+(imported.deps_added.length+1)+'</strong> layers to your project: <strong>'+links+'</strong>';
}
libtoaster.showChangeNotification(message);
$.removeCookie("layer-imported-alert", { path: "/"});
} }
/* Add/Rm layer functionality */ /* Add/Rm layer functionality */