From 56d3f9875c039ca46c8ba0c9b941b016247eef08 Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 30 Nov 2020 22:58:14 +0100 Subject: [PATCH] PossibleCandidates get saved to their own database now CHANGED VotingController: - changed 'candidateSaving' possibleCandidates get Located by name and category and get saved now CHANGED PossibleCandidateRepository: - removed 'findByNameAndCategoryID' - added 'findByNameAndCategory' ADDED addingCandidates.css: - added basic styling CHANGED voting.css: - bug that div gets cut off resolved CHANGED addingCandidates.html: - changed display method from table to div CHANGED: voting.html: - added div to style the site (bugfix) --- .../controller/VotingController.java | 7 +- .../PossibleCandidateRepository.java | 3 +- .../static/styles/addingCandidates.css | 64 +++++++++++++++++++ src/main/resources/static/styles/voting.css | 9 ++- .../resources/templates/addingCandidates.html | 31 ++++----- src/main/resources/templates/voting.html | 24 +++---- 6 files changed, 101 insertions(+), 37 deletions(-) create mode 100644 src/main/resources/static/styles/addingCandidates.css diff --git a/src/main/java/com/github/cato447/AbizeitungVotingSystem/controller/VotingController.java b/src/main/java/com/github/cato447/AbizeitungVotingSystem/controller/VotingController.java index 9e4dcf4..8c28b5b 100644 --- a/src/main/java/com/github/cato447/AbizeitungVotingSystem/controller/VotingController.java +++ b/src/main/java/com/github/cato447/AbizeitungVotingSystem/controller/VotingController.java @@ -138,14 +138,15 @@ public class VotingController { @RequestMapping("/saveCandidates") public String candidateSaving(@ModelAttribute PossibleCandidateWrapper possibleCandidates){ - LOGGER.info(tableAction.logPossibleCandidates(possibleCandidates.getPossibleCandidates(), categoryRepository)); LinkedList posCandidates = possibleCandidates.getPossibleCandidates(); long index = 1; for (PossibleCandidate posCandidate : posCandidates){ if (posCandidate.getName() != "") { - if (possibleCandidateRepository.findByName(posCandidate.getName()) != null) { - PossibleCandidate p = possibleCandidateRepository.findByName(posCandidate.getName()); + if (possibleCandidateRepository.findByNameAndCategory(posCandidate.getName(), categoryRepository.findById(index).get()) != null) { + PossibleCandidate p = possibleCandidateRepository.findByNameAndCategory(posCandidate.getName(), categoryRepository.findById(index).get()); + LOGGER.warn(p.getVotes()); p.setVotes(p.getVotes() + 1); + possibleCandidateRepository.save(p); } else { PossibleCandidate possibleCandidate = new PossibleCandidate(posCandidate.getName(), categoryRepository.findById(index).get()); possibleCandidateRepository.save(possibleCandidate); diff --git a/src/main/java/com/github/cato447/AbizeitungVotingSystem/repositories/PossibleCandidateRepository.java b/src/main/java/com/github/cato447/AbizeitungVotingSystem/repositories/PossibleCandidateRepository.java index 572d24e..10bf456 100644 --- a/src/main/java/com/github/cato447/AbizeitungVotingSystem/repositories/PossibleCandidateRepository.java +++ b/src/main/java/com/github/cato447/AbizeitungVotingSystem/repositories/PossibleCandidateRepository.java @@ -1,5 +1,6 @@ package com.github.cato447.AbizeitungVotingSystem.repositories; +import com.github.cato447.AbizeitungVotingSystem.entities.Category; import com.github.cato447.AbizeitungVotingSystem.entities.PossibleCandidate; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @@ -9,7 +10,7 @@ import java.util.Optional; @Repository public interface PossibleCandidateRepository extends JpaRepository { - public PossibleCandidate findByNameAndCategoryID(String name, Long category_id); + public PossibleCandidate findByNameAndCategory(String name, Category category); Optional findById(Long id); diff --git a/src/main/resources/static/styles/addingCandidates.css b/src/main/resources/static/styles/addingCandidates.css new file mode 100644 index 0000000..2744139 --- /dev/null +++ b/src/main/resources/static/styles/addingCandidates.css @@ -0,0 +1,64 @@ +body { + background-color: rgb(44, 49, 54); + font-family: Arial, Helvetica, sans-serif; +} + +.center-screen { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + text-align: center; +} + +.centered { + background: transparent; + margin: 0 auto; + padding: 20px; + width: 100%; + overflow: auto; +} + +h1 { + margin-top: 5%; + color: #FFF; + margin-bottom: 5%; +} + +h2.categoryHeader { + color: #FFF; +} + +input { + background: #bb1515b2; + border: none; + color: #FFF; + font-size: .875rem; + font-weight: normal; + text-transform: uppercase; + text-align: left; + transition: opacity .25s .5s; +} + +#submitButton { + margin-top: 5%; + margin-bottom: 5%; + border: 0; + outline: 0; + background: #bb1515; + color: rgba(255, 255, 255, 0.85); + font-size: 2rem; + width: 500px; + letter-spacing: .0625rem; + border-radius: 12px; + box-shadow: 0 3px 5px 1px rgba(0, 0, 0, 0.25); + text-shadow: 0 -2px 0 rgba(0, 0, 0, 0.25), 0 1px 0 rgba(255, 255, 255, 0.2); +} + +html, +body { + width: 100%; + height: 100%; + background-image: linear-gradient(to bottom right, #111E25 0%, #111 100%) fixed; + font-family: 'Lato', sans-serif; +} \ No newline at end of file diff --git a/src/main/resources/static/styles/voting.css b/src/main/resources/static/styles/voting.css index 2cec353..f2776cf 100644 --- a/src/main/resources/static/styles/voting.css +++ b/src/main/resources/static/styles/voting.css @@ -9,7 +9,14 @@ body { justify-content: center; align-items: center; text-align: center; - min-height: 100vh; +} + +.centered { + background: transparent; + margin: 0 auto; + padding: 20px; + width: 100%; + overflow: auto; } h1 { diff --git a/src/main/resources/templates/addingCandidates.html b/src/main/resources/templates/addingCandidates.html index 65484a4..a364299 100644 --- a/src/main/resources/templates/addingCandidates.html +++ b/src/main/resources/templates/addingCandidates.html @@ -4,29 +4,20 @@ Title + - -

Schlage für jede Kategorie eine/n Kandiadt/en vor:

-
-
- - - - - - - - - - - - - -
Kategorie Kandidat/in
+ +
+

Schlage für jede Kategorie eine/n Kandiadt/en vor:

+ +
+

+ +
-
-
+ + \ No newline at end of file diff --git a/src/main/resources/templates/voting.html b/src/main/resources/templates/voting.html index 4b9d0ba..9dbb4ea 100644 --- a/src/main/resources/templates/voting.html +++ b/src/main/resources/templates/voting.html @@ -44,20 +44,20 @@ input.value = voteIds; } - -

Wähle deine Kandidaten:

-
-

-
- +
+

Wähle deine Kandidaten:

+
+

+
+ +
+
+ + + +
-
- - - -
- \ No newline at end of file