From c6677c229a05e8652bcaaf8264160c81c1f5dc25 Mon Sep 17 00:00:00 2001 From: Rob Cresswell Date: Wed, 3 Jun 2015 15:11:42 +0100 Subject: [PATCH] JSCS Cleanup - tech-debt and auth JSCS cleanup for files in: - horizon/static/auth - horizon/static/framework/util/tech-debt/ - openstack_dashboard/static/dashboard/tech-debt/ NOTE: These files were previously in horizon/static/dashboard-app, but were moved between patches, causing the seemingly random selection of cleanups Change-Id: I63c3c641bf42152d8ff99702078d06df22812555 Partially-Implements: blueprint jscs-cleanup --- .../auth/login/login-finder.directive.js | 43 +++++++------ horizon/static/auth/login/login.spec.js | 62 +++++++++---------- .../util/tech-debt/helper-functions.js | 12 ++-- .../util/tech-debt/helper-functions.spec.js | 4 +- .../util/tech-debt/image-file-on-change.js | 31 +++++----- .../modal-form-update-metadata-ctrl.js | 6 +- .../util/tech-debt/tech-debt.module.js | 2 +- openstack_dashboard/enabled/_10_project.py | 2 +- openstack_dashboard/enabled/_20_admin.py | 4 +- .../tech-debt/image-form-controller.js | 18 ------ .../dashboard/tech-debt/image-form-ctrl.js | 17 +++++ ...espace-controller.js => namespace-ctrl.js} | 3 +- 12 files changed, 102 insertions(+), 102 deletions(-) delete mode 100644 openstack_dashboard/static/dashboard/tech-debt/image-form-controller.js create mode 100644 openstack_dashboard/static/dashboard/tech-debt/image-form-ctrl.js rename openstack_dashboard/static/dashboard/tech-debt/{namespace-controller.js => namespace-ctrl.js} (86%) diff --git a/horizon/static/auth/login/login-finder.directive.js b/horizon/static/auth/login/login-finder.directive.js index 2ac21631da..54d84621c6 100644 --- a/horizon/static/auth/login/login-finder.directive.js +++ b/horizon/static/auth/login/login-finder.directive.js @@ -16,7 +16,8 @@ (function() { 'use strict'; - angular.module('horizon.auth.login') + angular + .module('horizon.auth.login') /** * @ngdoc hzLoginFinder * @description @@ -31,29 +32,33 @@ restrict: 'A', link: function(scope, element) { - // test code does not have access to document - // so we are restricted to search through the element + /** + * Test code does not have access to document, + * so we are restricted to search through the element + */ var authType = element.find('#id_auth_type'); var userInput = element.find("#id_username").parents('.form-group'); var passwordInput = element.find("#id_password").parents('.form-group'); var domainInput = element.find('#id_domain').parents('form-group'); var regionInput = element.find('#id_region').parents('form-group'); - // helptext exists outside of element - // we have to traverse one node up + /** + * `helpText` exists outside of element, + * so we have to traverse one node up + */ var helpText = element.parent().find('#help_text'); helpText.hide(); - // update the visuals - // when user selects item from dropdown + // Update the visuals when user selects item from dropdown function onChange() { $timeout(function() { - // if type is credential - // show the username and password fields - // and domain and region if applicable + /** + * If auth_type is 'credential', show the username and password fields, + * and domain and region if applicable + */ scope.auth_type = authType.val(); - switch(scope.auth_type) { + switch (scope.auth_type) { case 'credentials': userInput.show(); passwordInput.show(); @@ -66,26 +71,24 @@ domainInput.hide(); regionInput.hide(); } - }); // end of timeout } // end of onChange - // if authType field exists - // then websso was enabled + // If authType field exists then websso was enabled if (authType.length > 0) { - // programmatically insert help text after dropdown - // this is the only way to do it since template is - // generated server side via form_fields + /** + * Programmatically insert help text after dropdown. + * This is the only way to do it since template is generated server side, + * via form_fields + */ authType.after(helpText); helpText.show(); - // trigger the onChange on first load - // so that initial choice is auto-selected + // Trigger the onChange on first load so that initial choice is auto-selected onChange(); authType.change(onChange); } - } // end of link }; // end of return }); // end of directive diff --git a/horizon/static/auth/login/login.spec.js b/horizon/static/auth/login/login.spec.js index 7e1f6dbb6f..f1901b7b80 100644 --- a/horizon/static/auth/login/login.spec.js +++ b/horizon/static/auth/login/login.spec.js @@ -14,32 +14,30 @@ * under the License. */ -(function(){ +(function() { 'use strict'; - describe('hzLoginCtrl', function(){ - + describe('hzLoginCtrl', function() { var $controller; beforeEach(module('horizon.auth.login')); - beforeEach(inject(function(_$controller_){ + beforeEach(inject(function(_$controller_) { $controller = _$controller_; })); - describe('$scope.auth_type', function(){ - it('should initialize to credentials', function(){ + describe('$scope.auth_type', function() { + it('should initialize to credentials', function() { var scope = {}; $controller('hzLoginCtrl', { $scope: scope }); expect(scope.auth_type).toEqual('credentials'); }); }); - }); - describe('hzLoginFinder', function(){ + describe('hzLoginFinder', function() { var $compile, $rootScope, $timeout; - var websso_markup = + var webssoMarkup = '
' + '

Some help text.

' + '
' + @@ -54,7 +52,7 @@ '
' + '
'; - var regular_markup = + var regularMarkup = '
' + '

Some help text.

' + '
' + @@ -64,7 +62,7 @@ ''; beforeEach(module('horizon.auth.login')); - beforeEach(inject(function(_$compile_, _$rootScope_, _$timeout_){ + beforeEach(inject(function(_$compile_, _$rootScope_, _$timeout_) { $compile = _$compile_; $rootScope = _$rootScope_; $timeout = _$timeout_; @@ -73,14 +71,14 @@ // jquery show is not consistent across different browsers // on FF, it is 'block' while on chrome it is 'inline' // to reconcile this difference, we need a custom matcher - toBeVisible: function(){ + toBeVisible: function() { return { - compare: function(actual){ + compare: function(actual) { var pass = (actual.css('display') !== 'none'); var result = { pass: pass, - message: pass? - 'Expected element to be visible': + message: pass ? + 'Expected element to be visible' : 'Expected element to be visible, but it is hidden' }; return result; @@ -90,14 +88,13 @@ }); })); - describe('when websso is not enabled', function(){ - + describe('when websso is not enabled', function() { var element, helpText, authType, userInput, passwordInput; - beforeEach(function(){ - element = $compile(regular_markup)($rootScope); + beforeEach(function() { + element = $compile(regularMarkup)($rootScope); authType = element.find('#id_auth_type'); userInput = element.find("#id_username").parents('.form-group'); passwordInput = element.find("#id_password").parents('.form-group'); @@ -105,29 +102,28 @@ $rootScope.$digest(); }); - it('should not contain auth_type select input', function(){ + it('should not contain auth_type select input', function() { expect(authType.length).toEqual(0); }); - it('should hide help text', function(){ + it('should hide help text', function() { expect(helpText).not.toBeVisible(); }); - it('should show username and password inputs', function(){ + it('should show username and password inputs', function() { expect(userInput).toBeVisible(); expect(passwordInput).toBeVisible(); }); - }); - describe('when websso is enabled', function(){ + describe('when websso is enabled', function() { var element, helpText, authType, userInput, passwordInput; - beforeEach(function(){ - element = $compile(websso_markup)($rootScope); + beforeEach(function() { + element = $compile(webssoMarkup)($rootScope); authType = element.find('#id_auth_type'); userInput = element.find("#id_username").parents('.form-group'); passwordInput = element.find("#id_password").parents('.form-group'); @@ -135,32 +131,30 @@ $rootScope.$digest(); }); - it('should contain auth_type select input', function(){ + it('should contain auth_type select input', function() { expect(authType.length).toEqual(1); }); - it('should show help text below auth_type', function(){ + it('should show help text below auth_type', function() { expect(authType.next().get(0)).toEqual(helpText.get(0)); }); - it('should show help text', function(){ + it('should show help text', function() { expect(helpText).toBeVisible(); }); - it('should show username and password inputs', function(){ + it('should show username and password inputs', function() { expect(userInput).toBeVisible(); expect(passwordInput).toBeVisible(); }); - it('should hide username and password when user picks oidc', function(){ + it('should hide username and password when user picks oidc', function() { authType.val('oidc'); authType.change(); $timeout.flush(); expect(userInput).not.toBeVisible(); expect(passwordInput).not.toBeVisible(); }); - }); - }); -})(); \ No newline at end of file +})(); diff --git a/horizon/static/framework/util/tech-debt/helper-functions.js b/horizon/static/framework/util/tech-debt/helper-functions.js index 28d5cfd725..ee8589da64 100644 --- a/horizon/static/framework/util/tech-debt/helper-functions.js +++ b/horizon/static/framework/util/tech-debt/helper-functions.js @@ -1,11 +1,11 @@ (function () { 'use strict'; - angular.module('horizon.framework.util.tech-debt') + angular + .module('horizon.framework.util.tech-debt') .service('horizon.framework.util.tech-debt.helper-functions', utils); - // An example of using the John Papa recommended $inject instead of in-line - // array syntax + // An example of using the John Papa recommended $inject instead of in-line array syntax utils.$inject = [ 'horizon.dashboard-app.conf', '$log', @@ -65,9 +65,7 @@ Compilation fails when it could not find a directive, fails silently on this, it is an angular behaviour. */ - - }, - + } }; } -}()); \ No newline at end of file +}()); diff --git a/horizon/static/framework/util/tech-debt/helper-functions.spec.js b/horizon/static/framework/util/tech-debt/helper-functions.spec.js index bf23259d91..0c6b1f333d 100644 --- a/horizon/static/framework/util/tech-debt/helper-functions.spec.js +++ b/horizon/static/framework/util/tech-debt/helper-functions.spec.js @@ -92,7 +92,7 @@ toBe(string); }); - it('should add an ellipsis if needed ', function () { + it('should add an ellipsis if needed', function () { expect(hzUtils.truncate(string, 15, true)). toBe(string.slice(0, 12) + ellipsis); @@ -116,7 +116,7 @@ spyOn(rootScope, '$apply'); }); - it('should call a compile and apply ', function () { + it('should call a compile and apply', function () { hzUtils.loadAngular(element); //checks the use of apply function expect(rootScope.$apply).toHaveBeenCalled(); diff --git a/horizon/static/framework/util/tech-debt/image-file-on-change.js b/horizon/static/framework/util/tech-debt/image-file-on-change.js index daa02d7b61..dae0eed4ef 100644 --- a/horizon/static/framework/util/tech-debt/image-file-on-change.js +++ b/horizon/static/framework/util/tech-debt/image-file-on-change.js @@ -1,18 +1,21 @@ (function () { 'use strict'; - angular.module('horizon.framework.util.tech-debt') - .directive('imageFileOnChange', function () { - return { - require: 'ngModel', - restrict: 'A', - link: function ($scope, element, attrs, ngModel) { - element.bind('change', function (event) { - var files = event.target.files, file = files[0]; - ngModel.$setViewValue(file); - $scope.$apply(); - }); - } - }; - }); + angular + .module('horizon.framework.util.tech-debt') + + .directive('imageFileOnChange', function () { + return { + require: 'ngModel', + restrict: 'A', + link: function ($scope, element, attrs, ngModel) { + element.bind('change', function (event) { + var files = event.target.files; + var file = files[0]; + ngModel.$setViewValue(file); + $scope.$apply(); + }); + } + }; + }); }()); diff --git a/horizon/static/framework/util/tech-debt/modal-form-update-metadata-ctrl.js b/horizon/static/framework/util/tech-debt/modal-form-update-metadata-ctrl.js index 2139516505..5d868369cc 100644 --- a/horizon/static/framework/util/tech-debt/modal-form-update-metadata-ctrl.js +++ b/horizon/static/framework/util/tech-debt/modal-form-update-metadata-ctrl.js @@ -1,6 +1,8 @@ (function () { 'use strict'; - angular.module('horizon.framework.util.tech-debt') + + angular + .module('horizon.framework.util.tech-debt') .controller('hzModalFormUpdateMetadataCtrl', [ '$scope', '$window', function ($scope, $window) { @@ -20,4 +22,4 @@ }; } ]); -}()); \ No newline at end of file +}()); diff --git a/horizon/static/framework/util/tech-debt/tech-debt.module.js b/horizon/static/framework/util/tech-debt/tech-debt.module.js index 1d973e7927..ed2d103981 100644 --- a/horizon/static/framework/util/tech-debt/tech-debt.module.js +++ b/horizon/static/framework/util/tech-debt/tech-debt.module.js @@ -3,4 +3,4 @@ angular.module('horizon.framework.util.tech-debt', []); -}()); \ No newline at end of file +}()); diff --git a/openstack_dashboard/enabled/_10_project.py b/openstack_dashboard/enabled/_10_project.py index c5ab9ef407..be3200c0b0 100644 --- a/openstack_dashboard/enabled/_10_project.py +++ b/openstack_dashboard/enabled/_10_project.py @@ -41,7 +41,7 @@ ADD_JS_FILES = [ LAUNCH_INST + 'configuration/load-edit.js', 'dashboard/tech-debt/tech-debt.module.js', - 'dashboard/tech-debt/image-form-controller.js', + 'dashboard/tech-debt/image-form-ctrl.js', ] ADD_JS_SPEC_FILES = [ diff --git a/openstack_dashboard/enabled/_20_admin.py b/openstack_dashboard/enabled/_20_admin.py index 4f9676634c..3413b41c0e 100644 --- a/openstack_dashboard/enabled/_20_admin.py +++ b/openstack_dashboard/enabled/_20_admin.py @@ -22,6 +22,6 @@ ADD_INSTALLED_APPS = [ ADD_JS_FILES = [ 'dashboard/tech-debt/tech-debt.module.js', - 'dashboard/tech-debt/namespace-controller.js', - 'dashboard/tech-debt/image-form-controller.js', + 'dashboard/tech-debt/namespace-ctrl.js', + 'dashboard/tech-debt/image-form-ctrl.js', ] diff --git a/openstack_dashboard/static/dashboard/tech-debt/image-form-controller.js b/openstack_dashboard/static/dashboard/tech-debt/image-form-controller.js deleted file mode 100644 index d230816bd3..0000000000 --- a/openstack_dashboard/static/dashboard/tech-debt/image-form-controller.js +++ /dev/null @@ -1,18 +0,0 @@ -(function () { - 'use strict'; - - angular.module('hz.dashboard.tech-debt') - .controller('ImageFormCtrl', ['$scope', function ($scope) { - $scope.selectImageFormat = function (path) { - if (!path) { return; } - var format = path.substr(path.lastIndexOf(".") + 1) - .toLowerCase().replace(/[^a-z0-9]+/gi, ""); - if ($('#id_disk_format').find('[value=' + format + ']').length !== 0) { - $scope.diskFormat = format; - } else { - $scope.diskFormat = ""; - } - }; - }]); - -}()); diff --git a/openstack_dashboard/static/dashboard/tech-debt/image-form-ctrl.js b/openstack_dashboard/static/dashboard/tech-debt/image-form-ctrl.js new file mode 100644 index 0000000000..6904ff3aaf --- /dev/null +++ b/openstack_dashboard/static/dashboard/tech-debt/image-form-ctrl.js @@ -0,0 +1,17 @@ +(function () { + 'use strict'; + angular + .module('hz.dashboard.tech-debt') + .controller('ImageFormCtrl', ['$scope', function ($scope) { + $scope.selectImageFormat = function (path) { + if (!path) { return; } + var format = path.substr(path.lastIndexOf(".") + 1) + .toLowerCase().replace(/[^a-z0-9]+/gi, ""); + if ($('#id_disk_format').find('[value=' + format + ']').length !== 0) { + $scope.diskFormat = format; + } else { + $scope.diskFormat = ""; + } + }; + }]); +}()); diff --git a/openstack_dashboard/static/dashboard/tech-debt/namespace-controller.js b/openstack_dashboard/static/dashboard/tech-debt/namespace-ctrl.js similarity index 86% rename from openstack_dashboard/static/dashboard/tech-debt/namespace-controller.js rename to openstack_dashboard/static/dashboard/tech-debt/namespace-ctrl.js index 5572b5c19c..2728abb95d 100644 --- a/openstack_dashboard/static/dashboard/tech-debt/namespace-controller.js +++ b/openstack_dashboard/static/dashboard/tech-debt/namespace-ctrl.js @@ -1,6 +1,7 @@ (function () { 'use strict'; - angular.module('hz.dashboard.tech-debt') + angular + .module('hz.dashboard.tech-debt') .controller('hzNamespaceResourceTypeFormController', function($scope, $window) { $scope.resource_types = $window.resource_types;