100 lines
3.0 KiB
JavaScript
100 lines
3.0 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, additionalData) {
|
|
if (this.logger)
|
|
this.logger.showError(message, additionalData);
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
getUrl(route, appName = 'lilium') {
|
|
const index = window.location.hash.indexOf(route.toLowerCase());
|
|
let newRoute = index < 0 ? route : window.location.hash.substring(index);
|
|
const env = process.env.NODE_ENV;
|
|
const filter = {
|
|
where: {and: [
|
|
{appName: appName},
|
|
{environment: env}
|
|
]}
|
|
};
|
|
|
|
const hasId = !isNaN(parseInt(route.split('/')[1]));
|
|
|
|
if (this.logger.$params.q) {
|
|
let tableValue = this.logger.$params.q;
|
|
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}`);
|
|
}
|
|
} else if (!hasId && this.logger.$params.id && newRoute.indexOf(this.logger.$params.id) < 0)
|
|
newRoute = newRoute.concat(`${this.logger.$params.id}`);
|
|
|
|
return this.logger.$http.get('Urls/findOne', {filter})
|
|
.then(res => {
|
|
if (res && res.data)
|
|
return res.data.url + newRoute;
|
|
})
|
|
.catch(() => {
|
|
this.showError('Direction not found');
|
|
});
|
|
}
|
|
}
|
|
|
|
ngModule.service('vnApp', App);
|