navModel.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import { NavModel, NavModelItem } from 'app/types';
  2. import { PluginMeta, DataSourceSettings } from '@grafana/ui/src/types';
  3. import config from 'app/core/config';
  4. export function buildNavModel(dataSource: DataSourceSettings, pluginMeta: PluginMeta): NavModelItem {
  5. const navModel = {
  6. img: pluginMeta.info.logos.large,
  7. id: 'datasource-' + dataSource.id,
  8. subTitle: `Type: ${pluginMeta.name}`,
  9. url: '',
  10. text: dataSource.name,
  11. breadcrumbs: [{ title: 'Data Sources', url: 'datasources' }],
  12. children: [
  13. {
  14. active: false,
  15. icon: 'fa fa-fw fa-sliders',
  16. id: `datasource-settings-${dataSource.id}`,
  17. text: 'Settings',
  18. url: `datasources/edit/${dataSource.id}`,
  19. },
  20. ],
  21. };
  22. if (pluginMeta.includes && hasDashboards(pluginMeta.includes)) {
  23. navModel.children.push({
  24. active: false,
  25. icon: 'fa fa-fw fa-th-large',
  26. id: `datasource-dashboards-${dataSource.id}`,
  27. text: 'Dashboards',
  28. url: `datasources/edit/${dataSource.id}/dashboards`,
  29. });
  30. }
  31. if (config.buildInfo.isEnterprise) {
  32. navModel.children.push({
  33. active: false,
  34. icon: 'fa fa-fw fa-lock',
  35. id: `datasource-permissions-${dataSource.id}`,
  36. text: 'Permissions',
  37. url: `datasources/edit/${dataSource.id}/permissions`,
  38. });
  39. }
  40. return navModel;
  41. }
  42. export function getDataSourceLoadingNav(pageName: string): NavModel {
  43. const main = buildNavModel(
  44. {
  45. access: '',
  46. basicAuth: false,
  47. basicAuthUser: '',
  48. basicAuthPassword: '',
  49. withCredentials: false,
  50. database: '',
  51. id: 1,
  52. isDefault: false,
  53. jsonData: { authType: 'credentials', defaultRegion: 'eu-west-2' },
  54. name: 'Loading',
  55. orgId: 1,
  56. password: '',
  57. readOnly: false,
  58. type: 'Loading',
  59. typeLogoUrl: 'public/img/icn-datasource.svg',
  60. url: '',
  61. user: '',
  62. },
  63. {
  64. id: '1',
  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: [{ type: '', name: '', path: '' }],
  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. }