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:
parent
729c36c381
commit
c6677c229a
@ -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
|
||||
|
@ -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 =
|
||||
'<form>' +
|
||||
'<p id="help_text">Some help text.</p>' +
|
||||
'<fieldset hz-login-finder>' +
|
||||
@ -54,7 +52,7 @@
|
||||
'</fieldset>' +
|
||||
'</form>';
|
||||
|
||||
var regular_markup =
|
||||
var regularMarkup =
|
||||
'<form>' +
|
||||
'<p id="help_text">Some help text.</p>' +
|
||||
'<fieldset hz-login-finder>' +
|
||||
@ -64,7 +62,7 @@
|
||||
'</form>';
|
||||
|
||||
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();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
})();
|
||||
})();
|
||||
|
@ -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.
|
||||
*/
|
||||
|
||||
},
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
}());
|
||||
}());
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
||||
}());
|
||||
|
@ -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 @@
|
||||
};
|
||||
}
|
||||
]);
|
||||
}());
|
||||
}());
|
||||
|
@ -3,4 +3,4 @@
|
||||
|
||||
angular.module('horizon.framework.util.tech-debt', []);
|
||||
|
||||
}());
|
||||
}());
|
||||
|
@ -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 = [
|
||||
|
@ -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',
|
||||
]
|
||||
|
@ -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 = "";
|
||||
}
|
||||
};
|
||||
}]);
|
||||
|
||||
}());
|
@ -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 = "";
|
||||
}
|
||||
};
|
||||
}]);
|
||||
}());
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user