grafana/public/app/features/datasources/state/navModel.ts

114 lines
2.6 KiB
TypeScript
Raw Normal View History

2019-01-17 10:37:34 -06:00
import { DataSource, NavModel, NavModelItem } from 'app/types';
import { PluginMeta } from '@grafana/ui/src/types';
import config from 'app/core/config';
2018-10-08 07:09:02 -05:00
export function buildNavModel(dataSource: DataSource, pluginMeta: PluginMeta): NavModelItem {
const navModel = {
img: pluginMeta.info.logos.large,
id: 'datasource-' + dataSource.id,
subTitle: `Type: ${pluginMeta.name}`,
url: '',
text: dataSource.name,
breadcrumbs: [{ title: 'Data Sources', url: 'datasources' }],
children: [
{
active: false,
icon: 'fa fa-fw fa-sliders',
id: `datasource-settings-${dataSource.id}`,
text: 'Settings',
2018-10-12 01:54:37 -05:00
url: `datasources/edit/${dataSource.id}`,
2018-10-08 07:09:02 -05:00
},
],
};
if (pluginMeta.includes && hasDashboards(pluginMeta.includes)) {
2018-10-08 07:09:02 -05:00
navModel.children.push({
active: false,
icon: 'fa fa-fw fa-th-large',
2018-10-08 07:09:02 -05:00
id: `datasource-dashboards-${dataSource.id}`,
text: 'Dashboards',
url: `datasources/edit/${dataSource.id}/dashboards`,
});
}
if (config.buildInfo.isEnterprise) {
navModel.children.push({
active: false,
icon: 'fa fa-fw fa-lock',
id: `datasource-permissions-${dataSource.id}`,
text: 'Permissions',
url: `datasources/edit/${dataSource.id}/permissions`,
});
}
2018-10-08 07:09:02 -05:00
return navModel;
}
export function getDataSourceLoadingNav(pageName: string): NavModel {
const main = buildNavModel(
{
access: '',
basicAuth: false,
2018-10-15 09:45:39 -05:00
basicAuthUser: '',
basicAuthPassword: '',
withCredentials: false,
2018-10-08 07:09:02 -05:00
database: '',
id: 1,
isDefault: false,
jsonData: { authType: 'credentials', defaultRegion: 'eu-west-2' },
name: 'Loading',
orgId: 1,
password: '',
readOnly: false,
type: 'Loading',
typeLogoUrl: 'public/img/icn-datasource.svg',
url: '',
user: '',
},
{
id: '1',
name: '',
info: {
author: {
name: '',
url: '',
},
description: '',
2018-12-18 07:40:54 -06:00
links: [{ name: '', url: '' }],
2018-10-08 07:09:02 -05:00
logos: {
large: '',
small: '',
},
2018-11-13 00:54:02 -06:00
screenshots: [],
2018-10-08 07:09:02 -05:00
updated: '',
version: '',
},
includes: [{ type: '', name: '', path: '' }],
}
);
let node: NavModelItem;
// find active page
for (const child of main.children) {
if (child.id.indexOf(pageName) > 0) {
child.active = true;
node = child;
break;
}
}
return {
main: main,
node: node,
};
}
function hasDashboards(includes) {
return (
includes.filter(include => {
return include.type === 'dashboard';
}).length > 0
);
}