Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SearchKit - Rename crmSearchActions module to crmSearchTasks & add hook #20307

Merged
merged 1 commit into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions ext/search_kit/Civi/Api4/Action/SearchDisplay/GetSearchTasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,16 @@ class GetSearchTasks extends \Civi\Api4\Generic\AbstractAction {
public function _run(\Civi\Api4\Generic\Result $result) {
$entity = Entity::get($this->checkPermissions)->addWhere('name', '=', $this->entity)
->addSelect('name', 'title_plural')
->setChain(['actions' => [$this->entity, 'getActions', ['where' => [['name', 'IN', ['update', 'delete']]]], 'name']])
->setChain(['actions' => ['$name', 'getActions', ['where' => [['name', 'IN', ['update', 'delete']]]], 'name']])
->execute()->first();

if (!$entity) {
return;
}
$tasks = [];
$tasks = [$entity['name'] => []];

if (array_key_exists($entity['name'], \CRM_Export_BAO_Export::getComponents())) {
$tasks[] = [
'name' => 'export',
$tasks[$entity['name']]['export'] = [
'title' => E::ts('Export %1', [1 => $entity['title_plural']]),
'icon' => 'fa-file-excel-o',
'crmPopup' => [
Expand All @@ -47,20 +46,20 @@ public function _run(\Civi\Api4\Generic\Result $result) {
}

if (array_key_exists('update', $entity['actions'])) {
$tasks[] = [
'name' => 'update',
$tasks[$entity['name']]['update'] = [
'module' => 'crmSearchTasks',
'title' => E::ts('Update %1', [1 => $entity['title_plural']]),
'icon' => 'fa-save',
'uiDialog' => ['templateUrl' => '~/crmSearchActions/crmSearchActionUpdate.html'],
'uiDialog' => ['templateUrl' => '~/crmSearchTasks/crmSearchTaskUpdate.html'],
];
}

if (array_key_exists('delete', $entity['actions'])) {
$tasks[] = [
'name' => 'delete',
$tasks[$entity['name']]['delete'] = [
'module' => 'crmSearchTasks',
'title' => E::ts('Delete %1', [1 => $entity['title_plural']]),
'icon' => 'fa-trash',
'uiDialog' => ['templateUrl' => '~/crmSearchActions/crmSearchActionDelete.html'],
'uiDialog' => ['templateUrl' => '~/crmSearchTasks/crmSearchTaskDelete.html'],
];
}

Expand All @@ -72,8 +71,7 @@ public function _run(\Civi\Api4\Generic\Result $result) {
if ($task['url'] === 'civicrm/task/pick-profile') {
$task['title'] = E::ts('Profile Update');
}
$tasks[] = [
'name' => 'contact.' . $id,
$tasks[$entity['name']]['contact.' . $id] = [
'title' => $task['title'],
'icon' => $task['icon'] ?? 'fa-gear',
'crmPopup' => [
Expand All @@ -88,8 +86,7 @@ public function _run(\Civi\Api4\Generic\Result $result) {
if ($entity['name'] === 'Contribution') {
foreach (\CRM_Contribute_Task::tasks() as $id => $task) {
if (!empty($task['url'])) {
$tasks[] = [
'name' => 'contribution.' . $id,
$tasks[$entity['name']]['contribution.' . $id] = [
'title' => $task['title'],
'icon' => $task['icon'] ?? 'fa-gear',
'crmPopup' => [
Expand All @@ -101,11 +98,20 @@ public function _run(\Civi\Api4\Generic\Result $result) {
}
}

usort($tasks, function($a, $b) {
$null = NULL;
\CRM_Utils_Hook::singleton()->invoke(['tasks'], $tasks,
$null, $null, $null, $null, $null, 'civicrm_searchKitTasks'
);

usort($tasks[$entity['name']], function($a, $b) {
return strnatcasecmp($a['title'], $b['title']);
});

$result->exchangeArray($tasks);
foreach ($tasks[$entity['name']] as $name => &$task) {
$task['name'] = $name;
}

$result->exchangeArray(array_values($tasks[$entity['name']]));
}

}
2 changes: 1 addition & 1 deletion ext/search_kit/ang/crmSearchAdmin.ang.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
],
'bundles' => ['bootstrap3'],
'basePages' => ['civicrm/admin/search'],
'requires' => ['crmUi', 'crmUtil', 'ngRoute', 'ui.sortable', 'ui.bootstrap', 'api4', 'crmSearchActions', 'crmRouteBinder'],
'requires' => ['crmUi', 'crmUtil', 'ngRoute', 'ui.sortable', 'ui.bootstrap', 'api4', 'crmSearchTasks', 'crmRouteBinder'],
'settingsFactory' => ['\Civi\Search\Admin', 'getAdminSettings'],
];
2 changes: 1 addition & 1 deletion ext/search_kit/ang/crmSearchAdmin/compose/controls.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
{{:: ts('Auto') }}
</button>
</div>
<crm-search-actions entity="$ctrl.savedSearch.api_entity" ids="$ctrl.selectedRows" refresh="$ctrl.refreshPage()"></crm-search-actions>
<crm-search-tasks entity="$ctrl.savedSearch.api_entity" ids="$ctrl.selectedRows" refresh="$ctrl.refreshPage()"></crm-search-tasks>
</div>
2 changes: 1 addition & 1 deletion ext/search_kit/ang/crmSearchDisplayTable.ang.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
'ang/crmSearchDisplayTable',
],
'basePages' => ['civicrm/search', 'civicrm/admin/search'],
'requires' => ['crmSearchDisplay', 'crmUi', 'crmSearchActions', 'ui.bootstrap'],
'requires' => ['crmSearchDisplay', 'crmUi', 'crmSearchTasks', 'ui.bootstrap'],
'bundles' => ['bootstrap3'],
'exports' => [
'crm-search-display-table' => 'E',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="crm-search-display crm-search-display-table">
<div class="form-inline" ng-if="$ctrl.settings.actions">
<crm-search-actions entity="$ctrl.apiEntity" ids="$ctrl.selectedRows" refresh="$ctrl.getResults()"></crm-search-actions>
<crm-search-tasks entity="$ctrl.apiEntity" ids="$ctrl.selectedRows" refresh="$ctrl.getResults()"></crm-search-tasks>
</div>
<table>
<thead>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// Search actions module - provides dropdown menu with bulk actions to take on selected rows.
return [
'js' => [
'ang/crmSearchActions.module.js',
'ang/crmSearchActions/*.js',
'ang/crmSearchActions/*/*.js',
'ang/crmSearchTasks.module.js',
'ang/crmSearchTasks/*.js',
'ang/crmSearchTasks/*/*.js',
],
'partials' => [
'ang/crmSearchActions',
'ang/crmSearchTasks',
],
'css' => [
'css/crmSearchActions.css',
'css/crmSearchTasks.css',
],
'basePages' => [],
'requires' => ['crmUi', 'crmUtil', 'dialogService', 'api4', 'checklist-model'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"use strict";

// Declare module
angular.module('crmSearchActions', CRM.angRequires('crmSearchActions'))
angular.module('crmSearchTasks', CRM.angRequires('crmSearchTasks'))

// Reformat an array of objects for compatibility with select2
// Todo this probably belongs in core
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function(angular, $, _) {
"use strict";

angular.module('crmSearchActions').component('crmSearchBatchRunner', {
angular.module('crmSearchTasks').component('crmSearchBatchRunner', {
bindings: {
entity: '<',
action: '@',
Expand All @@ -10,7 +10,7 @@
success: '&',
error: '&'
},
templateUrl: '~/crmSearchActions/crmSearchBatchRunner.html',
templateUrl: '~/crmSearchTasks/crmSearchBatchRunner.html',
controller: function($scope, $timeout, $interval, crmApi4) {
var ts = $scope.ts = CRM.ts('org.civicrm.search_kit'),
ctrl = this,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function(angular, $, _) {
"use strict";

angular.module('crmSearchActions')
angular.module('crmSearchTasks')
.directive('crmMultiSelectDate', function () {
return {
restrict: 'A',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
(function(angular, $, _) {
"use strict";

angular.module('crmSearchActions').component('crmSearchInput', {
angular.module('crmSearchTasks').component('crmSearchInput', {
bindings: {
field: '<',
'op': '<',
'format': '<',
'optionKey': '<'
},
require: {ngModel: 'ngModel'},
templateUrl: '~/crmSearchActions/crmSearchInput/crmSearchInput.html',
templateUrl: '~/crmSearchTasks/crmSearchInput/crmSearchInput.html',
controller: function($scope) {
var ts = $scope.ts = CRM.ts('org.civicrm.search_kit'),
ctrl = this;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function(angular, $, _) {
"use strict";

angular.module('crmSearchActions').component('crmSearchInputVal', {
angular.module('crmSearchTasks').component('crmSearchInputVal', {
bindings: {
field: '<',
'multi': '<',
Expand All @@ -15,7 +15,7 @@

this.$onInit = function() {
var rendered = false;
ctrl.dateRanges = CRM.crmSearchActions.dateRanges;
ctrl.dateRanges = CRM.crmSearchTasks.dateRanges;
ctrl.entity = ctrl.field.fk_entity || ctrl.field.entity;

this.ngModel.$render = function() {
Expand Down Expand Up @@ -87,30 +87,30 @@
this.getTemplate = function() {

if (ctrl.field.input_type === 'Date') {
return '~/crmSearchActions/crmSearchInput/date.html';
return '~/crmSearchTasks/crmSearchInput/date.html';
}

if (ctrl.field.data_type === 'Boolean') {
return '~/crmSearchActions/crmSearchInput/boolean.html';
return '~/crmSearchTasks/crmSearchInput/boolean.html';
}

if (ctrl.field.options) {
return '~/crmSearchActions/crmSearchInput/select.html';
return '~/crmSearchTasks/crmSearchInput/select.html';
}

if (ctrl.field.fk_entity || ctrl.field.name === 'id') {
return '~/crmSearchActions/crmSearchInput/entityRef.html';
return '~/crmSearchTasks/crmSearchInput/entityRef.html';
}

if (ctrl.field.data_type === 'Integer') {
return '~/crmSearchActions/crmSearchInput/integer.html';
return '~/crmSearchTasks/crmSearchInput/integer.html';
}

if (ctrl.field.data_type === 'Float') {
return '~/crmSearchActions/crmSearchInput/float.html';
return '~/crmSearchTasks/crmSearchInput/float.html';
}

return '~/crmSearchActions/crmSearchInput/text.html';
return '~/crmSearchTasks/crmSearchInput/text.html';
};

this.getFieldOptions = function() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
(function(angular, $, _) {
"use strict";

angular.module('crmSearchActions').controller('crmSearchActionDelete', function($scope, dialogService) {
angular.module('crmSearchTasks').controller('crmSearchTaskDelete', function($scope, dialogService) {
var ts = $scope.ts = CRM.ts('org.civicrm.search_kit'),
model = $scope.model,
ctrl = this;

this.entityTitle = model.ids.length === 1 ? model.entityInfo.title : model.entityInfo.title_plural;

this.cancel = function() {
dialogService.cancel('crmSearchAction');
dialogService.cancel('crmSearchTask');
};

this.delete = function() {
Expand All @@ -19,12 +19,12 @@

this.onSuccess = function() {
CRM.alert(ts('Successfully deleted %1 %2.', {1: model.ids.length, 2: ctrl.entityTitle}), ts('Deleted'), 'success');
dialogService.close('crmSearchAction');
dialogService.close('crmSearchTask');
};

this.onError = function() {
CRM.alert(ts('An error occurred while attempting to delete %1 %2.', {1: model.ids.length, 2: ctrl.entityTitle}), ts('Error'), 'error');
dialogService.close('crmSearchAction');
dialogService.close('crmSearchTask');
};

});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<div id="bootstrap-theme">
<form ng-controller="crmSearchActionDelete as $ctrl">
<form ng-controller="crmSearchTaskDelete as $ctrl">
<p><strong>{{:: ts('Are you sure you want to delete %1 %2?', {1: model.ids.length, 2: $ctrl.entityTitle}) }}</strong></p>
<hr />
<div ng-if="$ctrl.run" class="crm-search-action-progress">
<div ng-if="$ctrl.run" class="crm-search-task-progress">
<h5>{{:: ts('Deleting %1 %2...', {1: model.ids.length, 2: $ctrl.entityTitle}) }}</h5>
<crm-search-batch-runner entity="model.entity" action="Delete" params="$ctrl.run" ids="model.ids" success="$ctrl.onSuccess()" error="$ctrl.onError()" ></crm-search-batch-runner>
</div>
Expand All @@ -17,4 +17,5 @@ <h5>{{:: ts('Deleting %1 %2...', {1: model.ids.length, 2: $ctrl.entityTitle}) }}
{{:: ts('Delete %1', {1: $ctrl.entityTitle}) }}
</button>
</div>
</form>
</div>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function(angular, $, _) {
"use strict";

angular.module('crmSearchActions').controller('crmSearchActionUpdate', function ($scope, $timeout, crmApi4, dialogService) {
angular.module('crmSearchTasks').controller('crmSearchTaskUpdate', function ($scope, $timeout, crmApi4, dialogService) {
var ts = $scope.ts = CRM.ts('org.civicrm.search_kit'),
model = $scope.model,
ctrl = this;
Expand Down Expand Up @@ -68,7 +68,7 @@
};

this.cancel = function() {
dialogService.cancel('crmSearchAction');
dialogService.cancel('crmSearchTask');
};

this.save = function() {
Expand All @@ -80,12 +80,12 @@

this.onSuccess = function() {
CRM.alert(ts('Successfully updated %1 %2.', {1: model.ids.length, 2: ctrl.entityTitle}), ts('Saved'), 'success');
dialogService.close('crmSearchAction');
dialogService.close('crmSearchTask');
};

this.onError = function() {
CRM.alert(ts('An error occurred while attempting to update %1 %2.', {1: model.ids.length, 2: ctrl.entityTitle}), ts('Error'), 'error');
dialogService.close('crmSearchAction');
dialogService.close('crmSearchTask');
};

});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div id="bootstrap-theme">
<form ng-controller="crmSearchActionUpdate as $ctrl">
<form ng-controller="crmSearchTaskUpdate as $ctrl">
<p><strong>{{:: ts('Update the %1 selected %2 with the following values:', {1: model.ids.length, 2: $ctrl.entityTitle}) }}</strong></p>
<div class="form-inline" ng-repeat="clause in $ctrl.values" >
<input class="form-control" ng-change="$ctrl.updateField($index)" ng-disabled="$ctrl.run" ng-model="clause[0]" crm-ui-select="{data: $ctrl.availableFields, allowClear: true, placeholder: 'Field'}" />
Expand All @@ -8,7 +8,7 @@
<div class="form-inline" ng-hide="$ctrl.run">
<input class="form-control twenty" style="width: 15em;" ng-model="$ctrl.add" ng-change="$ctrl.addField()" ng-disabled="!$ctrl.fields" ng-class="{loading: !$ctrl.fields}" crm-ui-select="{data: $ctrl.availableFields, placeholder: ts('Add Value')}"/>
</div>
<div ng-if="$ctrl.run" class="crm-search-action-progress">
<div ng-if="$ctrl.run" class="crm-search-task-progress">
<h5>{{:: ts('Updating %1 %2...', {1: model.ids.length, 2: $ctrl.entityTitle}) }}</h5>
<crm-search-batch-runner entity="model.entity" action="Update" params="$ctrl.run" ids="model.ids" success="$ctrl.onSuccess()" error="$ctrl.onError()" ></crm-search-batch-runner>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
(function(angular, $, _) {
"use strict";

angular.module('crmSearchActions').component('crmSearchActions', {
angular.module('crmSearchTasks').component('crmSearchTasks', {
bindings: {
entity: '<',
refresh: '&',
ids: '<'
},
templateUrl: '~/crmSearchActions/crmSearchActions.html',
templateUrl: '~/crmSearchTasks/crmSearchTasks.html',
controller: function($scope, crmApi4, dialogService) {
var ts = $scope.ts = CRM.ts('org.civicrm.search_kit'),
ctrl = this,
Expand Down Expand Up @@ -58,7 +58,7 @@
autoOpen: false,
title: action.title
});
dialogService.open('crmSearchAction', action.uiDialog.templateUrl, data, options)
dialogService.open('crmSearchTask', action.uiDialog.templateUrl, data, options)
.then(ctrl.refresh);
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.crm-search-action-progress {
.crm-search-task-progress {
padding: 10px;
margin-top: 10px;
border: 1px solid lightgrey;
Expand Down
Loading