DashNavCtrl.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import moment from 'moment';
  2. import angular from 'angular';
  3. import { appEvents, NavModel } from 'app/core/core';
  4. import { DashboardModel } from '../../state/DashboardModel';
  5. export class DashNavCtrl {
  6. dashboard: DashboardModel;
  7. navModel: NavModel;
  8. titleTooltip: string;
  9. /** @ngInject */
  10. constructor(private $scope, private dashboardSrv, private $location, public playlistSrv) {
  11. if (this.dashboard.meta.isSnapshot) {
  12. const meta = this.dashboard.meta;
  13. this.titleTooltip = 'Created:  ' + moment(meta.created).calendar();
  14. if (meta.expires) {
  15. this.titleTooltip += '<br>Expires: &nbsp;' + moment(meta.expires).fromNow() + '<br>';
  16. }
  17. }
  18. }
  19. toggleSettings() {
  20. const search = this.$location.search();
  21. if (search.editview) {
  22. delete search.editview;
  23. } else {
  24. search.editview = 'settings';
  25. }
  26. this.$location.search(search);
  27. }
  28. toggleViewMode() {
  29. appEvents.emit('toggle-kiosk-mode');
  30. }
  31. close() {
  32. const search = this.$location.search();
  33. if (search.editview) {
  34. delete search.editview;
  35. } else if (search.fullscreen) {
  36. delete search.fullscreen;
  37. delete search.edit;
  38. delete search.tab;
  39. delete search.panelId;
  40. }
  41. this.$location.search(search);
  42. }
  43. starDashboard() {
  44. this.dashboardSrv.starDashboard(this.dashboard.id, this.dashboard.meta.isStarred).then(newState => {
  45. this.dashboard.meta.isStarred = newState;
  46. });
  47. }
  48. shareDashboard(tabIndex) {
  49. const modalScope = this.$scope.$new();
  50. modalScope.tabIndex = tabIndex;
  51. modalScope.dashboard = this.dashboard;
  52. appEvents.emit('show-modal', {
  53. src: 'public/app/features/dashboard/components/ShareModal/template.html',
  54. scope: modalScope,
  55. });
  56. }
  57. hideTooltip(evt) {
  58. angular.element(evt.currentTarget).tooltip('hide');
  59. }
  60. saveDashboard() {
  61. return this.dashboardSrv.saveDashboard();
  62. }
  63. showSearch() {
  64. if (this.dashboard.meta.fullscreen) {
  65. this.close();
  66. return;
  67. }
  68. appEvents.emit('show-dash-search');
  69. }
  70. addPanel() {
  71. appEvents.emit('dash-scroll', { animate: true, evt: 0 });
  72. if (this.dashboard.panels.length > 0 && this.dashboard.panels[0].type === 'add-panel') {
  73. return; // Return if the "Add panel" exists already
  74. }
  75. this.dashboard.addPanel({
  76. type: 'add-panel',
  77. gridPos: { x: 0, y: 0, w: 12, h: 8 },
  78. title: 'Panel Title',
  79. });
  80. }
  81. navItemClicked(navItem, evt) {
  82. if (navItem.clickHandler) {
  83. navItem.clickHandler();
  84. evt.preventDefault();
  85. }
  86. }
  87. }
  88. export function dashNavDirective() {
  89. return {
  90. restrict: 'E',
  91. templateUrl: 'public/app/features/dashboard/components/DashNav/template.html',
  92. controller: DashNavCtrl,
  93. bindToController: true,
  94. controllerAs: 'ctrl',
  95. transclude: true,
  96. scope: { dashboard: '=' },
  97. };
  98. }
  99. angular.module('grafana.directives').directive('dashnav', dashNavDirective);