From d4f7d860f788438b88b125bbc52f847b452d5f80 Mon Sep 17 00:00:00 2001 From: Dmitry Isaenko Date: Sat, 20 Jan 2024 01:33:12 +0300 Subject: [PATCH] Re-write search process: checkboxes! --- .../library/web/SearchController.java | 42 ++++++++++++++----- src/main/resources/static/styles/styles.css | 27 +++++++++++- .../resources/templates/fragments/header.html | 36 +++++++++++----- src/main/resources/templates/search.html | 13 +++--- 4 files changed, 89 insertions(+), 29 deletions(-) diff --git a/src/main/java/ru/redrise/marinesco/library/web/SearchController.java b/src/main/java/ru/redrise/marinesco/library/web/SearchController.java index 5b15b38..5bda079 100644 --- a/src/main/java/ru/redrise/marinesco/library/web/SearchController.java +++ b/src/main/java/ru/redrise/marinesco/library/web/SearchController.java @@ -28,20 +28,42 @@ public class SearchController { } @GetMapping - public String requestMethodName(@RequestParam String search, Model model) { - + public String requestMethodName(@RequestParam String search, + @RequestParam(value = "title", required = false) Boolean title, + @RequestParam(value = "series", required = false) Boolean series, + @RequestParam(value = "author", required = false) Boolean author, + Model model) { + if (search.trim().equals("")) return "search"; - - List books = inpEntryRepository.findByTitleContainingIgnoreCase(search); - model.addAttribute("books", books); - - List bookSeries = inpEntryRepository.findBySeriesContainingIgnoreCase(search); - model.addAttribute("series", bookSeries); - List authors = authorRepository.findByAuthorNameContainingIgnoreCase(search); - model.addAttribute("authors", authors); + if (search.length() < 4){ + model.addAttribute("error", "Should be at least 4 chars"); + return "search"; + } + + if (title != null){ + List books = inpEntryRepository.findByTitleContainingIgnoreCase(search); + if (books.size() != 0) + model.addAttribute("books", books); + model.addAttribute("isTitle", true); + } + + if (series != null){ + List bookSeries = inpEntryRepository.findBySeriesContainingIgnoreCase(search); + if (bookSeries.size() != 0) + model.addAttribute("series", bookSeries); + model.addAttribute("isSeries", true); + } + + if (author != null){ + List authors = authorRepository.findByAuthorNameContainingIgnoreCase(search); + if (authors.size() != 0) + model.addAttribute("authors", authors); + model.addAttribute("isAuthor", true); + } return "search"; } + } diff --git a/src/main/resources/static/styles/styles.css b/src/main/resources/static/styles/styles.css index a10c96b..34b6bca 100644 --- a/src/main/resources/static/styles/styles.css +++ b/src/main/resources/static/styles/styles.css @@ -121,6 +121,15 @@ header { padding: 0%; } +.search_line{ + margin-left: 2px; + margin-right: 2px; + margin-top: 7px; + margin-bottom: 7px; + flex-grow: 1; + justify-content: center; +} + .ul_right_block { margin: 0 !important; padding: 0 !important; @@ -146,6 +155,20 @@ header { color: #74bfbd; } +.search_entry{ + text-decoration: none; + font-variant: small-caps; + font-size: 0.75em; + text-shadow: -1px -1px 0 #1e1e1e, 1px -1px 0 #1e1e1e, -1px 1px 0 #1e1e1e, 1px 1px 0 #1e1e1e; + color: #74bfbd; +} + +.search_checkbox{ + flex: auto; + flex-grow: 1; +} + + .header_logo_link:link { color: #74bfbd; } @@ -180,10 +203,10 @@ header { .button-header { - margin: 1em 0; + margin: 0 0.25em; font-family: sans-serif; font-style: normal; - font-weight: normal; + font-weight: bold; text-align: center; font-variant: small-caps !important; background-color: #74bfbd !important; diff --git a/src/main/resources/templates/fragments/header.html b/src/main/resources/templates/fragments/header.html index 42f6fe2..6b59ee2 100644 --- a/src/main/resources/templates/fragments/header.html +++ b/src/main/resources/templates/fragments/header.html @@ -8,7 +8,7 @@
- Marinesco + Marinesco
-
-
+ +