salix/front/core/services/app.js

60 lines
1.4 KiB
JavaScript

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() {
this.loaderStatus = 0;
this.loading = false;
this.versionInterval = setInterval(this.getVersion.bind(this), 300000);
}
showMessage(message) {
if (this.logger)
this.logger.showMessage(message);
}
showSuccess(message) {
if (this.logger)
this.logger.showSuccess(message);
}
showError(message) {
if (this.logger)
this.logger.showError(message);
}
pushLoader() {
this.loaderStatus++;
if (this.loaderStatus === 1)
this.loading = true;
}
popLoader() {
this.loaderStatus--;
if (this.loaderStatus === 0)
this.loading = false;
}
getVersion() {
this.logger.$http.get('Applications/status');
}
setVersion(newVersion) {
if (newVersion) {
const currentVersion = localStorage.getItem('salix-version');
if (newVersion != currentVersion) {
this.hasNewVersion = true;
clearInterval(this.versionInterval);
}
localStorage.setItem('salix-version', newVersion);
}
}
}
ngModule.service('vnApp', App);