From 2b02bf9bcd6abcbe337f555497e45fe64c06226b Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 22 Nov 2021 14:12:01 -0500 Subject: [PATCH] SearchKit - Include default clauses in routbinding params --- .../crmSearchAdmin.component.js | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/ext/search_kit/ang/crmSearchAdmin/crmSearchAdmin.component.js b/ext/search_kit/ang/crmSearchAdmin/crmSearchAdmin.component.js index 8cbc617780..d0b8750bc3 100644 --- a/ext/search_kit/ang/crmSearchAdmin/crmSearchAdmin.component.js +++ b/ext/search_kit/ang/crmSearchAdmin/crmSearchAdmin.component.js @@ -40,16 +40,23 @@ this.groupExists = !!this.savedSearch.groups.length; if (!this.savedSearch.id) { + var defaults = { + version: 4, + select: getDefaultSelect(), + orderBy: {}, + where: [], + }; + _.each(['groupBy', 'join', 'having'], function(param) { + if (ctrl.paramExists(param)) { + defaults[param] = []; + } + }); + $scope.$bindToRoute({ param: 'params', expr: '$ctrl.savedSearch.api_params', deep: true, - default: { - version: 4, - select: getDefaultSelect(), - orderBy: {}, - where: [], - } + default: defaults }); } @@ -57,18 +64,6 @@ $scope.$watchCollection('$ctrl.savedSearch.api_params.select', onChangeSelect); - if (this.paramExists('groupBy')) { - this.savedSearch.api_params.groupBy = this.savedSearch.api_params.groupBy || []; - } - - if (this.paramExists('join')) { - this.savedSearch.api_params.join = this.savedSearch.api_params.join || []; - } - - if (this.paramExists('having')) { - this.savedSearch.api_params.having = this.savedSearch.api_params.having || []; - } - $scope.$watch('$ctrl.savedSearch', onChangeAnything, true); // After watcher runs for the first time and messes up the status, set it correctly -- 2.25.1