2017-12-20 05:33:33 -06:00
|
|
|
import coreModule from 'app/core/core_module';
|
|
|
|
import config from 'app/core/config';
|
2021-04-21 02:38:00 -05:00
|
|
|
import { find, isNumber } from 'lodash';
|
2019-06-18 10:17:27 -05:00
|
|
|
import { NavModel } from '@grafana/data';
|
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
|
|
|
|
2017-12-13 06:16:44 -06:00
|
|
|
constructor() {
|
2017-08-15 10:52:52 -05:00
|
|
|
this.navItems = config.bootData.navTree;
|
|
|
|
}
|
|
|
|
|
|
|
|
getCfgNode() {
|
2021-04-21 02:38:00 -05:00
|
|
|
return find(this.navItems, { id: 'cfg' });
|
2017-08-15 10:52:52 -05:00
|
|
|
}
|
|
|
|
|
2019-06-05 08:18:31 -05:00
|
|
|
getNav(...args: Array<string | number>) {
|
2018-08-30 01:58:43 -05:00
|
|
|
let children = this.navItems;
|
2019-04-30 09:46:46 -05:00
|
|
|
const nav = {
|
|
|
|
breadcrumbs: [],
|
Chore: Fix all Typescript strict null errors (#26204)
* Chore: Fix typescript strict null errors
* Added new limit
* Fixed ts issue
* fixed tests
* trying to fix type inference
* Fixing more ts errors
* Revert tsconfig option
* Fix
* Fixed code
* More fixes
* fix tests
* Updated snapshot
* Chore: More ts strict null fixes
* More fixes in some really messed up azure config components
* More fixes, current count: 441
* 419
* More fixes
* Fixed invalid initial state in explore
* Fixing tests
* Fixed tests
* Explore fix
* More fixes
* Progress
* Sub 300
* Now at 218
* Progress
* Update
* Progress
* Updated tests
* at 159
* fixed tests
* Progress
* YAy blow 100! at 94
* 10,9,8,7,6,5,4,3,2,1... lift off
* Fixed tests
* Fixed more type errors
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2020-07-10 05:46:59 -05:00
|
|
|
} as any;
|
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
|
2021-04-21 02:38:00 -05:00
|
|
|
if (isNumber(id)) {
|
2017-11-30 08:37:03 -06:00
|
|
|
nav.main = nav.breadcrumbs[id];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-04-21 02:38:00 -05:00
|
|
|
const node: any = 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() {
|
2019-05-02 12:15:39 -05:00
|
|
|
return getNotFoundNav(); // the exported function
|
2017-06-02 07:00:42 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-05 08:47:25 -05:00
|
|
|
export function getExceptionNav(error: any): NavModel {
|
|
|
|
console.error(error);
|
|
|
|
return getWarningNav('Exception thrown', 'See console for details');
|
|
|
|
}
|
|
|
|
|
2019-05-02 12:15:39 -05:00
|
|
|
export function getNotFoundNav(): NavModel {
|
|
|
|
return getWarningNav('Page not found', '404 Error');
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getWarningNav(text: string, subTitle?: string): NavModel {
|
|
|
|
const node = {
|
|
|
|
text,
|
|
|
|
subTitle,
|
2020-04-12 15:20:02 -05:00
|
|
|
icon: 'exclamation-triangle',
|
2019-05-02 12:15:39 -05:00
|
|
|
};
|
|
|
|
return {
|
|
|
|
breadcrumbs: [node],
|
|
|
|
node: node,
|
|
|
|
main: node,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-12-20 05:33:33 -06:00
|
|
|
coreModule.service('navModelSrv', NavModelSrv);
|