From a019205fc264637a5e99814d9bb8b2d2bb7ddce4 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 11 Mar 2021 14:12:56 -0500 Subject: [PATCH] SearchKit: Support custom fields when saving smart group --- ext/search/Civi/Search/Actions.php | 13 -------- .../crmSearchInput/entityRef.html | 2 +- ext/search/ang/crmSearchAdmin.module.js | 2 +- .../crmSearchAdmin.component.js | 15 +++++++-- ext/search/ang/crmSearchAdmin/group.html | 32 ++++++++++++------- 5 files changed, 36 insertions(+), 28 deletions(-) diff --git a/ext/search/Civi/Search/Actions.php b/ext/search/Civi/Search/Actions.php index 9671d45676..f425b43e43 100644 --- a/ext/search/Civi/Search/Actions.php +++ b/ext/search/Civi/Search/Actions.php @@ -25,23 +25,10 @@ class Actions { public static function getActionSettings():array { return [ 'tasks' => self::getTasks(), - 'groupOptions' => self::getGroupOptions(), 'dateRanges' => \CRM_Utils_Array::makeNonAssociative(\CRM_Core_OptionGroup::values('relative_date_filters'), 'id', 'text'), ]; } - /** - * @return array - */ - public static function getGroupOptions():array { - return \Civi\Api4\Group::getFields(FALSE) - ->setLoadOptions(['id', 'label']) - ->addWhere('name', 'IN', ['group_type', 'visibility']) - ->execute() - ->indexBy('name') - ->column('options'); - } - /** * @return array */ diff --git a/ext/search/ang/crmSearchActions/crmSearchInput/entityRef.html b/ext/search/ang/crmSearchActions/crmSearchInput/entityRef.html index 7d9704e99b..731e8df9ad 100644 --- a/ext/search/ang/crmSearchActions/crmSearchInput/entityRef.html +++ b/ext/search/ang/crmSearchActions/crmSearchInput/entityRef.html @@ -1,5 +1,5 @@
- +
diff --git a/ext/search/ang/crmSearchAdmin.module.js b/ext/search/ang/crmSearchAdmin.module.js index 6ade8b2cd0..7aa5b7eb60 100644 --- a/ext/search/ang/crmSearchAdmin.module.js +++ b/ext/search/ang/crmSearchAdmin.module.js @@ -50,7 +50,7 @@ return crmApi4('SavedSearch', 'get', { where: [['id', '=', params.id]], chain: { - groups: ['Group', 'get', {select: ['id', 'title', 'description', 'visibility', 'group_type'], where: [['saved_search_id', '=', '$id']]}], + groups: ['Group', 'get', {select: ['id', 'title', 'description', 'visibility', 'group_type', 'custom.*'], where: [['saved_search_id', '=', '$id']]}], displays: ['SearchDisplay', 'get', {where: [['saved_search_id', '=', '$id']]}] } }, 0); diff --git a/ext/search/ang/crmSearchAdmin/crmSearchAdmin.component.js b/ext/search/ang/crmSearchAdmin/crmSearchAdmin.component.js index 8b4fc42aaa..a26a5b4066 100644 --- a/ext/search/ang/crmSearchAdmin/crmSearchAdmin.component.js +++ b/ext/search/ang/crmSearchAdmin/crmSearchAdmin.component.js @@ -26,13 +26,14 @@ $scope.controls = {tab: 'compose'}; $scope.joinTypes = [{k: false, v: ts('Optional')}, {k: true, v: ts('Required')}]; - $scope.groupOptions = CRM.crmSearchActions.groupOptions; // Try to create a sensible list of entities one might want to search for, // excluding those whos primary purpose is to provide joins or option lists to other entities var primaryEntities = _.filter(CRM.crmSearchAdmin.schema, function(entity) { return !_.includes(entity.type, 'EntityBridge') && !_.includes(entity.type, 'OptionList'); }); $scope.entities = formatForSelect2(primaryEntities, 'name', 'title_plural', ['description', 'icon']); + $scope.getEntity = searchMeta.getEntity; + $scope.getField = searchMeta.getField; this.perm = { editGroups: CRM.checkPerm('edit groups') }; @@ -170,6 +171,7 @@ $scope.selectTab = function(tab) { if (tab === 'group') { + loadFieldOptions('Group'); $scope.smartGroupColumns = searchMeta.getSmartGroupColumns(ctrl.savedSearch.api_entity, ctrl.savedSearch.api_params); var smartGroupColumns = _.map($scope.smartGroupColumns, 'id'); if (smartGroupColumns.length && !_.includes(smartGroupColumns, ctrl.savedSearch.api_params.select[0])) { @@ -182,6 +184,7 @@ this.removeGroup = function() { ctrl.groupExists = !ctrl.groupExists; + $scope.status = 'unsaved'; if (!ctrl.groupExists && (!ctrl.savedSearch.groups.length || !ctrl.savedSearch.groups[0].id)) { ctrl.savedSearch.groups.length = 0; } @@ -823,8 +826,10 @@ * Fetch pseudoconstants for main entity + joined entities * * Sets an optionsLoaded property on each entity to avoid duplicate requests + * + * @var string entity - optional additional entity to load */ - function loadFieldOptions() { + function loadFieldOptions(entity) { var mainEntity = searchMeta.getEntity(ctrl.savedSearch.api_entity), entities = {}; @@ -840,6 +845,12 @@ if (typeof mainEntity.optionsLoaded === 'undefined') { enqueue(mainEntity); } + + // Optional additional entity + if (entity && typeof searchMeta.getEntity(entity).optionsLoaded === 'undefined') { + enqueue(searchMeta.getEntity(entity)); + } + _.each(ctrl.savedSearch.api_params.join, function(join) { var joinInfo = searchMeta.getJoin(join[0]), joinEntity = searchMeta.getEntity(joinInfo.entity), diff --git a/ext/search/ang/crmSearchAdmin/group.html b/ext/search/ang/crmSearchAdmin/group.html index 64bf4a30c4..dabb22b1d4 100644 --- a/ext/search/ang/crmSearchAdmin/group.html +++ b/ext/search/ang/crmSearchAdmin/group.html @@ -9,19 +9,29 @@
- + -
- -
  -   +
+
+ +
  +   +
+
+
+ + +
+
+
+ +
-
- - +
+
-- 2.25.1