LocationProvider should be set up on the Horizon App

Allow the $locationProvider to set up
on the 'horizon.app' module so that the configuration
is global.

It sets the HTML5 mode on with Hash Prefix to '!'.

Change-Id: I533db1422a8bc558d74e669fa4ce19ddac0833c5
Partially-Implements: blueprint angularize-images-table
This commit is contained in:
Rajat Vig 2015-12-22 15:02:01 -08:00
parent 171f54bfe7
commit 77656a8cb0
2 changed files with 68 additions and 30 deletions

View File

@ -57,12 +57,21 @@
*/
angular
.module('horizon.app', []
.concat(libraryModules)
.concat(horizonBuiltInModules)
.concat(horizonPlugInModules)
)
.concat(libraryModules)
.concat(horizonBuiltInModules)
.concat(horizonPlugInModules)
)
.config(configHorizon)
.run(updateHorizon);
configHorizon.$inject = [
'$locationProvider'
];
function configHorizon($locationProvider) {
$locationProvider.html5Mode(true).hashPrefix('!');
}
updateHorizon.$inject = [
'gettextCatalog',
'horizon.framework.conf.spinner_options',
@ -78,36 +87,37 @@
hzUtils,
$cookieStore,
$http,
$cookies) {
$cookies
) {
$http.defaults.headers.post['X-CSRFToken'] = $cookies.csrftoken;
$http.defaults.headers.post['X-CSRFToken'] = $cookies.csrftoken;
// expose the legacy utils module
horizon.utils = hzUtils;
// expose the legacy utils module
horizon.utils = hzUtils;
horizon.conf.spinner_options = spinnerOptions;
horizon.conf.spinner_options = spinnerOptions;
horizon.cookies = angular.extend({}, $cookieStore, {
put: put,
getRaw: getRaw
horizon.cookies = angular.extend({}, $cookieStore, {
put: put,
getRaw: getRaw
});
// rewire the angular-gettext catalog to use django catalog
gettextCatalog.setCurrentLanguage(horizon.languageCode);
gettextCatalog.setStrings(horizon.languageCode, django.catalog);
/*
* cookies are updated at the end of current $eval, so for the horizon
* namespace we need to wrap it in a $apply function.
*/
function put(key, value) {
angular.element('body').scope().$apply(function () {
$cookieStore.put(key, value);
});
// rewire the angular-gettext catalog to use django catalog
gettextCatalog.setCurrentLanguage(horizon.languageCode);
gettextCatalog.setStrings(horizon.languageCode, django.catalog);
/*
* cookies are updated at the end of current $eval, so for the horizon
* namespace we need to wrap it in a $apply function.
*/
function put(key, value) {
angular.element('body').scope().$apply(function () {
$cookieStore.put(key, value);
});
}
function getRaw(key) {
return $cookies[key];
}
}
function getRaw(key) {
return $cookies[key];
}
}
}());

View File

@ -22,4 +22,32 @@
});
});
describe('$locationProvider', function() {
var $locationProvider;
beforeEach(function() {
angular.module('horizon.auth', []);
angular.module('locationProviderConfig', [])
.config(function(_$locationProvider_) {
$locationProvider = _$locationProvider_;
spyOn($locationProvider, 'html5Mode').and.callThrough();
spyOn($locationProvider, 'hashPrefix').and.callThrough();
});
module('locationProviderConfig');
module('horizon.app');
inject();
});
it('should set html5 mode', function() {
expect($locationProvider.html5Mode).toHaveBeenCalledWith(true);
});
it('should set hashPrefix', function() {
expect($locationProvider.hashPrefix).toHaveBeenCalledWith('!');
});
});
})();