Re-write search process: checkboxes!

master
Dmitry Isaenko 2024-01-20 01:33:12 +03:00
parent 76e0dcd77a
commit d4f7d860f7
4 changed files with 89 additions and 29 deletions

View File

@ -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<Book> books = inpEntryRepository.findByTitleContainingIgnoreCase(search);
model.addAttribute("books", books);
List<Book> bookSeries = inpEntryRepository.findBySeriesContainingIgnoreCase(search);
model.addAttribute("series", bookSeries);
List<Author> 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<Book> books = inpEntryRepository.findByTitleContainingIgnoreCase(search);
if (books.size() != 0)
model.addAttribute("books", books);
model.addAttribute("isTitle", true);
}
if (series != null){
List<Book> bookSeries = inpEntryRepository.findBySeriesContainingIgnoreCase(search);
if (bookSeries.size() != 0)
model.addAttribute("series", bookSeries);
model.addAttribute("isSeries", true);
}
if (author != null){
List<Author> authors = authorRepository.findByAuthorNameContainingIgnoreCase(search);
if (authors.size() != 0)
model.addAttribute("authors", authors);
model.addAttribute("isAuthor", true);
}
return "search";
}
}

View File

@ -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;

View File

@ -8,7 +8,7 @@
<div class="container">
<header>
<div class="header_branding block_inner">
<img height="65px" th:src="@{/images/s_logo.svg}" alt="Marinesco">
<img height="65px" th:src="@{/images/s_logo.svg}" alt="Marinesco">
</div>
<nav id="header_right_block" class="block">
<div class="block_inner">
@ -58,20 +58,36 @@
</div>
</nav>
<nav id="header_menu_block" class="header_entry">
<nav id="header_menu_block" class="search_entry wrapper">
<ul class="ul_right_block">
<li class="li_header_block">
<form action="/search" method="get">
<input type="text" name="search">
<button class="button-header" type="submit">Search</button>
</form>
<form action="/search" method="get">
<div class="wrapper">
<input class="search_line" type="text" name="search">
</div>
<div class="wrapper" style="justify-content: space-evenly; align-items: baseline; ">
<div class="search_checkbox">
<input th:checked="${isTitle}" name="title" type="checkbox" />
<label for="title">Title</label>
</div>
<div class="search_checkbox">
<input th:checked="${isSeries}" name="series" type="checkbox" />
<label for="series">Series</label>
</div>
<div class="search_checkbox">
<input th:checked="${isAuthor}" name="author" type="checkbox" />
<label for="author">Author</label>
</div>
<div class="" style="margin-right: auto;">
<button class="button-header" type="submit">Search</button>
</div>
</div>
</form>
</li>
</ul>
</nav>
</header>
</div>
</header>
</div>
</div>
<!--
<div th:replace="~{fragments/header :: ${#authentication.principal.isAdmin()} ? 'header-admin' : 'header'}"></div>

View File

@ -12,7 +12,8 @@
<div class="page">
<div th:replace="~{fragments/header :: ${#authorization.expression('isAuthenticated()')} ? 'header-auth' : 'header-anon'}"></div>
<div class="container base">
<div th:if="${books} != null">
<div class="validationError" th:if="${error != null}" th:text="${error}"></div>
<div th:if="${books != null}">
<h3>Titles</h3>
<div th:each="book : ${books}">
<a th:href="${'/book/' + book.id}">
@ -33,10 +34,9 @@
<span th:text="${' (' + book.fileExtension + ' ' + book.fileSizeForHumans + ')'}"></span>
<p></p>
</div>
</div>
<div th:if="${series} != null">
<hr>
</div>
<div th:if="${series != null}">
<h3>Series</h3>
<div th:each="book : ${books}">
<a th:href="${'/book/' + book.id}">
@ -57,10 +57,9 @@
<span th:text="${' (' + book.fileExtension + ' ' + book.fileSizeForHumans + ')'}"></span>
<p></p>
</div>
</div>
<div th:if="${authors} != null">
<hr>
</div>
<div th:if="${authors != null}">
<h3>Authors</h3>
<div th:each="author : ${authors}">
<a th:href="${'/author/' + author.id}">