panel_ctrl.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. ///<reference path="../../headers/common.d.ts" />
  2. import config from 'app/core/config';
  3. function generalOptionsTabEditorTab() {
  4. return {templateUrl: 'public/app/partials/panelgeneral.html'};
  5. }
  6. export class PanelCtrl {
  7. panel: any;
  8. row: any;
  9. dashboard: any;
  10. editorTabIndex: number;
  11. name: string;
  12. icon: string;
  13. editorTabs: any;
  14. $scope: any;
  15. $injector: any;
  16. fullscreen: boolean;
  17. inspector: any;
  18. constructor($scope, $injector) {
  19. var plugin = config.panels[this.panel.type];
  20. this.$injector = $injector;
  21. this.$scope = $scope;
  22. this.name = plugin.name;
  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. }
  30. refresh() {
  31. return;
  32. }
  33. publishAppEvent(evtName, evt) {
  34. this.$scope.$root.appEvent(evtName, evt);
  35. }
  36. changeView(fullscreen, edit) {
  37. this.publishAppEvent('panel-change-view', {
  38. fullscreen: fullscreen, edit: edit, panelId: this.panel.id
  39. });
  40. }
  41. viewPanel() {
  42. this.changeView(true, false);
  43. }
  44. editPanel() {
  45. if (!this.editorTabs) {
  46. this.editorTabs = [];
  47. this.editorTabs.push({title: 'General', directiveFn: generalOptionsTabEditorTab});
  48. this.initEditorTabs();
  49. }
  50. this.changeView(true, true);
  51. }
  52. exitFullscreen() {
  53. this.changeView(false, false);
  54. }
  55. initEditorTabs() {
  56. return;
  57. }
  58. addEditorTab(title, directiveFn) {
  59. this.editorTabs.push({title: title, directiveFn: directiveFn});
  60. }
  61. getMenu() {
  62. let menu = [];
  63. menu.push({text: 'View', click: 'ctrl.viewPanel(); dismiss();'});
  64. menu.push({text: 'Edit', click: 'ctrl.editPanel(); dismiss();', role: 'Editor'});
  65. menu.push({text: 'Duplicate', click: 'ctrl.duplicate()', role: 'Editor' });
  66. menu.push({text: 'Share', click: 'ctrl.share(); dismiss();'});
  67. return menu;
  68. }
  69. otherPanelInFullscreenMode() {
  70. return this.dashboard.meta.fullscreen && !this.fullscreen;
  71. }
  72. }