dashnav.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import moment from 'moment';
  2. import angular from 'angular';
  3. import { appEvents, NavModel } from 'app/core/core';
  4. import { DashboardModel } from '../dashboard_model';
  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. }
  40. this.$location.search(search);
  41. }
  42. starDashboard() {
  43. this.dashboardSrv.starDashboard(this.dashboard.id, this.dashboard.meta.isStarred).then(newState => {
  44. this.dashboard.meta.isStarred = newState;
  45. });
  46. }
  47. shareDashboard(tabIndex) {
  48. const modalScope = this.$scope.$new();
  49. modalScope.tabIndex = tabIndex;
  50. modalScope.dashboard = this.dashboard;
  51. appEvents.emit('show-modal', {
  52. src: 'public/app/features/dashboard/partials/shareModal.html',
  53. scope: modalScope,
  54. });
  55. }
  56. hideTooltip(evt) {
  57. angular.element(evt.currentTarget).tooltip('hide');
  58. }
  59. saveDashboard() {
  60. return this.dashboardSrv.saveDashboard();
  61. }
  62. showSearch() {
  63. appEvents.emit('show-dash-search');
  64. }
  65. addPanel() {
  66. appEvents.emit('dash-scroll', { animate: true, evt: 0 });
  67. if (this.dashboard.panels.length > 0 && this.dashboard.panels[0].type === 'add-panel') {
  68. return; // Return if the "Add panel" exists already
  69. }
  70. this.dashboard.addPanel({
  71. type: 'add-panel',
  72. gridPos: { x: 0, y: 0, w: 12, h: 9 },
  73. title: 'Panel Title',
  74. });
  75. }
  76. navItemClicked(navItem, evt) {
  77. if (navItem.clickHandler) {
  78. navItem.clickHandler();
  79. evt.preventDefault();
  80. }
  81. }
  82. }
  83. export function dashNavDirective() {
  84. return {
  85. restrict: 'E',
  86. templateUrl: 'public/app/features/dashboard/dashnav/dashnav.html',
  87. controller: DashNavCtrl,
  88. bindToController: true,
  89. controllerAs: 'ctrl',
  90. transclude: true,
  91. scope: { dashboard: '=' },
  92. };
  93. }
  94. angular.module('grafana.directives').directive('dashnav', dashNavDirective);