chg: [component:CRUD] Include meta-fields in REST queries and clever pagination support for REST queries

refacto/CRUDComponent
Sami Mokaddem 2023-08-29 14:57:48 +02:00
parent 633ae86886
commit 1ea7c796ac
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
2 changed files with 7 additions and 2 deletions

View File

@ -96,17 +96,18 @@ class CRUDComponent extends Component
$query->order($sort . ' ' . $direction); $query->order($sort . ' ' . $direction);
} }
} }
if ($this->metaFieldsSupported() && !$this->Controller->ParamHandler->isRest()) { if ($this->metaFieldsSupported()) {
$query = $this->includeRequestedMetaFields($query); $query = $this->includeRequestedMetaFields($query);
} }
if (!$this->Controller->ParamHandler->isRest()) { if (!$this->Controller->ParamHandler->isRest()) {
$this->setRequestedEntryAmount(); $this->setRequestedEntryAmount();
} else if (!empty($this->request->getQuery('limit'))) {
$this->Controller->paginate['limit'] = PHP_INT_MAX; // Make sure to download the entire filtered table
} }
$data = $this->Controller->paginate($query, $this->Controller->paginate ?? []); $data = $this->Controller->paginate($query, $this->Controller->paginate ?? []);
$totalCount = $this->Controller->getRequest()->getAttribute('paging')[$this->TableAlias]['count']; $totalCount = $this->Controller->getRequest()->getAttribute('paging')[$this->TableAlias]['count'];
if ($this->Controller->ParamHandler->isRest()) { if ($this->Controller->ParamHandler->isRest()) {
$data = $this->Controller->paginate($query, $this->Controller->paginate ?? []);
if (isset($options['hidden'])) { if (isset($options['hidden'])) {
$data->each(function($value, $key) use ($options) { $data->each(function($value, $key) use ($options) {
$hidden = is_array($options['hidden']) ? $options['hidden'] : [$options['hidden']]; $hidden = is_array($options['hidden']) ? $options['hidden'] : [$options['hidden']];
@ -795,6 +796,9 @@ class CRUDComponent extends Component
$user = $this->Controller->ACL->getUser(); $user = $this->Controller->ACL->getUser();
$tableSettings = IndexSetting::getTableSetting($user, $this->Table); $tableSettings = IndexSetting::getTableSetting($user, $this->Table);
if (!empty($tableSettings['number_of_element'])) { if (!empty($tableSettings['number_of_element'])) {
if ($tableSettings['number_of_element'] === 'all') {
$tableSettings['number_of_element'] = 10000; // Even with all, sure not to return too much data
}
$this->Controller->paginate['limit'] = intval($tableSettings['number_of_element']); $this->Controller->paginate['limit'] = intval($tableSettings['number_of_element']);
} }
} }

View File

@ -10,6 +10,7 @@ $numberOfElementSelectSeed = 'seed-' . mt_rand();
<option value="50" <?= $numberOfElement == 50 ? 'selected' : '' ?>><?= __('50') ?></option> <option value="50" <?= $numberOfElement == 50 ? 'selected' : '' ?>><?= __('50') ?></option>
<option value="100" <?= $numberOfElement == 100 ? 'selected' : '' ?>><?= __('100') ?></option> <option value="100" <?= $numberOfElement == 100 ? 'selected' : '' ?>><?= __('100') ?></option>
<option value="200" <?= $numberOfElement == 200 ? 'selected' : '' ?>><?= __('200') ?></option> <option value="200" <?= $numberOfElement == 200 ? 'selected' : '' ?>><?= __('200') ?></option>
<option value="all" <?= $numberOfElement == 'all' ? 'selected' : '' ?>><?= __('All') ?></option>
</select> </select>
</label> </label>