panel_ctrl.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. isMetricsPanel: boolean;
  16. constructor($scope) {
  17. var plugin = config.panels[this.panel.type];
  18. this.$scope = $scope;
  19. this.name = plugin.name;
  20. this.icon = plugin.info.icon;
  21. this.editorTabIndex = 0;
  22. this.publishAppEvent('panel-instantiated', {scope: $scope});
  23. $scope.$on("refresh", () => this.refresh());
  24. }
  25. refresh() {
  26. return;
  27. }
  28. publishAppEvent(evtName, evt) {
  29. this.$scope.$root.appEvent(evtName, evt);
  30. }
  31. changeView(fullscreen, edit) {
  32. this.publishAppEvent('panel-change-view', {
  33. fullscreen: fullscreen, edit: edit, panelId: this.panel.id
  34. });
  35. }
  36. viewPanel() {
  37. this.changeView(true, false);
  38. }
  39. editPanel() {
  40. if (!this.editorTabs) {
  41. this.editorTabs = [];
  42. this.editorTabs.push({title: 'General', directiveFn: generalOptionsTabEditorTab});
  43. this.initEditorTabs();
  44. }
  45. this.changeView(true, true);
  46. }
  47. exitFullscreen() {
  48. this.changeView(false, false);
  49. }
  50. initEditorTabs() {
  51. return;
  52. }
  53. addEditorTab(title, directiveFn) {
  54. this.editorTabs.push({title: title, directiveFn: directiveFn});
  55. }
  56. getMenu() {
  57. let menu = [];
  58. menu.push({text: 'View', click: 'ctrl.viewPanel(); dismiss();'});
  59. menu.push({text: 'Edit', click: 'ctrl.editPanel(); dismiss();', role: 'Editor'});
  60. menu.push({text: 'Duplicate', click: 'ctrl.duplicate()', role: 'Editor' });
  61. menu.push({text: 'Share', click: 'ctrl.share(); dismiss();'});
  62. return menu;
  63. }
  64. }