bitbake: toaster: Importlayer add notify exactly which layers changed

This changes when the dependencies are added to the project so that we
can know which ones were successfully added by waiting for the server to
respond with a list. This is more reliable because we may have specified
dependencies which are already in the project.

To pass this information to the project page a temporary cookie is used
with the values for the notification.

(Bitbake rev: 23ca89dc3e0f0ea387649f1e9e8d7d50846048d6)

Signed-off-by: Michael Wood <michael.g.wood@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Michael Wood
2014-12-05 17:25:51 +00:00
committed by Richard Purdie
parent bd6b8796a1
commit dadc11a52f
4 changed files with 82 additions and 23 deletions

View File

@@ -78,8 +78,14 @@ function importLayerPageInit (ctx) {
});
importAndAddBtn.click(function(){
/* This is a list of the names from layerDeps for the layer deps
* modal dialog body
*/
var depNames = [];
/* arrray of all layer dep ids includes parent and child deps */
var allDeps = [];
/* temporary object to use to do a reduce on the dependencies for each
* layer dependency added
*/
@@ -96,6 +102,7 @@ function importLayerPageInit (ctx) {
depDeps[layer.id] = layer;
}
}
depNames.push(layerDeps[key].name);
allDeps.push(layerDeps[key].id);
}
@@ -106,10 +113,14 @@ function importLayerPageInit (ctx) {
if (depDepsArray.length > 0) {
var layer = { name: layerNameInput.val(), url: "#", id: -1 };
show_layer_deps_modal(ctx.projectId, layer, depDepsArray, function(selected){
var title = "Layer";
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>";
show_layer_deps_modal(ctx.projectId, layer, depDepsArray, title, body, false, function(selected){
/* Add the accepted dependencies to the allDeps array */
if (selected.length > 0){
allDeps.concat (selected);
allDeps = allDeps.concat (selected);
}
import_and_add ();
});
@@ -141,8 +152,10 @@ function importLayerPageInit (ctx) {
show_error_message(data, layerData);
console.log(data.error);
} else {
layerData.layersAdded = data.layers_added;
/* Success layer import now go to the project page */
window.location.replace(ctx.projectPageUrl+'#/layerimported='+layerData.name);
$.cookie('layer-imported-alert', JSON.stringify(layerData), { path: '/'});
window.location.replace(ctx.projectPageUrl+'#/layerimported');
}
},
error: function (data) {

View File

@@ -128,7 +128,7 @@ projectApp.filter('timediff', function() {
// main controller for the project page
projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $location, $cookies, $q, $sce, $anchorScroll, $animate, $sanitize) {
projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $location, $cookies, $cookieStore, $q, $sce, $anchorScroll, $animate, $sanitize) {
$scope.getSuggestions = function(type, currentValue) {
var deffered = $q.defer();
@@ -572,9 +572,28 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc
});
_cmdExecuteWithParam("/layerimported", function (layer) {
$scope.displayAlert($scope.zone2alerts,
"You have imported <strong>" + layer +
"</strong> and added it to your project.", "alert-success");
var imported = $cookieStore.get("layer-imported-alert");
var text;
if (!imported)
return;
if (imported.layersAdded.length == 0) {
text = "You have imported <strong>"+imported.name+
"</strong> and added it to your project.";
} else {
text = "You have imported <strong>"+imported.name+
"</strong> and added <strong>"+imported.layersAdded.length+
"</strong> layers to your project. <strong>"+
imported.layersAdded.join(", ")+"</strong>";
}
$scope.displayAlert($scope.zone2alerts, text, "alert-info");
// This doesn't work
$cookieStore.remove("layer-imported-alert");
//use jquery plugin instead
$.removeCookie("layer-imported-alert", { path: "/"});
});
_cmdExecuteWithParam("/targetbuild=", function (targets) {

View File

@@ -3,10 +3,10 @@
<form id="dependencies_modal_form">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
<h3><span class="layer-name"></span> dependencies</h3>
<h3><span id="title"></span> dependencies</h3>
</div>
<div class="modal-body">
<p><strong class="layer-name"></strong> depends on some layers that are not added to your project. Select the ones you want to add:</p>
<p id="body-text"> <strong id="layer-name"></strong> depends on some layers that are not added to your project. Select the ones you want to add:</p>
<ul class="unstyled" id="dependencies_list">
</ul>
</div>
@@ -18,9 +18,20 @@
</div>
<script>
function show_layer_deps_modal(projectId, layer, dependencies, successAdd) {
function show_layer_deps_modal(projectId, layer, dependencies, title, body, addToProject, successAdd) {
// update layer name
$('.layer-name').text(layer.name);
if (title) {
$('#dependencies_modal #title').text(title);
} else {
$('#dependencies_modal #title').text(layer.name);
}
if (body) {
$("#dependencies_modal #body-text").html(body);
} else {
$("#dependencies_modal #layer-name").text(layer.name);
}
var deplistHtml = "";
for (var i = 0; i < dependencies.length; i++) {
deplistHtml += "<li><label class=\"checkbox\"><input name=\"dependencies\" value=\"";
@@ -31,7 +42,13 @@ function show_layer_deps_modal(projectId, layer, dependencies, successAdd) {
}
$('#dependencies_list').html(deplistHtml);
var selected = [layer.id];
var selected = [];
/* -1 is a special dummy Id which we use when the layer isn't yet in the
* system, normally we would add the current layer to the selection.
*/
if (layer.id != -1)
selected.push(layer.id);
var layer_link_list = "<a href='"+layer.url+"'>"+layer.name+"</a>";
$("#dependencies_modal_form").submit(function (e) {
@@ -54,15 +71,20 @@ function show_layer_deps_modal(projectId, layer, dependencies, successAdd) {
$('#dependencies_modal').modal('hide');
var editProjectUrl = "{% url 'xhr_projectedit' project.id %}";
libtoaster.editProject(editProjectUrl, projectId, { 'layerAdd': selected.join(",") }, function () {
if (successAdd) {
successAdd(selected);
}
}, function () {
console.log ("Adding layers to project failed");
});
if (addToProject) {
var editProjectUrl = "{% url 'xhr_projectedit' project.id %}";
libtoaster.editProject(editProjectUrl, projectId, { 'layerAdd': selected.join(",") }, function () {
if (successAdd) {
successAdd(selected);
}
}, function () {
console.log ("Adding layers to project failed");
});
} else {
successAdd(selected);
}
});
$('#dependencies_modal').modal('show');
}
</script>

View File

@@ -2253,6 +2253,8 @@ if toastermain.settings.MANAGED:
not request.POST.has_key('project_id')):
return HttpResponse(jsonfilter({"error": "Missing parameters; requires vcs_url, name, git_ref and project_id"}), content_type = "application/json")
layers_added = [];
# Rudimentary check for any possible html tags
if "<" in request.POST:
return HttpResponse(jsonfilter({"error": "Invalid character <"}), content_type = "application/json")
@@ -2315,9 +2317,12 @@ if toastermain.settings.MANAGED:
# if the project now contains the exact
# dependency already (like modified on another page)
try:
ProjectLayer.objects.get_or_create(layercommit=layer_dep_obj, project=prj)
prj_layer, prj_layer_created = ProjectLayer.objects.get_or_create(layercommit=layer_dep_obj, project=prj)
except:
pass
continue
if prj_layer_created:
layers_added.append(Layer.objects.get(id=layer_dep_obj.layer_id).name)
# If an old layer version exists in our project then remove it
@@ -2337,7 +2342,7 @@ if toastermain.settings.MANAGED:
return HttpResponse(jsonfilter({"error": "Uncaught error: Could not create layer version"}), content_type = "application/json")
return HttpResponse(jsonfilter({"error": "ok"}), content_type = "application/json")
return HttpResponse(jsonfilter({"error": "ok", "layers_added": layers_added}), content_type = "application/json")