DashNavCtrl.ts 3.0 KB

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