Commit f1efce56 by Torkel Ödegaard

feat(panels): fixed duplicate and remove panel

parent 34b82caa
...@@ -127,10 +127,6 @@ function (angular, _, config) { ...@@ -127,10 +127,6 @@ function (angular, _, config) {
}); });
}; };
$scope.updatePanelSpan = function(panel, span) {
panel.span = Math.min(Math.max(Math.floor(panel.span + span), 1), 12);
};
$scope.replacePanel = function(newPanel, oldPanel) { $scope.replacePanel = function(newPanel, oldPanel) {
var row = $scope.row; var row = $scope.row;
var index = _.indexOf(row.panels, oldPanel); var index = _.indexOf(row.panels, oldPanel);
......
...@@ -32,7 +32,6 @@ class MetricsPanelCtrl extends PanelCtrl { ...@@ -32,7 +32,6 @@ class MetricsPanelCtrl extends PanelCtrl {
// make metrics tab the default // make metrics tab the default
this.editorTabIndex = 1; this.editorTabIndex = 1;
this.$q = $injector.get('$q'); this.$q = $injector.get('$q');
this.$timeout = $injector.get('$timeout');
this.datasourceSrv = $injector.get('datasourceSrv'); this.datasourceSrv = $injector.get('datasourceSrv');
this.timeSrv = $injector.get('timeSrv'); this.timeSrv = $injector.get('timeSrv');
......
///<reference path="../../headers/common.d.ts" /> ///<reference path="../../headers/common.d.ts" />
import config from 'app/core/config'; import config from 'app/core/config';
import _ from 'lodash';
export class PanelCtrl { export class PanelCtrl {
panel: any; panel: any;
...@@ -13,6 +14,7 @@ export class PanelCtrl { ...@@ -13,6 +14,7 @@ export class PanelCtrl {
editorTabs: any; editorTabs: any;
$scope: any; $scope: any;
$injector: any; $injector: any;
$timeout: any;
fullscreen: boolean; fullscreen: boolean;
inspector: any; inspector: any;
editModeInitiated: boolean; editModeInitiated: boolean;
...@@ -23,6 +25,7 @@ export class PanelCtrl { ...@@ -23,6 +25,7 @@ export class PanelCtrl {
this.$injector = $injector; this.$injector = $injector;
this.$scope = $scope; this.$scope = $scope;
this.$timeout = $injector.get('$timeout');
this.pluginName = plugin.name; this.pluginName = plugin.name;
this.pluginId = plugin.id; this.pluginId = plugin.id;
this.icon = plugin.info.icon; this.icon = plugin.info.icon;
...@@ -102,12 +105,34 @@ export class PanelCtrl { ...@@ -102,12 +105,34 @@ export class PanelCtrl {
this.$scope.$broadcast('render', arg1, arg2); this.$scope.$broadcast('render', arg1, arg2);
} }
toggleEditorHelp(index) { toggleEditorHelp(index) {
if (this.editorHelpIndex === index) { if (this.editorHelpIndex === index) {
this.editorHelpIndex = null; this.editorHelpIndex = null;
return; return;
} }
this.editorHelpIndex = index; this.editorHelpIndex = index;
} }
duplicate() {
this.dashboard.duplicatePanel(this.panel, this.row);
}
updateColumnSpan(span) {
this.panel.span = Math.min(Math.max(Math.floor(this.panel.span + span), 1), 12);
this.$timeout(() => {
this.broadcastRender();
});
}
removePanel() {
this.publishAppEvent('confirm-modal', {
title: 'Are you sure you want to remove this panel?',
icon: 'fa-trash',
yesText: 'Delete',
onConfirm: () => {
this.row.panels = _.without(this.row.panels, this.panel);
}
});
}
} }
...@@ -34,9 +34,9 @@ function (angular, $, _) { ...@@ -34,9 +34,9 @@ function (angular, $, _) {
if (ctrl.dashboard.meta.canEdit) { if (ctrl.dashboard.meta.canEdit) {
template += '<div class="panel-menu-inner">'; template += '<div class="panel-menu-inner">';
template += '<div class="panel-menu-row">'; template += '<div class="panel-menu-row">';
template += '<a class="panel-menu-icon pull-left" ng-click="updateColumnSpan(-1)"><i class="fa fa-minus"></i></a>'; template += '<a class="panel-menu-icon pull-left" ng-click="ctrl.updateColumnSpan(-1)"><i class="fa fa-minus"></i></a>';
template += '<a class="panel-menu-icon pull-left" ng-click="updateColumnSpan(1)"><i class="fa fa-plus"></i></a>'; template += '<a class="panel-menu-icon pull-left" ng-click="ctrl.updateColumnSpan(1)"><i class="fa fa-plus"></i></a>';
template += '<a class="panel-menu-icon pull-right" ng-click="removePanel(panel)"><i class="fa fa-remove"></i></a>'; template += '<a class="panel-menu-icon pull-right" ng-click="ctrl.removePanel()"><i class="fa fa-remove"></i></a>';
template += '<div class="clearfix"></div>'; template += '<div class="clearfix"></div>';
template += '</div>'; template += '</div>';
} }
...@@ -96,7 +96,7 @@ function (angular, $, _) { ...@@ -96,7 +96,7 @@ function (angular, $, _) {
// if hovering or draging pospone close // if hovering or draging pospone close
if (force !== true) { if (force !== true) {
if ($menu.is(':hover') || $scope.dashboard.$$panelDragging) { if ($menu.is(':hover') || $scope.ctrl.dashboard.$$panelDragging) {
dismiss(2200); dismiss(2200);
return; return;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment