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 {
|
2020-03-11 11:20:15 +00:00
|
|
|
constructor(aclService, $window, $translate) {
|
2019-01-23 12:11:44 +00:00
|
|
|
Object.assign(this, {
|
|
|
|
aclService,
|
2020-03-11 11:20:15 +00:00
|
|
|
$window,
|
|
|
|
$translate
|
2019-01-23 12:11:44 +00:00
|
|
|
});
|
|
|
|
}
|
2019-11-01 12:02:47 +00:00
|
|
|
|
2019-01-23 12:11:44 +00:00
|
|
|
reset() {
|
|
|
|
this.modules = null;
|
|
|
|
}
|
2019-11-01 12:02:47 +00:00
|
|
|
|
2019-01-23 12:11:44 +00:00
|
|
|
get() {
|
|
|
|
if (this.modules)
|
|
|
|
return this.modules;
|
|
|
|
|
2020-03-11 11:20:15 +00:00
|
|
|
const modules = [];
|
2019-01-23 12:11:44 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2020-03-11 11:20:15 +00:00
|
|
|
modules.push({
|
2019-01-23 12:11:44 +00:00
|
|
|
name: mod.name || mod.module,
|
|
|
|
icon: mod.icon || null,
|
|
|
|
route,
|
|
|
|
keyBind
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-03-11 11:20:15 +00:00
|
|
|
const sortedModules = modules.sort((a, b) => {
|
|
|
|
const translatedNameA = this.$translate.instant(a.name);
|
|
|
|
const translatedNameB = this.$translate.instant(b.name);
|
|
|
|
return translatedNameA.localeCompare(translatedNameB);
|
|
|
|
});
|
2020-03-11 12:36:56 +00:00
|
|
|
this.modules = sortedModules;
|
2020-03-11 11:20:15 +00:00
|
|
|
|
2020-03-11 12:36:56 +00:00
|
|
|
return this.modules;
|
2019-01-23 12:11:44 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-11 11:20:15 +00:00
|
|
|
Modules.$inject = ['aclService', '$window', '$translate'];
|
2019-01-23 12:11:44 +00:00
|
|
|
|
|
|
|
ngModule.service('vnModules', Modules);
|