dashnav.ts 2.8 KB

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