navModel.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import { DataSource, NavModel, NavModelItem, PluginMeta } from 'app/types';
  2. import config from 'app/core/config';
  3. export function buildNavModel(dataSource: DataSource, 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. name: '',
  65. info: {
  66. author: {
  67. name: '',
  68. url: '',
  69. },
  70. description: '',
  71. links: [''],
  72. logos: {
  73. large: '',
  74. small: '',
  75. },
  76. screenshots: [],
  77. updated: '',
  78. version: '',
  79. },
  80. includes: [{ type: '', name: '', path: '' }],
  81. }
  82. );
  83. let node: NavModelItem;
  84. // find active page
  85. for (const child of main.children) {
  86. if (child.id.indexOf(pageName) > 0) {
  87. child.active = true;
  88. node = child;
  89. break;
  90. }
  91. }
  92. return {
  93. main: main,
  94. node: node,
  95. };
  96. }
  97. function hasDashboards(includes) {
  98. return (
  99. includes.filter(include => {
  100. return include.type === 'dashboard';
  101. }).length > 0
  102. );
  103. }