2018-12-27 11:54:16 +00:00
|
|
|
import {ng} from 'core/vendor';
|
2020-04-25 09:50:04 +00:00
|
|
|
import appConfig from './config.json';
|
2017-05-17 19:23:47 +00:00
|
|
|
import 'core';
|
2017-01-31 13:13:06 +00:00
|
|
|
|
2018-02-10 15:18:01 +00:00
|
|
|
export const appName = 'salix';
|
|
|
|
|
2017-06-05 07:01:21 +00:00
|
|
|
const ngModule = ng.module('salix', ['vnCore']);
|
2017-05-18 15:35:07 +00:00
|
|
|
export default ngModule;
|
2018-02-10 15:18:01 +00:00
|
|
|
|
2020-11-27 12:10:39 +00:00
|
|
|
run.$inject = ['$window', '$rootScope', 'vnAuth', 'vnApp', 'vnToken', '$state'];
|
|
|
|
export function run($window, $rootScope, vnAuth, vnApp, vnToken, $state) {
|
|
|
|
$rootScope.imagePath = (collection, size, id) => {
|
|
|
|
if (!collection || !size || !id) return;
|
|
|
|
|
|
|
|
const basePath = `/api/Images/${collection}/${size}/${id}`;
|
2024-02-26 05:53:30 +00:00
|
|
|
return `${basePath}/download?access_token=${vnToken.tokenMultimedia}`;
|
2020-11-27 12:10:39 +00:00
|
|
|
};
|
2020-04-25 09:50:04 +00:00
|
|
|
|
2018-02-10 15:18:01 +00:00
|
|
|
$window.validations = {};
|
|
|
|
vnApp.name = appName;
|
|
|
|
|
2019-01-23 12:11:44 +00:00
|
|
|
vnAuth.initialize();
|
|
|
|
|
2018-02-10 15:18:01 +00:00
|
|
|
$rootScope.$on('$viewContentLoaded', () => {});
|
|
|
|
window.myAppErrorLog = [];
|
|
|
|
$state.defaultErrorHandler(function(error) {
|
2018-05-25 15:25:35 +00:00
|
|
|
if (error.type === 3) // ABORTED_TRANSITION
|
2018-02-10 15:18:01 +00:00
|
|
|
window.myAppErrorLog.push(error);
|
|
|
|
});
|
2018-09-14 11:51:28 +00:00
|
|
|
|
2019-01-23 16:49:28 +00:00
|
|
|
if ($window.routes) {
|
2019-01-24 08:25:51 +00:00
|
|
|
let keybindings = {};
|
|
|
|
|
2019-01-23 16:49:28 +00:00
|
|
|
for (const mod of $window.routes) {
|
|
|
|
if (!mod || !mod.keybindings)
|
|
|
|
continue;
|
2018-09-14 11:51:28 +00:00
|
|
|
|
2019-01-23 16:49:28 +00:00
|
|
|
for (const binding of mod.keybindings) {
|
2019-01-24 08:25:51 +00:00
|
|
|
let err;
|
|
|
|
if (!binding.key)
|
|
|
|
err = `Missing attribute 'key' in binding`;
|
|
|
|
else if (!binding.state)
|
|
|
|
err = `Missing attribute 'state' in binding`;
|
|
|
|
else if (keybindings[binding.key])
|
|
|
|
err = `Binding key redeclared`;
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
console.warn(`${err}: ${mod.module}: ${JSON.stringify(binding)}`);
|
|
|
|
else
|
|
|
|
keybindings[binding.key] = binding.state;
|
|
|
|
}
|
|
|
|
}
|
2018-09-14 11:51:28 +00:00
|
|
|
|
2019-01-24 08:25:51 +00:00
|
|
|
$window.addEventListener('keyup', function(event) {
|
|
|
|
if (event.defaultPrevented || !event.altKey || !event.ctrlKey)
|
|
|
|
return;
|
2019-01-23 16:49:28 +00:00
|
|
|
|
2019-01-24 08:25:51 +00:00
|
|
|
let state = keybindings[event.key];
|
|
|
|
if (state) {
|
|
|
|
$state.go(state);
|
|
|
|
event.preventDefault();
|
2018-09-14 11:51:28 +00:00
|
|
|
}
|
2019-01-24 08:25:51 +00:00
|
|
|
});
|
2018-09-14 11:51:28 +00:00
|
|
|
}
|
2018-02-10 15:18:01 +00:00
|
|
|
}
|
|
|
|
ngModule.run(run);
|
2018-05-25 15:25:35 +00:00
|
|
|
|
2020-04-25 09:50:04 +00:00
|
|
|
config.$inject = ['$translateProvider', '$translatePartialLoaderProvider', '$httpProvider', '$compileProvider'];
|
|
|
|
export function config($translateProvider, $translatePartialLoaderProvider, $httpProvider, $compileProvider) {
|
|
|
|
const langOptions = appConfig.langOptions;
|
|
|
|
$translateProvider
|
|
|
|
.registerAvailableLanguageKeys(langOptions.langs, langOptions.langAliases)
|
|
|
|
// TODO: Circular dependency due to vnInterceptor
|
|
|
|
// .fallbackLanguage(langOptions.fallbackLang)
|
|
|
|
.determinePreferredLanguage(() => {
|
|
|
|
const locale = $translateProvider.resolveClientLocale();
|
|
|
|
if (langOptions.langs.indexOf(locale) !== -1)
|
|
|
|
return locale;
|
|
|
|
if (langOptions.langAliases[locale])
|
|
|
|
return langOptions.langAliases[locale];
|
2020-06-17 11:09:40 +00:00
|
|
|
return langOptions.fallbackLang;
|
2020-04-25 09:50:04 +00:00
|
|
|
});
|
|
|
|
|
2018-05-25 15:25:35 +00:00
|
|
|
$translatePartialLoaderProvider.addPart(appName);
|
|
|
|
$httpProvider.interceptors.push('vnInterceptor');
|
2019-10-09 22:47:29 +00:00
|
|
|
|
2019-11-10 10:08:44 +00:00
|
|
|
$compileProvider
|
|
|
|
.commentDirectivesEnabled(false)
|
|
|
|
.cssClassDirectivesEnabled(false);
|
2020-03-07 12:52:02 +00:00
|
|
|
|
|
|
|
let env = process.env.NODE_ENV;
|
2020-03-13 19:33:12 +00:00
|
|
|
if (env && env !== 'development')
|
2020-03-07 12:52:02 +00:00
|
|
|
$compileProvider.debugInfoEnabled(false);
|
2018-05-25 15:25:35 +00:00
|
|
|
}
|
|
|
|
ngModule.config(config);
|
|
|
|
|
|
|
|
// Unhandled exceptions
|
|
|
|
|
2019-01-25 14:09:29 +00:00
|
|
|
$exceptionHandler.$inject = ['vnApp', '$window', '$state', '$injector'];
|
|
|
|
function $exceptionHandler(vnApp, $window, $state, $injector) {
|
2018-05-25 15:25:35 +00:00
|
|
|
return function(exception, cause) {
|
|
|
|
let message;
|
2019-01-25 14:09:29 +00:00
|
|
|
let messageT;
|
|
|
|
let $translate = $injector.get('$translate');
|
2018-05-25 15:25:35 +00:00
|
|
|
|
|
|
|
if (exception.name == 'HttpError') {
|
|
|
|
switch (exception.xhrStatus) {
|
|
|
|
case 'timeout':
|
|
|
|
case 'abort':
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-25 14:09:29 +00:00
|
|
|
switch (exception.status) {
|
|
|
|
case 401:
|
2022-09-21 13:15:19 +00:00
|
|
|
if (!$state.current.name.includes('login')) {
|
2019-01-25 16:05:53 +00:00
|
|
|
messageT = 'Session has expired';
|
2019-01-25 14:09:29 +00:00
|
|
|
let params = {continue: $window.location.hash};
|
2022-09-22 07:22:24 +00:00
|
|
|
$state.go('login', params);
|
2019-01-25 14:09:29 +00:00
|
|
|
} else
|
|
|
|
messageT = 'Invalid login';
|
|
|
|
break;
|
|
|
|
case 403:
|
2023-12-14 14:09:07 +00:00
|
|
|
messageT = exception.data?.error?.message || 'Access Denied';
|
2019-01-25 14:09:29 +00:00
|
|
|
break;
|
|
|
|
case 502:
|
|
|
|
messageT = 'It seems that the server has fall down';
|
|
|
|
break;
|
|
|
|
case -1:
|
|
|
|
messageT = 'Could not contact the server';
|
|
|
|
break;
|
|
|
|
}
|
2018-05-25 15:25:35 +00:00
|
|
|
|
2019-01-25 14:09:29 +00:00
|
|
|
if (!messageT) {
|
|
|
|
let data = exception.data;
|
2018-05-25 15:25:35 +00:00
|
|
|
|
2019-01-25 14:09:29 +00:00
|
|
|
if (data && data.error instanceof Object)
|
|
|
|
message = data.error.message;
|
|
|
|
else
|
2019-01-26 12:12:18 +00:00
|
|
|
message = exception.statusText;
|
2018-05-25 15:25:35 +00:00
|
|
|
}
|
2018-12-27 11:54:16 +00:00
|
|
|
} else if (exception.name == 'UserError')
|
2019-01-25 14:09:29 +00:00
|
|
|
messageT = exception.message;
|
2018-12-27 11:54:16 +00:00
|
|
|
else {
|
2018-10-18 18:48:21 +00:00
|
|
|
vnApp.showError('Ups! Something went wrong');
|
2018-10-22 06:23:10 +00:00
|
|
|
console.error(exception);
|
2018-10-18 18:48:21 +00:00
|
|
|
throw exception;
|
2018-05-25 15:25:35 +00:00
|
|
|
}
|
|
|
|
|
2019-01-25 14:09:29 +00:00
|
|
|
if (messageT)
|
|
|
|
message = $translate.instant(messageT);
|
2023-06-30 12:24:50 +00:00
|
|
|
|
|
|
|
const additonalData = {
|
|
|
|
frontPath: $state.current.name,
|
2023-08-11 11:20:02 +00:00
|
|
|
httpRequest: cause?.replace('Possibly unhandled rejection: ', ''),
|
2023-07-14 12:30:08 +00:00
|
|
|
backError: exception
|
2023-06-30 12:24:50 +00:00
|
|
|
};
|
|
|
|
vnApp.showError(message, additonalData);
|
2018-05-25 15:25:35 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
ngModule.factory('$exceptionHandler', $exceptionHandler);
|