Re-write search process: checkboxes!
This commit is contained in:
parent
76e0dcd77a
commit
d4f7d860f7
4 changed files with 89 additions and 29 deletions
|
@ -28,20 +28,42 @@ public class SearchController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping
|
@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(""))
|
if (search.trim().equals(""))
|
||||||
return "search";
|
return "search";
|
||||||
|
|
||||||
List<Book> books = inpEntryRepository.findByTitleContainingIgnoreCase(search);
|
if (search.length() < 4){
|
||||||
model.addAttribute("books", books);
|
model.addAttribute("error", "Should be at least 4 chars");
|
||||||
|
return "search";
|
||||||
|
}
|
||||||
|
|
||||||
List<Book> bookSeries = inpEntryRepository.findBySeriesContainingIgnoreCase(search);
|
if (title != null){
|
||||||
model.addAttribute("series", bookSeries);
|
List<Book> books = inpEntryRepository.findByTitleContainingIgnoreCase(search);
|
||||||
|
if (books.size() != 0)
|
||||||
|
model.addAttribute("books", books);
|
||||||
|
model.addAttribute("isTitle", true);
|
||||||
|
}
|
||||||
|
|
||||||
List<Author> authors = authorRepository.findByAuthorNameContainingIgnoreCase(search);
|
if (series != null){
|
||||||
model.addAttribute("authors", authors);
|
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";
|
return "search";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,6 +121,15 @@ header {
|
||||||
padding: 0%;
|
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 {
|
.ul_right_block {
|
||||||
margin: 0 !important;
|
margin: 0 !important;
|
||||||
padding: 0 !important;
|
padding: 0 !important;
|
||||||
|
@ -146,6 +155,20 @@ header {
|
||||||
color: #74bfbd;
|
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 {
|
.header_logo_link:link {
|
||||||
color: #74bfbd;
|
color: #74bfbd;
|
||||||
}
|
}
|
||||||
|
@ -180,10 +203,10 @@ header {
|
||||||
|
|
||||||
|
|
||||||
.button-header {
|
.button-header {
|
||||||
margin: 1em 0;
|
margin: 0 0.25em;
|
||||||
font-family: sans-serif;
|
font-family: sans-serif;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
font-weight: normal;
|
font-weight: bold;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
font-variant: small-caps !important;
|
font-variant: small-caps !important;
|
||||||
background-color: #74bfbd !important;
|
background-color: #74bfbd !important;
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<header>
|
<header>
|
||||||
<div class="header_branding block_inner">
|
<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>
|
</div>
|
||||||
<nav id="header_right_block" class="block">
|
<nav id="header_right_block" class="block">
|
||||||
<div class="block_inner">
|
<div class="block_inner">
|
||||||
|
@ -58,20 +58,36 @@
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<nav id="header_menu_block" class="header_entry">
|
<nav id="header_menu_block" class="search_entry wrapper">
|
||||||
<ul class="ul_right_block">
|
<ul class="ul_right_block">
|
||||||
<li class="li_header_block">
|
<li class="li_header_block">
|
||||||
<form action="/search" method="get">
|
<form action="/search" method="get">
|
||||||
<input type="text" name="search">
|
<div class="wrapper">
|
||||||
<button class="button-header" type="submit">Search</button>
|
<input class="search_line" type="text" name="search">
|
||||||
</form>
|
</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>
|
</li>
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
</header>
|
||||||
</header>
|
</div>
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<!--
|
<!--
|
||||||
<div th:replace="~{fragments/header :: ${#authentication.principal.isAdmin()} ? 'header-admin' : 'header'}"></div>
|
<div th:replace="~{fragments/header :: ${#authentication.principal.isAdmin()} ? 'header-admin' : 'header'}"></div>
|
||||||
|
|
|
@ -12,7 +12,8 @@
|
||||||
<div class="page">
|
<div class="page">
|
||||||
<div th:replace="~{fragments/header :: ${#authorization.expression('isAuthenticated()')} ? 'header-auth' : 'header-anon'}"></div>
|
<div th:replace="~{fragments/header :: ${#authorization.expression('isAuthenticated()')} ? 'header-auth' : 'header-anon'}"></div>
|
||||||
<div class="container base">
|
<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>
|
<h3>Titles</h3>
|
||||||
<div th:each="book : ${books}">
|
<div th:each="book : ${books}">
|
||||||
<a th:href="${'/book/' + book.id}">
|
<a th:href="${'/book/' + book.id}">
|
||||||
|
@ -33,10 +34,9 @@
|
||||||
<span th:text="${' (' + book.fileExtension + ' ' + book.fileSizeForHumans + ')'}"></span>
|
<span th:text="${' (' + book.fileExtension + ' ' + book.fileSizeForHumans + ')'}"></span>
|
||||||
<p></p>
|
<p></p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div th:if="${series} != null">
|
|
||||||
<hr>
|
<hr>
|
||||||
|
</div>
|
||||||
|
<div th:if="${series != null}">
|
||||||
<h3>Series</h3>
|
<h3>Series</h3>
|
||||||
<div th:each="book : ${books}">
|
<div th:each="book : ${books}">
|
||||||
<a th:href="${'/book/' + book.id}">
|
<a th:href="${'/book/' + book.id}">
|
||||||
|
@ -57,10 +57,9 @@
|
||||||
<span th:text="${' (' + book.fileExtension + ' ' + book.fileSizeForHumans + ')'}"></span>
|
<span th:text="${' (' + book.fileExtension + ' ' + book.fileSizeForHumans + ')'}"></span>
|
||||||
<p></p>
|
<p></p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div th:if="${authors} != null">
|
|
||||||
<hr>
|
<hr>
|
||||||
|
</div>
|
||||||
|
<div th:if="${authors != null}">
|
||||||
<h3>Authors</h3>
|
<h3>Authors</h3>
|
||||||
<div th:each="author : ${authors}">
|
<div th:each="author : ${authors}">
|
||||||
<a th:href="${'/author/' + author.id}">
|
<a th:href="${'/author/' + author.id}">
|
||||||
|
|
Loading…
Reference in a new issue