diff --git a/ext/afform/admin/ang/afAdmin/afAdminList.controller.js b/ext/afform/admin/ang/afAdmin/afAdminList.controller.js index 2b1ee33b9464..019281936b04 100644 --- a/ext/afform/admin/ang/afAdmin/afAdminList.controller.js +++ b/ext/afform/admin/ang/afAdmin/afAdminList.controller.js @@ -57,10 +57,13 @@ $scope.$bindToRoute({ expr: '$ctrl.tab', param: 'tab', - format: 'raw', - default: ctrl.tabs[0].name + format: 'raw' }); + if (!ctrl.tab) { + ctrl.tab = ctrl.tabs[0].name; + } + this.createLinks = function() { ctrl.searchCreateLinks = ''; if ($scope.types[ctrl.tab].options) { diff --git a/ext/search_kit/ang/crmSearchAdmin.module.js b/ext/search_kit/ang/crmSearchAdmin.module.js index b920e7ba90ac..8ac46b3938b8 100644 --- a/ext/search_kit/ang/crmSearchAdmin.module.js +++ b/ext/search_kit/ang/crmSearchAdmin.module.js @@ -11,10 +11,9 @@ .config(function($routeProvider) { $routeProvider.when('/list', { - controller: function() { - searchEntity = 'SavedSearch'; - }, - template: '', + controller: 'searchList', + reloadOnSearch: false, + templateUrl: '~/crmSearchAdmin/searchListing/crmSearchAdminSearchListing.html', }); $routeProvider.when('/create/:entity', { controller: 'searchCreate', @@ -45,6 +44,36 @@ }); }) + // Controller for tabbed view of SavedSearches + .controller('searchList', function($scope, searchMeta, formatForSelect2) { + var ts = $scope.ts = CRM.ts('org.civicrm.search_kit'), + ctrl = $scope.$ctrl = this; + searchEntity = 'SavedSearch'; + + // Metadata needed for filters + this.entitySelect = searchMeta.getPrimaryAndSecondaryEntitySelect(); + this.modules = _.sortBy(_.transform((CRM.crmSearchAdmin.modules), function(modules, label, key) { + modules.push({text: label, id: key}); + }, []), 'text'); + this.getTags = function() { + return {results: formatForSelect2(CRM.crmSearchAdmin.tags, 'id', 'name', ['color', 'description'])}; + }; + + // Tabs include a rowCount which will be updated by the search controller + this.tabs = [ + {name: 'custom', title: ts('Custom Searches'), icon: 'fa-search-plus', rowCount: null, filters: {has_base: false}}, + {name: 'packaged', title: ts('Packaged Searches'), icon: 'fa-gift', rowCount: null, filters: {has_base: true}} + ]; + $scope.$bindToRoute({ + expr: '$ctrl.tab', + param: 'tab', + format: 'raw' + }); + if (!this.tab) { + this.tab = this.tabs[0].name; + } + }) + // Controller for creating a new search .controller('searchCreate', function($scope, $routeParams, $location) { searchEntity = $routeParams.entity; diff --git a/ext/search_kit/ang/crmSearchAdmin/crmSearchAdmin.component.js b/ext/search_kit/ang/crmSearchAdmin/crmSearchAdmin.component.js index 8cbc6177805a..d0b8750bc3e3 100644 --- a/ext/search_kit/ang/crmSearchAdmin/crmSearchAdmin.component.js +++ b/ext/search_kit/ang/crmSearchAdmin/crmSearchAdmin.component.js @@ -40,16 +40,23 @@ this.groupExists = !!this.savedSearch.groups.length; if (!this.savedSearch.id) { + var defaults = { + version: 4, + select: getDefaultSelect(), + orderBy: {}, + where: [], + }; + _.each(['groupBy', 'join', 'having'], function(param) { + if (ctrl.paramExists(param)) { + defaults[param] = []; + } + }); + $scope.$bindToRoute({ param: 'params', expr: '$ctrl.savedSearch.api_params', deep: true, - default: { - version: 4, - select: getDefaultSelect(), - orderBy: {}, - where: [], - } + default: defaults }); } @@ -57,18 +64,6 @@ $scope.$watchCollection('$ctrl.savedSearch.api_params.select', onChangeSelect); - if (this.paramExists('groupBy')) { - this.savedSearch.api_params.groupBy = this.savedSearch.api_params.groupBy || []; - } - - if (this.paramExists('join')) { - this.savedSearch.api_params.join = this.savedSearch.api_params.join || []; - } - - if (this.paramExists('having')) { - this.savedSearch.api_params.having = this.savedSearch.api_params.having || []; - } - $scope.$watch('$ctrl.savedSearch', onChangeAnything, true); // After watcher runs for the first time and messes up the status, set it correctly diff --git a/ext/search_kit/ang/crmSearchAdmin/searchListing/buttons.html b/ext/search_kit/ang/crmSearchAdmin/searchListing/buttons.html index 61611498c34f..e7ed5a67b108 100644 --- a/ext/search_kit/ang/crmSearchAdmin/searchListing/buttons.html +++ b/ext/search_kit/ang/crmSearchAdmin/searchListing/buttons.html @@ -1,12 +1,12 @@ {{:: ts('View') }} - + {{:: ts('Edit') }} {{:: ts('Clone') }} - + {{ row.data['base_module:label'] ? ts('Revert') : ts('Delete') }} diff --git a/ext/search_kit/ang/crmSearchAdmin/searchListing/crmSearchAdminSearchListing.component.js b/ext/search_kit/ang/crmSearchAdmin/searchListing/crmSearchAdminSearchListing.component.js index 82d690bea9a8..5b18b02ee09f 100644 --- a/ext/search_kit/ang/crmSearchAdmin/searchListing/crmSearchAdminSearchListing.component.js +++ b/ext/search_kit/ang/crmSearchAdmin/searchListing/crmSearchAdminSearchListing.component.js @@ -3,8 +3,12 @@ // Specialized searchDisplay, only used by Admins angular.module('crmSearchAdmin').component('crmSearchAdminSearchListing', { - templateUrl: '~/crmSearchAdmin/searchListing/crmSearchAdminSearchListing.html', - controller: function($scope, $q, crmApi4, crmStatus, searchMeta, searchDisplayBaseTrait, searchDisplaySortableTrait, formatForSelect2) { + bindings: { + filters: '<', + tabCount: '=' + }, + templateUrl: '~/crmSearchDisplayTable/crmSearchDisplayTable.html', + controller: function($scope, $q, crmApi4, crmStatus, searchMeta, searchDisplayBaseTrait, searchDisplaySortableTrait) { var ts = $scope.ts = CRM.ts('org.civicrm.search_kit'), // Mix in traits to this controller ctrl = angular.extend(this, searchDisplayBaseTrait, searchDisplaySortableTrait), @@ -14,13 +18,6 @@ this.afformPath = CRM.url('civicrm/admin/afform'); this.afformEnabled = CRM.crmSearchAdmin.afformEnabled; this.afformAdminEnabled = CRM.crmSearchAdmin.afformAdminEnabled; - this.entitySelect = searchMeta.getPrimaryAndSecondaryEntitySelect(); - this.modules = _.sortBy(_.transform((CRM.crmSearchAdmin.modules), function(modules, label, key) { - modules.push({text: label, id: key}); - }, []), 'text'); - - this.filters = {has_base: false}; - this.totals = {}; this.apiEntity = 'SavedSearch'; this.search = { @@ -41,6 +38,7 @@ 'modified_date', 'has_base', 'base_module:label', + 'local_modified_date', 'DATE(created_date) AS date_created', 'DATE(modified_date) AS date_modified', 'GROUP_CONCAT(display.name ORDER BY display.id) AS display_name', @@ -66,25 +64,10 @@ this.initializeDisplay($scope, $()); // Keep tab counts up-to-date - put rowCount in current tab if there are no other filters $scope.$watch('$ctrl.rowCount', function(val) { - if (typeof val === 'number' && angular.equals({has_base: true}, ctrl.filters)) { - ctrl.totals.has_base = val; - } - else if (typeof val === 'number' && angular.equals({has_base: false}, ctrl.filters)) { - ctrl.totals.no_base = val; + if (typeof val === 'number' && angular.equals(['has_base'], _.keys(ctrl.filters))) { + ctrl.tabCount = val; } }); - // Initialize count for inactive tab - var params = ctrl.getApiParams('row_count'); - params.filters.has_base = true; - crmApi4('SearchDisplay', 'run', params).then(function(result) { - ctrl.totals.has_base = result.count; - }); - }; - - // Change tabs and clear other filters - this.setHasBaseFilter = function(val) { - ctrl.filters = {has_base: val}; - buildDisplaySettings(); }; this.onPostRun.push(function(result) { @@ -179,10 +162,6 @@ ); }; - this.getTags = function() { - return {results: formatForSelect2(CRM.crmSearchAdmin.tags, 'id', 'name', ['color', 'description'])}; - }; - function buildDisplaySettings() { ctrl.display = { type: 'table', @@ -237,6 +216,19 @@ ] }) ); + ctrl.display.settings.columns.push( + // Using 'local_modified_date' as the column + an empty_value will only show the rewritten value + // if the record has been modified from its packaged state. + searchMeta.fieldToColumn('local_modified_date', { + label: ts('Modified'), + empty_value: ts('No'), + title: ts('Whether and when a search was modified from its packaged settings'), + rewrite: ts('%1 by %2', {1: '[date_modified]', 2: '[modified_id.display_name]'}), + cssRules: [ + ['font-italic', 'local_modified_date', 'IS EMPTY'] + ] + }) + ); } else { ctrl.display.settings.columns.push( searchMeta.fieldToColumn('created_date', { @@ -245,14 +237,14 @@ rewrite: ts('%1 by %2', {1: '[date_created]', 2: '[created_id.display_name]'}) }) ); + ctrl.display.settings.columns.push( + searchMeta.fieldToColumn('modified_date', { + label: ts('Modified'), + title: '[modified_date]', + rewrite: ts('%1 by %2', {1: '[date_modified]', 2: '[modified_id.display_name]'}) + }) + ); } - ctrl.display.settings.columns.push( - searchMeta.fieldToColumn('modified_date', { - label: ts('Last Modified'), - title: '[modified_date]', - rewrite: ts('%1 by %2', {1: '[date_modified]', 2: '[modified_id.display_name]'}) - }) - ); ctrl.display.settings.columns.push({ type: 'include', alignment: 'text-right', diff --git a/ext/search_kit/ang/crmSearchAdmin/searchListing/crmSearchAdminSearchListing.html b/ext/search_kit/ang/crmSearchAdmin/searchListing/crmSearchAdminSearchListing.html index 84e8358a4fef..2f0361fd1a33 100644 --- a/ext/search_kit/ang/crmSearchAdmin/searchListing/crmSearchAdminSearchListing.html +++ b/ext/search_kit/ang/crmSearchAdmin/searchListing/crmSearchAdminSearchListing.html @@ -3,35 +3,30 @@

{{:: ts('Saved Searches') }}

- -
- - - - - - - - - - - - {{:: ts('New Search') }} - +
+
+ + + + + + + + + + + + {{:: ts('New Search') }} + +
+
-