From db0552d09e5467cbec745a5a63a1dc3cfac93d0c Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 19 May 2021 10:41:39 -0400 Subject: [PATCH] SearchKit - Click-sort column headers on list page --- .../crmSearchAdmin/searchList.controller.js | 35 +++++++---- .../ang/crmSearchAdmin/searchList.html | 60 ++++++++++++++----- 2 files changed, 69 insertions(+), 26 deletions(-) diff --git a/ext/search_kit/ang/crmSearchAdmin/searchList.controller.js b/ext/search_kit/ang/crmSearchAdmin/searchList.controller.js index 53e4ac32b1..be17c652da 100644 --- a/ext/search_kit/ang/crmSearchAdmin/searchList.controller.js +++ b/ext/search_kit/ang/crmSearchAdmin/searchList.controller.js @@ -1,17 +1,20 @@ (function(angular, $, _) { "use strict"; - angular.module('crmSearchAdmin').controller('searchList', function($scope, savedSearches, crmApi4) { + angular.module('crmSearchAdmin').controller('searchList', function($scope, savedSearches, crmApi4, searchMeta) { var ts = $scope.ts = CRM.ts('org.civicrm.search_kit'), ctrl = $scope.$ctrl = this; $scope.formatDate = CRM.utils.formatDate; this.savedSearches = savedSearches; + this.sortField = 'modified_date'; + this.sortDir = true; this.afformEnabled = CRM.crmSearchAdmin.afformEnabled; this.afformAdminEnabled = CRM.crmSearchAdmin.afformAdminEnabled; - this.entityTitles = _.transform(CRM.crmSearchAdmin.schema, function(titles, entity) { - titles[entity.name] = entity.title_plural; - }, {}); + _.each(savedSearches, function(search) { + search.entity_title = searchMeta.getEntity(search.api_entity).title_plural; + search.afform_count = 0; + }); this.searchPath = CRM.url('civicrm/search'); this.afformPath = CRM.url('civicrm/admin/afform'); @@ -20,6 +23,12 @@ return encodeURI(angular.toJson(params)); }; + // Change sort field/direction when clicking a column header + this.sortBy = function(col) { + ctrl.sortDir = ctrl.sortField === col ? !ctrl.sortDir : false; + ctrl.sortField = col; + }; + this.deleteSearch = function(search) { var index = _.findIndex(savedSearches, {id: search.id}); if (index > -1) { @@ -45,13 +54,17 @@ _.each(afforms, function(afform) { var searchName = afform.layout.match(/]+search-name[ ]*=[ ]*['"]([^"']+)/); if (searchName) { - ctrl.afforms[searchName[1]] = ctrl.afforms[searchName[1]] || []; - ctrl.afforms[searchName[1]].push({ - title: afform.title, - name: afform.name, - // FIXME: This is the view url, currently not exposed to the UI, as BS3 doesn't support submenus. - url: afform.server_route ? CRM.url(afform.server_route) : null - }); + var search = _.find(ctrl.savedSearches, {name: searchName[1]}); + if (search) { + search.afform_count++; + ctrl.afforms[searchName[1]] = ctrl.afforms[searchName[1]] || []; + ctrl.afforms[searchName[1]].push({ + title: afform.title, + name: afform.name, + // FIXME: This is the view url, currently not exposed to the UI, as BS3 doesn't support submenus. + url: afform.server_route ? CRM.url(afform.server_route) : null + }); + } } }); }); diff --git a/ext/search_kit/ang/crmSearchAdmin/searchList.html b/ext/search_kit/ang/crmSearchAdmin/searchList.html index 8eef0258c5..ce4eb169ae 100644 --- a/ext/search_kit/ang/crmSearchAdmin/searchList.html +++ b/ext/search_kit/ang/crmSearchAdmin/searchList.html @@ -11,22 +11,48 @@ - - - - - - - - + + + + + + + - - + - + - - + +
{{:: ts('ID') }}{{:: ts('Label') }}{{:: ts('For') }}{{:: ts('Displays') }}{{:: ts('Smart Group') }}{{:: ts('Forms') }}{{:: ts('Created') }}{{:: ts('Last Modified') }} + + + {{:: ts('Label') }} + + + + {{:: ts('For') }} + + + + {{:: ts('Displays') }} + + + + {{:: ts('Smart Group') }} + + + + {{:: ts('Forms') }} + + + + {{:: ts('Created') }} + + + + {{:: ts('Last Modified') }} +
{{:: search.id }}
{{:: search.label }}{{:: $ctrl.entityTitles[search.api_entity] }}{{:: search.entity_title }}
{{:: ts('%1 by %2', {1: formatDate(search.created_date), 2: search['created.display_name']}) }}{{:: ts('%1 by %2', {1: formatDate(search.created_date), 2: search['modified.display_name']}) }} + {{:: search['created.display_name'] ? ts('%1 by %2', {1: formatDate(search.created_date), 2: search['created.display_name']}) : formatDate(search.created_date) }} + + {{:: search['modified.display_name'] ? ts('%1 by %2', {1: formatDate(search.modified_date), 2: search['modified.display_name']}) : formatDate(search.modified_date) }} + {{:: ts('Edit') }} {{:: ts('Clone') }} -- 2.25.1