|
@@ -10,105 +10,123 @@ import {transformers} from './transformers';
|
|
|
import kbn from 'app/core/utils/kbn';
|
|
import kbn from 'app/core/utils/kbn';
|
|
|
|
|
|
|
|
export class TablePanelEditorCtrl {
|
|
export class TablePanelEditorCtrl {
|
|
|
|
|
+ panel: any;
|
|
|
|
|
+ panelCtrl: any;
|
|
|
|
|
+ transformers: any;
|
|
|
|
|
+ colorModes: any;
|
|
|
|
|
+ columnStyles: any;
|
|
|
|
|
+ columnTypes: any;
|
|
|
|
|
+ fontSizes: any;
|
|
|
|
|
+ dateFormats: any;
|
|
|
|
|
+ addColumnSegment: any;
|
|
|
|
|
+ unitFormats: any;
|
|
|
|
|
+ getColumnNames: any;
|
|
|
|
|
|
|
|
/** @ngInject */
|
|
/** @ngInject */
|
|
|
- constructor($scope, $q, uiSegmentSrv) {
|
|
|
|
|
- $scope.transformers = transformers;
|
|
|
|
|
- $scope.unitFormats = kbn.getUnitFormats();
|
|
|
|
|
- $scope.colorModes = [
|
|
|
|
|
|
|
+ constructor($scope, private $q, private uiSegmentSrv) {
|
|
|
|
|
+ $scope.editor = this;
|
|
|
|
|
+ this.panelCtrl = $scope.ctrl;
|
|
|
|
|
+ this.panel = this.panelCtrl.panel;
|
|
|
|
|
+ this.transformers = transformers;
|
|
|
|
|
+ this.unitFormats = kbn.getUnitFormats();
|
|
|
|
|
+ this.colorModes = [
|
|
|
{text: 'Disabled', value: null},
|
|
{text: 'Disabled', value: null},
|
|
|
{text: 'Cell', value: 'cell'},
|
|
{text: 'Cell', value: 'cell'},
|
|
|
{text: 'Value', value: 'value'},
|
|
{text: 'Value', value: 'value'},
|
|
|
{text: 'Row', value: 'row'},
|
|
{text: 'Row', value: 'row'},
|
|
|
];
|
|
];
|
|
|
- $scope.columnTypes = [
|
|
|
|
|
|
|
+ this.columnTypes = [
|
|
|
{text: 'Number', value: 'number'},
|
|
{text: 'Number', value: 'number'},
|
|
|
{text: 'String', value: 'string'},
|
|
{text: 'String', value: 'string'},
|
|
|
{text: 'Date', value: 'date'},
|
|
{text: 'Date', value: 'date'},
|
|
|
];
|
|
];
|
|
|
- $scope.fontSizes = ['80%', '90%', '100%', '110%', '120%', '130%', '150%', '160%', '180%', '200%', '220%', '250%'];
|
|
|
|
|
- $scope.dateFormats = [
|
|
|
|
|
|
|
+ this.fontSizes = ['80%', '90%', '100%', '110%', '120%', '130%', '150%', '160%', '180%', '200%', '220%', '250%'];
|
|
|
|
|
+ this.dateFormats = [
|
|
|
{text: 'YYYY-MM-DD HH:mm:ss', value: 'YYYY-MM-DD HH:mm:ss'},
|
|
{text: 'YYYY-MM-DD HH:mm:ss', value: 'YYYY-MM-DD HH:mm:ss'},
|
|
|
{text: 'MM/DD/YY h:mm:ss a', value: 'MM/DD/YY h:mm:ss a'},
|
|
{text: 'MM/DD/YY h:mm:ss a', value: 'MM/DD/YY h:mm:ss a'},
|
|
|
{text: 'MMMM D, YYYY LT', value: 'MMMM D, YYYY LT'},
|
|
{text: 'MMMM D, YYYY LT', value: 'MMMM D, YYYY LT'},
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
- $scope.addColumnSegment = uiSegmentSrv.newPlusButton();
|
|
|
|
|
|
|
+ this.addColumnSegment = uiSegmentSrv.newPlusButton();
|
|
|
|
|
|
|
|
- $scope.getColumnOptions = function() {
|
|
|
|
|
- if (!$scope.dataRaw) {
|
|
|
|
|
- return $q.when([]);
|
|
|
|
|
|
|
+ // this is used from bs-typeahead and needs to be instance bound
|
|
|
|
|
+ this.getColumnNames = () => {
|
|
|
|
|
+ if (!this.panelCtrl.table) {
|
|
|
|
|
+ return [];
|
|
|
}
|
|
}
|
|
|
- var columns = transformers[$scope.panel.transform].getColumns($scope.dataRaw);
|
|
|
|
|
- var segments = _.map(columns, (c: any) => uiSegmentSrv.newSegment({value: c.text}));
|
|
|
|
|
- return $q.when(segments);
|
|
|
|
|
|
|
+ return _.map(this.panelCtrl.table.columns, function(col: any) {
|
|
|
|
|
+ return col.text;
|
|
|
|
|
+ });
|
|
|
};
|
|
};
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- $scope.addColumn = function() {
|
|
|
|
|
- var columns = transformers[$scope.panel.transform].getColumns($scope.dataRaw);
|
|
|
|
|
- var column = _.findWhere(columns, {text: $scope.addColumnSegment.value});
|
|
|
|
|
|
|
+ getColumnOptions() {
|
|
|
|
|
+ if (!this.panelCtrl.dataRaw) {
|
|
|
|
|
+ return this.$q.when([]);
|
|
|
|
|
+ }
|
|
|
|
|
+ var columns = this.transformers[this.panel.transform].getColumns(this.panelCtrl.dataRaw);
|
|
|
|
|
+ var segments = _.map(columns, (c: any) => this.uiSegmentSrv.newSegment({value: c.text}));
|
|
|
|
|
+ return this.$q.when(segments);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if (column) {
|
|
|
|
|
- $scope.panel.columns.push(column);
|
|
|
|
|
- $scope.render();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ addColumn() {
|
|
|
|
|
+ var columns = transformers[this.panel.transform].getColumns(this.panelCtrl.dataRaw);
|
|
|
|
|
+ var column = _.findWhere(columns, {text: this.addColumnSegment.value});
|
|
|
|
|
|
|
|
- var plusButton = uiSegmentSrv.newPlusButton();
|
|
|
|
|
- $scope.addColumnSegment.html = plusButton.html;
|
|
|
|
|
- $scope.addColumnSegment.value = plusButton.value;
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ if (column) {
|
|
|
|
|
+ this.panel.columns.push(column);
|
|
|
|
|
+ this.render();
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- $scope.transformChanged = function() {
|
|
|
|
|
- $scope.panel.columns = [];
|
|
|
|
|
- $scope.render();
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ var plusButton = this.uiSegmentSrv.newPlusButton();
|
|
|
|
|
+ this.addColumnSegment.html = plusButton.html;
|
|
|
|
|
+ this.addColumnSegment.value = plusButton.value;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- $scope.removeColumn = function(column) {
|
|
|
|
|
- $scope.panel.columns = _.without($scope.panel.columns, column);
|
|
|
|
|
- $scope.render();
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ transformChanged() {
|
|
|
|
|
+ this.panel.columns = [];
|
|
|
|
|
+ this.render();
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- $scope.setUnitFormat = function(column, subItem) {
|
|
|
|
|
- column.unit = subItem.value;
|
|
|
|
|
- $scope.render();
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ render() {
|
|
|
|
|
+ this.panelCtrl.render();
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- $scope.addColumnStyle = function() {
|
|
|
|
|
- var columnStyleDefaults = {
|
|
|
|
|
- unit: 'short',
|
|
|
|
|
- type: 'number',
|
|
|
|
|
- decimals: 2,
|
|
|
|
|
- colors: ["rgba(245, 54, 54, 0.9)", "rgba(237, 129, 40, 0.89)", "rgba(50, 172, 45, 0.97)"],
|
|
|
|
|
- colorMode: null,
|
|
|
|
|
- pattern: '/.*/',
|
|
|
|
|
- dateFormat: 'YYYY-MM-DD HH:mm:ss',
|
|
|
|
|
- thresholds: [],
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- $scope.panel.styles.push(angular.copy(columnStyleDefaults));
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ removeColumn(column) {
|
|
|
|
|
+ this.panel.columns = _.without(this.panel.columns, column);
|
|
|
|
|
+ this.panelCtrl.render();
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- $scope.removeColumnStyle = function(style) {
|
|
|
|
|
- $scope.panel.styles = _.without($scope.panel.styles, style);
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ setUnitFormat(column, subItem) {
|
|
|
|
|
+ column.unit = subItem.value;
|
|
|
|
|
+ this.panelCtrl.render();
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
- $scope.getColumnNames = function() {
|
|
|
|
|
- if (!$scope.table) {
|
|
|
|
|
- return [];
|
|
|
|
|
- }
|
|
|
|
|
- return _.map($scope.table.columns, function(col: any) {
|
|
|
|
|
- return col.text;
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ addColumnStyle() {
|
|
|
|
|
+ var columnStyleDefaults = {
|
|
|
|
|
+ unit: 'short',
|
|
|
|
|
+ type: 'number',
|
|
|
|
|
+ decimals: 2,
|
|
|
|
|
+ colors: ["rgba(245, 54, 54, 0.9)", "rgba(237, 129, 40, 0.89)", "rgba(50, 172, 45, 0.97)"],
|
|
|
|
|
+ colorMode: null,
|
|
|
|
|
+ pattern: '/.*/',
|
|
|
|
|
+ dateFormat: 'YYYY-MM-DD HH:mm:ss',
|
|
|
|
|
+ thresholds: [],
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- $scope.invertColorOrder = function(index) {
|
|
|
|
|
- var ref = $scope.panel.styles[index].colors;
|
|
|
|
|
- var copy = ref[0];
|
|
|
|
|
- ref[0] = ref[2];
|
|
|
|
|
- ref[2] = copy;
|
|
|
|
|
- $scope.render();
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ this.panel.styles.push(angular.copy(columnStyleDefaults));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ removeColumnStyle(style) {
|
|
|
|
|
+ this.panel.styles = _.without(this.panel.styles, style);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ invertColorOrder(index) {
|
|
|
|
|
+ var ref = this.panel.styles[index].colors;
|
|
|
|
|
+ var copy = ref[0];
|
|
|
|
|
+ ref[0] = ref[2];
|
|
|
|
|
+ ref[2] = copy;
|
|
|
|
|
+ this.panelCtrl.render();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|