nav_model_srv.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. {title: 'Org User Groups', active: subPage === 3, url: 'org/user-groups', icon: 'fa fa-fw fa-users'},
  88. ]
  89. };
  90. }
  91. getAdminNav(subPage) {
  92. return {
  93. section: {
  94. title: 'Admin',
  95. url: 'admin',
  96. icon: 'fa fa-fw fa-cogs'
  97. },
  98. menu: [
  99. {title: 'Users', active: subPage === 0, url: 'admin/users', icon: 'fa fa-fw fa-user'},
  100. {title: 'Orgs', active: subPage === 1, url: 'admin/orgs', icon: 'fa fa-fw fa-users'},
  101. {title: 'Server Settings', active: subPage === 2, url: 'admin/settings', icon: 'fa fa-fw fa-cogs'},
  102. {title: 'Server Stats', active: subPage === 2, url: 'admin/stats', icon: 'fa fa-fw fa-line-chart'},
  103. {title: 'Style Guide', active: subPage === 2, url: 'styleguide', icon: 'fa fa-fw fa-key'},
  104. ]
  105. };
  106. }
  107. getPluginsNav() {
  108. return {
  109. section: {
  110. title: 'Plugins',
  111. url: 'plugins',
  112. icon: 'icon-gf icon-gf-apps'
  113. },
  114. menu: []
  115. };
  116. }
  117. getDashboardNav(dashboard, dashNavCtrl) {
  118. // special handling for snapshots
  119. if (dashboard.meta.isSnapshot) {
  120. return {
  121. section: {
  122. title: dashboard.title,
  123. icon: 'icon-gf icon-gf-snapshot'
  124. },
  125. menu: [
  126. {
  127. title: 'Go to original dashboard',
  128. icon: 'fa fa-fw fa-external-link',
  129. url: dashboard.snapshot.originalUrl,
  130. }
  131. ]
  132. };
  133. }
  134. var menu = [];
  135. if (dashboard.meta.canEdit) {
  136. menu.push({
  137. title: 'Settings',
  138. icon: 'fa fa-fw fa-cog',
  139. clickHandler: () => dashNavCtrl.openEditView('settings')
  140. });
  141. menu.push({
  142. title: 'Templating',
  143. icon: 'fa fa-fw fa-code',
  144. clickHandler: () => dashNavCtrl.openEditView('templating')
  145. });
  146. menu.push({
  147. title: 'Annotations',
  148. icon: 'fa fa-fw fa-bolt',
  149. clickHandler: () => dashNavCtrl.openEditView('annotations')
  150. });
  151. if (!dashboard.meta.isHome) {
  152. menu.push({
  153. title: 'Version history',
  154. icon: 'fa fa-fw fa-history',
  155. clickHandler: () => dashNavCtrl.openEditView('history')
  156. });
  157. }
  158. menu.push({
  159. title: 'View JSON',
  160. icon: 'fa fa-fw fa-eye',
  161. clickHandler: () => dashNavCtrl.viewJson()
  162. });
  163. }
  164. if (this.contextSrv.isEditor && !dashboard.editable) {
  165. menu.push({
  166. title: 'Make Editable',
  167. icon: 'fa fa-fw fa-edit',
  168. clickHandler: () => dashNavCtrl.makeEditable()
  169. });
  170. }
  171. menu.push({
  172. title: 'Shortcuts',
  173. icon: 'fa fa-fw fa-keyboard-o',
  174. clickHandler: () => dashNavCtrl.showHelpModal()
  175. });
  176. if (this.contextSrv.isEditor) {
  177. menu.push({
  178. title: 'Save As ...',
  179. icon: 'fa fa-fw fa-save',
  180. clickHandler: () => dashNavCtrl.saveDashboardAs()
  181. });
  182. }
  183. if (dashboard.meta.canSave) {
  184. menu.push({
  185. title: 'Delete',
  186. icon: 'fa fa-fw fa-trash',
  187. clickHandler: () => dashNavCtrl.deleteDashboard()
  188. });
  189. }
  190. return {
  191. section: {
  192. title: dashboard.title,
  193. icon: 'icon-gf icon-gf-dashboard'
  194. },
  195. menu: menu
  196. };
  197. }
  198. }
  199. coreModule.service('navModelSrv', NavModelSrv);