From 428e7dde5b13de8b90c0afbb5e5f0ec829b0f87c Mon Sep 17 00:00:00 2001 From: Dmitry Isaenko Date: Sat, 13 Jan 2024 22:06:38 +0300 Subject: [PATCH] Add Genre settings - add human-readable description --- .../settings/GenreSettingsController.java | 61 +++++++++++++++++++ src/main/resources/static/styles/styles.css | 18 ++++++ .../resources/templates/genres_settings.html | 29 +++++++++ src/main/resources/templates/settings.html | 1 + 4 files changed, 109 insertions(+) create mode 100644 src/main/java/ru/redrise/marinesco/library/settings/GenreSettingsController.java create mode 100644 src/main/resources/templates/genres_settings.html diff --git a/src/main/java/ru/redrise/marinesco/library/settings/GenreSettingsController.java b/src/main/java/ru/redrise/marinesco/library/settings/GenreSettingsController.java new file mode 100644 index 0000000..da69524 --- /dev/null +++ b/src/main/java/ru/redrise/marinesco/library/settings/GenreSettingsController.java @@ -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 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 genres; + } +} diff --git a/src/main/resources/static/styles/styles.css b/src/main/resources/static/styles/styles.css index 85b89cb..8615e39 100644 --- a/src/main/resources/static/styles/styles.css +++ b/src/main/resources/static/styles/styles.css @@ -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; } \ No newline at end of file diff --git a/src/main/resources/templates/genres_settings.html b/src/main/resources/templates/genres_settings.html new file mode 100644 index 0000000..66eed90 --- /dev/null +++ b/src/main/resources/templates/genres_settings.html @@ -0,0 +1,29 @@ + + + + + Marinesco - Genre settings + + + + + + +
+
+
+
+
+ + + +
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/src/main/resources/templates/settings.html b/src/main/resources/templates/settings.html index 9b70f40..5840ce2 100644 --- a/src/main/resources/templates/settings.html +++ b/src/main/resources/templates/settings.html @@ -25,6 +25,7 @@

+ Edit genre descriptions