Skip to content

Commit

Permalink
SearchKit - Add column for scheduled communications to savedSearch li…
Browse files Browse the repository at this point in the history
…sting
  • Loading branch information
colemanw committed Sep 5, 2023
1 parent 6ec95aa commit ff4b31d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<div class="btn-group">
<button type="button" ng-click="row.openScheduleMenu = true" class="btn btn-xs dropdown-toggle btn-primary-outline" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{:: row.data.schedule_id.length === 1 ? ts('1 Communication') : ts('%1 Communications', {1: row.data.schedule_id ? row.data.schedule_id.length : 0}) }} <span class="caret"></span>
</button>
<ul class="dropdown-menu" ng-if=":: row.openScheduleMenu">
<li ng-repeat="schedule_id in row.data.schedule_id" title="{{:: ts('Edit Scheduled Communication') }}">
<a ng-href="{{ crmUrl('civicrm/admin/scheduleReminders/edit?reset=1&action=update&mapping_id=saved_search&id=' + schedule_id + '&entity_value=' + row.data.id) }}" target="crm-popup">
<i class="crm-i fa-pencil"></i>
{{ row.data.schedule_title[$index] }}
</a>
</li>
<li class="divider" role="separator"></li>
<li title="{{:: ts('Add Scheduled Communication') }}">
<a ng-href="{{ crmUrl('civicrm/admin/scheduleReminders/edit?reset=1&action=add&mapping_id=saved_search&entity_value=' + row.data.id) }}" target="crm-popup">
<i class="crm-i fa-plus"></i>
{{:: ts('New Communication') }}
</a>
</li>
</ul>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
ctrl = angular.extend(this, _.cloneDeep(searchDisplayBaseTrait), _.cloneDeep(searchDisplaySortableTrait)),
afformLoad;

$scope.crmUrl = CRM.url;
this.searchDisplayPath = CRM.url('civicrm/search');
this.afformPath = CRM.url('civicrm/admin/afform');
this.afformEnabled = 'org.civicrm.afform' in CRM.crmSearchAdmin.modules;
this.afformAdminEnabled = (CRM.checkPerm('administer CiviCRM') || CRM.checkPerm('administer afform')) &&
'org.civicrm.afform_admin' in CRM.crmSearchAdmin.modules;
const scheduledCommunicationsEnabled = 'scheduled_communications' in CRM.crmSearchAdmin.modules;

this.apiEntity = 'SavedSearch';
this.search = {
Expand All @@ -45,24 +47,33 @@
'DATE(created_date) AS date_created',
'DATE(modified_date) AS date_modified',
'DATE(expires_date) AS expires',
'GROUP_CONCAT(display.name ORDER BY display.id) AS display_name',
'GROUP_CONCAT(display.label ORDER BY display.id) AS display_label',
'GROUP_CONCAT(display.type:icon ORDER BY display.id) AS display_icon',
'GROUP_CONCAT(display.acl_bypass ORDER BY display.id) AS display_acl_bypass',
// Get all search displays
'GROUP_CONCAT(UNIQUE display.name ORDER BY display.label) AS display_name',
'GROUP_CONCAT(UNIQUE display.label ORDER BY display.label) AS display_label',
'GROUP_CONCAT(UNIQUE display.type:icon ORDER BY display.label) AS display_icon',
'GROUP_CONCAT(UNIQUE display.acl_bypass ORDER BY display.label) AS display_acl_bypass',
'tags', // Not a selectable field but this hacks around the requirement that filters be in the select clause
'GROUP_CONCAT(DISTINCT entity_tag.tag_id) AS tag_id',
'GROUP_CONCAT(DISTINCT group.title) AS groups'
'GROUP_CONCAT(UNIQUE entity_tag.tag_id) AS tag_id',
// Really there can only be 1 smart group per saved-search; aggregation is just for the sake of the query
'GROUP_CONCAT(UNIQUE group.id) AS group_id',
'GROUP_CONCAT(UNIQUE group.title) AS groups'
],
join: [
['SearchDisplay AS display', 'LEFT', ['id', '=', 'display.saved_search_id']],
['Group AS group', 'LEFT', ['id', '=', 'group.saved_search_id']],
['EntityTag AS entity_tag', 'LEFT', ['entity_tag.entity_table', '=', '"civicrm_saved_search"'], ['id', '=', 'entity_tag.entity_id']],
['ActionSchedule AS schedule', 'LEFT', ['schedule.mapping_id', '=', '"saved_search"'], ['id', '=', 'schedule.entity_value']],
],
where: [['api_entity', 'IS NOT NULL'], ['is_current', '=', true]],
groupBy: ['id']
}
};

if (scheduledCommunicationsEnabled) {
this.search.api_params.select.push('GROUP_CONCAT(UNIQUE schedule.id ORDER BY schedule.title) AS schedule_id');
this.search.api_params.select.push('GROUP_CONCAT(UNIQUE schedule.title ORDER BY schedule.title) AS schedule_title');
}

this.$onInit = function() {
buildDisplaySettings();
this.initializeDisplay($scope, $element);
Expand Down Expand Up @@ -228,8 +239,15 @@
path: '~/crmSearchAdmin/searchListing/afforms.html'
});
}
if (scheduledCommunicationsEnabled) {
ctrl.display.settings.columns.push({
type: 'include',
label: ts('Communications'),
path: '~/crmSearchAdmin/searchListing/communications.html'
});
}
ctrl.display.settings.columns.push(
searchMeta.fieldToColumn('GROUP_CONCAT(DISTINCT group.title) AS groups', {
searchMeta.fieldToColumn('GROUP_CONCAT(UNIQUE group.title) AS groups', {
label: ts('Smart Group')
})
);
Expand Down

0 comments on commit ff4b31d

Please sign in to comment.