2019-01-23 12:11:44 +00:00
|
|
|
import ngModule from '../module';
|
2019-01-23 16:49:28 +00:00
|
|
|
import getMainRoute from '../lib/get-main-route';
|
2019-01-23 12:11:44 +00:00
|
|
|
|
|
|
|
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;
|
2019-01-23 16:49:28 +00:00
|
|
|
if (mod.keybindings) {
|
2019-01-24 08:25:51 +00:00
|
|
|
let res = mod.keybindings.find(i => i.state == route.state);
|
2019-01-23 12:11:44 +00:00
|
|
|
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);
|