SearchKit - Add links to admin table and refresh after popups
authorColeman Watts <coleman@civicrm.org>
Wed, 1 Sep 2021 19:41:22 +0000 (15:41 -0400)
committerColeman Watts <coleman@civicrm.org>
Wed, 1 Sep 2021 19:41:22 +0000 (15:41 -0400)
ext/search_kit/Civi/Search/Admin.php
ext/search_kit/ang/crmSearchAdmin/crmSearchAdmin.component.js
ext/search_kit/ang/crmSearchAdmin/crmSearchAdminLinkGroup.component.js
ext/search_kit/ang/crmSearchAdmin/displays/colType/menu.html
ext/search_kit/ang/crmSearchAdmin/resultsTable/crmSearchAdminResultsTable.component.js
ext/search_kit/ang/crmSearchDisplay/traits/searchDisplayBaseTrait.service.js

index 901c0a14406f73e4009c0aab2ced538b887afc11..963b02c44dc7a6c65a7aadec38277fb54a982e0d 100644 (file)
@@ -68,6 +68,7 @@ class Admin {
     return [
       'default' => E::ts('Default'),
       'primary' => E::ts('Primary'),
+      'secondary' => E::ts('Secondary'),
       'success' => E::ts('Success'),
       'info' => E::ts('Info'),
       'warning' => E::ts('Warning'),
index 86e9fa816ab49a88654e9f6dd3d8c4027a058962..d8f13c449d3967f60a1aa0a3692527544f259d54 100644 (file)
           switch (link.action) {
             case 'view':
               link.title = ts('View %1', {1: entityName});
+              link.icon = 'fa-external-link';
+              link.style = 'default';
               break;
 
             case 'update':
               link.title = ts('Edit %1', {1: entityName});
+              link.icon = 'fa-pencil';
+              link.style = 'default';
               break;
 
             case 'delete':
               link.title = ts('Delete %1', {1: entityName});
+              link.icon = 'fa-trash';
+              link.style = 'danger';
               break;
           }
         }
 
         // Links to main entity
+        // @return {Array}
         var mainEntity = searchMeta.getEntity(ctrl.savedSearch.api_entity),
           links = _.cloneDeep(mainEntity.paths || []);
         _.each(links, function(link) {
index f6e47996596e2d909ad8c3a3e1f7a716c71b58ef..5053c6ba17e2a48519833ddcc4cdd8f52aaad50c 100644 (file)
         }
       };
 
-      var defaultIcons = {
-        view: 'fa-external-link',
-        update: 'fa-pencil',
-        delete: 'fa-trash'
-      };
-
-      var defaultStyles = {
-        view: 'primary',
-        update: 'warning',
-        delete: 'danger'
-      };
-
       $scope.pickIcon = function(index) {
         searchMeta.pickIcon().then(function(icon) {
           ctrl.group[index].icon = icon;
@@ -53,9 +41,9 @@
         var link = ctrl.getLink(path);
         ctrl.group.push({
           path: path,
-          style: link && defaultStyles[link.action] || 'default',
+          style: link && link.style || 'default',
           text: link ? link.title : ts('Link'),
-          icon: link && defaultIcons[link.action] || 'fa-external-link'
+          icon: link && link.icon || 'fa-external-link'
         });
       };
 
index a7987926acb35469783206699a347aebe3f5badb..9b0e15e7cd75b976b7bddcf052ac33237cfe752b 100644 (file)
     {{:: ts('Style') }}
   </label>
   <select id="crm-search-admin-col-style-{{$index}}" class="form-control" ng-model="col.style">
-    <option ng-repeat="opt in $ctrl.parent.styles" value="{{ opt.key }}">{{ opt.value }}</option>
+    <option ng-repeat="opt in $ctrl.parent.styles" value="{{:: opt.key }}">{{:: opt.value }}</option>
+    <option ng-repeat="opt in $ctrl.parent.styles" value="{{:: opt.key + '-outline' }}">{{:: opt.value + ' ' + ts('Outline') }}</option>
   </select>
 </div>
 <div class="form-inline">
   <label>
-    {{:: ts('Menu Text/Icon') }}
+    {{:: ts('Menu Icon/Text') }}
   </label>
   <div class="btn-group">
     <button type="button" class="btn btn-{{ col.style + ' ' + col.size }}">
index fbf615db771dfd6ad54dd079a46389da2e0f73f5..db24c865bb8c19b19340590f2fc0d705b5931cfb 100644 (file)
@@ -10,7 +10,7 @@
       crmSearchAdmin: '^crmSearchAdmin'
     },
     templateUrl: '~/crmSearchAdmin/resultsTable/crmSearchAdminResultsTable.html',
-    controller: function($scope, searchMeta, searchDisplayBaseTrait, searchDisplayTasksTrait, searchDisplaySortableTrait) {
+    controller: function($scope, $element, searchMeta, searchDisplayBaseTrait, searchDisplayTasksTrait, searchDisplaySortableTrait) {
       var ts = $scope.ts = CRM.ts('org.civicrm.search_kit'),
         // Mix in traits to this controller
         ctrl = angular.extend(this, searchDisplayBaseTrait, searchDisplayTasksTrait, searchDisplaySortableTrait);
             })
           }
         };
+        if (links.length) {
+          ctrl.display.settings.columns.push({
+            text: '',
+            icon: 'fa-bars',
+            type: 'menu',
+            size: 'btn-xs',
+            style: 'secondary-outline',
+            alignment: 'text-right',
+            links: _.transform(links, function(links, link) {
+              links.push({
+                path: link.path,
+                text: link.title,
+                icon: link.icon,
+                style: link.style,
+                target: link.action === 'view' ? '_blank' : 'crm-popup'
+              });
+            })
+          });
+        }
         ctrl.debug = {
           apiParams: JSON.stringify(ctrl.search.api_params, null, 2)
         };
@@ -57,7 +76,7 @@
 
       this.$onInit = function() {
         buildSettings();
-        this.initializeDisplay($scope, $());
+        this.initializeDisplay($scope, $element);
         $scope.$watch('$ctrl.search.api_entity', buildSettings);
         $scope.$watch('$ctrl.search.api_params', buildSettings, true);
       };
index 5dd5b827db7dd20f98e2d548411ab7ee5f795081..f4700a6b01882f9ae5d4e1c82d0f46f0b8c37605 100644 (file)
@@ -90,6 +90,8 @@
           });
         }
 
+        $element.on('crmPopupFormSuccess', this.getResults);
+
         function onChangeFilters() {
           ctrl.page = 1;
           ctrl.rowCount = null;