mirror of
https://github.com/getredash/redash.git
synced 2026-03-23 04:00:09 -04:00
* getredash/redash#2641 Step 1: split Add Widget/Add Textbox buttons * Convert Add widget/textbox dialogs to React components * getredash/redash#2641 Step 2: Implement new dashboard parameters logic * Resolve conflicts and fix build errors * getredash/redash#2641 Refactoring and improve code quality * Add Edit parameter mappings dialog to the widget * getredash/redash#2641 Changes after code review * Use Ant's Select component instead on <select> tags * Fix Antd imports * Fix Antd imports * Fix Cannot read property 'getParametersDefs' of undefined * Fix widgets static params bugs (don't show input, don't init from URL) * Minor UI/UX fixes
98 lines
2.4 KiB
JavaScript
98 lines
2.4 KiB
JavaScript
import { includes, words, capitalize, extend } from 'lodash';
|
|
import template from './parameters.html';
|
|
import parameterSettingsTemplate from './parameter-settings.html';
|
|
|
|
function humanize(str) {
|
|
return capitalize(words(str).join(' '));
|
|
}
|
|
|
|
const ParameterSettingsComponent = {
|
|
template: parameterSettingsTemplate,
|
|
bindings: {
|
|
resolve: '<',
|
|
close: '&',
|
|
dismiss: '&',
|
|
},
|
|
controller($sce, Query) {
|
|
'ngInject';
|
|
|
|
this.trustAsHtml = html => $sce.trustAsHtml(html);
|
|
this.parameter = this.resolve.parameter;
|
|
this.isNewParameter = this.parameter.name === '';
|
|
this.shouldGenerateTitle = this.isNewParameter && this.parameter.title === '';
|
|
|
|
this.parameterAlreadyExists = name => includes(this.resolve.existingParameters, name);
|
|
|
|
if (this.parameter.queryId) {
|
|
Query.get({ id: this.parameter.queryId }, (query) => {
|
|
this.queries = [query];
|
|
});
|
|
}
|
|
|
|
this.searchQueries = (term) => {
|
|
if (!term || term.length < 3) {
|
|
return;
|
|
}
|
|
|
|
Query.query({ q: term }, (results) => {
|
|
this.queries = results.results;
|
|
});
|
|
};
|
|
|
|
this.updateTitle = () => {
|
|
if (this.shouldGenerateTitle) {
|
|
this.parameter.title = humanize(this.parameter.name);
|
|
}
|
|
};
|
|
},
|
|
};
|
|
|
|
function ParametersDirective($location, $uibModal) {
|
|
return {
|
|
restrict: 'E',
|
|
transclude: true,
|
|
scope: {
|
|
parameters: '=',
|
|
syncValues: '=?',
|
|
editable: '=?',
|
|
changed: '&onChange',
|
|
},
|
|
template,
|
|
link(scope) {
|
|
// is this the correct location for this logic?
|
|
if (scope.syncValues !== false) {
|
|
scope.$watch(
|
|
'parameters',
|
|
() => {
|
|
if (scope.changed) {
|
|
scope.changed({});
|
|
}
|
|
const params = extend({}, $location.search());
|
|
scope.parameters.forEach((param) => {
|
|
extend(params, param.toUrlParams());
|
|
});
|
|
$location.search(params);
|
|
},
|
|
true,
|
|
);
|
|
}
|
|
|
|
scope.showParameterSettings = (param) => {
|
|
$uibModal.open({
|
|
component: 'parameterSettings',
|
|
resolve: {
|
|
parameter: param,
|
|
},
|
|
});
|
|
};
|
|
},
|
|
};
|
|
}
|
|
|
|
export default function init(ngModule) {
|
|
ngModule.directive('parameters', ParametersDirective);
|
|
ngModule.component('parameterSettings', ParameterSettingsComponent);
|
|
}
|
|
|
|
init.init = true;
|