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

87 lines
1.6 KiB

import coreModule from "app/core/core_module";
import config from "app/core/config";
import _ from "lodash";
export interface NavModelItem {
text: string;
url: string;
icon?: string;
img?: string;
id: string;
active?: boolean;
hideFromTabs?: boolean;
divider?: boolean;
children: NavModelItem[];
target?: string;
}
export class NavModel {
breadcrumbs: NavModelItem[];
main: NavModelItem;
node: NavModelItem;
constructor() {
this.breadcrumbs = [];
}
}
export class NavModelSrv {
navItems: any;
/** @ngInject */
constructor() {
this.navItems = config.bootData.navTree;
}
getCfgNode() {
return _.find(this.navItems, { id: "cfg" });
}
getNav(...args) {
var children = this.navItems;
var nav = new NavModel();
for (let 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;
}
let node = _.find(children, { id: id });
nav.breadcrumbs.push(node);
nav.node = node;
nav.main = node;
children = node.children;
}
if (nav.main.children) {
for (let item of nav.main.children) {
item.active = false;
if (item.url === nav.node.url) {
item.active = true;
}
}
}
return nav;
}
getNotFoundNav() {
var node = {
text: "Page not found",
icon: "fa fa-fw fa-warning",
subTitle: "404 Error"
};
return {
breadcrumbs: [node],
node: node,
main: node
};
}
}
coreModule.service("navModelSrv", NavModelSrv);