summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/toastergui/static/js/projectapp.js
diff options
context:
space:
mode:
authorAlexandru DAMIAN <alexandru.damian@intel.com>2014-11-07 13:26:45 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2014-11-12 17:04:49 +0000
commit7b65fa9bbbee2843e10cf8b8ba8128912100a345 (patch)
tree7ef9b0d29756f4da2e4a3bb0faa660e469d9d883 /bitbake/lib/toaster/toastergui/static/js/projectapp.js
parentabf7551f60cd56129b9abc22730f45e336ece582 (diff)
downloadpoky-7b65fa9bbbee2843e10cf8b8ba8128912100a345.tar.gz
bitbake: toastergui: changes for the Project page, round 3 of reviews
This patch implements the round 3 of reviews for the Project page, including fixing the time display, fixing the build list display, with fade-in and fade-out animations, and various small layout fixes. [YOCTO #6587] [YOCTO #6731] (Bitbake rev: 09e3ba8f800a03de731b022543cae33a46be17ef) Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster/toastergui/static/js/projectapp.js')
-rw-r--r--bitbake/lib/toaster/toastergui/static/js/projectapp.js182
1 files changed, 141 insertions, 41 deletions
diff --git a/bitbake/lib/toaster/toastergui/static/js/projectapp.js b/bitbake/lib/toaster/toastergui/static/js/projectapp.js
index b347451e88..356b92fc5a 100644
--- a/bitbake/lib/toaster/toastergui/static/js/projectapp.js
+++ b/bitbake/lib/toaster/toastergui/static/js/projectapp.js
@@ -74,17 +74,34 @@ angular_formpost = function($httpProvider) {
74 * 74 *
75 * no return 75 * no return
76 */ 76 */
77function _diffArrays(oldArray, newArray, compareElements, onAdded, onDeleted ) { 77function _diffArrays(existingArray, newArray, compareElements, onAdded, onDeleted ) {
78 if (onDeleted !== undefined) { 78 var added = [];
79 oldArray.filter(function (e) { var found = 0; newArray.map(function (f) { if (compareElements(e, f)) {found = 1};}); return !found;}).map(onDeleted); 79 var removed = [];
80 newArray.forEach( function( newElement, newIndex, _newArray) {
81 var existingIndex = existingArray.findIndex(function ( existingElement, _existingIndex, _existingArray ) {
82 return compareElements(newElement, existingElement);
83 });
84 if (existingIndex < 0 && onAdded) { added.push(newElement); }
85 });
86 existingArray.forEach( function( existingElement, existingIndex, _existingArray) {
87 var newIndex = newArray.findIndex(function ( newElement, _newIndex, _newArray ) {
88 return compareElements(newElement, existingElement);
89 });
90 if (newIndex < 0 && onDeleted) { removed.push(existingElement); }
91 });
92
93 if (onAdded) {
94 added.map(onAdded);
80 } 95 }
81 if (onAdded !== undefined) { 96
82 newArray.filter(function (e) { var found = 0; oldArray.map(function (f) { if (compareElements(e, f)) {found = 1};}); return !found;}).map(onAdded); 97 if (onDeleted) {
98 removed.map(onDeleted);
83 } 99 }
100
84} 101}
85 102
86 103
87var projectApp = angular.module('project', ['ui.bootstrap', 'ngCookies'], angular_formpost); 104var projectApp = angular.module('project', ['ngCookies', 'ngAnimate', 'ui.bootstrap' ], angular_formpost);
88 105
89// modify the template tag markers to prevent conflicts with Django 106// modify the template tag markers to prevent conflicts with Django
90projectApp.config(function($interpolateProvider) { 107projectApp.config(function($interpolateProvider) {
@@ -111,7 +128,7 @@ projectApp.filter('timediff', function() {
111 128
112 129
113// main controller for the project page 130// main controller for the project page
114projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $location, $cookies, $q, $sce) { 131projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $location, $cookies, $q, $sce, $anchorScroll, $animate) {
115 132
116 $scope.getSuggestions = function(type, currentValue) { 133 $scope.getSuggestions = function(type, currentValue) {
117 var deffered = $q.defer(); 134 var deffered = $q.defer();
@@ -159,40 +176,65 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc
159 deffered.reject(_data.error); 176 deffered.reject(_data.error);
160 } 177 }
161 else { 178 else {
162 // TODO: update screen data if we have fields here
163 179
164 if (_data.builds !== undefined) { 180 if (_data.builds !== undefined) {
165 181 var toDelete = [];
166 var oldbuilds = $scope.builds; 182 // step 1 - delete entries not found
167 $scope.builds = _data.builds; 183 $scope.builds.forEach(function (elem) {
168 184 if (-1 == _data.builds.findIndex(function (elemX) { return elemX.id == elem.id && elemX.status == elem.status; })) {
169 // identify canceled builds here, so we can display them. 185 toDelete.push(elem);
170 _diffArrays(oldbuilds, $scope.builds, 186 }
171 function (e,f) { return e.id == f.id }, // compare 187 });
172 undefined, // added 188 toDelete.forEach(function (elem) {
173 function (e) { // deleted 189 $scope.builds.splice($scope.builds.indexOf(elem),1);
174 if (e.status == "deleted") return; 190 });
175 e.status = "deleted"; 191 // step 2 - merge new entries
176 for (var i = 0; i < $scope.builds.length; i++) { 192 _data.builds.forEach(function (elem) {
177 if ($scope.builds[i].status == "queued" && $scope.builds[i].id > e.id) 193 var found = false;
178 continue; 194 var i = 0;
179 $scope.builds.splice(i, 0, e); 195 for (i = 0 ; i < $scope.builds.length; i ++) {
180 break; 196 if ($scope.builds[i].id > elem.id) continue;
181 } 197 if ($scope.builds[i].id == elem.id) { found=true; break;}
182 }); 198 if ($scope.builds[i].id < elem.id) break;
199 }
200 if (!found) {
201 $scope.builds.splice(i, 0, elem);
202 }
203 });
183 204
184 } 205 }
185 if (_data.layers !== undefined) { 206 if (_data.layers !== undefined) {
186 var oldlayers = $scope.layers;
187 $scope.layers = _data.layers;
188 207
189 // show added/deleted layer notifications
190 var addedLayers = []; 208 var addedLayers = [];
191 var deletedLayers = []; 209 var deletedLayers = [];
192 _diffArrays( oldlayers, $scope.layers, function (e, f) { return e.id == f.id },
193 function (e) { console.log("new layer", e);addedLayers.push(e); },
194 function (e) { console.log("del layer", e);deletedLayers.push(e); });
195 210
211 // step 1 - delete entries not found
212 $scope.layers.forEach(function (elem) {
213 if (-1 == _data.layers.findIndex(function (elemX) { return elemX.id == elem.id && elemX.name == elem.name; })) {
214 deletedLayers.push(elem);
215 }
216 });
217 deletedLayers.forEach(function (elem) {
218 $scope.layers.splice($scope.layers.indexOf(elem),1);
219 });
220 // step 2 - merge new entries
221 _data.layers.forEach(function (elem) {
222 var found = false;
223 var i;
224 for (i = 0 ; i < $scope.layers.length; i ++) {
225 if ($scope.layers[i].orderid < elem.orderid) continue;
226 if ($scope.layers[i].orderid == elem.orderid) {
227 found = true; break;
228 }
229 if ($scope.layers[i].orderid > elem.orderid) break;
230 }
231 if (!found) {
232 $scope.layers.splice(i, 0, elem);
233 addedLayers.push(elem);
234 }
235 });
236
237 // step 3 - display alerts.
196 if (addedLayers.length > 0) { 238 if (addedLayers.length > 0) {
197 $scope.displayAlert($scope.zone2alerts, "You have added <b>"+addedLayers.length+"</b> layer" + ((addedLayers.length>1)?"s: ":": ") + addedLayers.map(function (e) { return "<a href=\""+e.layerdetailurl+"\">"+e.name+"</a>" }).join(", "), "alert-info"); 239 $scope.displayAlert($scope.zone2alerts, "You have added <b>"+addedLayers.length+"</b> layer" + ((addedLayers.length>1)?"s: ":": ") + addedLayers.map(function (e) { return "<a href=\""+e.layerdetailurl+"\">"+e.name+"</a>" }).join(", "), "alert-info");
198 } 240 }
@@ -253,7 +295,7 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc
253 } 295 }
254 296
255 $scope.targetNamedBuild = function(target) { 297 $scope.targetNamedBuild = function(target) {
256 if ($scope.targetName === undefined){ 298 if ($scope.targetName === undefined && $scope.targetName1 === undefined){
257 alert("No target defined, please type in a target name"); 299 alert("No target defined, please type in a target name");
258 return; 300 return;
259 } 301 }
@@ -263,17 +305,26 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc
263 $scope._makeXHRCall({ 305 $scope._makeXHRCall({
264 method: "POST", url: $scope.urls.xhr_build, 306 method: "POST", url: $scope.urls.xhr_build,
265 data : { 307 data : {
266 targets: $scope.targetName 308 targets: $scope.safeTargetName,
267 } 309 }
268 }).then(function (data) { 310 }).then(function (data) {
269 console.log("received ", data); 311 console.log("received ", data);
270 $scope.targetName = undefined; 312 $scope.targetName = undefined;
313 $scope.targetName1 = undefined;
314 $location.hash('buildslist');
315 // call $anchorScroll()
316 $anchorScroll();
271 }); 317 });
272 } 318 }
273 319
274 $scope.sanitizeTargetName = function() { 320 $scope.sanitizeTargetName = function() {
275 if (undefined === $scope.targetName) return; 321 $scope.safeTargetName = undefined;
276 $scope.targetName = $scope.targetName.replace(/\[.*\]/, '').trim(); 322 if (undefined === $scope.targetName) $scope.safeTargetName = $scope.targetName1;
323 if (undefined === $scope.targetName1) $scope.safeTargetName = $scope.targetName;
324
325 if (undefined === $scope.safeTargetName) return;
326
327 $scope.safeTargetName = $scope.safeTargetName.replace(/\[.*\]/, '').trim();
277 } 328 }
278 329
279 $scope.buildCancel = function(id) { 330 $scope.buildCancel = function(id) {
@@ -285,6 +336,16 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc
285 }); 336 });
286 } 337 }
287 338
339 $scope.buildDelete = function(id) {
340 $scope._makeXHRCall({
341 method: "POST", url: $scope.urls.xhr_build,
342 data: {
343 buildDelete: id,
344 }
345 });
346 }
347
348
288 $scope.onLayerSelect = function (item, model, label) { 349 $scope.onLayerSelect = function (item, model, label) {
289 $scope.layerAddId = item.id; 350 $scope.layerAddId = item.id;
290 } 351 }
@@ -413,6 +474,7 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc
413 console.log("edit with ", elementid); 474 console.log("edit with ", elementid);
414 var alertText = undefined; 475 var alertText = undefined;
415 var alertZone = undefined; 476 var alertZone = undefined;
477 var oldLayers = [];
416 switch(elementid) { 478 switch(elementid) {
417 case '#select-machine': 479 case '#select-machine':
418 alertText = "You have changed the machine to: <b>" + $scope.machineName + "</b>"; 480 alertText = "You have changed the machine to: <b>" + $scope.machineName + "</b>";
@@ -428,25 +490,61 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc
428 data['projectVersion'] = $scope.projectVersion; 490 data['projectVersion'] = $scope.projectVersion;
429 alertText = "You have changed the release to: "; 491 alertText = "You have changed the release to: ";
430 alertZone = $scope.zone3alerts; 492 alertZone = $scope.zone3alerts;
493 // save old layers
494 oldLayers = $scope.layers.slice(0);
431 break; 495 break;
432 default: 496 default:
433 throw "FIXME: implement conversion for element " + elementid; 497 throw "FIXME: implement conversion for element " + elementid;
434 } 498 }
435 499
436 console.log("calling edit with ", data);
437 $scope._makeXHRCall({ 500 $scope._makeXHRCall({
438 method: "POST", url: $scope.urls.xhr_edit, data: data, 501 method: "POST", url: $scope.urls.xhr_edit, data: data,
439 }).then( function () { 502 }).then( function (_data) {
440 $scope.toggle(elementid); 503 $scope.toggle(elementid);
441 if (data['projectVersion'] != undefined) { 504 if (data['projectVersion'] != undefined) {
442 alertText += "<b>" + $scope.project.release.name + "</b>"; 505 alertText += "<strong>" + $scope.project.release.desc + "</strong>. ";
506 }
507 if (elementid == '#change-project-version') {
508 // requirement https://bugzilla.yoctoproject.org/attachment.cgi?id=2229, notification for changed version to include layers
509 $scope.zone2alerts.forEach(function (e) { e.close() });
510 alertText += "This has caused the following changes in your project layers:<ul>"
511
512 if (_data.layers !== undefined) {
513 // show added/deleted layer notifications; scope.layers is already updated by this point.
514 var addedLayers = [];
515 var deletedLayers = [];
516 _diffArrays( oldLayers, $scope.layers, function (e, f) { return e.id == f.id },
517 function (e) {addedLayers.push(e); },
518 function (e) {deletedLayers.push(e); });
519
520 // some of the deleted layers are actually replaced (changed) layers
521 var changedLayers = [];
522 deletedLayers.forEach(function (e) {
523 if ( -1 < addedLayers.findIndex(function (f) { return f.name == e.name })) {
524 changedLayers.push(e);
525 }
526 });
527
528 changedLayers.forEach(function (e) {
529 deletedLayers.splice(deletedLayers.indexOf(e), 1);
530 });
531
532 if (addedLayers.length > 0) {
533 alertText += "<li><strong>"+addedLayers.length+"</strong> layer" + ((addedLayers.length>1)?"s changed: ":" changed: ") + addedLayers.map(function (e) { return "<a href=\""+e.layerdetailurl+"\">"+e.name+"</a>" }).join(", ") + "</li>";
534 }
535 if (deletedLayers.length > 0) {
536 alertText += "<li><strong>"+deletedLayers.length+"</strong> layer" + ((deletedLayers.length>1)?"s deleted: ":"deleted: ") + deletedLayers.map(function (e) { return "<a href=\""+e.layerdetailurl+"\">"+e.name+"</a>" }).join(", ") + "</li>";
537 }
538
539 }
540 alertText += "</ul>";
443 } 541 }
444 $scope.displayAlert(alertZone, alertText, "alert-info"); 542 $scope.displayAlert(alertZone, alertText, "alert-info");
445 }); 543 });
446 } 544 }
447 545
448 546
449 $scope.executeCommands = function() { 547 $scope.updateDisplayWithCommands = function() {
450 cmd = $location.path(); 548 cmd = $location.path();
451 549
452 function _cmdExecuteWithParam(param, f) { 550 function _cmdExecuteWithParam(param, f) {
@@ -524,7 +622,7 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc
524 // init code 622 // init code
525 // 623 //
526 $scope.init = function() { 624 $scope.init = function() {
527 $scope.pollHandle = $interval(function () { $scope._makeXHRCall({method: "GET", url: $scope.urls.xhr_edit, data: undefined});}, 4000, 0); 625 $scope.pollHandle = $interval(function () { $scope._makeXHRCall({method: "GET", url: $scope.urls.xhr_edit, data: undefined});}, 2000, 0);
528 } 626 }
529 627
530 $scope.init(); 628 $scope.init();
@@ -539,6 +637,8 @@ function test_diff_arrays() {
539 _diffArrays([1,2,3], [2,3,4], function(e,f) { return e==f; }, function(e) {console.log("added", e)}, function(e) {console.log("deleted", e);}) 637 _diffArrays([1,2,3], [2,3,4], function(e,f) { return e==f; }, function(e) {console.log("added", e)}, function(e) {console.log("deleted", e);})
540} 638}
541 639
640// test_diff_arrays();
641
542var s = undefined; 642var s = undefined;
543 643
544function test_set_alert(text) { 644function test_set_alert(text) {