From 1b64e476a3e480d00d5cd9b2e98aa0a96a5ecf23 Mon Sep 17 00:00:00 2001 From: Curtis Conard Date: Mon, 16 Dec 2024 17:45:24 -0500 Subject: [PATCH] add pager and small adjustments --- .../Knowbase/KnowbaseItemController.php | 25 ++--- templates/components/pager.html.twig | 35 +++---- templates/pages/tools/search_solution.twig | 96 ++++++++++++------- 3 files changed, 94 insertions(+), 62 deletions(-) diff --git a/src/Glpi/Controller/Knowbase/KnowbaseItemController.php b/src/Glpi/Controller/Knowbase/KnowbaseItemController.php index 5d238816671..bc20148ae57 100644 --- a/src/Glpi/Controller/Knowbase/KnowbaseItemController.php +++ b/src/Glpi/Controller/Knowbase/KnowbaseItemController.php @@ -125,14 +125,14 @@ public function searchSolution(Request $request): Response $criteria = KnowbaseItem::getListRequest([ 'contains' => $contains, ]); + $count_criteria = $criteria; $criteria['START'] = $start; $criteria['LIMIT'] = $_SESSION['glpilist_limit']; - $count_criteria = $criteria; - unset($count_criteria['SELECT'], $count_criteria['ORDERBY']); + unset($count_criteria['SELECT'], $count_criteria['ORDERBY'], $count_criteria['GROUPBY']); $count_criteria['COUNT'] = 'cpt'; $it = $DB->request($criteria); - $total_count = $DB->request($count_criteria)->current()['cpt']; + $total_count = $DB->request($count_criteria)->current()['cpt'] ?? 0; $results = []; foreach ($it as $data) { @@ -164,14 +164,17 @@ public function searchSolution(Request $request): Response ]; } - return new StreamedResponse(static function () use ($contains, $itemtype, $items_id, $results, $request) { - $twig_params = [ - 'contains' => $contains, - 'results' => $results, - 'itemtype' => $itemtype, - 'items_id' => $items_id, - 'is_ajax' => $request->get('ajax_reload', 0), - ]; + $twig_params = [ + 'contains' => $contains, + 'results' => $results, + 'itemtype' => $itemtype, + 'items_id' => $items_id, + 'is_ajax' => $request->get('ajax_reload', 0), + 'count' => $total_count, + 'start' => $start, + ]; + + return new StreamedResponse(static function () use ($twig_params) { TemplateRenderer::getInstance()->display('pages/tools/search_solution.twig', $twig_params); }); } diff --git a/templates/components/pager.html.twig b/templates/components/pager.html.twig index 49544a93329..98a35819191 100644 --- a/templates/components/pager.html.twig +++ b/templates/components/pager.html.twig @@ -65,6 +65,7 @@ {% set current_page = ((current_start - 1) / limit)|round(0, 'ceil') + 1 %} {% set short_display = short_display|default(false) %} +{% set no_limit_display = no_limit_display|default(false) %} {# limit the number of adjacents links displayed #} {% set adjacents = 2 %} @@ -72,29 +73,31 @@ {% set rand = rand|default(random()) %}
- {% if not short_display %} - + {% if not no_limit_display %} + {% if not short_display %} + + {% include 'components/dropdown/limit.html.twig' with { + 'no_onchange': fluid_search|default(false), + 'select_class': 'search-limit-dropdown', + 'href': href|replace({'%start%': start}), + 'additional_attributes': short_display ? { + 'title': __('Rows per page'), + } : { + 'aria-labelledby': 'list_limit' ~ rand ~ '_label', + }, + 'rand': rand, + } %} + {{ __('rows / page') }} + + {% endif %} + {% include 'components/dropdown/limit.html.twig' with { 'no_onchange': fluid_search|default(false), 'select_class': 'search-limit-dropdown', 'href': href|replace({'%start%': start}), - 'additional_attributes': short_display ? { - 'title': __('Rows per page'), - } : { - 'aria-labelledby': 'list_limit' ~ rand ~ '_label', - }, - 'rand': rand, } %} - {{ __('rows / page') }} {% endif %} - - {% include 'components/dropdown/limit.html.twig' with { - 'no_onchange': fluid_search|default(false), - 'select_class': 'search-limit-dropdown', - 'href': href|replace({'%start%': start}), - } %} - {% if not short_display %}

diff --git a/templates/pages/tools/search_solution.twig b/templates/pages/tools/search_solution.twig index 7994f44c415..06b8c1003b6 100644 --- a/templates/pages/tools/search_solution.twig +++ b/templates/pages/tools/search_solution.twig @@ -41,28 +41,39 @@

{{ inputs.text('contains', contains, {additional_attributes: {size: 50}, input_addclass: 'me-1'}) }} {{ inputs.button('search', _x('button', 'Search')) }} + {{ inputs.hidden('start', start) }}
-
- {% for result in results %} -
-
- + {% if results|length %} + {{ include('components/pager.html.twig', { + no_limit_display: true, + }) }} +
+ {% for result in results %} +
+
+ +
+
+
{{ result.name }}
+
{{ result.content_preview }}
+
+
+ + +
-
-
{{ result.name }}
-
{{ result.content_preview }}
-
-
- - -
-
- {% endfor %} -
+ {% endfor %} +
+ {% else %} +
+ {{ __('No data') }} +
+ {% endif %} +