mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
fix(panels): avoid deep copy problem for panel defaults
Moves the defaults to be an instance property. This solves the problem of lodash defaults function not doing a deep copy. The symptom of this is that new deep properties for a panel are assigned to every panel of the same type by the defaults function in the constructor.
This commit is contained in:
@@ -13,7 +13,20 @@ import TimeSeries from 'app/core/time_series2';
|
|||||||
import * as fileExport from 'app/core/utils/file_export';
|
import * as fileExport from 'app/core/utils/file_export';
|
||||||
import {MetricsPanelCtrl} from 'app/plugins/sdk';
|
import {MetricsPanelCtrl} from 'app/plugins/sdk';
|
||||||
|
|
||||||
var panelDefaults = {
|
class GraphCtrl extends MetricsPanelCtrl {
|
||||||
|
static template = template;
|
||||||
|
|
||||||
|
hiddenSeries: any = {};
|
||||||
|
seriesList: any = [];
|
||||||
|
logScales: any;
|
||||||
|
unitFormats: any;
|
||||||
|
annotationsPromise: any;
|
||||||
|
datapointsCount: number;
|
||||||
|
datapointsOutside: boolean;
|
||||||
|
datapointsWarning: boolean;
|
||||||
|
colors: any = [];
|
||||||
|
|
||||||
|
panelDefaults = {
|
||||||
// datasource name, null = default datasource
|
// datasource name, null = default datasource
|
||||||
datasource: null,
|
datasource: null,
|
||||||
// sets client side (flot) or native graphite png renderer (png)
|
// sets client side (flot) or native graphite png renderer (png)
|
||||||
@@ -90,29 +103,16 @@ var panelDefaults = {
|
|||||||
aliasColors: {},
|
aliasColors: {},
|
||||||
// other style overrides
|
// other style overrides
|
||||||
seriesOverrides: [],
|
seriesOverrides: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
class GraphCtrl extends MetricsPanelCtrl {
|
|
||||||
static template = template;
|
|
||||||
|
|
||||||
hiddenSeries: any = {};
|
|
||||||
seriesList: any = [];
|
|
||||||
logScales: any;
|
|
||||||
unitFormats: any;
|
|
||||||
annotationsPromise: any;
|
|
||||||
datapointsCount: number;
|
|
||||||
datapointsOutside: boolean;
|
|
||||||
datapointsWarning: boolean;
|
|
||||||
colors: any = [];
|
|
||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
constructor($scope, $injector, private annotationsSrv) {
|
constructor($scope, $injector, private annotationsSrv) {
|
||||||
super($scope, $injector);
|
super($scope, $injector);
|
||||||
|
|
||||||
_.defaults(this.panel, angular.copy(panelDefaults));
|
_.defaults(this.panel, angular.copy(this.panelDefaults));
|
||||||
_.defaults(this.panel.tooltip, panelDefaults.tooltip);
|
_.defaults(this.panel.tooltip, this.panelDefaults.tooltip);
|
||||||
_.defaults(this.panel.grid, panelDefaults.grid);
|
_.defaults(this.panel.grid, this.panelDefaults.grid);
|
||||||
_.defaults(this.panel.legend, panelDefaults.legend);
|
_.defaults(this.panel.legend, this.panelDefaults.legend);
|
||||||
|
|
||||||
this.colors = $scope.$root.colors;
|
this.colors = $scope.$root.colors;
|
||||||
|
|
||||||
|
|||||||
@@ -4,20 +4,20 @@ import _ from 'lodash';
|
|||||||
import config from 'app/core/config';
|
import config from 'app/core/config';
|
||||||
import {PanelCtrl} from '../../../features/panel/panel_ctrl';
|
import {PanelCtrl} from '../../../features/panel/panel_ctrl';
|
||||||
|
|
||||||
// Set and populate defaults
|
|
||||||
var panelDefaults = {
|
|
||||||
};
|
|
||||||
|
|
||||||
class PluginListCtrl extends PanelCtrl {
|
class PluginListCtrl extends PanelCtrl {
|
||||||
static templateUrl = 'module.html';
|
static templateUrl = 'module.html';
|
||||||
|
|
||||||
pluginList: any[];
|
pluginList: any[];
|
||||||
viewModel: any;
|
viewModel: any;
|
||||||
|
|
||||||
|
// Set and populate defaults
|
||||||
|
panelDefaults = {
|
||||||
|
};
|
||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
constructor($scope, $injector, private backendSrv, private $location) {
|
constructor($scope, $injector, private backendSrv, private $location) {
|
||||||
super($scope, $injector);
|
super($scope, $injector);
|
||||||
_.defaults(this.panel, panelDefaults);
|
_.defaults(this.panel, this.panelDefaults);
|
||||||
|
|
||||||
this.events.on('init-edit-mode', this.onInitEditMode.bind(this));
|
this.events.on('init-edit-mode', this.onInitEditMode.bind(this));
|
||||||
this.pluginList = [];
|
this.pluginList = [];
|
||||||
|
|||||||
@@ -11,8 +11,16 @@ import config from 'app/core/config';
|
|||||||
import TimeSeries from 'app/core/time_series2';
|
import TimeSeries from 'app/core/time_series2';
|
||||||
import {MetricsPanelCtrl} from 'app/plugins/sdk';
|
import {MetricsPanelCtrl} from 'app/plugins/sdk';
|
||||||
|
|
||||||
// Set and populate defaults
|
class SingleStatCtrl extends MetricsPanelCtrl {
|
||||||
var panelDefaults = {
|
static templateUrl = 'module.html';
|
||||||
|
|
||||||
|
series: any[];
|
||||||
|
data: any;
|
||||||
|
fontSizes: any[];
|
||||||
|
unitFormats: any[];
|
||||||
|
|
||||||
|
// Set and populate defaults
|
||||||
|
panelDefaults = {
|
||||||
links: [],
|
links: [],
|
||||||
datasource: null,
|
datasource: null,
|
||||||
maxDataPoints: 100,
|
maxDataPoints: 100,
|
||||||
@@ -47,20 +55,12 @@ var panelDefaults = {
|
|||||||
maxValue: 100,
|
maxValue: 100,
|
||||||
thresholdLabels: true
|
thresholdLabels: true
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class SingleStatCtrl extends MetricsPanelCtrl {
|
|
||||||
static templateUrl = 'module.html';
|
|
||||||
|
|
||||||
series: any[];
|
|
||||||
data: any;
|
|
||||||
fontSizes: any[];
|
|
||||||
unitFormats: any[];
|
|
||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
constructor($scope, $injector, private $location, private linkSrv) {
|
constructor($scope, $injector, private $location, private linkSrv) {
|
||||||
super($scope, $injector);
|
super($scope, $injector);
|
||||||
_.defaults(this.panel, panelDefaults);
|
_.defaults(this.panel, this.panelDefaults);
|
||||||
|
|
||||||
this.events.on('data-received', this.onDataReceived.bind(this));
|
this.events.on('data-received', this.onDataReceived.bind(this));
|
||||||
this.events.on('data-error', this.onDataError.bind(this));
|
this.events.on('data-error', this.onDataError.bind(this));
|
||||||
|
|||||||
@@ -10,7 +10,14 @@ import {transformDataToTable} from './transformers';
|
|||||||
import {tablePanelEditor} from './editor';
|
import {tablePanelEditor} from './editor';
|
||||||
import {TableRenderer} from './renderer';
|
import {TableRenderer} from './renderer';
|
||||||
|
|
||||||
var panelDefaults = {
|
class TablePanelCtrl extends MetricsPanelCtrl {
|
||||||
|
static templateUrl = 'module.html';
|
||||||
|
|
||||||
|
pageIndex: number;
|
||||||
|
dataRaw: any;
|
||||||
|
table: any;
|
||||||
|
|
||||||
|
panelDefaults = {
|
||||||
targets: [{}],
|
targets: [{}],
|
||||||
transform: 'timeseries_to_columns',
|
transform: 'timeseries_to_columns',
|
||||||
pageSize: null,
|
pageSize: null,
|
||||||
@@ -35,14 +42,7 @@ var panelDefaults = {
|
|||||||
scroll: true,
|
scroll: true,
|
||||||
fontSize: '100%',
|
fontSize: '100%',
|
||||||
sort: {col: 0, desc: true},
|
sort: {col: 0, desc: true},
|
||||||
};
|
};
|
||||||
|
|
||||||
class TablePanelCtrl extends MetricsPanelCtrl {
|
|
||||||
static templateUrl = 'module.html';
|
|
||||||
|
|
||||||
pageIndex: number;
|
|
||||||
dataRaw: any;
|
|
||||||
table: any;
|
|
||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
constructor($scope, $injector, private annotationsSrv) {
|
constructor($scope, $injector, private annotationsSrv) {
|
||||||
@@ -56,7 +56,7 @@ class TablePanelCtrl extends MetricsPanelCtrl {
|
|||||||
delete this.panel.fields;
|
delete this.panel.fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
_.defaults(this.panel, panelDefaults);
|
_.defaults(this.panel, this.panelDefaults);
|
||||||
|
|
||||||
this.events.on('data-received', this.onDataReceived.bind(this));
|
this.events.on('data-received', this.onDataReceived.bind(this));
|
||||||
this.events.on('data-error', this.onDataError.bind(this));
|
this.events.on('data-error', this.onDataError.bind(this));
|
||||||
|
|||||||
@@ -3,23 +3,21 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import {PanelCtrl} from 'app/plugins/sdk';
|
import {PanelCtrl} from 'app/plugins/sdk';
|
||||||
|
|
||||||
// Set and populate defaults
|
|
||||||
var panelDefaults = {
|
|
||||||
mode : "markdown", // 'html', 'markdown', 'text'
|
|
||||||
content : "# title",
|
|
||||||
};
|
|
||||||
|
|
||||||
export class TextPanelCtrl extends PanelCtrl {
|
export class TextPanelCtrl extends PanelCtrl {
|
||||||
static templateUrl = `public/app/plugins/panel/text/module.html`;
|
static templateUrl = `public/app/plugins/panel/text/module.html`;
|
||||||
|
|
||||||
remarkable: any;
|
remarkable: any;
|
||||||
content: string;
|
content: string;
|
||||||
|
// Set and populate defaults
|
||||||
|
panelDefaults = {
|
||||||
|
mode : "markdown", // 'html', 'markdown', 'text'
|
||||||
|
content : "# title",
|
||||||
|
};
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
constructor($scope, $injector, private templateSrv, private $sce) {
|
constructor($scope, $injector, private templateSrv, private $sce) {
|
||||||
super($scope, $injector);
|
super($scope, $injector);
|
||||||
|
|
||||||
_.defaults(this.panel, panelDefaults);
|
_.defaults(this.panel, this.panelDefaults);
|
||||||
|
|
||||||
this.events.on('init-edit-mode', this.onInitEditMode.bind(this));
|
this.events.on('init-edit-mode', this.onInitEditMode.bind(this));
|
||||||
this.events.on('refresh', this.onRender.bind(this));
|
this.events.on('refresh', this.onRender.bind(this));
|
||||||
|
|||||||
Reference in New Issue
Block a user