mirror of
https://github.com/grafana/grafana.git
synced 2024-12-02 05:29:42 -06:00
093498a03b
* Angular: Prevent angular from loading when disabled * remove stuff
60 lines
1.3 KiB
TypeScript
60 lines
1.3 KiB
TypeScript
import { NavModelItem } from '@grafana/data';
|
|
import coreModule from 'app/angular/core_module';
|
|
import config from 'app/core/config';
|
|
import { getNotFoundNav } from 'app/core/navigation/errorModels';
|
|
|
|
interface Nav {
|
|
breadcrumbs: NavModelItem[];
|
|
node?: NavModelItem;
|
|
main?: NavModelItem;
|
|
}
|
|
|
|
export class NavModelSrv {
|
|
navItems: NavModelItem[];
|
|
|
|
constructor() {
|
|
this.navItems = config.bootData.navTree;
|
|
}
|
|
|
|
getCfgNode() {
|
|
return this.navItems.find((navItem) => navItem.id === 'cfg');
|
|
}
|
|
|
|
getNav(...args: Array<string | number>) {
|
|
let children = this.navItems;
|
|
const nav: Nav = {
|
|
breadcrumbs: [],
|
|
};
|
|
|
|
for (const id of args) {
|
|
// if its a number then it's the index to use for main
|
|
if (typeof id === 'number') {
|
|
nav.main = nav.breadcrumbs[id];
|
|
break;
|
|
}
|
|
|
|
const node = children.find((child) => child.id === id);
|
|
if (node) {
|
|
nav.breadcrumbs.push(node);
|
|
nav.node = node;
|
|
nav.main = node;
|
|
children = node.children ?? [];
|
|
}
|
|
}
|
|
|
|
if (nav.main?.children) {
|
|
for (const item of nav.main.children) {
|
|
item.active = item.url === nav.node?.url;
|
|
}
|
|
}
|
|
|
|
return nav;
|
|
}
|
|
|
|
getNotFoundNav() {
|
|
return getNotFoundNav(); // the exported function
|
|
}
|
|
}
|
|
|
|
coreModule.service('navModelSrv', NavModelSrv);
|