chg: [instance:search_all] Support of total entry found
parent
464e6c6951
commit
f00798db44
|
@ -30,12 +30,12 @@ class InstanceController extends AppController
|
||||||
return $this->RestResponse->viewData($data, 'json');
|
return $this->RestResponse->viewData($data, 'json');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function searchAll()
|
public function searchAll($limit = 5)
|
||||||
{
|
{
|
||||||
$searchValue = $this->request->getQuery('search');
|
$searchValue = $this->request->getQuery('search');
|
||||||
$data = [];
|
$data = [];
|
||||||
if (!empty($searchValue)) {
|
if (!empty($searchValue)) {
|
||||||
$data = $this->Instance->searchAll($searchValue);
|
$data = $this->Instance->searchAll($searchValue, $limit);
|
||||||
}
|
}
|
||||||
if ($this->ParamHandler->isRest()) {
|
if ($this->ParamHandler->isRest()) {
|
||||||
return $this->RestResponse->viewData($data, 'json');
|
return $this->RestResponse->viewData($data, 'json');
|
||||||
|
|
|
@ -24,7 +24,7 @@ class InstanceTable extends AppTable
|
||||||
return $validator;
|
return $validator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function searchAll($value)
|
public function searchAll($value, $limit=5)
|
||||||
{
|
{
|
||||||
$results = [];
|
$results = [];
|
||||||
foreach ($this->seachAllTables as $tableName) {
|
foreach ($this->seachAllTables as $tableName) {
|
||||||
|
@ -41,12 +41,12 @@ class InstanceTable extends AppTable
|
||||||
if (!empty($containFields)) {
|
if (!empty($containFields)) {
|
||||||
$query->contain($containFields);
|
$query->contain($containFields);
|
||||||
}
|
}
|
||||||
$result = $query->limit(5)->all()->toList();
|
$results[$tableName]['amount'] = $query->count();
|
||||||
|
$result = $query->limit($limit)->all()->toList();
|
||||||
if (!empty($result)) {
|
if (!empty($result)) {
|
||||||
$results[$tableName] = $result;
|
$results[$tableName]['entries'] = $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
$sections = [];
|
$sections = [];
|
||||||
foreach ($data as $tableName => $tableResult) {
|
foreach ($data as $tableName => $tableResult) {
|
||||||
|
if (empty($tableResult['amount'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$section = '';
|
$section = '';
|
||||||
$table = Cake\ORM\TableRegistry::get($tableName);
|
$table = Cake\ORM\TableRegistry::get($tableName);
|
||||||
$fieldPath = !empty($table->getDisplayField()) ? $table->getDisplayField() : 'id';
|
$fieldPath = !empty($table->getDisplayField()) ? $table->getDisplayField() : 'id';
|
||||||
|
@ -11,7 +14,7 @@
|
||||||
</span>
|
</span>
|
||||||
</span>', h($tableName));
|
</span>', h($tableName));
|
||||||
|
|
||||||
foreach ($tableResult as $entry) {
|
foreach ($tableResult['entries'] as $entry) {
|
||||||
$section .= sprintf('<a class="dropdown-item" href="%s">%s</a>',
|
$section .= sprintf('<a class="dropdown-item" href="%s">%s</a>',
|
||||||
Cake\Routing\Router::URL([
|
Cake\Routing\Router::URL([
|
||||||
'controller' => Cake\Utility\Inflector::pluralize($entry->getSource()),
|
'controller' => Cake\Utility\Inflector::pluralize($entry->getSource()),
|
||||||
|
@ -21,6 +24,13 @@
|
||||||
h($entry[$fieldPath])
|
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;
|
$sections[] = $section;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -139,6 +139,16 @@ main.content {
|
||||||
margin: auto 0;
|
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 {
|
.global-search-result-container .search-container-model .model-text {
|
||||||
font-size: 0.75rem;
|
font-size: 0.75rem;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
|
|
Loading…
Reference in New Issue