dashnav.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. navModelSrv) {
  17. this.navModel = navModelSrv.getDashboardNav(this.dashboard, this);
  18. appEvents.on('save-dashboard', this.saveDashboard.bind(this), $scope);
  19. if (this.dashboard.meta.isSnapshot) {
  20. var meta = this.dashboard.meta;
  21. this.titleTooltip = 'Created:  ' + moment(meta.created).calendar();
  22. if (meta.expires) {
  23. this.titleTooltip += '<br>Expires: &nbsp;' + moment(meta.expires).fromNow() + '<br>';
  24. }
  25. }
  26. }
  27. toggleSettings() {
  28. let search = this.$location.search();
  29. if (search.editview) {
  30. delete search.editview;
  31. } else {
  32. search.editview = 'settings';
  33. }
  34. this.$location.search(search);
  35. }
  36. close() {
  37. let search = this.$location.search();
  38. if (search.editview) {
  39. delete search.editview;
  40. }
  41. if (search.fullscreen) {
  42. delete search.fullscreen;
  43. delete search.edit;
  44. }
  45. this.$location.search(search);
  46. }
  47. starDashboard() {
  48. this.dashboardSrv.starDashboard(this.dashboard.id, this.dashboard.meta.isStarred)
  49. .then(newState => {
  50. this.dashboard.meta.isStarred = newState;
  51. });
  52. }
  53. shareDashboard(tabIndex) {
  54. var modalScope = this.$scope.$new();
  55. modalScope.tabIndex = tabIndex;
  56. modalScope.dashboard = this.dashboard;
  57. appEvents.emit('show-modal', {
  58. src: 'public/app/features/dashboard/partials/shareModal.html',
  59. scope: modalScope
  60. });
  61. }
  62. hideTooltip(evt) {
  63. angular.element(evt.currentTarget).tooltip('hide');
  64. }
  65. saveDashboard() {
  66. return this.dashboardSrv.saveDashboard();
  67. }
  68. showSearch() {
  69. this.$rootScope.appEvent('show-dash-search');
  70. }
  71. addPanel() {
  72. if (this.dashboard.panels.length > 0 && this.dashboard.panels[0].type === 'add-panel') {
  73. this.dashboard.removePanel(this.dashboard.panels[0]);
  74. return;
  75. }
  76. this.dashboard.addPanel({
  77. type: 'add-panel',
  78. gridPos: {x: 0, y: 0, w: 12, h: 9},
  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/dashnav/dashnav.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);