2019-10-14 13:45:09 +00:00
|
|
|
import $ from 'jquery';
|
2020-04-10 21:54:53 +00:00
|
|
|
|
2021-12-09 07:38:07 +00:00
|
|
|
/* @ngInject */
|
2022-11-02 11:29:26 +00:00
|
|
|
export function onStartupAngular($rootScope, $state, LocalStorage, cfpLoadingBar, $transitions, HttpRequestHelper, EndpointProvider) {
|
2021-12-09 07:38:07 +00:00
|
|
|
$rootScope.$state = $state;
|
2022-06-23 07:25:56 +00:00
|
|
|
const defaultTitle = document.title;
|
|
|
|
|
|
|
|
$transitions.onEnter({}, () => {
|
|
|
|
const endpoint = EndpointProvider.currentEndpoint();
|
2022-09-06 23:08:45 +00:00
|
|
|
document.title = endpoint ? `${defaultTitle} | ${endpoint.Name}` : `${defaultTitle}`;
|
2022-06-23 07:25:56 +00:00
|
|
|
});
|
2021-12-09 07:38:07 +00:00
|
|
|
|
|
|
|
// Workaround to prevent the loading bar from going backward
|
|
|
|
// https://github.com/chieffancypants/angular-loading-bar/issues/273
|
|
|
|
const originalSet = cfpLoadingBar.set;
|
|
|
|
cfpLoadingBar.set = function overrideSet(n) {
|
|
|
|
if (n > cfpLoadingBar.status()) {
|
|
|
|
originalSet.apply(cfpLoadingBar, arguments);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$transitions.onBefore({}, () => {
|
|
|
|
HttpRequestHelper.resetAgentHeaders();
|
|
|
|
});
|
|
|
|
|
|
|
|
$(document).ajaxSend((event, jqXhr, jqOpts) => {
|
|
|
|
const type = jqOpts.type === 'POST' || jqOpts.type === 'PUT' || jqOpts.type === 'PATCH';
|
|
|
|
const hasNoContentType = jqOpts.contentType !== 'application/json' && jqOpts.headers && !jqOpts.headers['Content-Type'];
|
|
|
|
if (type && hasNoContentType) {
|
|
|
|
jqXhr.setRequestHeader('Content-Type', 'application/json');
|
|
|
|
}
|
|
|
|
jqXhr.setRequestHeader('Authorization', 'Bearer ' + LocalStorage.getJWT());
|
|
|
|
});
|
|
|
|
}
|