diff --git a/bitbake/lib/toaster/toastergui/static/js/projectapp.js b/bitbake/lib/toaster/toastergui/static/js/projectapp.js index df811fb4a3..82db10781c 100644 --- a/bitbake/lib/toaster/toastergui/static/js/projectapp.js +++ b/bitbake/lib/toaster/toastergui/static/js/projectapp.js @@ -61,7 +61,7 @@ angular_formpost = function($httpProvider) { $httpProvider.defaults.transformRequest = [function(data) { return angular.isObject(data) && String(data) !== '[object File]' ? param(data) : data; }]; -} +}; /** @@ -77,14 +77,14 @@ angular_formpost = function($httpProvider) { function _diffArrays(existingArray, newArray, compareElements, onAdded, onDeleted ) { var added = []; var removed = []; - newArray.forEach( function( newElement, newIndex, _newArray) { - var existingIndex = existingArray.findIndex(function ( existingElement, _existingIndex, _existingArray ) { + newArray.forEach( function( newElement ) { + var existingIndex = existingArray.findIndex(function ( existingElement ) { return compareElements(newElement, existingElement); }); if (existingIndex < 0 && onAdded) { added.push(newElement); } }); - existingArray.forEach( function( existingElement, existingIndex, _existingArray) { - var newIndex = newArray.findIndex(function ( newElement, _newIndex, _newArray ) { + existingArray.forEach( function( existingElement ) { + var newIndex = newArray.findIndex(function ( newElement ) { return compareElements(newElement, existingElement); }); if (newIndex < 0 && onDeleted) { removed.push(existingElement); } @@ -108,7 +108,7 @@ if (Array.prototype.findIndex === undefined) { for ( i = 0; i < this.length; i++ ) if (callback(this[i], i, this)) return i; return -1; - } + }; } var projectApp = angular.module('project', ['ngCookies', 'ngAnimate', 'ui.bootstrap', 'ngRoute', 'ngSanitize'], angular_formpost); @@ -124,7 +124,7 @@ projectApp.config(function($interpolateProvider) { projectApp.filter('timediff', function() { return function(input) { function pad(j) { - if (parseInt(j) < 10) {return "0" + j} + if (parseInt(j) < 10) {return "0" + j;} return j; } seconds = parseInt(input); @@ -133,7 +133,7 @@ projectApp.filter('timediff', function() { hours = Math.floor(seconds / 3600); seconds = seconds - hours * 3600; return pad(hours) + ":" + pad(minutes) + ":" + pad(seconds); - } + }; }); // add "time to future" eta that computes time from now to a point in the future @@ -143,7 +143,7 @@ projectApp.filter('toeta', function() { diff = (parseInt(input) - crtmiliseconds ) / 1000; console.log("Debug: future time ", input, "crt time", crtmiliseconds, ":", diff); return diff < 0 ? 300 : diff; - } + }; }); /** @@ -169,7 +169,7 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc }); return deffered.promise; - } + }; var inXHRcall = false; @@ -194,7 +194,7 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc } var deffered = $q.defer(); - if (undefined === callparams.headers) { callparams.headers = {} }; + if (undefined === callparams.headers) { callparams.headers = {}; } callparams.headers['X-CSRFToken'] = $cookies.csrftoken; $http(callparams).success(function(_data, _status, _headers, _config) { @@ -239,12 +239,14 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc // step 3 - display alerts. if (addedLayers.length > 0) { - $scope.displayAlert($scope.zone2alerts, "You have added "+addedLayers.length+" layer" + ((addedLayers.length>1)?"s: ":": ") + addedLayers.map(function (e) { return ""+e.name+"" }).join(", "), "alert-info"); + $scope.displayAlert($scope.zone2alerts, + "You have added "+addedLayers.length+" layer" + ((addedLayers.length>1)?"s: ":": ") + addedLayers.map(function (e) { return ""+e.name+""; }).join(", "), + "alert-info"); // invalidate error layer data based on current layers $scope.layersForTargets = {}; } if (deletedLayers.length > 0) { - $scope.displayAlert($scope.zone2alerts, "You have deleted "+deletedLayers.length+" layer" + ((deletedLayers.length>1)?"s: ":": ") + deletedLayers.map(function (e) { return ""+e.name+"" }).join(", "), "alert-info"); + $scope.displayAlert($scope.zone2alerts, "You have deleted "+deletedLayers.length+" layer" + ((deletedLayers.length>1)?"s: ":": ") + deletedLayers.map(function (e) { return ""+e.name+""; }).join(", "), "alert-info"); // invalidate error layer data based on current layers $scope.layersForTargets = {}; } @@ -323,9 +325,9 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc deffered.resolve(_data); } }).error(function(_data, _status, _headers, _config) { - if (_status == 0) { + if (_status === 0) { // the server has gone away - alert("The server is not responding. The application will terminate now") + alert("The server is not responding. The application will terminate now"); $interval.cancel($scope.pollHandle); } else { @@ -336,7 +338,7 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc }); return deffered.promise; - } + }; $scope.layeralert = undefined; /** @@ -344,33 +346,34 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc */ $scope.validateData = function () { - if ($scope.layers.length == 0) { + if ($scope.layers.length === 0) { $scope.layeralert = $scope.displayAlert($scope.zone1alerts, "You need to add some layers to this project. View all layers available in Toaster or import a layer"); } else { - if ($scope.layeralert != undefined) { + if ($scope.layeralert !== undefined) { $scope.layeralert.close(); $scope.layeralert = undefined; } } - } + }; $scope.buildExistingTarget = function(targets) { - $scope.buildTargetList(targets.map(function(v,i,a){return v.target})); - } + $scope.buildTargetList(targets.map(function(v){return v.target;})); + }; $scope.buildTargetList = function(targetlist) { var oldTargetName = $scope.targetName; $scope.targetName = targetlist.join(' '); $scope.buildNamedTarget(); $scope.targetName = oldTargetName; - } + }; - $scope.buildNamedTarget = function(target) { + $scope.buildNamedTarget = function() { if ($scope.targetName === undefined && $scope.targetName1 === undefined){ console.warn("No target defined, please type in a target name"); return; } + // this writes the $scope.safeTargetName variable $scope.sanitizeTargetName(); $scope._makeXHRCall({ @@ -379,6 +382,8 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc targets: $scope.safeTargetName, } }).then(function (data) { + // make sure nobody re-uses the current $safeTargetName + delete $scope.safeTargetName; console.warn("TRC3: received ", data); $scope.targetName = undefined; $scope.targetName1 = undefined; @@ -386,7 +391,7 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc // call $anchorScroll() $anchorScroll(); }); - } + }; $scope.sanitizeTargetName = function() { $scope.safeTargetName = undefined; @@ -396,7 +401,7 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc if (undefined === $scope.safeTargetName) return; $scope.safeTargetName = $scope.safeTargetName.replace(/\[.*\]/, '').trim(); - } + }; $scope.buildCancel = function(build) { $scope._makeXHRCall({ @@ -405,25 +410,25 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc buildCancel: build.id, } }).then( function () { - build['status'] = "deleted"; + build.status = "deleted"; $scope.canceledBuilds.push(build); }); - } + }; $scope.buildDelete = function(build) { $scope.canceledBuilds.splice($scope.canceledBuilds.indexOf(build), 1); - } + }; - $scope.onLayerSelect = function (item, model, label) { + $scope.onLayerSelect = function (item) { $scope.layerAddId = item.id; - } + }; $scope.layerAddById = function (id) { $scope.layerAddId = id; $scope.layerAdd(); - } + }; $scope.layerAdd = function() { @@ -439,7 +444,12 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc controller: function ($scope, $modalInstance, items, layerAddName) { $scope.items = items; $scope.layerAddName = layerAddName; - $scope.selectedItems = (function () { s = {}; for (var i = 0; i < items.length; i++) { s[items[i].id] = true; };return s; })(); + $scope.selectedItems = (function () { + s = {}; + for (var i = 0; i < items.length; i++) + { s[items[i].id] = true; } + return s; + })(); $scope.ok = function() { console.warn("TRC4: scope selected is ", $scope.selectedItems); @@ -490,7 +500,7 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc } } }); - } + }; $scope.layerDel = function(id) { $scope._makeXHRCall({ @@ -499,7 +509,7 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc layerDel: id, } }); - } + }; /** @@ -545,13 +555,13 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc } }); - modalInstance.result.then(function () { $scope.editProjectSettings(elementid)}); + modalInstance.result.then(function () { $scope.editProjectSettings(elementid); }); } else { $scope.editProjectSettings(elementid); } } }); - } + }; /** * Performs changes to project settings, and updates the user interface accordingly. @@ -560,23 +570,23 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc $scope.editProjectSettings = function(elementid) { var data = {}; console.warn("TRC7: editProjectSettings with ", elementid); - var alertText = undefined; - var alertZone = undefined; + var alertText; + var alertZone; var oldLayers = []; switch(elementid) { case '#select-machine': alertText = "You have changed the machine to: " + $scope.machineName + ""; alertZone = $scope.zone2alerts; - data['machineName'] = $scope.machineName; + data.machineName = $scope.machineName; break; case '#change-project-name': - data['projectName'] = $scope.projectName; + data.projectName = $scope.projectName; alertText = "You have changed the project name to: " + $scope.projectName + ""; alertZone = $scope.zone3alerts; break; case '#change-project-version': - data['projectVersion'] = $scope.projectVersion; + data.projectVersion = $scope.projectVersion; alertText = "You have changed the release to: "; alertZone = $scope.zone3alerts; // save old layers @@ -590,15 +600,15 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc method: "POST", url: $scope.urls.xhr_edit, data: data, }).then( function (_data) { $scope.toggle(elementid); - if (data['projectVersion'] != undefined) { + if (data.projectVersion !== undefined) { alertText += "" + $scope.project.release.desc + ". "; } if (elementid == '#change-project-version') { $scope.layersForTargets = {}; // invalidate error layers for the targets, since layers changed // requirement https://bugzilla.yoctoproject.org/attachment.cgi?id=2229, notification for changed version to include layers - $scope.zone2alerts.forEach(function (e) { e.close() }); - alertText += "This has caused the following changes in your project layers: