salix/front/core/services/modules.js

46 lines
1.1 KiB
JavaScript
Raw Normal View History

import ngModule from '../module';
import getMainRoute from '../lib/get-main-route';
export default class Modules {
constructor(aclService, $window) {
Object.assign(this, {
aclService,
$window
});
}
reset() {
this.modules = null;
}
get() {
if (this.modules)
return this.modules;
this.modules = [];
for (let mod of this.$window.routes) {
if (!mod || !mod.routes) continue;
let route = getMainRoute(mod.routes);
if (!route || (route.acl && !this.aclService.hasAny(route.acl)))
continue;
let keyBind;
if (mod.keybindings) {
2019-01-24 08:25:51 +00:00
let res = mod.keybindings.find(i => i.state == route.state);
if (res) keyBind = res.key.toUpperCase();
}
this.modules.push({
name: mod.name || mod.module,
icon: mod.icon || null,
route,
keyBind
});
}
return this.modules;
}
}
Modules.$inject = ['aclService', '$window'];
ngModule.service('vnModules', Modules);