Commit 86204abb by Alexander Zobnin Committed by Torkel Ödegaard

Move panel JSON editor to modal dialog (#10156)

* panel: fix JSON edit, #10149

* panel: show JSON editor in modal, #10149
parent bbd0b98b
...@@ -2,6 +2,7 @@ import config from 'app/core/config'; ...@@ -2,6 +2,7 @@ import config from 'app/core/config';
import _ from 'lodash'; import _ from 'lodash';
import $ from 'jquery'; import $ from 'jquery';
import {appEvents, profiler} from 'app/core/core'; import {appEvents, profiler} from 'app/core/core';
import { PanelModel } from 'app/features/dashboard/panel_model';
import Remarkable from 'remarkable'; import Remarkable from 'remarkable';
import {GRID_CELL_HEIGHT, GRID_CELL_VMARGIN} from 'app/core/constants'; import {GRID_CELL_HEIGHT, GRID_CELL_VMARGIN} from 'app/core/constants';
...@@ -190,8 +191,9 @@ export class PanelCtrl { ...@@ -190,8 +191,9 @@ export class PanelCtrl {
duplicate() { duplicate() {
this.dashboard.duplicatePanel(this.panel); this.dashboard.duplicatePanel(this.panel);
let self = this;
this.$timeout(() => { this.$timeout(() => {
this.$scope.$root.$broadcast('render'); self.$scope.$root.$broadcast('render');
}); });
} }
...@@ -223,21 +225,32 @@ export class PanelCtrl { ...@@ -223,21 +225,32 @@ export class PanelCtrl {
} }
editPanelJson() { editPanelJson() {
this.publishAppEvent('show-json-editor', { let editScope = this.$scope.$root.$new();
object: this.panel.getSaveModel(), editScope.object = this.panel.getSaveModel();
updateHandler: this.replacePanel.bind(this) editScope.updateHandler = this.replacePanel.bind(this);
this.publishAppEvent('show-modal', {
src: 'public/app/partials/edit_json.html',
scope: editScope
}); });
} }
replacePanel(newPanel, oldPanel) { replacePanel(newPanel, oldPanel) {
var index = _.indexOf(this.dashboard.panels, oldPanel); let dashboard = this.dashboard;
this.dashboard.panels.splice(index, 1); let index = _.findIndex(dashboard.panels, (panel) => {
return panel.id === oldPanel.id;
});
let deletedPanel = dashboard.panels.splice(index, 1);
this.dashboard.events.emit('panel-removed', deletedPanel);
// adding it back needs to be done in next digest // adding it back needs to be done in next digest
this.$timeout(() => { this.$timeout(() => {
newPanel = new PanelModel(newPanel);
newPanel.id = oldPanel.id; newPanel.id = oldPanel.id;
newPanel.width = oldPanel.width;
this.dashboard.panels.splice(index, 0, newPanel); dashboard.panels.splice(index, 0, newPanel);
dashboard.sortPanelsByGridPos();
dashboard.events.emit('panel-added', newPanel);
}); });
} }
......
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