From 1f8a4d92dab52947088b0dba315854f44abe68d4 Mon Sep 17 00:00:00 2001 From: Arlen Johnson Date: Tue, 6 Dec 2022 10:54:29 -0700 Subject: [PATCH] Improve global search bar and search results page (CFM-220) (#59) * Improve global search bar and search results page; fix double-encoding of flash messages. (CFM-220) * Improve global search result count messages (CFM-220) --- app/resources/locales/en_US/operation.po | 3 + app/resources/locales/en_US/result.po | 15 +- app/src/Controller/DashboardsController.php | 19 +- app/templates/Dashboards/search.php | 201 ++++++++++++++--- app/templates/element/flash/default.php | 2 +- app/templates/element/flash/error.php | 2 +- app/templates/element/flash/information.php | 4 +- app/templates/element/flash/success.php | 2 +- app/templates/element/javascript.php | 29 ++- app/templates/element/searchGlobal.php | 33 ++- app/templates/layout/default.php | 10 +- app/webroot/css/co-base.css | 231 +++++++++++--------- app/webroot/css/co-color.css | 2 + app/webroot/css/co-responsive.css | 60 +++-- 14 files changed, 422 insertions(+), 191 deletions(-) diff --git a/app/resources/locales/en_US/operation.po b/app/resources/locales/en_US/operation.po index 29198eb27..56341ea64 100644 --- a/app/resources/locales/en_US/operation.po +++ b/app/resources/locales/en_US/operation.po @@ -117,6 +117,9 @@ msgstr "Save" msgid "search" msgstr "Search" +msgid "search.global" +msgstr "Global Search" + msgid "skip_to_content" msgstr "Skip to main content" diff --git a/app/resources/locales/en_US/result.po b/app/resources/locales/en_US/result.po index 5399338f8..c928acd01 100644 --- a/app/resources/locales/en_US/result.po +++ b/app/resources/locales/en_US/result.po @@ -87,11 +87,20 @@ msgstr "Search limit reached" msgid "search.none" msgstr "No results found" +msgid "search.result.found" +msgstr "Found" + +msgid "search.result.found.modelCount" +msgstr "{0} {1}" + msgid "search.result.id" -msgstr "({0})" +msgstr "ID {0}" msgid "search.result.related" -msgstr "({0}, {1}: {2})" +msgstr "{0}: {1}, ID {2}" msgid "search.results" -msgstr "Search Results" \ No newline at end of file +msgstr "Search Results" + +msgid "search.retry" +msgstr "Please select an option from a menu, or try your search again." \ No newline at end of file diff --git a/app/src/Controller/DashboardsController.php b/app/src/Controller/DashboardsController.php index 93b2bb27c..36c015613 100644 --- a/app/src/Controller/DashboardsController.php +++ b/app/src/Controller/DashboardsController.php @@ -195,12 +195,21 @@ public function search() { // XXX Still need to implement this (see also CFM-126) $roles = []; - - if(!empty($this->request->getData('q')) - // Only process the request if there are non-space characters - && !ctype_space($this->request->getData('q'))) { - // Trim leading and trailing whitespace + + // Gather our search string. + $q = ''; + if(!empty($this->request->getData('global-search-q'))) { + // A search was passed in from the global search-bar. + $q = trim($this->request->getData('global-search-q')); + // Now pass the search string to the in-page search form and empty the global search bar. + $this->setRequest($this->getRequest()->withData('global-search-q', '')->withData('q', $q)); + } elseif(!empty($this->request->getData('q'))) { + // A search was passed in from the form on the Global Search page. $q = trim($this->request->getData('q')); + } + + // Only process the request if we have a string of non-space characters + if(!empty($q)) { // Pull our search configuration $CoSettings = TableRegistry::getTableLocator()->get('CoSettings'); diff --git a/app/templates/Dashboards/search.php b/app/templates/Dashboards/search.php index 5428514ab..42050bd1f 100644 --- a/app/templates/Dashboards/search.php +++ b/app/templates/Dashboards/search.php @@ -25,47 +25,178 @@ * @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) */ -// Start with the Primary Registry objects -foreach(['People', 'Groups'] as $pm) { - if(!empty($vv_results[$pm])) { - print "

" . __d('controller', $pm, 2) . "

\n"; - print "\n"; - } -} + +

+ +

+ + + diff --git a/app/templates/element/flash/default.php b/app/templates/element/flash/default.php index b395c63de..5c05e86a8 100644 --- a/app/templates/element/flash/default.php +++ b/app/templates/element/flash/default.php @@ -10,6 +10,6 @@ ?> - Alert->alert(h($message), 'warning', true, __d('information','flash.default')) ?> + Alert->alert($message, 'warning', true, __d('information','flash.default')) ?> diff --git a/app/templates/element/flash/error.php b/app/templates/element/flash/error.php index 2188d8162..04fd0e19a 100644 --- a/app/templates/element/flash/error.php +++ b/app/templates/element/flash/error.php @@ -8,5 +8,5 @@ */ ?> - Alert->alert(h($message), 'danger', true, __d('information','flash.error')) ?> + Alert->alert($message, 'danger', true, __d('information','flash.error')) ?> diff --git a/app/templates/element/flash/information.php b/app/templates/element/flash/information.php index 7211ef457..1df1a9641 100644 --- a/app/templates/element/flash/information.php +++ b/app/templates/element/flash/information.php @@ -5,5 +5,7 @@ ?> - Alert->alert(h($message), 'information', true, __d('information','flash.information')) ?> + + Alert->alert($message, 'information', true) ?> \ No newline at end of file diff --git a/app/templates/element/flash/success.php b/app/templates/element/flash/success.php index f4c80a68e..f71124cfa 100644 --- a/app/templates/element/flash/success.php +++ b/app/templates/element/flash/success.php @@ -5,5 +5,5 @@ ?> - Alert->alert(h($message), 'success', true, __d('information','flash.success')) ?> + Alert->alert($message, 'success', true, __d('information','flash.success')) ?> \ No newline at end of file diff --git a/app/templates/element/javascript.php b/app/templates/element/javascript.php index 6ad827fd5..3d7d50d9b 100644 --- a/app/templates/element/javascript.php +++ b/app/templates/element/javascript.php @@ -51,9 +51,32 @@ // END DESKTOP MENU DRAWER BEHAVIOR - // GLOBAL SEARCH - $('#search-bar input').focus(function() { - $('#search-bar button').addClass('visible'); + // SEARCH + // Persistent search bar form: + $('#global-search form').submit(function () { + // Disallow submit on blank + if($.trim($('#global-search-q').val()) == '') { + return false; + } + }); + // Select search text on focus + $('#global-search-q').focus(function() { + $('#global-search-q').select(); + }); + + // Search page form: + $('#search').submit(function () { + // Disallow submit on blank + if($.trim($('#q').val()) == '') { + return false; + } + }); + $('#search-clear').click(function () { + $('#q').val(''); + $('#q').focus(); + }); + $('#q').focus(function() { + $('#q').select(); }); // TOP FILTER FORM diff --git a/app/templates/element/searchGlobal.php b/app/templates/element/searchGlobal.php index a0d3c1fea..c44626838 100644 --- a/app/templates/element/searchGlobal.php +++ b/app/templates/element/searchGlobal.php @@ -31,16 +31,29 @@ 'plugin' => null, 'controller' => 'dashboards', 'action' => 'search' - ] + ], + 'id' => 'global-search-form' ]; -print $this->Form->create(null, $options); -print $this->Form->hidden('co_id', ['default' => $vv_cur_co->id]); -print $this->Form->label('q', __d('field','search.placeholder'), ['class' => 'visually-hidden']); -print $this->Form->input('q',['id' => 'q','placeholder' => __d('field','search.placeholder')]); -print $this->Form->button( - __d('operation','search'), - ['type' => 'submit', 'escapeTitle' => false, 'class' => 'btn btn-primary'] -); -print $this->Form->end(); +?> + + + + + \ No newline at end of file diff --git a/app/templates/layout/default.php b/app/templates/layout/default.php index c1cd1fa83..ee2b7377a 100644 --- a/app/templates/layout/default.php +++ b/app/templates/layout/default.php @@ -93,7 +93,7 @@ ?>
- +
@@ -150,12 +150,8 @@
-
menu
- -