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
This commit is contained in:
Rob Cresswell
2015-06-03 15:11:42 +01:00
parent 729c36c381
commit c6677c229a
12 changed files with 102 additions and 102 deletions

View File

@@ -16,7 +16,8 @@
(function() { (function() {
'use strict'; 'use strict';
angular.module('horizon.auth.login') angular
.module('horizon.auth.login')
/** /**
* @ngdoc hzLoginFinder * @ngdoc hzLoginFinder
* @description * @description
@@ -31,29 +32,33 @@
restrict: 'A', restrict: 'A',
link: function(scope, element) { 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 authType = element.find('#id_auth_type');
var userInput = element.find("#id_username").parents('.form-group'); var userInput = element.find("#id_username").parents('.form-group');
var passwordInput = element.find("#id_password").parents('.form-group'); var passwordInput = element.find("#id_password").parents('.form-group');
var domainInput = element.find('#id_domain').parents('form-group'); var domainInput = element.find('#id_domain').parents('form-group');
var regionInput = element.find('#id_region').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'); var helpText = element.parent().find('#help_text');
helpText.hide(); helpText.hide();
// update the visuals // Update the visuals when user selects item from dropdown
// when user selects item from dropdown
function onChange() { function onChange() {
$timeout(function() { $timeout(function() {
// if type is credential /**
// show the username and password fields * If auth_type is 'credential', show the username and password fields,
// and domain and region if applicable * and domain and region if applicable
*/
scope.auth_type = authType.val(); scope.auth_type = authType.val();
switch(scope.auth_type) { switch (scope.auth_type) {
case 'credentials': case 'credentials':
userInput.show(); userInput.show();
passwordInput.show(); passwordInput.show();
@@ -66,26 +71,24 @@
domainInput.hide(); domainInput.hide();
regionInput.hide(); regionInput.hide();
} }
}); // end of timeout }); // end of timeout
} // end of onChange } // end of onChange
// if authType field exists // If authType field exists then websso was enabled
// then websso was enabled
if (authType.length > 0) { if (authType.length > 0) {
// programmatically insert help text after dropdown /**
// this is the only way to do it since template is * Programmatically insert help text after dropdown.
// generated server side via form_fields * This is the only way to do it since template is generated server side,
* via form_fields
*/
authType.after(helpText); authType.after(helpText);
helpText.show(); helpText.show();
// trigger the onChange on first load // Trigger the onChange on first load so that initial choice is auto-selected
// so that initial choice is auto-selected
onChange(); onChange();
authType.change(onChange); authType.change(onChange);
} }
} // end of link } // end of link
}; // end of return }; // end of return
}); // end of directive }); // end of directive

View File

@@ -14,32 +14,30 @@
* under the License. * under the License.
*/ */
(function(){ (function() {
'use strict'; 'use strict';
describe('hzLoginCtrl', function(){ describe('hzLoginCtrl', function() {
var $controller; var $controller;
beforeEach(module('horizon.auth.login')); beforeEach(module('horizon.auth.login'));
beforeEach(inject(function(_$controller_){ beforeEach(inject(function(_$controller_) {
$controller = _$controller_; $controller = _$controller_;
})); }));
describe('$scope.auth_type', function(){ describe('$scope.auth_type', function() {
it('should initialize to credentials', function(){ it('should initialize to credentials', function() {
var scope = {}; var scope = {};
$controller('hzLoginCtrl', { $scope: scope }); $controller('hzLoginCtrl', { $scope: scope });
expect(scope.auth_type).toEqual('credentials'); expect(scope.auth_type).toEqual('credentials');
}); });
}); });
}); });
describe('hzLoginFinder', function(){ describe('hzLoginFinder', function() {
var $compile, $rootScope, $timeout; var $compile, $rootScope, $timeout;
var websso_markup = var webssoMarkup =
'<form>' + '<form>' +
'<p id="help_text">Some help text.</p>' + '<p id="help_text">Some help text.</p>' +
'<fieldset hz-login-finder>' + '<fieldset hz-login-finder>' +
@@ -54,7 +52,7 @@
'</fieldset>' + '</fieldset>' +
'</form>'; '</form>';
var regular_markup = var regularMarkup =
'<form>' + '<form>' +
'<p id="help_text">Some help text.</p>' + '<p id="help_text">Some help text.</p>' +
'<fieldset hz-login-finder>' + '<fieldset hz-login-finder>' +
@@ -64,7 +62,7 @@
'</form>'; '</form>';
beforeEach(module('horizon.auth.login')); beforeEach(module('horizon.auth.login'));
beforeEach(inject(function(_$compile_, _$rootScope_, _$timeout_){ beforeEach(inject(function(_$compile_, _$rootScope_, _$timeout_) {
$compile = _$compile_; $compile = _$compile_;
$rootScope = _$rootScope_; $rootScope = _$rootScope_;
$timeout = _$timeout_; $timeout = _$timeout_;
@@ -73,14 +71,14 @@
// jquery show is not consistent across different browsers // jquery show is not consistent across different browsers
// on FF, it is 'block' while on chrome it is 'inline' // on FF, it is 'block' while on chrome it is 'inline'
// to reconcile this difference, we need a custom matcher // to reconcile this difference, we need a custom matcher
toBeVisible: function(){ toBeVisible: function() {
return { return {
compare: function(actual){ compare: function(actual) {
var pass = (actual.css('display') !== 'none'); var pass = (actual.css('display') !== 'none');
var result = { var result = {
pass: pass, pass: pass,
message: pass? message: pass ?
'Expected element to be visible': 'Expected element to be visible' :
'Expected element to be visible, but it is hidden' 'Expected element to be visible, but it is hidden'
}; };
return result; return result;
@@ -90,14 +88,13 @@
}); });
})); }));
describe('when websso is not enabled', function(){ describe('when websso is not enabled', function() {
var element, var element,
helpText, authType, helpText, authType,
userInput, passwordInput; userInput, passwordInput;
beforeEach(function(){ beforeEach(function() {
element = $compile(regular_markup)($rootScope); element = $compile(regularMarkup)($rootScope);
authType = element.find('#id_auth_type'); authType = element.find('#id_auth_type');
userInput = element.find("#id_username").parents('.form-group'); userInput = element.find("#id_username").parents('.form-group');
passwordInput = element.find("#id_password").parents('.form-group'); passwordInput = element.find("#id_password").parents('.form-group');
@@ -105,29 +102,28 @@
$rootScope.$digest(); $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); expect(authType.length).toEqual(0);
}); });
it('should hide help text', function(){ it('should hide help text', function() {
expect(helpText).not.toBeVisible(); expect(helpText).not.toBeVisible();
}); });
it('should show username and password inputs', function(){ it('should show username and password inputs', function() {
expect(userInput).toBeVisible(); expect(userInput).toBeVisible();
expect(passwordInput).toBeVisible(); expect(passwordInput).toBeVisible();
}); });
}); });
describe('when websso is enabled', function(){ describe('when websso is enabled', function() {
var element, var element,
helpText, authType, helpText, authType,
userInput, passwordInput; userInput, passwordInput;
beforeEach(function(){ beforeEach(function() {
element = $compile(websso_markup)($rootScope); element = $compile(webssoMarkup)($rootScope);
authType = element.find('#id_auth_type'); authType = element.find('#id_auth_type');
userInput = element.find("#id_username").parents('.form-group'); userInput = element.find("#id_username").parents('.form-group');
passwordInput = element.find("#id_password").parents('.form-group'); passwordInput = element.find("#id_password").parents('.form-group');
@@ -135,32 +131,30 @@
$rootScope.$digest(); $rootScope.$digest();
}); });
it('should contain auth_type select input', function(){ it('should contain auth_type select input', function() {
expect(authType.length).toEqual(1); 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)); expect(authType.next().get(0)).toEqual(helpText.get(0));
}); });
it('should show help text', function(){ it('should show help text', function() {
expect(helpText).toBeVisible(); expect(helpText).toBeVisible();
}); });
it('should show username and password inputs', function(){ it('should show username and password inputs', function() {
expect(userInput).toBeVisible(); expect(userInput).toBeVisible();
expect(passwordInput).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.val('oidc');
authType.change(); authType.change();
$timeout.flush(); $timeout.flush();
expect(userInput).not.toBeVisible(); expect(userInput).not.toBeVisible();
expect(passwordInput).not.toBeVisible(); expect(passwordInput).not.toBeVisible();
}); });
}); });
}); });
})(); })();

View File

@@ -1,11 +1,11 @@
(function () { (function () {
'use strict'; '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); .service('horizon.framework.util.tech-debt.helper-functions', utils);
// An example of using the John Papa recommended $inject instead of in-line // An example of using the John Papa recommended $inject instead of in-line array syntax
// array syntax
utils.$inject = [ utils.$inject = [
'horizon.dashboard-app.conf', 'horizon.dashboard-app.conf',
'$log', '$log',
@@ -65,9 +65,7 @@
Compilation fails when it could not find a directive, Compilation fails when it could not find a directive,
fails silently on this, it is an angular behaviour. fails silently on this, it is an angular behaviour.
*/ */
}
},
}; };
} }
}()); }());

View File

@@ -92,7 +92,7 @@
toBe(string); toBe(string);
}); });
it('should add an ellipsis if needed ', function () { it('should add an ellipsis if needed', function () {
expect(hzUtils.truncate(string, 15, true)). expect(hzUtils.truncate(string, 15, true)).
toBe(string.slice(0, 12) + ellipsis); toBe(string.slice(0, 12) + ellipsis);
@@ -116,7 +116,7 @@
spyOn(rootScope, '$apply'); spyOn(rootScope, '$apply');
}); });
it('should call a compile and apply ', function () { it('should call a compile and apply', function () {
hzUtils.loadAngular(element); hzUtils.loadAngular(element);
//checks the use of apply function //checks the use of apply function
expect(rootScope.$apply).toHaveBeenCalled(); expect(rootScope.$apply).toHaveBeenCalled();

View File

@@ -1,6 +1,8 @@
(function () { (function () {
'use strict'; 'use strict';
angular.module('horizon.framework.util.tech-debt')
angular
.module('horizon.framework.util.tech-debt')
.directive('imageFileOnChange', function () { .directive('imageFileOnChange', function () {
return { return {
@@ -8,7 +10,8 @@
restrict: 'A', restrict: 'A',
link: function ($scope, element, attrs, ngModel) { link: function ($scope, element, attrs, ngModel) {
element.bind('change', function (event) { element.bind('change', function (event) {
var files = event.target.files, file = files[0]; var files = event.target.files;
var file = files[0];
ngModel.$setViewValue(file); ngModel.$setViewValue(file);
$scope.$apply(); $scope.$apply();
}); });

View File

@@ -1,6 +1,8 @@
(function () { (function () {
'use strict'; 'use strict';
angular.module('horizon.framework.util.tech-debt')
angular
.module('horizon.framework.util.tech-debt')
.controller('hzModalFormUpdateMetadataCtrl', [ .controller('hzModalFormUpdateMetadataCtrl', [
'$scope', '$window', '$scope', '$window',
function ($scope, $window) { function ($scope, $window) {

View File

@@ -41,7 +41,7 @@ ADD_JS_FILES = [
LAUNCH_INST + 'configuration/load-edit.js', LAUNCH_INST + 'configuration/load-edit.js',
'dashboard/tech-debt/tech-debt.module.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 = [ ADD_JS_SPEC_FILES = [

View File

@@ -22,6 +22,6 @@ ADD_INSTALLED_APPS = [
ADD_JS_FILES = [ ADD_JS_FILES = [
'dashboard/tech-debt/tech-debt.module.js', 'dashboard/tech-debt/tech-debt.module.js',
'dashboard/tech-debt/namespace-controller.js', 'dashboard/tech-debt/namespace-ctrl.js',
'dashboard/tech-debt/image-form-controller.js', 'dashboard/tech-debt/image-form-ctrl.js',
] ]

View File

@@ -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 = "";
}
};
}]);
}());

View File

@@ -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 = "";
}
};
}]);
}());

View File

@@ -1,6 +1,7 @@
(function () { (function () {
'use strict'; 'use strict';
angular.module('hz.dashboard.tech-debt') angular
.module('hz.dashboard.tech-debt')
.controller('hzNamespaceResourceTypeFormController', function($scope, $window) { .controller('hzNamespaceResourceTypeFormController', function($scope, $window) {
$scope.resource_types = $window.resource_types; $scope.resource_types = $window.resource_types;