nav_model_srv.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. ///<reference path="../headers/common.d.ts" />
  2. import coreModule from 'app/core/core_module';
  3. import config from 'app/core/config';
  4. import _ from 'lodash';
  5. export interface NavModelItem {
  6. title: string;
  7. url: string;
  8. icon?: string;
  9. iconUrl?: string;
  10. }
  11. export interface NavModel {
  12. section: NavModelItem;
  13. menu: NavModelItem[];
  14. }
  15. export class NavModelSrv {
  16. navItems: any;
  17. /** @ngInject */
  18. constructor(private contextSrv) {
  19. this.navItems = config.bootData.navTree;
  20. }
  21. getCfgNode() {
  22. return _.find(this.navItems, {id: 'cfg'});
  23. }
  24. getNav(...args) {
  25. var children = this.navItems;
  26. var nav = {breadcrumbs: [], node: null};
  27. for (let id of args) {
  28. let node = _.find(children, {id: id});
  29. nav.breadcrumbs.push(node);
  30. nav.node = node;
  31. children = node.children;
  32. }
  33. return nav;
  34. }
  35. getNotFoundNav() {
  36. var node = {
  37. text: "Page not found ",
  38. icon: "fa fa-fw fa-warning",
  39. };
  40. return {
  41. breadcrumbs: [node],
  42. node: node
  43. };
  44. }
  45. getDashboardNav(dashboard, dashNavCtrl) {
  46. // special handling for snapshots
  47. if (dashboard.meta.isSnapshot) {
  48. return {
  49. section: {
  50. title: dashboard.title,
  51. icon: 'icon-gf icon-gf-snapshot'
  52. },
  53. menu: [
  54. {
  55. title: 'Go to original dashboard',
  56. icon: 'fa fa-fw fa-external-link',
  57. url: dashboard.snapshot.originalUrl,
  58. }
  59. ]
  60. };
  61. }
  62. var menu = [];
  63. if (dashboard.meta.canEdit) {
  64. menu.push({
  65. title: 'Settings',
  66. icon: 'fa fa-fw fa-cog',
  67. clickHandler: () => dashNavCtrl.openEditView('settings')
  68. });
  69. menu.push({
  70. title: 'Templating',
  71. icon: 'fa fa-fw fa-code',
  72. clickHandler: () => dashNavCtrl.openEditView('templating')
  73. });
  74. menu.push({
  75. title: 'Annotations',
  76. icon: 'fa fa-fw fa-comment',
  77. clickHandler: () => dashNavCtrl.openEditView('annotations')
  78. });
  79. if (dashboard.meta.canAdmin) {
  80. menu.push({
  81. title: 'Permissions...',
  82. icon: 'fa fa-fw fa-lock',
  83. clickHandler: () => dashNavCtrl.openEditView('permissions')
  84. });
  85. }
  86. if (!dashboard.meta.isHome) {
  87. menu.push({
  88. title: 'Version history',
  89. icon: 'fa fa-fw fa-history',
  90. clickHandler: () => dashNavCtrl.openEditView('history')
  91. });
  92. }
  93. menu.push({
  94. title: 'View JSON',
  95. icon: 'fa fa-fw fa-eye',
  96. clickHandler: () => dashNavCtrl.viewJson()
  97. });
  98. }
  99. if (this.contextSrv.isEditor && !dashboard.editable) {
  100. menu.push({
  101. title: 'Make Editable',
  102. icon: 'fa fa-fw fa-edit',
  103. clickHandler: () => dashNavCtrl.makeEditable()
  104. });
  105. }
  106. if (this.contextSrv.isEditor && !dashboard.meta.isFolder) {
  107. menu.push({
  108. title: 'Save As...',
  109. icon: 'fa fa-fw fa-save',
  110. clickHandler: () => dashNavCtrl.saveDashboardAs()
  111. });
  112. }
  113. if (dashboard.meta.canSave) {
  114. menu.push({
  115. title: 'Delete',
  116. icon: 'fa fa-fw fa-trash',
  117. clickHandler: () => dashNavCtrl.deleteDashboard()
  118. });
  119. }
  120. return {
  121. section: {
  122. title: dashboard.title,
  123. icon: 'icon-gf icon-gf-dashboard'
  124. },
  125. menu: menu
  126. };
  127. }
  128. }
  129. coreModule.service('navModelSrv', NavModelSrv);