Skip to content

Commit

Permalink
Merge pull request #21343 from colemanw/searchKitLinks
Browse files Browse the repository at this point in the history
SearchKit - Add links to admin table and refresh after popups
  • Loading branch information
eileenmcnaughton authored Sep 2, 2021
2 parents c71dfd2 + 9a4c649 commit 2934bc6
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 18 deletions.
1 change: 1 addition & 0 deletions ext/search_kit/Civi/Search/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public static function getStyles():array {
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'),
Expand Down
7 changes: 7 additions & 0 deletions ext/search_kit/ang/crmSearchAdmin/crmSearchAdmin.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,19 +583,26 @@
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,6 @@
}
};

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;
Expand All @@ -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'
});
};

Expand Down
5 changes: 3 additions & 2 deletions ext/search_kit/ang/crmSearchAdmin/displays/colType/menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
{{:: 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 }}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -49,6 +49,25 @@
})
}
};
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)
};
Expand All @@ -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);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@
});
}

$element.on('crmPopupFormSuccess', this.getResults);

function onChangeFilters() {
ctrl.page = 1;
ctrl.rowCount = null;
Expand Down

0 comments on commit 2934bc6

Please sign in to comment.