From 9f6c0e4fcd1b57b60528533d18491add1363db00 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 9 Apr 2020 16:14:50 -0400 Subject: [PATCH] APIv4 Explorer: support HAVING --- ang/api4Explorer/Explorer.html | 2 ++ ang/api4Explorer/Explorer.js | 22 ++++++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/ang/api4Explorer/Explorer.html b/ang/api4Explorer/Explorer.html index 752a912bbb..e16f59a93a 100644 --- a/ang/api4Explorer/Explorer.html +++ b/ang/api4Explorer/Explorer.html @@ -107,6 +107,8 @@ +
+
orderBy *
diff --git a/ang/api4Explorer/Explorer.js b/ang/api4Explorer/Explorer.js index 413fc07b51..2affbcfdf2 100644 --- a/ang/api4Explorer/Explorer.js +++ b/ang/api4Explorer/Explorer.js @@ -25,6 +25,7 @@ $scope.entities = entities; $scope.actions = actions; $scope.fields = []; + $scope.havingOptions = []; $scope.fieldsAndJoins = []; $scope.fieldsAndJoinsAndFunctions = []; $scope.fieldsAndJoinsAndFunctionsAndWildcards = []; @@ -109,15 +110,6 @@ } } - // Turn a flat array into a select2 array - function arrayToSelect2(array) { - var out = []; - _.each(array, function(item) { - out.push({id: item, text: item}); - }); - return out; - } - // Reformat an existing array of objects for compatibility with select2 function formatForSelect2(input, container, key, extra, prefix) { _.each(input, function(item) { @@ -242,7 +234,7 @@ }; $scope.isSpecial = function(name) { - var specialParams = ['select', 'fields', 'action', 'where', 'values', 'defaults', 'orderBy', 'chain', 'groupBy']; + var specialParams = ['select', 'fields', 'action', 'where', 'values', 'defaults', 'orderBy', 'chain', 'groupBy', 'having']; if ($scope.availableParams.limit && $scope.availableParams.offset) { specialParams.push('limit', 'offset'); } @@ -410,6 +402,16 @@ }); }, true); } + if (name === 'select' && actionInfo.params.having) { + $scope.$watchCollection('params.select', function(values) { + $scope.havingOptions.length = 0; + _.each(values, function(item) { + var pieces = item.split(' AS '), + alias = _.trim(pieces[pieces.length - 1]); + $scope.havingOptions.push({id: alias, text: alias}); + }); + }); + } if (typeof objectParams[name] !== 'undefined' || name === 'groupBy' || name === 'select') { $scope.$watch('controls.' + name, function(value) { var field = value; -- 2.25.1