dashnav.ts 2.7 KB

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