46 lines
1.1 KiB
JavaScript
46 lines
1.1 KiB
JavaScript
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) {
|
|
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);
|