*/
protected $sort = [];
+ /**
+ * Number of results to return
+ * @var int
+ */
+ protected $limit;
+
/**
* Should this api call return a page of results or the row_count or the ids
* E.g. "page:1" or "row_count" or "id"
if (!empty($settings['pager']) && preg_match('/^page:\d+$/', $this->return)) {
$page = explode(':', $this->return)[1];
}
- $apiParams['limit'] = $settings['limit'] ?? NULL;
+ $limit = !empty($settings['pager']['expose_limit']) && $this->limit ? $this->limit : NULL;
+ $apiParams['limit'] = $limit ?? $settings['limit'] ?? NULL;
$apiParams['offset'] = $page ? $apiParams['limit'] * ($page - 1) : 0;
$apiParams['orderBy'] = $this->getOrderByFromSort();
$this->augmentSelectClause($apiParams);
'ang/crmSearchAdmin.module.js',
'ang/crmSearchAdmin/*.js',
'ang/crmSearchAdmin/*/*.js',
+ 'ang/crmSearchAdmin/*/*/*.js',
],
'css' => [
'css/crmSearchAdmin.css',
},
};
- this.toggleLimit = function() {
- if (ctrl.display.settings.limit) {
- ctrl.display.settings.limit = 0;
- if (ctrl.display.settings.pager) {
- ctrl.display.settings.pager = false;
- }
- } else {
- ctrl.display.settings.limit = CRM.crmSearchAdmin.defaultPagerSize;
- }
- };
-
// Drag-n-drop settings for reordering columns
this.sortableOptions = {
connectWith: '.crm-search-admin-edit-columns',
--- /dev/null
+(function(angular, $, _) {
+ "use strict";
+
+ angular.module('crmSearchAdmin').component('searchAdminPagerConfig', {
+ bindings: {
+ display: '<',
+ },
+ templateUrl: '~/crmSearchAdmin/displays/common/searchAdminPagerConfig.html',
+ controller: function($scope) {
+ var ts = $scope.ts = CRM.ts('org.civicrm.search_kit'),
+ ctrl = this;
+
+ function getDefaultSettings() {
+ return _.cloneDeep({
+ show_count: false,
+ expose_limit: false
+ });
+ }
+
+ this.$onInit = function() {
+ // Legacy support
+ if (this.display.settings.pager === true) {
+ this.display.settings.pager = getDefaultSettings();
+ }
+ if (this.display.settings.pager && !this.display.settings.limit) {
+ this.toggleLimit();
+ }
+ };
+
+ this.togglePager = function() {
+ this.display.settings.pager = this.display.settings.pager ? false : getDefaultSettings();
+ if (this.display.settings.pager && !this.display.settings.limit) {
+ this.toggleLimit();
+ }
+ };
+
+ this.toggleLimit = function() {
+ if (ctrl.display.settings.limit) {
+ ctrl.display.settings.limit = 0;
+ } else {
+ ctrl.display.settings.limit = CRM.crmSearchAdmin.defaultPagerSize;
+ }
+ };
+
+ }
+ });
+
+})(angular, CRM.$, CRM._);
--- /dev/null
+<div class="form-inline">
+ <div class="checkbox-inline form-control">
+ <label>
+ <input type="checkbox" ng-checked="$ctrl.display.settings.pager" ng-click="$ctrl.togglePager()">
+ <span>{{:: ts('Use Pager') }}</span>
+ </label>
+ </div>
+ <div class="checkbox-inline form-control" ng-if="!$ctrl.display.settings.pager">
+ <label>
+ <input type="checkbox" ng-checked="$ctrl.display.settings.limit" ng-click="$ctrl.toggleLimit()">
+ <span>{{:: ts('Limit Results') }}</span>
+ </label>
+ <input ng-if="$ctrl.display.settings.limit" type="number" min="1" step="1" class="form-control" ng-model="$ctrl.display.settings.limit">
+ </div>
+ <div class="form-group" ng-if="$ctrl.display.settings.pager">
+ <label for="crm-search-admin-display-limit">
+ {{:: ts('Page Size') }}
+ </label>
+ <input id="crm-search-admin-display-limit" ng-if="$ctrl.display.settings.limit" type="number" min="1" step="1" class="form-control" ng-model="$ctrl.display.settings.limit">
+ <div class="checkbox-inline form-control">
+ <label>
+ <input type="checkbox" ng-model="$ctrl.display.settings.pager.show_count" >
+ <span>{{:: ts('Show Count') }}</span>
+ </label>
+ </div>
+ <div class="checkbox-inline form-control">
+ <label>
+ <input type="checkbox" ng-model="$ctrl.display.settings.pager.expose_limit" >
+ <span>{{:: ts('Adjustable Page Size') }}</span>
+ </label>
+ </div>
+ </div>
+</div>
ctrl.display.settings = {
style: 'ul',
limit: CRM.crmSearchAdmin.defaultPagerSize,
- pager: true
+ pager: {}
};
}
ctrl.parent.initColumns({key: true, dataType: true, type: 'field'});
</option>
</select>
</div>
- <div class="form-inline">
- <div class="checkbox-inline form-control">
- <label>
- <input type="checkbox" ng-checked="$ctrl.display.settings.limit" ng-click="$ctrl.parent.toggleLimit()">
- <span>{{:: ts('Limit Results') }}</span>
- </label>
- <input id="crm-search-admin-display-limit" ng-if="$ctrl.display.settings.limit" type="number" min="1" step="1" class="form-control" ng-model="$ctrl.display.settings.limit">
- </div>
- <div class="checkbox-inline form-control">
- <label ng-class="{disabled: !$ctrl.display.settings.limit}">
- <input type="checkbox" ng-model="$ctrl.display.settings.pager" ng-disabled="!$ctrl.display.settings.limit">
- <span>{{:: ts('Use Pager') }}</span>
- </label>
- </div>
- </div>
+ <search-admin-pager-config display="$ctrl.display"></search-admin-pager-config>
</fieldset>
<fieldset class="crm-search-admin-edit-columns-wrapper">
<legend>
if (!ctrl.display.settings) {
ctrl.display.settings = {
limit: CRM.crmSearchAdmin.defaultPagerSize,
- pager: true
+ pager: {}
};
}
ctrl.parent.initColumns({key: true, label: true, dataType: true, type: 'field'});
<fieldset ng-include="'~/crmSearchAdmin/crmSearchAdminDisplaySort.html'"></fieldset>
<fieldset>
<div class="form-inline">
- <div class="checkbox-inline form-control">
- <label>
- <input type="checkbox" ng-checked="$ctrl.display.settings.limit" ng-click="$ctrl.parent.toggleLimit()">
- <span>{{:: ts('Limit Results') }}</span>
- </label>
- <input id="crm-search-admin-display-limit" ng-if="$ctrl.display.settings.limit" type="number" min="1" step="1" class="form-control" ng-model="$ctrl.display.settings.limit">
- </div>
- <div class="checkbox-inline form-control">
- <label ng-class="{disabled: !$ctrl.display.settings.limit}">
- <input type="checkbox" ng-model="$ctrl.display.settings.pager" ng-disabled="!$ctrl.display.settings.limit">
- <span>{{:: ts('Use Pager') }}</span>
- </label>
- </div>
<div class="checkbox-inline form-control">
<label>
<input type="checkbox" ng-model="$ctrl.display.settings.actions">
</label>
</div>
</div>
+ <search-admin-pager-config display="$ctrl.display"></search-admin-pager-config>
</fieldset>
<fieldset class="crm-search-admin-edit-columns-wrapper">
<legend>
-<div class="text-center" ng-if="$ctrl.rowCount && $ctrl.settings.pager">
- <ul uib-pagination
- class="pagination"
- boundary-links="true"
- total-items="$ctrl.rowCount"
- ng-model="$ctrl.page"
- ng-change="$ctrl.getResults()"
- items-per-page="$ctrl.settings.limit"
- max-size="6"
- force-ellipses="true"
- previous-text="‹"
- next-text="›"
- first-text="«"
- last-text="»"
- ></ul>
+<div class="crm-flex-box crm-search-display-pager" ng-if="$ctrl.rowCount && $ctrl.settings.pager">
+ <div>
+ <div class="form-inline" ng-if="$ctrl.settings.pager.show_count">
+ <label ng-if="$ctrl.rowCount === 1">
+ {{ $ctrl.selectedRows && $ctrl.selectedRows.length ? ts('%1 selected of 1 result', {1: $ctrl.selectedRows.length}) : ts('1 result') }}
+ </label>
+ <label ng-if="$ctrl.rowCount === 0 || $ctrl.rowCount > 1">
+ {{ $ctrl.selectedRows && $ctrl.selectedRows.length ? ts('%1 selected of %2 results', {1: $ctrl.selectedRows.length, 2: $ctrl.rowCount}) : ts('%1 results', {1: $ctrl.rowCount}) }}
+ </label>
+ </div>
+ </div>
+ <div class="text-center crm-flex-2">
+ <ul uib-pagination
+ class="pagination"
+ boundary-links="true"
+ total-items="$ctrl.rowCount"
+ ng-model="$ctrl.page"
+ ng-change="$ctrl.getResults()"
+ items-per-page="$ctrl.limit"
+ max-size="6"
+ force-ellipses="true"
+ previous-text="‹"
+ next-text="›"
+ first-text="«"
+ last-text="»"
+ ></ul>
+ </div>
+ <div>
+ <div class="form-inline text-right" ng-if="$ctrl.settings.pager.expose_limit">
+ <label for="crm-search-results-page-size" >
+ {{:: ts('Page Size') }}
+ </label>
+ <input class="form-control" id="crm-search-results-page-size" type="number" ng-model="$ctrl.limit" min="10" step="10" ng-change="onChangeLimit()">
+ </div>
+ </div>
</div>
// Called by the controller's $onInit function
initializeDisplay: function($scope, $element) {
var ctrl = this;
+ this.limit = this.settings.limit;
this.sort = this.settings.sort ? _.cloneDeep(this.settings.sort) : [];
this.getResults = _.debounce(function() {
ctrl.getResults();
}
+ function onChangePageSize() {
+ ctrl.page = 1;
+ ctrl.getResults();
+ }
+
if (this.afFieldset) {
$scope.$watch(this.afFieldset.getFieldData, onChangeFilters, true);
}
+ if (this.settings.pager && this.settings.pager.expose_limit) {
+ $scope.$watch('$ctrl.limit', onChangePageSize);
+ }
$scope.$watch('$ctrl.filters', onChangeFilters, true);
},
savedSearch: this.search,
display: this.display,
sort: this.sort,
+ limit: this.limit,
filters: _.assign({}, (this.afFieldset ? this.afFieldset.getFieldData() : {}), this.filters),
afform: this.afFieldset ? this.afFieldset.getFormName() : null
};
ctrl.results = results;
ctrl.editing = false;
if (!ctrl.rowCount) {
- if (!ctrl.settings.limit || results.length < ctrl.settings.limit) {
+ if (!ctrl.limit || results.length < ctrl.limit) {
ctrl.rowCount = results.length;
} else if (ctrl.settings.pager) {
var params = ctrl.getApiParams('row_count');
}
// Select all
ctrl.allRowsSelected = true;
- if (ctrl.page === 1 && ctrl.results.length < ctrl.settings.limit) {
+ if (ctrl.page === 1 && ctrl.results.length < ctrl.limit) {
ctrl.selectedRows = _.pluck(ctrl.results, 'id');
return;
}