salix/front/core/services/app.js

75 lines
1.8 KiB
JavaScript
Raw Permalink Normal View History

2018-02-10 15:18:01 +00:00
import ngModule from '../module';
/**
* The main application class.
*
* @property {String} name The application name.
* @property {Snackbar} snackbar The main object to show messages.
*/
export default class App {
constructor() {
2017-11-16 12:47:18 +00:00
this.loaderStatus = 0;
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
showMessage(message) {
if (this.logger)
this.logger.showMessage(message);
}
2018-06-19 06:12:36 +00:00
showSuccess(message) {
if (this.logger)
this.logger.showSuccess(message);
2018-06-19 06:12:36 +00:00
}
showError(message) {
if (this.logger)
this.logger.showError(message);
}
2018-06-19 06:12:36 +00:00
2017-11-16 12:47:18 +00:00
pushLoader() {
this.loaderStatus++;
if (this.loaderStatus === 1)
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)
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-30 06:59:49 +00:00
getUrl(route, appName = 'lilium') {
const env = process.env.NODE_ENV;
const filter = {
where: {and: [
{appName: appName},
{environment: env}
]}
};
return this.logger.$http.get('Urls/findOne', {filter})
.then(res => {
return res.data.url + route;
});
}
}
2017-11-16 12:47:18 +00:00
2018-02-10 15:18:01 +00:00
ngModule.service('vnApp', App);