Compare commits
2 commits
509d31e1d8
...
d66ab98e1f
Author | SHA1 | Date | |
---|---|---|---|
|
d66ab98e1f | ||
|
428e7dde5b |
5 changed files with 110 additions and 1 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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -238,3 +238,21 @@ button:hover {
|
||||||
.book_title{
|
.book_title{
|
||||||
font-weight: bold;
|
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>
|
|
@ -2,7 +2,7 @@
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
|
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<title>Marinesco</title>
|
<title>Marinesco - Login</title>
|
||||||
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
|
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
|
||||||
<link rel="alternate icon" href="/favicon.png" type="image/png">
|
<link rel="alternate icon" href="/favicon.png" type="image/png">
|
||||||
<link rel="stylesheet" th:href="@{/styles/styles.css}" />
|
<link rel="stylesheet" th:href="@{/styles/styles.css}" />
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
<br />
|
<br />
|
||||||
<span class="validationError" th:if="${lastScanErrors} != ''" th:text="${lastScanErrors}"></span>
|
<span class="validationError" th:if="${lastScanErrors} != ''" th:text="${lastScanErrors}"></span>
|
||||||
</p>
|
</p>
|
||||||
|
<a href="/settings/genres">Edit genre descriptions</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div th:replace="~{fragments/footer :: 'footer'}"></div>
|
<div th:replace="~{fragments/footer :: 'footer'}"></div>
|
||||||
|
|
Loading…
Reference in a new issue