56 lines
1.5 KiB
JavaScript
56 lines
1.5 KiB
JavaScript
import ngModule from '../module';
|
|
import getMainRoute from '../lib/get-main-route';
|
|
|
|
export default class Modules {
|
|
constructor(aclService, $window, $translate) {
|
|
Object.assign(this, {
|
|
aclService,
|
|
$window,
|
|
$translate
|
|
});
|
|
}
|
|
|
|
reset() {
|
|
this.modules = null;
|
|
}
|
|
|
|
get() {
|
|
if (this.modules)
|
|
return this.modules;
|
|
|
|
const 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();
|
|
}
|
|
|
|
modules.push({
|
|
name: mod.name || mod.module,
|
|
icon: mod.icon || null,
|
|
route,
|
|
keyBind
|
|
});
|
|
}
|
|
|
|
const sortedModules = modules.sort((a, b) => {
|
|
const translatedNameA = this.$translate.instant(a.name);
|
|
const translatedNameB = this.$translate.instant(b.name);
|
|
return translatedNameA.localeCompare(translatedNameB);
|
|
});
|
|
this.modules = sortedModules;
|
|
|
|
return this.modules;
|
|
}
|
|
}
|
|
Modules.$inject = ['aclService', '$window', '$translate'];
|
|
|
|
ngModule.service('vnModules', Modules);
|