From f5edfce70d089f47ce440701266122f814b4a94e Mon Sep 17 00:00:00 2001 From: Alexandru DAMIAN Date: Mon, 9 Mar 2015 13:03:39 +0000 Subject: [PATCH] bitbake: toaster: projectapp.js - clear up jslint warnings This patch clears up jslint warnings for the project app, and improves file readability. (Bitbake rev: 10e58867a0231c8039f6d2523b885b9ca7c7dff6) Signed-off-by: Alexandru DAMIAN Signed-off-by: Richard Purdie --- .../toastergui/static/js/projectapp.js | 181 ++++++++++-------- 1 file changed, 100 insertions(+), 81 deletions(-) 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:
    " + $scope.zone2alerts.forEach(function (e) { e.close(); }); + alertText += "This has caused the following changes in your project layers:
      "; // warnings - this is executed AFTER the generic XHRCall handling is done; at this point, @@ -606,14 +616,14 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc // show added/deleted layer notifications; scope.layers is already updated by this point. var addedLayers = []; var deletedLayers = []; - _diffArrays( oldLayers, $scope.layers, function (e, f) { return e.id == f.id }, + _diffArrays( oldLayers, $scope.layers, function (e, f) { return e.id == f.id; }, function (e) {addedLayers.push(e); }, function (e) {deletedLayers.push(e); }); // some of the deleted layers are actually replaced (changed) layers var changedLayers = []; deletedLayers.forEach(function (e) { - if ( -1 < addedLayers.findIndex(function (f) { return f.name == e.name })) { + if ( -1 < addedLayers.findIndex(function (f) { return f.name == e.name; })) { changedLayers.push(e); } }); @@ -623,10 +633,10 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc }); if (addedLayers.length > 0) { - alertText += "
    • "+addedLayers.length+" layer" + ((addedLayers.length>1)?"s changed: ":" changed: ") + addedLayers.map(function (e) { return ""+e.name+"" }).join(", ") + "
    • "; + alertText += "
    • "+addedLayers.length+" layer" + ((addedLayers.length>1)?"s changed: ":" changed: ") + addedLayers.map(function (e) { return ""+e.name+""; }).join(", ") + "
    • "; } if (deletedLayers.length > 0) { - alertText += "
    • "+deletedLayers.length+" layer" + ((deletedLayers.length>1)?"s deleted: ":"deleted: ") + deletedLayers.map(function (e) { return ""+e.name+"" }).join(", ") + "
    • "; + alertText += "
    • "+deletedLayers.length+" layer" + ((deletedLayers.length>1)?"s deleted: ":"deleted: ") + deletedLayers.map(function (e) { return ""+e.name+""; }).join(", ") + "
    • "; } } @@ -634,7 +644,7 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc } $scope.displayAlert(alertZone, alertText, "alert-info"); }); - } + }; /** @@ -645,15 +655,15 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc cmd = $location.path(); function _cmdExecuteWithParam(param, f) { - if (cmd.indexOf(param)==0) { + if (cmd.indexOf(param) === 0) { if (cmd.indexOf("=") > -1) { var parameter = cmd.split("=", 2)[1]; - if (parameter != undefined && parameter.length > 0) { + if (parameter !== undefined && parameter.length > 0) { f(parameter); } } else { f(); - }; + } } } @@ -674,14 +684,14 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc }); }); - _cmdExecuteWithParam("/layerimported", function (layer) { + _cmdExecuteWithParam("/layerimported", function () { var imported = $cookieStore.get("layer-imported-alert"); var text; if (!imported) return; - if (imported.deps_added.length == 0) { + if (imported.deps_added.length === 0) { text = "You have imported "+imported.imported_layer.name+ " and added it to your project."; @@ -694,7 +704,7 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc links +=""+item.name+ ""; /*If we're at the last element we don't want the trailing comma */ - if (imported.deps_added[index+1] != undefined) + if (imported.deps_added[index+1] !== undefined) links += ", "; }); @@ -731,7 +741,7 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc $scope.layerAdd(); }); }); - } + }; /** * Utility function to display an alert to the user @@ -740,16 +750,21 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc $scope.displayAlert = function(zone, text, type) { if (zone.maxid === undefined) { zone.maxid = 0; } var crtid = zone.maxid ++; - angular.forEach(zone, function (o) { o.close() }); + angular.forEach(zone, function (o) { o.close(); }); o = { id: crtid, text: text, type: type, close: function() { - zone.splice((function(id){ for (var i = 0; i < zone.length; i++) if (id == zone[i].id) { return i}; return undefined;})(crtid), 1); + zone.splice((function(id) { + for (var i = 0; i < zone.length; i++) + if (id == zone[i].id) + { return i; } + return undefined; + }) (crtid), 1); }, - } + }; zone.push(o); return o; - } + }; /** * Toggles display items between label and input box (the edit pencil icon) on selected settings in project page @@ -762,7 +777,7 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc angular.element(id).toggle(); angular.element(id+"-opposite").toggle(); - } + }; /** * Functionality related to "Most build targets" @@ -770,44 +785,48 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc $scope.enableBuildSelectedTargets = function () { var keys = Object.keys($scope.mostBuiltTargets); - keys = keys.filter(function (e) { if ($scope.mostBuiltTargets[e]) return e }); - return keys.length == 0; - } + keys = keys.filter(function (e) { if ($scope.mostBuiltTargets[e]) return e; }); + return keys.length === 0; + }; $scope.buildSelectedTargets = function () { var keys = Object.keys($scope.mostBuiltTargets); - keys = keys.filter(function (e) { if ($scope.mostBuiltTargets[e]) return e }); + keys = keys.filter(function (e) { if ($scope.mostBuiltTargets[e]) return e; }); $scope.buildTargetList(keys); for (var i = 0; i < keys.length; i++) { $scope.mostBuiltTargets[keys[i]] = 0; } - } + }; /** * Helper function to deal with error string recognition and manipulation */ $scope.getTargetNameFromErrorMsg = function (msg) { - targets = msg.split(" ").splice(2).map(function (v) { return v.replace(/'/g, '')}) - return targets; - } + return msg.split(" ").splice(2).map(function (v) { return v.replace(/'/g, ''); }); + }; + + /** + * Utility function to retrieve which layers can be added to the project if the target was not + * provided by any of the existing project layers + */ $scope.fetchLayersForTargets = function () { $scope.builds.forEach(function (buildrequest) { buildrequest.errors.forEach(function (error) { - if (error.msg.indexOf("Nothin") == 0) { + if (error.msg.indexOf("Nothin") === 0) { $scope.getTargetNameFromErrorMsg(error.msg).forEach(function (target) { if ($scope.layersForTargets[target] === undefined) $scope.getAutocompleteSuggestions("layers4target", target).then( function (list) { $scope.layersForTargets[target] = list; - }) - }) + }); + }); } - }) - }) - } + }); + }); + }; /** @@ -819,16 +838,16 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc $scope.layersForTargets = {}; $scope.fetchLayersForTargets(); $scope.pollHandle = $interval(function () { $scope._makeXHRCall({method: "GET", url: $scope.urls.xhr_edit, data: undefined});}, 2000, 0); - } + }; }); -var s = undefined; +var _testing_scope; function test_set_alert(text) { - s = angular.element("div#main").scope(); - s.displayAlert(s.zone3alerts, text); - console.warn("TRC8: zone3alerts", s.zone3alerts); - s.$digest(); + _testing_scope = angular.element("div#main").scope(); + _testing_scope.displayAlert(_testing_scope.zone3alerts, text); + console.warn("TRC8: zone3alerts", _testing_scope.zone3alerts); + _testing_scope.$digest(); }