The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/core/nav_model_srv.ts

73 lines
1.5 KiB

import coreModule from 'app/core/core_module';
import config from 'app/core/config';
import _ from 'lodash';
import { NavModel } from '@grafana/data';
export class NavModelSrv {
navItems: any;
/** @ngInject */
constructor() {
this.navItems = config.bootData.navTree;
}
getCfgNode() {
return _.find(this.navItems, { id: 'cfg' });
}
getNav(...args: Array<string | number>) {
let children = this.navItems;
const nav = {
breadcrumbs: [],
} as NavModel;
for (const id of args) {
// if its a number then it's the index to use for main
if (_.isNumber(id)) {
nav.main = nav.breadcrumbs[id];
break;
}
const node: any = _.find(children, { id: id });
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 = false;
if (item.url === nav.node.url) {
item.active = true;
}
}
}
return nav;
}
getNotFoundNav() {
return getNotFoundNav(); // the exported function
}
}
export function getNotFoundNav(): NavModel {
return getWarningNav('Page not found', '404 Error');
}
export function getWarningNav(text: string, subTitle?: string): NavModel {
const node = {
text,
subTitle,
icon: 'fa fa-fw fa-warning',
};
return {
breadcrumbs: [node],
node: node,
main: node,
};
}
coreModule.service('navModelSrv', NavModelSrv);