nav_model_srv.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. ///<reference path="../headers/common.d.ts" />
  2. import coreModule from 'app/core/core_module';
  3. export interface NavModelItem {
  4. title: string;
  5. url: string;
  6. icon?: string;
  7. iconUrl?: string;
  8. }
  9. export interface NavModel {
  10. section: NavModelItem;
  11. menu: NavModelItem[];
  12. }
  13. export class NavModelSrv {
  14. /** @ngInject */
  15. constructor(private contextSrv) {
  16. }
  17. getAlertingNav(subPage) {
  18. return {
  19. section: {
  20. title: 'Alerting',
  21. url: 'plugins',
  22. icon: 'icon-gf icon-gf-alert'
  23. },
  24. menu: [
  25. {title: 'Alert List', active: subPage === 0, url: 'alerting/list', icon: 'fa fa-list-ul'},
  26. {title: 'Notification channels', active: subPage === 1, url: 'alerting/notifications', icon: 'fa fa-bell-o'},
  27. ]
  28. };
  29. }
  30. getDatasourceNav(subPage) {
  31. return {
  32. section: {
  33. title: 'Data Sources',
  34. url: 'datasources',
  35. icon: 'icon-gf icon-gf-datasources'
  36. },
  37. menu: [
  38. {title: 'List view', active: subPage === 0, url: 'datasources', icon: 'fa fa-list-ul'},
  39. {title: 'Add data source', active: subPage === 1, url: 'datasources/new', icon: 'fa fa-plus'},
  40. ]
  41. };
  42. }
  43. getPlaylistsNav(subPage) {
  44. return {
  45. section: {
  46. title: 'Playlists',
  47. url: 'playlists',
  48. icon: 'fa fa-fw fa-film'
  49. },
  50. menu: [
  51. {title: 'List view', active: subPage === 0, url: 'playlists', icon: 'fa fa-list-ul'},
  52. {title: 'Add Playlist', active: subPage === 1, url: 'playlists/create', icon: 'fa fa-plus'},
  53. ]
  54. };
  55. }
  56. getProfileNav() {
  57. return {
  58. section: {
  59. title: 'User Profile',
  60. url: 'profile',
  61. icon: 'fa fa-fw fa-user'
  62. },
  63. menu: []
  64. };
  65. }
  66. getNotFoundNav() {
  67. return {
  68. section: {
  69. title: 'Page',
  70. url: '',
  71. icon: 'fa fa-fw fa-warning'
  72. },
  73. menu: []
  74. };
  75. }
  76. getOrgNav(subPage) {
  77. return {
  78. section: {
  79. title: 'Organization',
  80. url: 'org',
  81. icon: 'icon-gf icon-gf-users'
  82. },
  83. menu: [
  84. {title: 'Preferences', active: subPage === 0, url: 'org', icon: 'fa fa-fw fa-cog'},
  85. {title: 'Org Users', active: subPage === 1, url: 'org/users', icon: 'fa fa-fw fa-users'},
  86. {title: 'API Keys', active: subPage === 2, url: 'org/apikeys', icon: 'fa fa-fw fa-key'},
  87. ]
  88. };
  89. }
  90. getAdminNav(subPage) {
  91. return {
  92. section: {
  93. title: 'Admin',
  94. url: 'admin',
  95. icon: 'fa fa-fw fa-cogs'
  96. },
  97. menu: [
  98. {title: 'Users', active: subPage === 0, url: 'admin/users', icon: 'fa fa-fw fa-user'},
  99. {title: 'Orgs', active: subPage === 1, url: 'admin/orgs', icon: 'fa fa-fw fa-users'},
  100. {title: 'Server Settings', active: subPage === 2, url: 'admin/settings', icon: 'fa fa-fw fa-cogs'},
  101. {title: 'Server Stats', active: subPage === 2, url: 'admin/stats', icon: 'fa fa-fw fa-line-chart'},
  102. {title: 'Style Guide', active: subPage === 2, url: 'styleguide', icon: 'fa fa-fw fa-key'},
  103. ]
  104. };
  105. }
  106. getPluginsNav() {
  107. return {
  108. section: {
  109. title: 'Plugins',
  110. url: 'plugins',
  111. icon: 'icon-gf icon-gf-apps'
  112. },
  113. menu: []
  114. };
  115. }
  116. getDashboardNav(dashboard, dashNavCtrl) {
  117. // special handling for snapshots
  118. if (dashboard.meta.isSnapshot) {
  119. return {
  120. section: {
  121. title: dashboard.title,
  122. icon: 'icon-gf icon-gf-snapshot'
  123. },
  124. menu: [
  125. {
  126. title: 'Go to original dashboard',
  127. icon: 'fa fa-fw fa-external-link',
  128. url: dashboard.snapshot.originalUrl,
  129. }
  130. ]
  131. };
  132. }
  133. var menu = [];
  134. if (dashboard.meta.canEdit) {
  135. menu.push({
  136. title: 'Settings',
  137. icon: 'fa fa-fw fa-cog',
  138. clickHandler: () => dashNavCtrl.openEditView('settings')
  139. });
  140. menu.push({
  141. title: 'Templating',
  142. icon: 'fa fa-fw fa-code',
  143. clickHandler: () => dashNavCtrl.openEditView('templating')
  144. });
  145. menu.push({
  146. title: 'Annotations',
  147. icon: 'fa fa-fw fa-comment',
  148. clickHandler: () => dashNavCtrl.openEditView('annotations')
  149. });
  150. if (!dashboard.meta.isHome) {
  151. menu.push({
  152. title: 'Version history',
  153. icon: 'fa fa-fw fa-history',
  154. clickHandler: () => dashNavCtrl.openEditView('history')
  155. });
  156. }
  157. menu.push({
  158. title: 'View JSON',
  159. icon: 'fa fa-fw fa-eye',
  160. clickHandler: () => dashNavCtrl.viewJson()
  161. });
  162. }
  163. if (this.contextSrv.isEditor && !dashboard.editable) {
  164. menu.push({
  165. title: 'Make Editable',
  166. icon: 'fa fa-fw fa-edit',
  167. clickHandler: () => dashNavCtrl.makeEditable()
  168. });
  169. }
  170. menu.push({
  171. title: 'Shortcuts',
  172. icon: 'fa fa-fw fa-keyboard-o',
  173. clickHandler: () => dashNavCtrl.showHelpModal()
  174. });
  175. if (this.contextSrv.isEditor) {
  176. menu.push({
  177. title: 'Save As ...',
  178. icon: 'fa fa-fw fa-save',
  179. clickHandler: () => dashNavCtrl.saveDashboardAs()
  180. });
  181. }
  182. if (dashboard.meta.canSave) {
  183. menu.push({
  184. title: 'Delete',
  185. icon: 'fa fa-fw fa-trash',
  186. clickHandler: () => dashNavCtrl.deleteDashboard()
  187. });
  188. }
  189. return {
  190. section: {
  191. title: dashboard.title,
  192. icon: 'icon-gf icon-gf-dashboard'
  193. },
  194. menu: menu
  195. };
  196. }
  197. }
  198. coreModule.service('navModelSrv', NavModelSrv);