From: colemanw Date: Thu, 1 Jun 2023 15:22:40 +0000 (-0400) Subject: SearchKit - Add task to refresh smart/parent group cache X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=d56c752b7918b448bdfc654873566570e8326282;p=civicrm-core.git SearchKit - Add task to refresh smart/parent group cache --- diff --git a/ext/search_kit/Civi/Api4/Action/SearchDisplay/GetSearchTasks.php b/ext/search_kit/Civi/Api4/Action/SearchDisplay/GetSearchTasks.php index 68aaa044f5..9676e096d3 100644 --- a/ext/search_kit/Civi/Api4/Action/SearchDisplay/GetSearchTasks.php +++ b/ext/search_kit/Civi/Api4/Action/SearchDisplay/GetSearchTasks.php @@ -135,6 +135,24 @@ class GetSearchTasks extends \Civi\Api4\Generic\AbstractAction { ]; } + /* + * ENTITY-SPECIFIC TASKS BELOW + * FIXME: Move these somewhere? + */ + + if ($entity['name'] === 'Group') { + $tasks['Group']['refresh'] = [ + 'title' => E::ts('Refresh Group Cache'), + 'icon' => 'fa-refresh', + 'apiBatch' => [ + 'action' => 'refresh', + 'runMsg' => E::ts('Refreshing %1 %2...'), + 'successMsg' => E::ts('%1 %2 Refreshed.'), + 'errorMsg' => E::ts('An error occurred while attempting to refresh %1 %2.'), + ], + ]; + } + if ($entity['name'] === 'Contact') { // Add contact tasks which support standalone mode $contactTasks = $this->checkPermissions ? \CRM_Contact_Task::permissionedTaskTitles(\CRM_Core_Permission::getPermission()) : NULL; diff --git a/ext/search_kit/ang/crmSearchTasks/crmSearchBatchRunner.component.js b/ext/search_kit/ang/crmSearchTasks/crmSearchBatchRunner.component.js index 6ccffdacaf..0a056f787d 100644 --- a/ext/search_kit/ang/crmSearchTasks/crmSearchBatchRunner.component.js +++ b/ext/search_kit/ang/crmSearchTasks/crmSearchBatchRunner.component.js @@ -17,6 +17,7 @@ ctrl = this, currentBatch = 0, totalBatches, + processedCount = 0, incrementer; this.progress = 0; @@ -62,8 +63,10 @@ function(result) { stopIncrementer(); ctrl.progress = Math.floor(100 * ++currentBatch / totalBatches); + processedCount += result.count; if (ctrl.last >= ctrl.ids.length) { $timeout(function() { + result.batchCount = processedCount; ctrl.success({result: result}); }, 500); } else { diff --git a/ext/search_kit/ang/crmSearchTasks/crmSearchTaskApiBatch.ctrl.js b/ext/search_kit/ang/crmSearchTasks/crmSearchTaskApiBatch.ctrl.js index cb06c22f53..b2fc595374 100644 --- a/ext/search_kit/ang/crmSearchTasks/crmSearchTaskApiBatch.ctrl.js +++ b/ext/search_kit/ang/crmSearchTasks/crmSearchTaskApiBatch.ctrl.js @@ -14,8 +14,9 @@ ctrl.start(ctrl.apiBatch.params); } - this.onSuccess = function() { - CRM.alert(ts(ctrl.apiBatch.successMsg, {1: ctrl.ids.length, 2: ctrl.entityTitle}), ts('%1 Complete', {1: ctrl.taskTitle}), 'success'); + this.onSuccess = function(result) { + var entityTitle = this.getEntityTitle(result.batchCount); + CRM.alert(ts(ctrl.apiBatch.successMsg, {1: result.batchCount, 2: entityTitle}), ts('%1 Complete', {1: ctrl.taskTitle}), 'success'); this.close(); }; diff --git a/ext/search_kit/ang/crmSearchTasks/crmSearchTaskApiBatch.html b/ext/search_kit/ang/crmSearchTasks/crmSearchTaskApiBatch.html index a4ce4c5aab..6352890efb 100644 --- a/ext/search_kit/ang/crmSearchTasks/crmSearchTaskApiBatch.html +++ b/ext/search_kit/ang/crmSearchTasks/crmSearchTaskApiBatch.html @@ -4,7 +4,7 @@
{{:: ts(model.apiBatch.runMsg, {1: model.ids.length, 2: $ctrl.entityTitle}) }}
- +
diff --git a/ext/search_kit/ang/crmSearchTasks/traits/searchTaskBaseTrait.service.js b/ext/search_kit/ang/crmSearchTasks/traits/searchTaskBaseTrait.service.js index c6ae0c6ce7..68149e0f4a 100644 --- a/ext/search_kit/ang/crmSearchTasks/traits/searchTaskBaseTrait.service.js +++ b/ext/search_kit/ang/crmSearchTasks/traits/searchTaskBaseTrait.service.js @@ -8,8 +8,11 @@ // Trait properties get mixed into task controller using angular.extend() return { - getEntityTitle: function() { - return this.ids.length === 1 ? this.entityInfo.title : this.entityInfo.title_plural; + getEntityTitle: function(count) { + if (typeof count !== 'number') { + count = this.ids.length; + } + return count === 1 ? this.entityInfo.title : this.entityInfo.title_plural; }, start: function(runParams) {