summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Wood <michael.g.wood@intel.com>2014-12-05 17:25:51 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2014-12-18 10:24:07 +0000
commitdadc11a52f7048891f9be0118fa19c96c3061547 (patch)
treebfa0f453b46f507ccc67b2d588b80d4e161216b5
parentbd6b8796a1e12c06b98a9bd0a746d5b6896ca85c (diff)
downloadpoky-dadc11a52f7048891f9be0118fa19c96c3061547.tar.gz
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>
-rw-r--r--bitbake/lib/toaster/toastergui/static/js/importlayer.js19
-rw-r--r--bitbake/lib/toaster/toastergui/static/js/projectapp.js27
-rw-r--r--bitbake/lib/toaster/toastergui/templates/layers_dep_modal.html48
-rwxr-xr-xbitbake/lib/toaster/toastergui/views.py11
4 files changed, 82 insertions, 23 deletions
diff --git a/bitbake/lib/toaster/toastergui/static/js/importlayer.js b/bitbake/lib/toaster/toastergui/static/js/importlayer.js
index e2bc1ab607..15830dded5 100644
--- a/bitbake/lib/toaster/toastergui/static/js/importlayer.js
+++ b/bitbake/lib/toaster/toastergui/static/js/importlayer.js
@@ -78,8 +78,14 @@ function importLayerPageInit (ctx) {
78 }); 78 });
79 79
80 importAndAddBtn.click(function(){ 80 importAndAddBtn.click(function(){
81 /* This is a list of the names from layerDeps for the layer deps
82 * modal dialog body
83 */
84 var depNames = [];
85
81 /* arrray of all layer dep ids includes parent and child deps */ 86 /* arrray of all layer dep ids includes parent and child deps */
82 var allDeps = []; 87 var allDeps = [];
88
83 /* temporary object to use to do a reduce on the dependencies for each 89 /* temporary object to use to do a reduce on the dependencies for each
84 * layer dependency added 90 * layer dependency added
85 */ 91 */
@@ -96,6 +102,7 @@ function importLayerPageInit (ctx) {
96 depDeps[layer.id] = layer; 102 depDeps[layer.id] = layer;
97 } 103 }
98 } 104 }
105 depNames.push(layerDeps[key].name);
99 allDeps.push(layerDeps[key].id); 106 allDeps.push(layerDeps[key].id);
100 } 107 }
101 108
@@ -106,10 +113,14 @@ function importLayerPageInit (ctx) {
106 113
107 if (depDepsArray.length > 0) { 114 if (depDepsArray.length > 0) {
108 var layer = { name: layerNameInput.val(), url: "#", id: -1 }; 115 var layer = { name: layerNameInput.val(), url: "#", id: -1 };
109 show_layer_deps_modal(ctx.projectId, layer, depDepsArray, function(selected){ 116 var title = "Layer";
117 var body = "<strong>"+layer.name+"</strong>'s dependencies ("+
118 depNames.join(", ")+"</span>) require some layers that are not added to your project. Select the ones you want to add:</p>";
119
120 show_layer_deps_modal(ctx.projectId, layer, depDepsArray, title, body, false, function(selected){
110 /* Add the accepted dependencies to the allDeps array */ 121 /* Add the accepted dependencies to the allDeps array */
111 if (selected.length > 0){ 122 if (selected.length > 0){
112 allDeps.concat (selected); 123 allDeps = allDeps.concat (selected);
113 } 124 }
114 import_and_add (); 125 import_and_add ();
115 }); 126 });
@@ -141,8 +152,10 @@ function importLayerPageInit (ctx) {
141 show_error_message(data, layerData); 152 show_error_message(data, layerData);
142 console.log(data.error); 153 console.log(data.error);
143 } else { 154 } else {
155 layerData.layersAdded = data.layers_added;
144 /* Success layer import now go to the project page */ 156 /* Success layer import now go to the project page */
145 window.location.replace(ctx.projectPageUrl+'#/layerimported='+layerData.name); 157 $.cookie('layer-imported-alert', JSON.stringify(layerData), { path: '/'});
158 window.location.replace(ctx.projectPageUrl+'#/layerimported');
146 } 159 }
147 }, 160 },
148 error: function (data) { 161 error: function (data) {
diff --git a/bitbake/lib/toaster/toastergui/static/js/projectapp.js b/bitbake/lib/toaster/toastergui/static/js/projectapp.js
index 8e3499a94c..94c24f4a56 100644
--- a/bitbake/lib/toaster/toastergui/static/js/projectapp.js
+++ b/bitbake/lib/toaster/toastergui/static/js/projectapp.js
@@ -128,7 +128,7 @@ projectApp.filter('timediff', function() {
128 128
129 129
130// main controller for the project page 130// main controller for the project page
131projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $location, $cookies, $q, $sce, $anchorScroll, $animate, $sanitize) { 131projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $location, $cookies, $cookieStore, $q, $sce, $anchorScroll, $animate, $sanitize) {
132 132
133 $scope.getSuggestions = function(type, currentValue) { 133 $scope.getSuggestions = function(type, currentValue) {
134 var deffered = $q.defer(); 134 var deffered = $q.defer();
@@ -572,9 +572,28 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc
572 }); 572 });
573 573
574 _cmdExecuteWithParam("/layerimported", function (layer) { 574 _cmdExecuteWithParam("/layerimported", function (layer) {
575 $scope.displayAlert($scope.zone2alerts, 575 var imported = $cookieStore.get("layer-imported-alert");
576 "You have imported <strong>" + layer + 576 var text;
577 "</strong> and added it to your project.", "alert-success"); 577
578 if (!imported)
579 return;
580
581 if (imported.layersAdded.length == 0) {
582 text = "You have imported <strong>"+imported.name+
583 "</strong> and added it to your project.";
584 } else {
585 text = "You have imported <strong>"+imported.name+
586 "</strong> and added <strong>"+imported.layersAdded.length+
587 "</strong> layers to your project. <strong>"+
588 imported.layersAdded.join(", ")+"</strong>";
589 }
590
591 $scope.displayAlert($scope.zone2alerts, text, "alert-info");
592
593 // This doesn't work
594 $cookieStore.remove("layer-imported-alert");
595 //use jquery plugin instead
596 $.removeCookie("layer-imported-alert", { path: "/"});
578 }); 597 });
579 598
580 _cmdExecuteWithParam("/targetbuild=", function (targets) { 599 _cmdExecuteWithParam("/targetbuild=", function (targets) {
diff --git a/bitbake/lib/toaster/toastergui/templates/layers_dep_modal.html b/bitbake/lib/toaster/toastergui/templates/layers_dep_modal.html
index 821bbda296..b03fd0b218 100644
--- a/bitbake/lib/toaster/toastergui/templates/layers_dep_modal.html
+++ b/bitbake/lib/toaster/toastergui/templates/layers_dep_modal.html
@@ -3,10 +3,10 @@
3 <form id="dependencies_modal_form"> 3 <form id="dependencies_modal_form">
4 <div class="modal-header"> 4 <div class="modal-header">
5 <button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button> 5 <button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
6 <h3><span class="layer-name"></span> dependencies</h3> 6 <h3><span id="title"></span> dependencies</h3>
7 </div> 7 </div>
8 <div class="modal-body"> 8 <div class="modal-body">
9 <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> 9 <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>
10 <ul class="unstyled" id="dependencies_list"> 10 <ul class="unstyled" id="dependencies_list">
11 </ul> 11 </ul>
12 </div> 12 </div>
@@ -18,9 +18,20 @@
18 </div> 18 </div>
19 19
20<script> 20<script>
21function show_layer_deps_modal(projectId, layer, dependencies, successAdd) { 21function show_layer_deps_modal(projectId, layer, dependencies, title, body, addToProject, successAdd) {
22 // update layer name 22 // update layer name
23 $('.layer-name').text(layer.name); 23 if (title) {
24 $('#dependencies_modal #title').text(title);
25 } else {
26 $('#dependencies_modal #title').text(layer.name);
27 }
28
29 if (body) {
30 $("#dependencies_modal #body-text").html(body);
31 } else {
32 $("#dependencies_modal #layer-name").text(layer.name);
33 }
34
24 var deplistHtml = ""; 35 var deplistHtml = "";
25 for (var i = 0; i < dependencies.length; i++) { 36 for (var i = 0; i < dependencies.length; i++) {
26 deplistHtml += "<li><label class=\"checkbox\"><input name=\"dependencies\" value=\""; 37 deplistHtml += "<li><label class=\"checkbox\"><input name=\"dependencies\" value=\"";
@@ -31,7 +42,13 @@ function show_layer_deps_modal(projectId, layer, dependencies, successAdd) {
31 } 42 }
32 $('#dependencies_list').html(deplistHtml); 43 $('#dependencies_list').html(deplistHtml);
33 44
34 var selected = [layer.id]; 45 var selected = [];
46 /* -1 is a special dummy Id which we use when the layer isn't yet in the
47 * system, normally we would add the current layer to the selection.
48 */
49 if (layer.id != -1)
50 selected.push(layer.id);
51
35 var layer_link_list = "<a href='"+layer.url+"'>"+layer.name+"</a>"; 52 var layer_link_list = "<a href='"+layer.url+"'>"+layer.name+"</a>";
36 53
37 $("#dependencies_modal_form").submit(function (e) { 54 $("#dependencies_modal_form").submit(function (e) {
@@ -54,15 +71,20 @@ function show_layer_deps_modal(projectId, layer, dependencies, successAdd) {
54 71
55 $('#dependencies_modal').modal('hide'); 72 $('#dependencies_modal').modal('hide');
56 73
57 var editProjectUrl = "{% url 'xhr_projectedit' project.id %}"; 74 if (addToProject) {
58 libtoaster.editProject(editProjectUrl, projectId, { 'layerAdd': selected.join(",") }, function () { 75 var editProjectUrl = "{% url 'xhr_projectedit' project.id %}";
59 if (successAdd) { 76 libtoaster.editProject(editProjectUrl, projectId, { 'layerAdd': selected.join(",") }, function () {
60 successAdd(selected); 77 if (successAdd) {
61 } 78 successAdd(selected);
62 }, function () { 79 }
63 console.log ("Adding layers to project failed"); 80 }, function () {
64 }); 81 console.log ("Adding layers to project failed");
82 });
83 } else {
84 successAdd(selected);
85 }
65 }); 86 });
87
66 $('#dependencies_modal').modal('show'); 88 $('#dependencies_modal').modal('show');
67} 89}
68</script> 90</script>
diff --git a/bitbake/lib/toaster/toastergui/views.py b/bitbake/lib/toaster/toastergui/views.py
index ec055d392a..dd430805b1 100755
--- a/bitbake/lib/toaster/toastergui/views.py
+++ b/bitbake/lib/toaster/toastergui/views.py
@@ -2253,6 +2253,8 @@ if toastermain.settings.MANAGED:
2253 not request.POST.has_key('project_id')): 2253 not request.POST.has_key('project_id')):
2254 return HttpResponse(jsonfilter({"error": "Missing parameters; requires vcs_url, name, git_ref and project_id"}), content_type = "application/json") 2254 return HttpResponse(jsonfilter({"error": "Missing parameters; requires vcs_url, name, git_ref and project_id"}), content_type = "application/json")
2255 2255
2256 layers_added = [];
2257
2256 # Rudimentary check for any possible html tags 2258 # Rudimentary check for any possible html tags
2257 if "<" in request.POST: 2259 if "<" in request.POST:
2258 return HttpResponse(jsonfilter({"error": "Invalid character <"}), content_type = "application/json") 2260 return HttpResponse(jsonfilter({"error": "Invalid character <"}), content_type = "application/json")
@@ -2315,9 +2317,12 @@ if toastermain.settings.MANAGED:
2315 # if the project now contains the exact 2317 # if the project now contains the exact
2316 # dependency already (like modified on another page) 2318 # dependency already (like modified on another page)
2317 try: 2319 try:
2318 ProjectLayer.objects.get_or_create(layercommit=layer_dep_obj, project=prj) 2320 prj_layer, prj_layer_created = ProjectLayer.objects.get_or_create(layercommit=layer_dep_obj, project=prj)
2319 except: 2321 except:
2320 pass 2322 continue
2323
2324 if prj_layer_created:
2325 layers_added.append(Layer.objects.get(id=layer_dep_obj.layer_id).name)
2321 2326
2322 2327
2323 # If an old layer version exists in our project then remove it 2328 # If an old layer version exists in our project then remove it
@@ -2337,7 +2342,7 @@ if toastermain.settings.MANAGED:
2337 return HttpResponse(jsonfilter({"error": "Uncaught error: Could not create layer version"}), content_type = "application/json") 2342 return HttpResponse(jsonfilter({"error": "Uncaught error: Could not create layer version"}), content_type = "application/json")
2338 2343
2339 2344
2340 return HttpResponse(jsonfilter({"error": "ok"}), content_type = "application/json") 2345 return HttpResponse(jsonfilter({"error": "ok", "layers_added": layers_added}), content_type = "application/json")
2341 2346
2342 2347
2343 2348