From 8f38d9e998177c0bbb2e6bff561d6ddd097242c3 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sun, 12 Apr 2020 22:09:16 -0400 Subject: [PATCH] APIv4 Explorer - performance boost with less intensive loops --- ang/api4Explorer/Explorer.html | 8 ++++---- ang/api4Explorer/Explorer.js | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/ang/api4Explorer/Explorer.html b/ang/api4Explorer/Explorer.html index d6e08c74ed..becc31b500 100644 --- a/ang/api4Explorer/Explorer.html +++ b/ang/api4Explorer/Explorer.html @@ -31,7 +31,7 @@
-
-
+
-
+
-
+
diff --git a/ang/api4Explorer/Explorer.js b/ang/api4Explorer/Explorer.js index a9f0459c48..b1f1ab733a 100644 --- a/ang/api4Explorer/Explorer.js +++ b/ang/api4Explorer/Explorer.js @@ -222,12 +222,25 @@ } }; - $scope.isSpecial = function(name) { + // Gets params that should be represented as generic input fields in the explorer + // This fn doesn't have to be particularly efficient as its output is cached in one-time bindings + $scope.getGenericParams = function(paramType, defaultNull) { + // Returns undefined if params are not yet set; one-time bindings will stabilize when this function returns a value + if (_.isEmpty($scope.availableParams)) { + return; + } var specialParams = ['select', 'fields', 'action', 'where', 'values', 'defaults', 'orderBy', 'chain', 'groupBy', 'having']; if ($scope.availableParams.limit && $scope.availableParams.offset) { specialParams.push('limit', 'offset'); } - return _.contains(specialParams, name); + return _.transform($scope.availableParams, function(genericParams, param, name) { + if (!_.contains(specialParams, name) && + !(typeof paramType !== 'undefined' && !_.contains(paramType, param.type[0])) && + !(typeof defaultNull !== 'undefined' && ((param.default === null) !== defaultNull)) + ) { + genericParams[name] = param; + } + }); }; $scope.selectRowCount = function() { -- 2.25.1