From 6612cd6dc906db5e1ec1af10cb54e51c4e5025b5 Mon Sep 17 00:00:00 2001 From: colemanw Date: Sat, 10 Jun 2023 18:05:32 -0400 Subject: [PATCH] APIv4 Explorer - Expose entitySets with UNION ALL and UNION DISTINCT --- ang/api4Explorer/Explorer.html | 8 ++++++++ ang/api4Explorer/Explorer.js | 33 ++++++++++++++++++++++++++++++--- ang/api4Explorer/Set.html | 7 +++++++ css/api4-explorer.css | 3 +++ 4 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 ang/api4Explorer/Set.html diff --git a/ang/api4Explorer/Explorer.html b/ang/api4Explorer/Explorer.html index e6d1e4a0f7..454d71a26d 100644 --- a/ang/api4Explorer/Explorer.html +++ b/ang/api4Explorer/Explorer.html @@ -161,6 +161,14 @@ +
+ sets + + +
+ +
+
chain
diff --git a/ang/api4Explorer/Explorer.js b/ang/api4Explorer/Explorer.js index a5629119a8..90efb8a98e 100644 --- a/ang/api4Explorer/Explorer.js +++ b/ang/api4Explorer/Explorer.js @@ -352,7 +352,7 @@ if (_.isEmpty($scope.availableParams)) { return; } - var specialParams = ['select', 'fields', 'action', 'where', 'values', 'defaults', 'orderBy', 'chain', 'groupBy', 'having', 'join']; + var specialParams = ['select', 'fields', 'action', 'where', 'values', 'defaults', 'orderBy', 'chain', 'groupBy', 'having', 'join', 'sets']; if ($scope.availableParams.limit && $scope.availableParams.offset) { specialParams.push('limit', 'offset'); } @@ -611,7 +611,7 @@ }); }); } - if (typeof objectParams[name] !== 'undefined' || name === 'groupBy' || name === 'select' || name === 'join') { + if (typeof objectParams[name] !== 'undefined' || name === 'groupBy' || name === 'select' || name === 'join' || name === 'sets') { $scope.$watch('controls.' + name, function(value) { var field = value; $timeout(function() { @@ -620,6 +620,10 @@ $scope.params[name].push([field + ' AS ' + _.snakeCase(field), 'LEFT']); ctrl.buildFieldList(); } + else if (name === 'sets') { + var select = $scope.params.select && $scope.params.select.length ? $scope.params.select : ['id']; + $scope.params[name].push(['UNION ALL', field, 'get', '{select: [' + select.join(', ') + '], where: []}']); + } else if (typeof objectParams[name] === 'undefined') { $scope.params[name].push(field); } else { @@ -915,6 +919,11 @@ code += newLine + "->addChain('" + name + "', " + formatOOP(chain[0], chain[1], chain[2], 2 + indent); code += (chain.length > 3 ? ',' : '') + (!_.isEmpty(chain[2]) ? newLine : ' ') + (chain.length > 3 ? phpFormat(chain[3]) : '') + ')'; }); + } else if (key === 'sets') { + _.each(param, function(set) { + code += newLine + "->addSet(" + phpFormat(set[0]) + ', ' + formatOOP(set[1], set[2], set[3], 2 + indent); + code += newLine + ')'; + }); } else if (key === 'join') { _.each(param, function(join) { code += newLine + "->addJoin(" + phpFormat(join).slice(1, -1) + ')'; @@ -992,7 +1001,7 @@ // Fields marked 'localizable' in the schema should get wrapped in ts() for the php format var localizable = _.pluck(_.filter(_.findWhere(getEntity().actions, {name: $scope.action}).fields, {localizable: true}), 'name') || []; // More field names that probably should be translated - localizable = _.union(localizable, ['label', 'title', 'description', 'text']); + localizable = _.sets(localizable, ['label', 'title', 'description', 'text']); $scope.result.push(prettyPrintOne('return ' + _.escape(phpFormat(response.values, 2, 2, localizable)) + ';', 'php', 1)); break; } @@ -1422,6 +1431,24 @@ }; }); + angular.module('api4Explorer').component('api4ExpSet', { + bindings: { + set: '<', + deleteRow: '&', + entities: '<' + }, + templateUrl: '~/api4Explorer/Set.html', + controller: function($scope) { + var ctrl = this; + + $scope.$watch('$ctrl.set[1]', function(entity) { + if (!entity) { + ctrl.deleteRow(); + } + }); + } + }); + function getEntity(entityName) { return _.findWhere(schema, {name: entityName}); } diff --git a/ang/api4Explorer/Set.html b/ang/api4Explorer/Set.html new file mode 100644 index 0000000000..1f0e5335f7 --- /dev/null +++ b/ang/api4Explorer/Set.html @@ -0,0 +1,7 @@ + + + + diff --git a/css/api4-explorer.css b/css/api4-explorer.css index 1cd4635d4d..75791ea4cb 100644 --- a/css/api4-explorer.css +++ b/css/api4-explorer.css @@ -133,10 +133,13 @@ } #bootstrap-theme.api4-explorer-page .api4-operator, +#bootstrap-theme.api4-explorer-page .api4-sets-action, +#bootstrap-theme.api4-explorer-page .api4-sets-type, #bootstrap-theme.api4-explorer-page .api4-chain-index, #bootstrap-theme.api4-explorer-page .api4-chain-action { width: 90px; } +#bootstrap-theme.api4-explorer-page .api4-sets-params, #bootstrap-theme.api4-explorer-page .api4-chain-params { width: calc(100% - 390px); } -- 2.25.1