panel_ctrl.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. ///<reference path="../../headers/common.d.ts" />
  2. import config from 'app/core/config';
  3. export class PanelCtrl {
  4. panel: any;
  5. row: any;
  6. dashboard: any;
  7. editorTabIndex: number;
  8. pluginName: string;
  9. pluginId: string;
  10. icon: string;
  11. editorTabs: any;
  12. $scope: any;
  13. $injector: any;
  14. fullscreen: boolean;
  15. inspector: any;
  16. editModeInitiated: boolean;
  17. constructor($scope, $injector) {
  18. var plugin = config.panels[this.panel.type];
  19. this.$injector = $injector;
  20. this.$scope = $scope;
  21. this.pluginName = plugin.name;
  22. this.pluginId = plugin.id;
  23. this.icon = plugin.info.icon;
  24. this.editorTabIndex = 0;
  25. $scope.$on("refresh", () => this.refresh());
  26. }
  27. init() {
  28. this.publishAppEvent('panel-instantiated', {scope: this.$scope});
  29. this.refresh();
  30. }
  31. renderingCompleted() {
  32. this.$scope.$root.performance.panelsRendered++;
  33. }
  34. refresh() {
  35. return;
  36. }
  37. publishAppEvent(evtName, evt) {
  38. this.$scope.$root.appEvent(evtName, evt);
  39. }
  40. changeView(fullscreen, edit) {
  41. this.publishAppEvent('panel-change-view', {
  42. fullscreen: fullscreen, edit: edit, panelId: this.panel.id
  43. });
  44. }
  45. viewPanel() {
  46. this.changeView(true, false);
  47. }
  48. editPanel() {
  49. if (!this.editModeInitiated) {
  50. this.editorTabs = [];
  51. this.addEditorTab('General', 'public/app/partials/panelgeneral.html');
  52. this.initEditMode();
  53. }
  54. this.changeView(true, true);
  55. }
  56. exitFullscreen() {
  57. this.changeView(false, false);
  58. }
  59. initEditMode() {
  60. return;
  61. }
  62. addEditorTab(title, templateUrl) {
  63. this.editorTabs.push({
  64. title: title,
  65. directiveFn: function() {
  66. return {templateUrl: templateUrl};
  67. }
  68. });
  69. }
  70. getMenu() {
  71. let menu = [];
  72. menu.push({text: 'View', click: 'ctrl.viewPanel(); dismiss();'});
  73. menu.push({text: 'Edit', click: 'ctrl.editPanel(); dismiss();', role: 'Editor'});
  74. menu.push({text: 'Duplicate', click: 'ctrl.duplicate()', role: 'Editor' });
  75. menu.push({text: 'Share', click: 'ctrl.share(); dismiss();'});
  76. return menu;
  77. }
  78. otherPanelInFullscreenMode() {
  79. return this.dashboard.meta.fullscreen && !this.fullscreen;
  80. }
  81. broadcastRender(arg1?, arg2?) {
  82. this.$scope.$broadcast('render', arg1, arg2);
  83. }
  84. }