Merge "ngReorg - move dashboard-app to dashboard"

This commit is contained in:
Jenkins 2015-06-23 00:05:19 +00:00 committed by Gerrit Code Review
commit 9d4886e903
9 changed files with 92 additions and 154 deletions

View File

@ -66,9 +66,6 @@ module.exports = function(config) {
// from jasmine_tests.py; only those that are deps for others
'horizon/js/horizon.js',
'../../openstack_dashboard/static/openstack-service-api/openstack-service-api.module.js',
'dashboard-app/dashboard-app.module.js',
'dashboard-app/**/*.js',
'auth/auth.module.js',
'auth/login/login.module.js',
'framework/framework.module.js',

View File

@ -3,26 +3,14 @@
angular
.module('horizon.framework.util.tech-debt')
.service('horizon.framework.util.tech-debt.helper-functions', utils);
.factory('horizon.framework.util.tech-debt.helper-functions', utils);
// An example of using the John Papa recommended $inject instead of in-line array syntax
utils.$inject = [
'horizon.dashboard-app.conf',
'$log',
'$rootScope',
'$compile'];
// An example of using the John Papa recommended $inject instead of in-line
// array syntax
utils.$inject = ['$rootScope', '$compile'];
function utils(hzConfig, $log, $rootScope, $compile) {
function utils($rootScope, $compile) {
return {
/*
Use the log levels of http://docs.angularjs.org/api/ng.$log
default to log level.
*/
log: function (msg, lvl) {
if (hzConfig.debug) {
($log[lvl] || $log.log)(msg);
}
},
capitalize: function (string) {
return string.charAt(0).toUpperCase() + string.slice(1);
},

View File

@ -1,131 +1,86 @@
(function() {
'use strict';
describe('horizon.framework.util.tech-debt', function () {
describe('horizon.framework.util.tech-debt.helper-functions', function () {
beforeEach(function () {
angular.mock.module('horizon.framework.util.tech-debt');
});
describe('horizon.framework.util.tech-debt.helper-functions', function () {
var hzUtils;
beforeEach(function () {
angular.mock.inject(function ($injector) {
hzUtils = $injector.get('horizon.framework.util.tech-debt.helper-functions');
});
});
beforeEach(module('horizon.dashboard-app'));
beforeEach(function () {
angular.mock.module('horizon.framework.util.tech-debt');
describe('capitalize', function () {
it('should capitalize the first letter of a string', function () {
expect(hzUtils.capitalize('string to test')).toBe('String to test');
});
});
describe('humanizeNumbers', function () {
it('should add a comma every three number', function () {
expect(hzUtils.humanizeNumbers('1234')).toBe('1,234');
expect(hzUtils.humanizeNumbers('1234567')).toBe('1,234,567');
});
describe('horizon.framework.util.tech-debt.helper-functions', function () {
var hzUtils;
beforeEach(function () {
angular.mock.inject(function ($injector) {
hzUtils = $injector.get('horizon.framework.util.tech-debt.helper-functions');
});
it('should work with string or numbers', function () {
expect(hzUtils.humanizeNumbers('1234')).toBe('1,234');
expect(hzUtils.humanizeNumbers(1234)).toBe('1,234');
});
it('should work with multiple values through a string', function () {
expect(hzUtils.humanizeNumbers('My Total: 1234')).
toBe('My Total: 1,234');
expect(hzUtils.humanizeNumbers('My Total: 1234, His Total: 1234567')).
toBe('My Total: 1,234, His Total: 1,234,567');
});
});
describe('truncate', function () {
var string = 'This will be cut';
var ellipsis = '…';
it('should truncate a string at a given length', function () {
expect(hzUtils.truncate(string, 15)).
toBe(string.slice(0, 15));
expect(hzUtils.truncate(string, 20)).
toBe(string);
});
it('should add an ellipsis if needed ', function () {
expect(hzUtils.truncate(string, 15, true)).
toBe(string.slice(0, 12) + ellipsis);
expect(hzUtils.truncate(string, 20, true)).
toBe(string);
expect(hzUtils.truncate(string, 2, true)).
toBe(ellipsis);
});
});
describe('loadAngular', function () {
var rootScope, element;
beforeEach(function () {
element = angular.element('<div>');
angular.mock.inject(function ($injector) {
rootScope = $injector.get('$rootScope');
});
spyOn(rootScope, '$apply');
});
describe('log', function () {
var hzConfig, $log, log;
beforeEach(function () {
log = 'display a log';
angular.mock.inject(function ($injector) {
$log = $injector.get('$log');
hzConfig = $injector.get('horizon.dashboard-app.conf');
//jasmine cannot mock properties
hzConfig.debug = true;
});
});
it('should display a log at default log level', function () {
hzUtils.log(log);
expect($log.log.logs.length).toBe(1);
expect($log.log.logs[0][0]).toBe(log);
});
it('should have a configurable log level', function () {
hzUtils.log(log, 'debug');
expect($log.debug.logs.length).toBe(1);
hzUtils.log(log, 'error');
expect($log.error.logs.length).toBe(1);
hzUtils.log(log, 'info');
expect($log.info.logs.length).toBe(1);
hzUtils.log(log, 'log');
expect($log.log.logs.length).toBe(1);
hzUtils.log(log, 'warn');
expect($log.warn.logs.length).toBe(1);
});
});
describe('capitalize', function () {
it('should capitalize the first letter of a string', function () {
expect(hzUtils.capitalize('string to test')).toBe('String to test');
});
});
describe('humanizeNumbers', function () {
it('should add a comma every three number', function () {
expect(hzUtils.humanizeNumbers('1234')).toBe('1,234');
expect(hzUtils.humanizeNumbers('1234567')).toBe('1,234,567');
});
it('should work with string or numbers', function () {
expect(hzUtils.humanizeNumbers('1234')).toBe('1,234');
expect(hzUtils.humanizeNumbers(1234)).toBe('1,234');
});
it('should work with multiple values through a string', function () {
expect(hzUtils.humanizeNumbers('My Total: 1234')).
toBe('My Total: 1,234');
expect(hzUtils.humanizeNumbers('My Total: 1234, His Total: 1234567')).
toBe('My Total: 1,234, His Total: 1,234,567');
});
});
describe('truncate', function () {
var string = 'This will be cut';
var ellipsis = '&hellip;';
it('should truncate a string at a given length', function () {
expect(hzUtils.truncate(string, 15)).
toBe(string.slice(0, 15));
expect(hzUtils.truncate(string, 20)).
toBe(string);
});
it('should add an ellipsis if needed', function () {
expect(hzUtils.truncate(string, 15, true)).
toBe(string.slice(0, 12) + ellipsis);
expect(hzUtils.truncate(string, 20, true)).
toBe(string);
expect(hzUtils.truncate(string, 2, true)).
toBe(ellipsis);
});
});
describe('loadAngular', function () {
var rootScope, element;
beforeEach(function () {
element = angular.element('<div>');
angular.mock.inject(function ($injector) {
rootScope = $injector.get('$rootScope');
});
spyOn(rootScope, '$apply');
});
it('should call a compile and apply', function () {
hzUtils.loadAngular(element);
//checks the use of apply function
expect(rootScope.$apply).toHaveBeenCalled();
//checks the use of compile function
expect(element.hasClass('ng-scope')).toBeTruthy();
});
});
it('should call a compile and apply ', function () {
hzUtils.loadAngular(element);
//checks the use of apply function
expect(rootScope.$apply).toHaveBeenCalled();
//checks the use of compile function
expect(element.hasClass('ng-scope')).toBeTruthy();
});
});
});
})();

View File

@ -1,4 +1,4 @@
/* global STATIC_URL */
/* global STATIC_URL, console */
/* Namespace for core functionality related to DataTables. */
horizon.datatables = {
update: function () {
@ -56,7 +56,7 @@ horizon.datatables = {
horizon.datatables.update_actions();
break;
default:
horizon.utils.log(gettext("An error occurred while updating."));
console.log(gettext("An error occurred while updating."));
$row.removeClass("ajax-update");
$row.find("i.ajax-updating").remove();
break;
@ -127,7 +127,7 @@ horizon.datatables = {
horizon.ajax.queue({
url: $action.attr('data-update-url'),
error: function () {
horizon.utils.log(gettext("An error occurred while updating."));
console.log(gettext("An error occurred while updating."));
},
success: function (data) {
var $new_action = $(data);

View File

@ -32,8 +32,6 @@ class ServicesTests(test.JasmineTests):
'auth/login/login.controller.js',
'auth/login/login-finder.directive.js',
'dashboard-app/dashboard-app.module.js',
'framework/framework.module.js',
'framework/conf/conf.js',

View File

@ -71,7 +71,8 @@ module.exports = function(config) {
'openstack-service-api/openstack-service-api.module.js',
'openstack-service-api/**/*.js',
// This one seems to have to come first.
// first load dependencies in order that matters
"app/app.module.js",
"dashboard/dashboard.module.js",
"dashboard/workflow/workflow.js",
"dashboard/launch-instance/launch-instance.js",

View File

@ -2,15 +2,15 @@
(function () {
'use strict';
angular.module('horizon.dashboard-app', [
'horizon.framework',
angular.module('horizon.app', [
'horizon.auth',
'horizon.openstack-service-api',
'horizon.framework',
'hz.dashboard',
'ngCookies'].concat(angularModuleExtension))
.constant('horizon.dashboard-app.conf', {
.constant('horizon.app.conf', {
// Placeholders; updated by Django.
debug: null, //
static_url: null,
ajax: {
queue_limit: null
@ -19,7 +19,7 @@
.run([
'horizon.framework.conf.spinner_options',
'horizon.dashboard-app.conf',
'horizon.app.conf',
'horizon.framework.util.tech-debt.helper-functions',
'$cookieStore',
'$http',

View File

@ -14,7 +14,7 @@
{% include "horizon/client_side/_script_loader.html" %}
{% include "horizon/_custom_head_js.html" %}
</head>
<body id="{% block body_id %}{% endblock %}" ng-app='horizon.dashboard-app'>
<body id="{% block body_id %}{% endblock %}" ng-app='horizon.app'>
<noscript>
<div class="javascript_disabled_alert">
{% trans "This application requires JavaScript to be enabled in your web browser." %}

View File

@ -23,7 +23,7 @@
</script>
{% compress js %}
<script src='{{ STATIC_URL }}dashboard-app/dashboard-app.module.js' type='text/javascript' charset='utf-8'></script>
<script src="{{ STATIC_URL }}app/app.module.js"></script>
{% endcompress %}
<script type='text/javascript' charset='utf-8'>
@ -31,9 +31,8 @@
* should be aware of.
*/
angular.module('horizon.dashboard-app')
.config(['horizon.dashboard-app.conf', function (hzConfig) {
hzConfig.debug = {{ debug|yesno:"true,false" }};
angular.module('horizon.app')
.config(['horizon.app.conf', function (hzConfig) {
hzConfig.static_url = "{{ STATIC_URL }}";
hzConfig.ajax = {
queue_limit: {{ HORIZON_CONFIG.ajax_queue_limit|default:"null" }}