From f0f7da9ff0cb053c6bf303e9521d22a78a5567fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 27 Jan 2016 17:16:00 -0500 Subject: [PATCH] feat(panels): fixing broken stuff --- public/app/features/dashboard/rowCtrl.js | 25 -------------- public/app/features/panel/panel_ctrl.ts | 34 +++++++++++++++++--- public/app/features/panel/panel_directive.js | 3 +- public/app/features/panel/panel_loader.ts | 4 +-- public/app/features/panel/panel_menu.js | 2 +- public/app/plugins/panel/text/module.ts | 1 + public/app/plugins/panel/unknown/module.ts | 7 +++- 7 files changed, 40 insertions(+), 36 deletions(-) diff --git a/public/app/features/dashboard/rowCtrl.js b/public/app/features/dashboard/rowCtrl.js index 77f923d2377..e8abb5bbb05 100644 --- a/public/app/features/dashboard/rowCtrl.js +++ b/public/app/features/dashboard/rowCtrl.js @@ -116,32 +116,7 @@ function (angular, _, config) { $scope.$broadcast('render'); }; - $scope.removePanel = function(panel) { - $scope.appEvent('confirm-modal', { - title: 'Are you sure you want to remove this panel?', - icon: 'fa-trash', - yesText: 'Delete', - onConfirm: function() { - $scope.row.panels = _.without($scope.row.panels, panel); - } - }); - }; - - $scope.replacePanel = function(newPanel, oldPanel) { - var row = $scope.row; - var index = _.indexOf(row.panels, oldPanel); - row.panels.splice(index, 1); - - // adding it back needs to be done in next digest - $timeout(function() { - newPanel.id = oldPanel.id; - newPanel.span = oldPanel.span; - row.panels.splice(index, 0, newPanel); - }); - }; - $scope.init(); - }); module.directive('rowHeight', function() { diff --git a/public/app/features/panel/panel_ctrl.ts b/public/app/features/panel/panel_ctrl.ts index f3c1b159955..8e3dd9d09f2 100644 --- a/public/app/features/panel/panel_ctrl.ts +++ b/public/app/features/panel/panel_ctrl.ts @@ -21,16 +21,17 @@ export class PanelCtrl { editorHelpIndex: number; constructor($scope, $injector) { - var plugin = config.panels[this.panel.type]; - this.$injector = $injector; this.$scope = $scope; this.$timeout = $injector.get('$timeout'); - this.pluginName = plugin.name; - this.pluginId = plugin.id; - this.icon = plugin.info.icon; this.editorTabIndex = 0; + var plugin = config.panels[this.panel.type]; + if (plugin) { + this.pluginId = plugin.id; + this.pluginName = plugin.name; + } + $scope.$on("refresh", () => this.refresh()); } @@ -97,6 +98,10 @@ export class PanelCtrl { return menu; } + getExtendedMenu() { + return [{text: 'Panel JSON', click: 'ctrl.editPanelJson(); dismiss();'}]; + } + otherPanelInFullscreenMode() { return this.dashboard.meta.fullscreen && !this.fullscreen; } @@ -135,4 +140,23 @@ export class PanelCtrl { }); } + editPanelJson() { + this.publishAppEvent('show-json-editor', { + object: this.panel, + updateHandler: this.replacePanel.bind(this) + }); + } + + replacePanel(newPanel, oldPanel) { + var row = this.row; + var index = _.indexOf(this.row.panels, oldPanel); + this.row.panels.splice(index, 1); + + // adding it back needs to be done in next digest + this.$timeout(() => { + newPanel.id = oldPanel.id; + newPanel.span = oldPanel.span; + this.row.panels.splice(index, 0, newPanel); + }); + } } diff --git a/public/app/features/panel/panel_directive.js b/public/app/features/panel/panel_directive.js index 50cc4b57b26..ffe978a55ad 100644 --- a/public/app/features/panel/panel_directive.js +++ b/public/app/features/panel/panel_directive.js @@ -17,7 +17,6 @@ function (angular, $) { var panelContainer = elem.find('.panel-container'); var ctrl = scope.ctrl; scope.$watchGroup(['ctrl.fullscreen', 'ctrl.height', 'ctrl.panel.height', 'ctrl.row.height'], function() { - console.log('height: ', ctrl.height); panelContainer.css({ minHeight: ctrl.height || ctrl.panel.height || ctrl.row.height, display: 'block' }); elem.toggleClass('panel-fullscreen', ctrl.fullscreen ? true : false); }); @@ -80,7 +79,7 @@ function (angular, $) { function dragEndHandler() { // if close to 12 - var rowSpan = ctrl.dashboard.rowSpan(scope.row); + var rowSpan = ctrl.dashboard.rowSpan(ctrl.row); if (rowSpan < 12 && rowSpan > 11) { lastPanel.span += 12 - rowSpan; } diff --git a/public/app/features/panel/panel_loader.ts b/public/app/features/panel/panel_loader.ts index cf42458a9a7..73b154e8840 100644 --- a/public/app/features/panel/panel_loader.ts +++ b/public/app/features/panel/panel_loader.ts @@ -41,6 +41,7 @@ function panelLoader($compile, dynamicDirectiveSrv, $http, $q, $injector) { function addPanel(name, Panel) { if (Panel.registered) { addPanelAndCompile(name); + return; } if (Panel.promise) { @@ -62,14 +63,13 @@ function panelLoader($compile, dynamicDirectiveSrv, $http, $q, $injector) { Panel.registered = true; addPanelAndCompile(name); }); - - return; } var panelElemName = 'panel-directive-' + scope.panel.type; let panelInfo = config.panels[scope.panel.type]; if (!panelInfo) { addPanel(panelElemName, UnknownPanel); + return; } System.import(panelInfo.module).then(function(panelModule) { diff --git a/public/app/features/panel/panel_menu.js b/public/app/features/panel/panel_menu.js index 69629a6abcb..98e534e795a 100644 --- a/public/app/features/panel/panel_menu.js +++ b/public/app/features/panel/panel_menu.js @@ -64,7 +64,7 @@ function (angular, $, _) { } function getExtendedMenu(ctrl) { - return angular.copy(ctrl.extendedMenu); + return ctrl.getExtendedMenu(); } return { diff --git a/public/app/plugins/panel/text/module.ts b/public/app/plugins/panel/text/module.ts index bdef3bb4ced..87d51fbd5fe 100644 --- a/public/app/plugins/panel/text/module.ts +++ b/public/app/plugins/panel/text/module.ts @@ -59,6 +59,7 @@ export class TextPanelCtrl extends PanelCtrl { this.updateContent(this.converter.makeHtml(text)); } else { System.import('vendor/showdown').then(Showdown => { + console.log(this); this.converter = new Showdown.converter(); this.$scope.$apply(() => { this.updateContent(this.converter.makeHtml(text)); diff --git a/public/app/plugins/panel/unknown/module.ts b/public/app/plugins/panel/unknown/module.ts index 4f729649395..95adf934f81 100644 --- a/public/app/plugins/panel/unknown/module.ts +++ b/public/app/plugins/panel/unknown/module.ts @@ -2,10 +2,15 @@ import {PanelDirective} from '../../../features/panel/panel'; -export class UnknownPanel extends PanelDirective { +class UnknownPanel extends PanelDirective { template = `
Unknown panel type: {{ctrl.panel.type}}
`; } +export { + UnknownPanel, + UnknownPanel as Panel +} +