Add Genre settings - add human-readable description
This commit is contained in:
parent
509d31e1d8
commit
428e7dde5b
4 changed files with 109 additions and 0 deletions
|
@ -0,0 +1,61 @@
|
|||
package ru.redrise.marinesco.library.settings;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import ru.redrise.marinesco.data.GenreRepository;
|
||||
import ru.redrise.marinesco.library.Genre;
|
||||
|
||||
@Slf4j
|
||||
@Controller
|
||||
@RequestMapping("/settings/genres")
|
||||
@PreAuthorize("hasRole('ADMIN')")
|
||||
public class GenreSettingsController {
|
||||
|
||||
private GenreRepository genreRepository;
|
||||
|
||||
public GenreSettingsController(GenreRepository genreRepository) {
|
||||
this.genreRepository = genreRepository;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public String getPage(@ModelAttribute("rescanError") String err) {
|
||||
return "genres_settings";
|
||||
}
|
||||
|
||||
@ModelAttribute(name = "genresHolder")
|
||||
public GenresHolder setRegistrationSetting() {
|
||||
List<Genre> genres = new ArrayList<>();
|
||||
|
||||
genreRepository.findAll()
|
||||
.iterator()
|
||||
.forEachRemaining(element -> genres.add(element));
|
||||
|
||||
return new GenresHolder(genres);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public String getGenresUpdated(@ModelAttribute GenresHolder genreHolder) {
|
||||
|
||||
for (Genre genre : genreHolder.getGenres())
|
||||
genreRepository.save(genre);
|
||||
|
||||
return "genres_settings";
|
||||
}
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
private class GenresHolder {
|
||||
private List<Genre> genres;
|
||||
}
|
||||
}
|
|
@ -237,4 +237,22 @@ button:hover {
|
|||
|
||||
.book_title{
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.wrapper_centred{
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
}
|
||||
.item0{
|
||||
padding-right: 5px;
|
||||
padding-left: 5px;
|
||||
flex-grow: 0;
|
||||
flex-basis: 15%;
|
||||
}
|
||||
.item1{
|
||||
flex-grow: 0;
|
||||
padding-right: 5px;
|
||||
padding-left: 5px;
|
||||
flex-basis: 350px;
|
||||
}
|
29
src/main/resources/templates/genres_settings.html
Normal file
29
src/main/resources/templates/genres_settings.html
Normal file
|
@ -0,0 +1,29 @@
|
|||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
|
||||
|
||||
<head>
|
||||
<title>Marinesco - Genre settings</title>
|
||||
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
|
||||
<link rel="alternate icon" href="/favicon.png" type="image/png">
|
||||
<link rel="stylesheet" th:href="@{/styles/styles.css}" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="page">
|
||||
<div th:replace="~{fragments/header :: 'header'}"></div>
|
||||
<div class="container base">
|
||||
<form method="POST" th:action="@{/settings/genres}" th:object="${genresHolder}">
|
||||
<div class="wrapper_centred" th:each="genre, itemStat : ${genresHolder.genres}">
|
||||
<label for="displayname" th:text="${genre.genreId}" class="item0"></label>
|
||||
<input type="hidden" th:value="${genre.genreId}" th:field="*{genres[__${itemStat.index}__].genreId}" />
|
||||
<input class="item1" type="text" th:field="*{genres[__${itemStat.index}__].humanReadableDescription}"
|
||||
th:value="${genre.humanReadableDescription}" size="25%" />
|
||||
</div>
|
||||
<div class="wrapper_centred"><button class="sign" type="submit">Save Changes</button></div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div th:replace="~{fragments/footer :: 'footer'}"></div>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -25,6 +25,7 @@
|
|||
<br />
|
||||
<span class="validationError" th:if="${lastScanErrors} != ''" th:text="${lastScanErrors}"></span>
|
||||
</p>
|
||||
<a href="/settings/genres">Edit genre descriptions</a>
|
||||
</div>
|
||||
</div>
|
||||
<div th:replace="~{fragments/footer :: 'footer'}"></div>
|
||||
|
|
Loading…
Reference in a new issue