mirror of
https://github.com/valitydev/redash.git
synced 2024-11-07 17:38:54 +00:00
Merge pull request #1615 from deecay/pivot_hide_control
Add: option to hide pivot table controls
This commit is contained in:
commit
326a80895c
@ -3,6 +3,9 @@ import $ from 'jquery';
|
||||
import 'pivottable';
|
||||
import 'pivottable/dist/pivot.css';
|
||||
|
||||
import editorTemplate from './pivottable-editor.html';
|
||||
|
||||
|
||||
function pivotTableRenderer() {
|
||||
return {
|
||||
restrict: 'E',
|
||||
@ -13,48 +16,65 @@ function pivotTableRenderer() {
|
||||
template: '',
|
||||
replace: false,
|
||||
link($scope, element) {
|
||||
$scope.$watch('queryResult && queryResult.getData()', (data) => {
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($scope.queryResult.getData() !== null) {
|
||||
// We need to give the pivot table its own copy of the data, because it changes
|
||||
// it which interferes with other visualizations.
|
||||
data = angular.copy($scope.queryResult.getData());
|
||||
const options = {
|
||||
renderers: $.pivotUtilities.renderers,
|
||||
onRefresh(config) {
|
||||
const configCopy = Object.assign({}, config);
|
||||
// delete some values which are functions
|
||||
delete configCopy.aggregators;
|
||||
delete configCopy.renderers;
|
||||
delete configCopy.onRefresh;
|
||||
// delete some bulky default values
|
||||
delete configCopy.rendererOptions;
|
||||
delete configCopy.localeStrings;
|
||||
|
||||
if ($scope.visualization) {
|
||||
$scope.visualization.options = configCopy;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
if ($scope.visualization) {
|
||||
Object.assign(options, $scope.visualization.options);
|
||||
function updatePivot() {
|
||||
$scope.$watch('queryResult && queryResult.getData()', (data) => {
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
$(element).pivotUI(data, options, true);
|
||||
}
|
||||
});
|
||||
|
||||
if ($scope.queryResult.getData() !== null) {
|
||||
// We need to give the pivot table its own copy of the data, because it changes
|
||||
// it which interferes with other visualizations.
|
||||
data = angular.copy($scope.queryResult.getData());
|
||||
const options = {
|
||||
renderers: $.pivotUtilities.renderers,
|
||||
onRefresh(config) {
|
||||
const configCopy = Object.assign({}, config);
|
||||
// delete some values which are functions
|
||||
delete configCopy.aggregators;
|
||||
delete configCopy.renderers;
|
||||
delete configCopy.onRefresh;
|
||||
// delete some bulky default values
|
||||
delete configCopy.rendererOptions;
|
||||
delete configCopy.localeStrings;
|
||||
|
||||
if ($scope.visualization) {
|
||||
$scope.visualization.options = configCopy;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
if ($scope.visualization) {
|
||||
Object.assign(options, $scope.visualization.options);
|
||||
}
|
||||
$(element).pivotUI(data, options, true);
|
||||
if (options.controls && options.controls.enabled) {
|
||||
const controls = $('.pvtAxisContainer, .pvtRenderer, .pvtVals');
|
||||
for (let i = 0; i < controls.length; i += 1) { controls[i].style.display = 'none'; }
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$scope.$watch('queryResult && queryResult.getData()', updatePivot);
|
||||
$scope.$watch('visualization.options.controls.enabled', updatePivot);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function pivotTableEditor() {
|
||||
return {
|
||||
restrict: 'E',
|
||||
template: editorTemplate,
|
||||
};
|
||||
}
|
||||
|
||||
export default function (ngModule) {
|
||||
ngModule.directive('pivotTableRenderer', pivotTableRenderer);
|
||||
ngModule.directive('pivotTableEditor', pivotTableEditor);
|
||||
|
||||
ngModule.config((VisualizationProvider) => {
|
||||
const editTemplate = '<div/>';
|
||||
const editTemplate = '<pivot-table-editor></pivot-table-editor>';
|
||||
const defaultOptions = {
|
||||
};
|
||||
|
||||
|
8
client/app/visualizations/pivot/pivottable-editor.html
Normal file
8
client/app/visualizations/pivot/pivottable-editor.html
Normal file
@ -0,0 +1,8 @@
|
||||
<div class="form-horizontal">
|
||||
<div class="form-group">
|
||||
<div class="col-lg-6">
|
||||
<input type="checkbox" ng-model="visualization.options.controls.enabled">
|
||||
<i class="input-helper"></i> Hide Controls
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
Loading…
Reference in New Issue
Block a user