-
-
+
+
+
diff --git a/client/app/components/parameters.js b/client/app/components/parameters.js
index 38b25803f..739be9957 100644
--- a/client/app/components/parameters.js
+++ b/client/app/components/parameters.js
@@ -1,4 +1,4 @@
-import { find } from 'lodash';
+import { find, includes } from 'lodash';
import template from './parameters.html';
import queryBasedParameterTemplate from './query-based-parameter.html';
import parameterSettingsTemplate from './parameter-settings.html';
@@ -15,6 +15,9 @@ const ParameterSettingsComponent = {
this.trustAsHtml = html => $sce.trustAsHtml(html);
this.parameter = this.resolve.parameter;
+ this.isNewParameter = this.parameter.name === '';
+
+ this.parameterAlreadyExists = name => includes(this.resolve.existingParameters, name);
if (this.parameter.queryId) {
Query.get({ id: this.parameter.queryId }, (query) => {
diff --git a/client/app/pages/queries/query.html b/client/app/pages/queries/query.html
index 40ca16297..99fbf94b2 100644
--- a/client/app/pages/queries/query.html
+++ b/client/app/pages/queries/query.html
@@ -152,27 +152,28 @@
diff --git a/client/app/pages/queries/source-view.js b/client/app/pages/queries/source-view.js
index a2172af05..9f517911f 100644
--- a/client/app/pages/queries/source-view.js
+++ b/client/app/pages/queries/source-view.js
@@ -1,8 +1,10 @@
+import { map } from 'lodash';
import template from './query.html';
function QuerySourceCtrl(
- Events, toastr, $controller, $scope, $location, $http, $q,
+ Events, toastr, $controller, $scope, $location, $http, $q, $uibModal,
AlertDialog, currentUser, Query, Visualization, KeyboardShortcuts,
+ $rootScope,
) {
// extends QueryViewCtrl
$controller('QueryViewCtrl', { $scope });
@@ -30,6 +32,9 @@ function QuerySourceCtrl(
$scope.saveQuery();
}
},
+ 'shift+alt+p': () => {
+ $scope.addNewParameter();
+ },
};
KeyboardShortcuts.bind(shortcuts);
@@ -65,6 +70,25 @@ function QuerySourceCtrl(
.catch(error => toastr.error(error));
};
+ $scope.addNewParameter = () => {
+ $uibModal.open({
+ component: 'parameterSettings',
+ resolve: {
+ parameter: {
+ title: '',
+ name: '',
+ type: 'text',
+ value: null,
+ global: false,
+ },
+ existingParameters: () => map($scope.query.getParameters().get(), p => p.name),
+ },
+ }).result.then((param) => {
+ $rootScope.$broadcast('query-editor.paste', '{{ ' + param.name + ' }}');
+ $scope.query.getParameters().add(param);
+ });
+ };
+
$scope.$watch('query.query', (newQueryText) => {
$scope.isDirty = (newQueryText !== queryText);
});
diff --git a/client/app/services/query.js b/client/app/services/query.js
index 19530eb92..ca8e913dd 100644
--- a/client/app/services/query.js
+++ b/client/app/services/query.js
@@ -170,6 +170,14 @@ class Parameters {
return this.query.options.parameters;
}
+ add(parameterDef) {
+ if (isObject(parameterDef)) {
+ this.query.options.parameters = this.query.options.parameters
+ .filter(p => p.name !== parameterDef.name);
+ this.query.options.parameters.push(new Parameter(parameterDef));
+ }
+ }
+
getMissing() {
return map(filter(this.get(), p => p.isEmpty), i => i.title);
}