chg: [instance:search_all] Support of total entry found

pull/72/head
mokaddem 2021-09-10 14:46:56 +02:00
parent 464e6c6951
commit f00798db44
4 changed files with 27 additions and 7 deletions

View File

@ -30,12 +30,12 @@ class InstanceController extends AppController
return $this->RestResponse->viewData($data, 'json');
}
public function searchAll()
public function searchAll($limit = 5)
{
$searchValue = $this->request->getQuery('search');
$data = [];
if (!empty($searchValue)) {
$data = $this->Instance->searchAll($searchValue);
$data = $this->Instance->searchAll($searchValue, $limit);
}
if ($this->ParamHandler->isRest()) {
return $this->RestResponse->viewData($data, 'json');

View File

@ -24,7 +24,7 @@ class InstanceTable extends AppTable
return $validator;
}
public function searchAll($value)
public function searchAll($value, $limit=5)
{
$results = [];
foreach ($this->seachAllTables as $tableName) {
@ -41,12 +41,12 @@ class InstanceTable extends AppTable
if (!empty($containFields)) {
$query->contain($containFields);
}
$result = $query->limit(5)->all()->toList();
$results[$tableName]['amount'] = $query->count();
$result = $query->limit($limit)->all()->toList();
if (!empty($result)) {
$results[$tableName] = $result;
$results[$tableName]['entries'] = $result;
}
}
return $results;
}

View File

@ -1,6 +1,9 @@
<?php
$sections = [];
foreach ($data as $tableName => $tableResult) {
if (empty($tableResult['amount'])) {
continue;
}
$section = '';
$table = Cake\ORM\TableRegistry::get($tableName);
$fieldPath = !empty($table->getDisplayField()) ? $table->getDisplayField() : 'id';
@ -11,7 +14,7 @@
</span>
</span>', h($tableName));
foreach ($tableResult as $entry) {
foreach ($tableResult['entries'] as $entry) {
$section .= sprintf('<a class="dropdown-item" href="%s">%s</a>',
Cake\Routing\Router::URL([
'controller' => Cake\Utility\Inflector::pluralize($entry->getSource()),
@ -21,6 +24,13 @@
h($entry[$fieldPath])
);
}
$remaining = $tableResult['amount'] - count($tableResult['entries']);
if ($remaining > 0) {
$section .= sprintf('<span class="total-found d-block pr-2"><strong class="total-found-number text-primary">%s</strong><span class="total-found-text d-inline ml-1" href="#">%s</span></span>',
$remaining,
__('more results')
);
}
$sections[] = $section;
}

View File

@ -139,6 +139,16 @@ main.content {
margin: auto 0;
}
.global-search-result-container .total-found {
font-size: 0.75rem;
padding-top: 0rem;
text-align: end;
}
.global-search-result-container .total-found .total-found-number {
font-size: 0.9rem;
}
.global-search-result-container .search-container-model .model-text {
font-size: 0.75rem;
font-weight: 600;