2017-12-20 05:33:33 -06:00
|
|
|
import coreModule from 'app/core/core_module';
|
|
|
|
import config from 'app/core/config';
|
|
|
|
import _ from 'lodash';
|
2017-06-02 07:00:42 -05:00
|
|
|
|
|
|
|
export interface NavModelItem {
|
2017-11-30 04:31:38 -06:00
|
|
|
text: string;
|
2017-06-02 07:00:42 -05:00
|
|
|
url: string;
|
|
|
|
icon?: string;
|
2017-11-30 04:31:38 -06:00
|
|
|
img?: string;
|
2017-12-01 03:27:05 -06:00
|
|
|
id: string;
|
2017-11-30 08:37:03 -06:00
|
|
|
active?: boolean;
|
2017-12-01 04:32:00 -06:00
|
|
|
hideFromTabs?: boolean;
|
|
|
|
divider?: boolean;
|
2017-11-30 08:37:03 -06:00
|
|
|
children: NavModelItem[];
|
2017-12-13 09:28:36 -06:00
|
|
|
target?: string;
|
2017-06-02 07:00:42 -05:00
|
|
|
}
|
|
|
|
|
2017-11-30 04:31:38 -06:00
|
|
|
export class NavModel {
|
|
|
|
breadcrumbs: NavModelItem[];
|
2017-11-30 08:37:03 -06:00
|
|
|
main: NavModelItem;
|
2017-11-30 04:31:38 -06:00
|
|
|
node: NavModelItem;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
this.breadcrumbs = [];
|
|
|
|
}
|
2017-06-02 07:00:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export class NavModelSrv {
|
2017-08-15 10:52:52 -05:00
|
|
|
navItems: any;
|
2017-06-02 07:00:42 -05:00
|
|
|
|
|
|
|
/** @ngInject */
|
2017-12-13 06:16:44 -06:00
|
|
|
constructor() {
|
2017-08-15 10:52:52 -05:00
|
|
|
this.navItems = config.bootData.navTree;
|
|
|
|
}
|
|
|
|
|
|
|
|
getCfgNode() {
|
2017-12-20 05:33:33 -06:00
|
|
|
return _.find(this.navItems, { id: 'cfg' });
|
2017-08-15 10:52:52 -05:00
|
|
|
}
|
|
|
|
|
2017-08-15 13:24:16 -05:00
|
|
|
getNav(...args) {
|
2018-08-30 01:58:43 -05:00
|
|
|
let children = this.navItems;
|
2018-08-29 07:26:50 -05:00
|
|
|
const nav = new NavModel();
|
2017-08-15 13:24:16 -05:00
|
|
|
|
2018-08-26 10:14:40 -05:00
|
|
|
for (const id of args) {
|
2017-11-30 08:37:03 -06:00
|
|
|
// if its a number then it's the index to use for main
|
|
|
|
if (_.isNumber(id)) {
|
|
|
|
nav.main = nav.breadcrumbs[id];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-08-26 10:14:40 -05:00
|
|
|
const node = _.find(children, { id: id });
|
2017-08-15 13:24:16 -05:00
|
|
|
nav.breadcrumbs.push(node);
|
|
|
|
nav.node = node;
|
2017-11-30 08:37:03 -06:00
|
|
|
nav.main = node;
|
2017-08-15 13:24:16 -05:00
|
|
|
children = node.children;
|
|
|
|
}
|
2017-06-02 07:00:42 -05:00
|
|
|
|
2017-11-30 08:37:03 -06:00
|
|
|
if (nav.main.children) {
|
2018-08-26 10:14:40 -05:00
|
|
|
for (const item of nav.main.children) {
|
2017-11-30 08:37:03 -06:00
|
|
|
item.active = false;
|
|
|
|
|
|
|
|
if (item.url === nav.node.url) {
|
|
|
|
item.active = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-15 13:24:16 -05:00
|
|
|
return nav;
|
2017-06-02 07:00:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
getNotFoundNav() {
|
2018-08-29 07:26:50 -05:00
|
|
|
const node = {
|
2017-12-20 05:33:33 -06:00
|
|
|
text: 'Page not found',
|
|
|
|
icon: 'fa fa-fw fa-warning',
|
|
|
|
subTitle: '404 Error',
|
2017-08-15 10:52:52 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
2017-08-15 13:24:16 -05:00
|
|
|
breadcrumbs: [node],
|
2017-12-07 09:25:21 -06:00
|
|
|
node: node,
|
2017-12-20 05:33:33 -06:00
|
|
|
main: node,
|
2017-06-02 07:00:42 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-20 05:33:33 -06:00
|
|
|
coreModule.service('navModelSrv', NavModelSrv);
|