dashnav.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 dashboardSrv,
  13. private $location,
  14. public playlistSrv
  15. ) {
  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 +=
  22. "<br>Expires: &nbsp;" + moment(meta.expires).fromNow() + "<br>";
  23. }
  24. }
  25. }
  26. toggleSettings() {
  27. let search = this.$location.search();
  28. if (search.editview) {
  29. delete search.editview;
  30. } else {
  31. search.editview = "settings";
  32. }
  33. this.$location.search(search);
  34. }
  35. close() {
  36. let search = this.$location.search();
  37. if (search.editview) {
  38. delete search.editview;
  39. }
  40. if (search.fullscreen) {
  41. delete search.fullscreen;
  42. delete search.edit;
  43. }
  44. this.$location.search(search);
  45. }
  46. starDashboard() {
  47. this.dashboardSrv
  48. .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. appEvents.emit("show-dash-search");
  70. }
  71. addPanel() {
  72. if (
  73. this.dashboard.panels.length > 0 &&
  74. this.dashboard.panels[0].type === "add-panel"
  75. ) {
  76. this.dashboard.removePanel(this.dashboard.panels[0]);
  77. return;
  78. }
  79. this.dashboard.addPanel({
  80. type: "add-panel",
  81. gridPos: { x: 0, y: 0, w: 12, h: 9 },
  82. title: "Panel Title"
  83. });
  84. }
  85. navItemClicked(navItem, evt) {
  86. if (navItem.clickHandler) {
  87. navItem.clickHandler();
  88. evt.preventDefault();
  89. }
  90. }
  91. }
  92. export function dashNavDirective() {
  93. return {
  94. restrict: "E",
  95. templateUrl: "public/app/features/dashboard/dashnav/dashnav.html",
  96. controller: DashNavCtrl,
  97. bindToController: true,
  98. controllerAs: "ctrl",
  99. transclude: true,
  100. scope: { dashboard: "=" }
  101. };
  102. }
  103. angular.module("grafana.directives").directive("dashnav", dashNavDirective);