panel_ctrl.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. ///<reference path="../../headers/common.d.ts" />
  2. import config from 'app/core/config';
  3. import _ from 'lodash';
  4. export class PanelCtrl {
  5. panel: any;
  6. row: any;
  7. dashboard: any;
  8. editorTabIndex: number;
  9. pluginName: string;
  10. pluginId: string;
  11. icon: string;
  12. editorTabs: any;
  13. $scope: any;
  14. $injector: any;
  15. $timeout: any;
  16. fullscreen: boolean;
  17. inspector: any;
  18. editModeInitiated: boolean;
  19. editorHelpIndex: number;
  20. constructor($scope, $injector) {
  21. var plugin = config.panels[this.panel.type];
  22. this.$injector = $injector;
  23. this.$scope = $scope;
  24. this.$timeout = $injector.get('$timeout');
  25. this.pluginName = plugin.name;
  26. this.pluginId = plugin.id;
  27. this.icon = plugin.info.icon;
  28. this.editorTabIndex = 0;
  29. $scope.$on("refresh", () => this.refresh());
  30. }
  31. init() {
  32. this.publishAppEvent('panel-instantiated', {scope: this.$scope});
  33. this.refresh();
  34. }
  35. renderingCompleted() {
  36. this.$scope.$root.performance.panelsRendered++;
  37. }
  38. refresh() {
  39. return;
  40. }
  41. publishAppEvent(evtName, evt) {
  42. this.$scope.$root.appEvent(evtName, evt);
  43. }
  44. changeView(fullscreen, edit) {
  45. this.publishAppEvent('panel-change-view', {
  46. fullscreen: fullscreen, edit: edit, panelId: this.panel.id
  47. });
  48. }
  49. viewPanel() {
  50. this.changeView(true, false);
  51. }
  52. editPanel() {
  53. if (!this.editModeInitiated) {
  54. this.editorTabs = [];
  55. this.addEditorTab('General', 'public/app/partials/panelgeneral.html');
  56. this.initEditMode();
  57. }
  58. this.changeView(true, true);
  59. }
  60. exitFullscreen() {
  61. this.changeView(false, false);
  62. }
  63. initEditMode() {
  64. return;
  65. }
  66. addEditorTab(title, templateUrl) {
  67. this.editorTabs.push({
  68. title: title,
  69. directiveFn: function() {
  70. return {templateUrl: templateUrl};
  71. }
  72. });
  73. }
  74. getMenu() {
  75. let menu = [];
  76. menu.push({text: 'View', click: 'ctrl.viewPanel(); dismiss();'});
  77. menu.push({text: 'Edit', click: 'ctrl.editPanel(); dismiss();', role: 'Editor'});
  78. menu.push({text: 'Duplicate', click: 'ctrl.duplicate()', role: 'Editor' });
  79. menu.push({text: 'Share', click: 'ctrl.share(); dismiss();'});
  80. return menu;
  81. }
  82. otherPanelInFullscreenMode() {
  83. return this.dashboard.meta.fullscreen && !this.fullscreen;
  84. }
  85. broadcastRender(arg1?, arg2?) {
  86. this.$scope.$broadcast('render', arg1, arg2);
  87. }
  88. toggleEditorHelp(index) {
  89. if (this.editorHelpIndex === index) {
  90. this.editorHelpIndex = null;
  91. return;
  92. }
  93. this.editorHelpIndex = index;
  94. }
  95. duplicate() {
  96. this.dashboard.duplicatePanel(this.panel, this.row);
  97. }
  98. updateColumnSpan(span) {
  99. this.panel.span = Math.min(Math.max(Math.floor(this.panel.span + span), 1), 12);
  100. this.$timeout(() => {
  101. this.broadcastRender();
  102. });
  103. }
  104. removePanel() {
  105. this.publishAppEvent('confirm-modal', {
  106. title: 'Are you sure you want to remove this panel?',
  107. icon: 'fa-trash',
  108. yesText: 'Delete',
  109. onConfirm: () => {
  110. this.row.panels = _.without(this.row.panels, this.panel);
  111. }
  112. });
  113. }
  114. }