dashnav.ts 2.9 KB

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