Skip to content

Commit

Permalink
SearchKit - Improve user feedback when adding/removing tags
Browse files Browse the repository at this point in the history
Fixes dev/core#5678
  • Loading branch information
colemanw committed Jan 12, 2025
1 parent 63095fc commit 1640151
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
currentBatch = 0,
totalBatches,
processedCount = 0,
countMatched = 0,
incrementer;

this.progress = 0;
Expand Down Expand Up @@ -63,10 +64,12 @@
function(result) {
stopIncrementer();
ctrl.progress = Math.floor(100 * ++currentBatch / totalBatches);
processedCount += result.count;
processedCount += result.countFetched;
countMatched += (result.countMatched || result.count);
if (ctrl.last >= ctrl.ids.length) {
$timeout(function() {
result.batchCount = processedCount;
result.countMatched = countMatched;
ctrl.success({result: result});
}, 500);
} else {
Expand Down
14 changes: 11 additions & 3 deletions ext/search_kit/ang/crmSearchTasks/crmSearchTaskTag.ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,19 @@
});
};

this.onSuccess = function() {
this.onSuccess = function(result) {
let msg;
if (ctrl.action === 'delete') {
CRM.alert(ts('Removed tags from %1 %2.', {1: ctrl.ids.length, 2: ctrl.entityTitle}), ts('Saved'), 'success');
msg = result.batchCount === 1 ? ts('1 tag removed.') : ts('%1 tags removed.', {1: result.batchCount});
CRM.alert(msg, ts('Saved'), 'success');
} else {
CRM.alert(ts('Added tags to %1 %2.', {1: ctrl.ids.length, 2: ctrl.entityTitle}), ts('Saved'), 'success');
const added = result.batchCount - result.countMatched;
msg = added === 1 ? ts('1 tag added') : ts('%1 tags added.', {1: added});
msg += '<br/>';
if (result.countMatched > 0) {
msg += result.countMatched === 1 ? ts('1 tag already exists and was not added.') : ts('%1 tags already exist and were not added.', {1: result.countMatched});
}
CRM.alert(msg, ts('Saved'), 'success');
}
this.close();
};
Expand Down
2 changes: 1 addition & 1 deletion ext/search_kit/ang/crmSearchTasks/crmSearchTaskTag.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</fieldset>
<div ng-if="$ctrl.run" class="crm-search-task-progress">
<h5>{{:: $ctrl.action === 'save' ? ts('Adding tags...') : ts('Removing tags...') }}</h5>
<crm-search-batch-runner entity="'EntityTag'" action="{{ $ctrl.action }}" id-field="entity_id" params="$ctrl.run" ids="model.ids" success="$ctrl.onSuccess()" error="$ctrl.onError()" ></crm-search-batch-runner>
<crm-search-batch-runner entity="'EntityTag'" action="{{ $ctrl.action }}" id-field="entity_id" params="$ctrl.run" ids="model.ids" success="$ctrl.onSuccess(result)" error="$ctrl.onError()" ></crm-search-batch-runner>
</div>

<crm-dialog-button text="ts('Cancel')" icons="{primary: 'fa-times'}" on-click="$ctrl.cancel()" disabled="$ctrl.run" ></crm-dialog-button>
Expand Down

0 comments on commit 1640151

Please sign in to comment.