SearchKit - Add configuration to select tasks as links
authorcolemanw <coleman@civicrm.org>
Wed, 12 Jul 2023 01:22:58 +0000 (21:22 -0400)
committercolemanw <coleman@civicrm.org>
Wed, 12 Jul 2023 01:38:13 +0000 (21:38 -0400)
ext/search_kit/Civi/Api4/Action/SearchDisplay/GetSearchTasks.php
ext/search_kit/ang/crmSearchAdmin/crmSearchAdminDisplay.component.js
ext/search_kit/ang/crmSearchAdmin/crmSearchAdminLinkGroup.component.js
ext/search_kit/ang/crmSearchAdmin/crmSearchAdminLinkSelect.component.js
ext/search_kit/ang/crmSearchAdmin/crmSearchAdminLinkSelect.html
ext/search_kit/ang/crmSearchAdmin/displays/colType/field.html

index c8c36f386a08faa4cbc7c43194360226692897f3..9b04aaeeb24788017cdd4ebf534e218fa4215425 100644 (file)
@@ -269,7 +269,7 @@ class GetSearchTasks extends \Civi\Api4\Generic\AbstractAction {
         'name' => 'icon',
       ],
       [
-        'number' => 'icon',
+        'name' => 'number',
       ],
       [
         'name' => 'apiBatch',
index e6e9bbdc06836cda0e590afc8e18b19ed2ae54f6..f41155596eb4e0bf5033c7289d1ddff6f338be7a 100644 (file)
       this.getLinks = function(columnKey) {
         if (!ctrl.links) {
           ctrl.links = {'*': ctrl.crmSearchAdmin.buildLinks(), '0': []};
+          ctrl.links[''] = _.filter(ctrl.links['*'], {join: ''});
+          searchMeta.getSearchTasks(ctrl.savedSearch.api_entity).then(function(tasks) {
+            _.each(tasks, function (task) {
+              if (task.number === '> 0' || task.number === '=== 1') {
+                var link = {
+                  text: task.title,
+                  icon: task.icon,
+                  task: task.name,
+                  entity: ctrl.savedSearch.api_entity,
+                  target: 'crm-popup',
+                  join: '',
+                  style: task.name === 'delete' ? 'danger' : 'default'
+                };
+                ctrl.links['*'].push(link);
+                ctrl.links[''].push(link);
+              }
+            });
+          });
         }
         if (!columnKey) {
           return ctrl.links['*'];
index 7d2c2be802876434b9a22dc1dbd1a6d427658cd6..c766a4e86b563414b28a09be2ba5285ddf9eaa22 100644 (file)
@@ -15,7 +15,7 @@
     controller: function ($scope, $element, $timeout, searchMeta) {
       var ts = $scope.ts = CRM.ts('org.civicrm.search_kit'),
         ctrl = this,
-        linkProps = ['path', 'entity', 'action', 'join', 'target', 'icon', 'text', 'style', 'condition'];
+        linkProps = ['path', 'task', 'entity', 'action', 'join', 'target', 'icon', 'text', 'style', 'condition'];
 
       ctrl.permissionOperators = [
         {key: '=', value: ts('Has')},
@@ -98,7 +98,7 @@
           path: 'civicrm/'
         });
         var defaultLinks = _.filter(ctrl.links, function(link) {
-          return !link.join;
+          return link.action && !link.join;
         });
         _.each(ctrl.group, function(item) {
           setDefaults(item, item);
index 8291b3af39e9d6d0055253855d1b7fd4ca5f5ccf..1c1f5f248728f06a2736a261ee72fb4ef283609c 100644 (file)
       };
 
       this.getLink = function() {
-        return _.findWhere(ctrl.links, {action: ctrl.link.action, join: ctrl.link.join, entity: ctrl.link.entity});
+        return _.find(ctrl.links, function(link) {
+          if (ctrl.link.task && link.task === ctrl.link.task && link.entity === ctrl.link.entity) {
+            return true;
+          } else if (ctrl.link.action && link.action === ctrl.link.action && link.entity === ctrl.link.entity && link.join == ctrl.link.join) {
+            return true;
+          }
+          return false;
+        });
       };
 
     }
index 1fa7efac6a65c78592f58c5dcd74548540658c90..b7d2b16870bc594a98fdf96d3613a7441f7e00a4 100644 (file)
@@ -1,22 +1,26 @@
 <div class="crm-flex-1 input-group" >
-  <input type="text" class="form-control" ng-if="!$ctrl.link.action" ng-model="$ctrl.link.path" ng-model-options="{updateOn: 'blur'}" ng-change="$ctrl.onChange({newLink: $ctrl.link})">
-  <div class="input-group-btn" style="{{ $ctrl.link.action ? '' : 'width:27px' }}">
-    <button type="button" ng-click="$ctrl.menuOpen = true;" class="btn btn-sm btn-secondary-outline dropdown-toggle crm-search-admin-combo-button" ng-if="$ctrl.link.action" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
+  <input type="text" class="form-control" ng-if="!$ctrl.link.action && !$ctrl.link.task" ng-model="$ctrl.link.path" ng-model-options="{updateOn: 'blur'}" ng-change="$ctrl.onChange({newLink: $ctrl.link})">
+  <div class="input-group-btn" style="{{ $ctrl.link.action || $ctrl.link.task ? '' : 'width:27px' }}">
+    <button type="button" ng-click="$ctrl.menuOpen = true;" class="btn btn-sm btn-secondary-outline dropdown-toggle crm-search-admin-combo-button" ng-if="$ctrl.link.action || $ctrl.link.task" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
       {{ $ctrl.getLink().text }}
     </button>
     <button type="button" ng-click="$ctrl.menuOpen = true;" class="btn btn-sm btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
       <span class="caret"></span>
     </button>
-    <ul class="dropdown-menu {{ $ctrl.link.action ? '' : 'dropdown-menu-right' }}" style="min-width: 223px;">
+    <ul class="dropdown-menu {{ $ctrl.link.action || $ctrl.link.task ? '' : 'dropdown-menu-right' }}" style="min-width: 223px;">
       <li ng-repeat="link in $ctrl.links" ng-class="{disabled: link === $ctrl.getLink()}">
-        <a href ng-click="$ctrl.setValue(link)">{{:: link.text }}</a>
+        <a href ng-click="$ctrl.setValue(link)">
+          <i class="crm-i {{:: link.icon }}"></i>
+          {{:: link.text }}
+        </a>
       </li>
-      <li ng-class="{disabled: !$ctrl.link.action}">
+      <li ng-class="{disabled: !$ctrl.link.action && !$ctrl.link.task}">
         <a href ng-click="$ctrl.setValue({path: 'civicrm/'})">
+          <i class="crm-i fa-terminal"></i>
           {{:: ts('Other...') }}
         </a>
       </li>
     </ul>
   </div>
 </div>
-<crm-search-admin-token-select ng-if="!$ctrl.link.action" model="$ctrl.link" field="path"></crm-search-admin-token-select>
+<crm-search-admin-token-select ng-if="!$ctrl.link.action && !$ctrl.link.task" model="$ctrl.link" field="path"></crm-search-admin-token-select>
index 3714137f3b907e14a70438ce7557cec12c23aee1..27aee9a6bbd886cbd286f2969d881ada97fe3261 100644 (file)
@@ -20,7 +20,7 @@
     <option value="_blank">{{:: ts('New tab') }}</option>
     <option value="crm-popup">{{:: ts('Popup dialog') }}</option>
   </select>
-  <crm-search-admin-link-select ng-if="col.link" link="col.link" on-change="$ctrl.parent.onChangeLink(col, newLink)" api-entity="$ctrl.apiEntity" api-params="$ctrl.apiParams" links=":: $ctrl.parent.getLinks(col.key)">
+  <crm-search-admin-link-select ng-if="col.link" link="col.link" on-change="$ctrl.parent.onChangeLink(col, newLink)" api-entity="$ctrl.apiEntity" api-params="$ctrl.apiParams" links="$ctrl.parent.getLinks(col.key)">
   </crm-search-admin-link-select>
 </div>
 <div class="form-inline crm-search-admin-flex-row">