navModel.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import { PluginMeta, DataSourceSettings, PluginType, NavModel, NavModelItem } from '@grafana/ui';
  2. import config from 'app/core/config';
  3. export function buildNavModel(dataSource: DataSourceSettings, pluginMeta: PluginMeta): NavModelItem {
  4. const navModel = {
  5. img: pluginMeta.info.logos.large,
  6. id: 'datasource-' + dataSource.id,
  7. subTitle: `Type: ${pluginMeta.name}`,
  8. url: '',
  9. text: dataSource.name,
  10. breadcrumbs: [{ title: 'Data Sources', url: 'datasources' }],
  11. children: [
  12. {
  13. active: false,
  14. icon: 'fa fa-fw fa-sliders',
  15. id: `datasource-settings-${dataSource.id}`,
  16. text: 'Settings',
  17. url: `datasources/edit/${dataSource.id}`,
  18. },
  19. ],
  20. };
  21. if (pluginMeta.includes && hasDashboards(pluginMeta.includes)) {
  22. navModel.children.push({
  23. active: false,
  24. icon: 'fa fa-fw fa-th-large',
  25. id: `datasource-dashboards-${dataSource.id}`,
  26. text: 'Dashboards',
  27. url: `datasources/edit/${dataSource.id}/dashboards`,
  28. });
  29. }
  30. if (config.buildInfo.isEnterprise) {
  31. navModel.children.push({
  32. active: false,
  33. icon: 'fa fa-fw fa-lock',
  34. id: `datasource-permissions-${dataSource.id}`,
  35. text: 'Permissions',
  36. url: `datasources/edit/${dataSource.id}/permissions`,
  37. });
  38. }
  39. return navModel;
  40. }
  41. export function getDataSourceLoadingNav(pageName: string): NavModel {
  42. const main = buildNavModel(
  43. {
  44. access: '',
  45. basicAuth: false,
  46. basicAuthUser: '',
  47. basicAuthPassword: '',
  48. withCredentials: false,
  49. database: '',
  50. id: 1,
  51. isDefault: false,
  52. jsonData: { authType: 'credentials', defaultRegion: 'eu-west-2' },
  53. name: 'Loading',
  54. orgId: 1,
  55. password: '',
  56. readOnly: false,
  57. type: 'Loading',
  58. typeLogoUrl: 'public/img/icn-datasource.svg',
  59. url: '',
  60. user: '',
  61. },
  62. {
  63. id: '1',
  64. type: PluginType.datasource,
  65. name: '',
  66. info: {
  67. author: {
  68. name: '',
  69. url: '',
  70. },
  71. description: '',
  72. links: [{ name: '', url: '' }],
  73. logos: {
  74. large: '',
  75. small: '',
  76. },
  77. screenshots: [],
  78. updated: '',
  79. version: '',
  80. },
  81. includes: [],
  82. module: '',
  83. baseUrl: '',
  84. }
  85. );
  86. let node: NavModelItem;
  87. // find active page
  88. for (const child of main.children) {
  89. if (child.id.indexOf(pageName) > 0) {
  90. child.active = true;
  91. node = child;
  92. break;
  93. }
  94. }
  95. return {
  96. main: main,
  97. node: node,
  98. };
  99. }
  100. function hasDashboards(includes) {
  101. return (
  102. includes.filter(include => {
  103. return include.type === 'dashboard';
  104. }).length > 0
  105. );
  106. }