2018-02-10 15:18:01 +00:00
|
|
|
import ngModule from '../module';
|
2017-06-05 07:01:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The main application class.
|
|
|
|
*
|
|
|
|
* @property {String} name The application name.
|
|
|
|
* @property {Snackbar} snackbar The main object to show messages.
|
|
|
|
*/
|
|
|
|
export default class App {
|
2018-05-25 15:25:35 +00:00
|
|
|
constructor() {
|
2017-11-16 12:47:18 +00:00
|
|
|
this.loaderStatus = 0;
|
2018-05-25 15:25:35 +00:00
|
|
|
this.loading = false;
|
2022-06-14 08:16:41 +00:00
|
|
|
this.versionInterval = setInterval(this.getVersion.bind(this), 300000);
|
2017-11-16 12:47:18 +00:00
|
|
|
}
|
2018-06-19 06:12:36 +00:00
|
|
|
|
2017-06-05 07:01:21 +00:00
|
|
|
showMessage(message) {
|
2019-01-25 11:04:35 +00:00
|
|
|
if (this.logger)
|
|
|
|
this.logger.showMessage(message);
|
2017-06-05 07:01:21 +00:00
|
|
|
}
|
2018-06-19 06:12:36 +00:00
|
|
|
|
|
|
|
showSuccess(message) {
|
2019-01-25 11:04:35 +00:00
|
|
|
if (this.logger)
|
|
|
|
this.logger.showSuccess(message);
|
2018-06-19 06:12:36 +00:00
|
|
|
}
|
|
|
|
|
2023-06-30 12:24:50 +00:00
|
|
|
showError(message, additionalData) {
|
2019-01-25 11:04:35 +00:00
|
|
|
if (this.logger)
|
2023-06-30 12:24:50 +00:00
|
|
|
this.logger.showError(message, additionalData);
|
2017-06-05 07:01:21 +00:00
|
|
|
}
|
2018-06-19 06:12:36 +00:00
|
|
|
|
2017-11-16 12:47:18 +00:00
|
|
|
pushLoader() {
|
|
|
|
this.loaderStatus++;
|
|
|
|
if (this.loaderStatus === 1)
|
2018-05-25 15:25:35 +00:00
|
|
|
this.loading = true;
|
2017-11-16 12:47:18 +00:00
|
|
|
}
|
2018-06-19 06:12:36 +00:00
|
|
|
|
2017-11-16 12:47:18 +00:00
|
|
|
popLoader() {
|
|
|
|
this.loaderStatus--;
|
|
|
|
if (this.loaderStatus === 0)
|
2018-05-25 15:25:35 +00:00
|
|
|
this.loading = false;
|
2017-11-16 12:47:18 +00:00
|
|
|
}
|
2022-06-14 08:16:41 +00:00
|
|
|
|
|
|
|
getVersion() {
|
|
|
|
this.logger.$http.get('Applications/status');
|
|
|
|
}
|
2022-06-16 06:25:38 +00:00
|
|
|
|
|
|
|
setVersion(newVersion) {
|
|
|
|
if (newVersion) {
|
|
|
|
const currentVersion = localStorage.getItem('salix-version');
|
|
|
|
if (newVersion != currentVersion) {
|
|
|
|
this.hasNewVersion = true;
|
|
|
|
clearInterval(this.versionInterval);
|
|
|
|
}
|
|
|
|
localStorage.setItem('salix-version', newVersion);
|
|
|
|
}
|
|
|
|
}
|
2022-09-26 12:49:11 +00:00
|
|
|
|
2022-09-30 06:59:49 +00:00
|
|
|
getUrl(route, appName = 'lilium') {
|
2024-08-28 07:22:31 +00:00
|
|
|
const index = window.location.hash.indexOf(route.toLowerCase());
|
2024-09-26 12:38:27 +00:00
|
|
|
let newRoute = index < 0 ? route : window.location.hash.substring(index);
|
2022-09-26 12:49:11 +00:00
|
|
|
const env = process.env.NODE_ENV;
|
|
|
|
const filter = {
|
|
|
|
where: {and: [
|
|
|
|
{appName: appName},
|
|
|
|
{environment: env}
|
|
|
|
]}
|
|
|
|
};
|
|
|
|
|
2024-10-04 07:09:59 +00:00
|
|
|
const hasId = !isNaN(parseInt(route.split('/')[1]));
|
2024-10-03 20:07:24 +00:00
|
|
|
|
2024-10-03 05:48:41 +00:00
|
|
|
if (this.logger.$params.q) {
|
|
|
|
let tableValue = this.logger.$params.q;
|
2024-11-12 09:43:05 +00:00
|
|
|
if (Array.isArray(tableValue)) {
|
|
|
|
const [key, param1, param2] = tableValue;
|
|
|
|
const payload = key === 'createForm'
|
|
|
|
? {[param1]: param2}
|
|
|
|
: {[key]: param1};
|
|
|
|
newRoute += `?${key}=${JSON.stringify(payload)}`;
|
|
|
|
} else {
|
|
|
|
const q = JSON.parse(tableValue);
|
|
|
|
if (typeof q === 'number')
|
|
|
|
tableValue = JSON.stringify({id: tableValue});
|
|
|
|
newRoute = newRoute.concat(`?table=${tableValue}`);
|
|
|
|
}
|
2024-10-03 20:07:24 +00:00
|
|
|
} else if (!hasId && this.logger.$params.id && newRoute.indexOf(this.logger.$params.id) < 0)
|
2024-10-03 05:48:41 +00:00
|
|
|
newRoute = newRoute.concat(`${this.logger.$params.id}`);
|
2024-10-03 20:32:54 +00:00
|
|
|
|
2022-09-26 12:49:11 +00:00
|
|
|
return this.logger.$http.get('Urls/findOne', {filter})
|
|
|
|
.then(res => {
|
2023-05-31 09:32:37 +00:00
|
|
|
if (res && res.data)
|
2024-08-28 07:22:31 +00:00
|
|
|
return res.data.url + newRoute;
|
2023-05-31 09:32:37 +00:00
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
this.showError('Direction not found');
|
2022-09-26 12:49:11 +00:00
|
|
|
});
|
|
|
|
}
|
2017-06-05 07:01:21 +00:00
|
|
|
}
|
2017-11-16 12:47:18 +00:00
|
|
|
|
2018-02-10 15:18:01 +00:00
|
|
|
ngModule.service('vnApp', App);
|