mirror of
https://github.com/getredash/redash.git
synced 2026-03-23 22:00:10 -04:00
53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
import { extend } from 'lodash';
|
|
import template from './parameters.html';
|
|
import EditParameterSettingsDialog from './EditParameterSettingsDialog';
|
|
|
|
function ParametersDirective($location) {
|
|
return {
|
|
restrict: 'E',
|
|
transclude: true,
|
|
scope: {
|
|
parameters: '=',
|
|
syncValues: '=?',
|
|
editable: '=?',
|
|
changed: '&onChange',
|
|
onUpdated: '=',
|
|
},
|
|
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 = (parameter, index) => {
|
|
EditParameterSettingsDialog
|
|
.showModal({ parameter })
|
|
.result.then((updated) => {
|
|
scope.parameters[index] = extend(parameter, updated);
|
|
scope.onUpdated();
|
|
});
|
|
};
|
|
},
|
|
};
|
|
}
|
|
|
|
export default function init(ngModule) {
|
|
ngModule.directive('parameters', ParametersDirective);
|
|
}
|
|
|
|
init.init = true;
|