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)
This commit is contained in:
1263
logs/Voting.log
1263
logs/Voting.log
File diff suppressed because it is too large
Load Diff
@@ -138,14 +138,15 @@ public class VotingController {
|
|||||||
|
|
||||||
@RequestMapping("/saveCandidates")
|
@RequestMapping("/saveCandidates")
|
||||||
public String candidateSaving(@ModelAttribute PossibleCandidateWrapper possibleCandidates){
|
public String candidateSaving(@ModelAttribute PossibleCandidateWrapper possibleCandidates){
|
||||||
LOGGER.info(tableAction.logPossibleCandidates(possibleCandidates.getPossibleCandidates(), categoryRepository));
|
|
||||||
LinkedList<PossibleCandidate> posCandidates = possibleCandidates.getPossibleCandidates();
|
LinkedList<PossibleCandidate> posCandidates = possibleCandidates.getPossibleCandidates();
|
||||||
long index = 1;
|
long index = 1;
|
||||||
for (PossibleCandidate posCandidate : posCandidates){
|
for (PossibleCandidate posCandidate : posCandidates){
|
||||||
if (posCandidate.getName() != "") {
|
if (posCandidate.getName() != "") {
|
||||||
if (possibleCandidateRepository.findByName(posCandidate.getName()) != null) {
|
if (possibleCandidateRepository.findByNameAndCategory(posCandidate.getName(), categoryRepository.findById(index).get()) != null) {
|
||||||
PossibleCandidate p = possibleCandidateRepository.findByName(posCandidate.getName());
|
PossibleCandidate p = possibleCandidateRepository.findByNameAndCategory(posCandidate.getName(), categoryRepository.findById(index).get());
|
||||||
|
LOGGER.warn(p.getVotes());
|
||||||
p.setVotes(p.getVotes() + 1);
|
p.setVotes(p.getVotes() + 1);
|
||||||
|
possibleCandidateRepository.save(p);
|
||||||
} else {
|
} else {
|
||||||
PossibleCandidate possibleCandidate = new PossibleCandidate(posCandidate.getName(), categoryRepository.findById(index).get());
|
PossibleCandidate possibleCandidate = new PossibleCandidate(posCandidate.getName(), categoryRepository.findById(index).get());
|
||||||
possibleCandidateRepository.save(possibleCandidate);
|
possibleCandidateRepository.save(possibleCandidate);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.github.cato447.AbizeitungVotingSystem.repositories;
|
package com.github.cato447.AbizeitungVotingSystem.repositories;
|
||||||
|
|
||||||
|
import com.github.cato447.AbizeitungVotingSystem.entities.Category;
|
||||||
import com.github.cato447.AbizeitungVotingSystem.entities.PossibleCandidate;
|
import com.github.cato447.AbizeitungVotingSystem.entities.PossibleCandidate;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
@@ -9,7 +10,7 @@ import java.util.Optional;
|
|||||||
@Repository
|
@Repository
|
||||||
public interface PossibleCandidateRepository extends JpaRepository<PossibleCandidate, Integer> {
|
public interface PossibleCandidateRepository extends JpaRepository<PossibleCandidate, Integer> {
|
||||||
|
|
||||||
public PossibleCandidate findByNameAndCategoryID(String name, Long category_id);
|
public PossibleCandidate findByNameAndCategory(String name, Category category);
|
||||||
Optional<PossibleCandidate> findById(Long id);
|
Optional<PossibleCandidate> findById(Long id);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
64
src/main/resources/static/styles/addingCandidates.css
Normal file
64
src/main/resources/static/styles/addingCandidates.css
Normal file
@@ -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;
|
||||||
|
}
|
||||||
@@ -9,7 +9,14 @@ body {
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
min-height: 100vh;
|
}
|
||||||
|
|
||||||
|
.centered {
|
||||||
|
background: transparent;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 20px;
|
||||||
|
width: 100%;
|
||||||
|
overflow: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
|
|||||||
@@ -4,29 +4,20 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>Title</title>
|
<title>Title</title>
|
||||||
|
<link th:href="@{/styles/addingCandidates.css}" rel="stylesheet" />
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body class="center-screen">
|
||||||
<h1>Schlage für jede Kategorie eine/n Kandiadt/en vor:</h1>
|
<div class="centered">
|
||||||
<form action="#" th:action="@{/saveCandidates}" th:object="${form}" method="post">
|
<h1>Schlage für jede Kategorie eine/n Kandiadt/en vor:</h1>
|
||||||
<fieldset>
|
<form action="#" th:action="@{/saveCandidates}" th:object="${form}" method="post">
|
||||||
<table>
|
<div th:each="category, itemStat : ${categories}">
|
||||||
<thead>
|
<h2 class="categoryHeader" th:text="${category.name}"></h2>
|
||||||
<tr>
|
<input th:field="*{possibleCandidates[__${itemStat.index}__].name}" />
|
||||||
<th> Kategorie</th>
|
</div>
|
||||||
<th> Kandidat/in</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<tr th:each="category, itemStat : ${categories}">
|
|
||||||
<td th:text="${category.name}"></td>
|
|
||||||
<td><input th:field="*{possibleCandidates[__${itemStat.index}__].name}" /></td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
<input type="submit" id="submitButton" th:value="Confirm"></button>
|
<input type="submit" id="submitButton" th:value="Confirm"></button>
|
||||||
</fieldset>
|
</form>
|
||||||
</form>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
@@ -44,20 +44,20 @@
|
|||||||
input.value = voteIds;
|
input.value = voteIds;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
<div class="centered">
|
||||||
<h1>Wähle deine Kandidaten:</h1>
|
<h1>Wähle deine Kandidaten:</h1>
|
||||||
<div th:each="category,iter : ${categories}">
|
<div th:each="category,iter : ${categories}">
|
||||||
<h2 class="categoryHeader" th:text="${category.name}"></h2>
|
<h2 class="categoryHeader" th:text="${category.name}"></h2>
|
||||||
<div th:each="candidate : ${category.candidateList}" class="voteDiv">
|
<div th:each="candidate : ${category.candidateList}" class="voteDiv">
|
||||||
<button class="inputButton" th:id="|category${category.id}_candidate${candidate.id}|" th:text="${candidate.name}" th:onclick="|setColor(category${category.id}_candidate${candidate.id})|"></button>
|
<button class="inputButton" th:id="|category${category.id}_candidate${candidate.id}|" th:text="${candidate.name}" th:onclick="|setColor(category${category.id}_candidate${candidate.id})|"></button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<form action="#" th:action="@{/processVote}" method="post">
|
||||||
|
<input id="voteValues" type="hidden" name="voteValues" value="" />
|
||||||
|
<input id="voterName" type="hidden" name="voterEmail" th:value="${name}" />
|
||||||
|
<button type="submit" id="submitButton" onclick="getVotes()">Auswahl bestätigen</button>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<form action="#" th:action="@{/processVote}" method="post">
|
|
||||||
<input id="voteValues" type="hidden" name="voteValues" value="" />
|
|
||||||
<input id="voterName" type="hidden" name="voterEmail" th:value="${name}" />
|
|
||||||
<button type="submit" id="submitButton" onclick="getVotes()">Auswahl bestätigen</button>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user