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:
2020-11-30 22:58:14 +01:00
parent 361433bf22
commit 525074af15
7 changed files with 1204 additions and 197 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -138,14 +138,15 @@ public class VotingController {
@RequestMapping("/saveCandidates")
public String candidateSaving(@ModelAttribute PossibleCandidateWrapper possibleCandidates){
LOGGER.info(tableAction.logPossibleCandidates(possibleCandidates.getPossibleCandidates(), categoryRepository));
LinkedList<PossibleCandidate> 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);

View File

@@ -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<PossibleCandidate, Integer> {
public PossibleCandidate findByNameAndCategoryID(String name, Long category_id);
public PossibleCandidate findByNameAndCategory(String name, Category category);
Optional<PossibleCandidate> findById(Long id);

View 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;
}

View File

@@ -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 {

View File

@@ -4,29 +4,20 @@
<head>
<meta charset="UTF-8">
<title>Title</title>
<link th:href="@{/styles/addingCandidates.css}" rel="stylesheet" />
</head>
<body>
<h1>Schlage für jede Kategorie eine/n Kandiadt/en vor:</h1>
<form action="#" th:action="@{/saveCandidates}" th:object="${form}" method="post">
<fieldset>
<table>
<thead>
<tr>
<th> Kategorie</th>
<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>
<body class="center-screen">
<div class="centered">
<h1>Schlage für jede Kategorie eine/n Kandiadt/en vor:</h1>
<form action="#" th:action="@{/saveCandidates}" th:object="${form}" method="post">
<div th:each="category, itemStat : ${categories}">
<h2 class="categoryHeader" th:text="${category.name}"></h2>
<input th:field="*{possibleCandidates[__${itemStat.index}__].name}" />
</div>
<input type="submit" id="submitButton" th:value="Confirm"></button>
</fieldset>
</form>
</form>
</div>
</body>
</html>

View File

@@ -44,20 +44,20 @@
input.value = voteIds;
}
</script>
<h1>Wähle deine Kandidaten:</h1>
<div th:each="category,iter : ${categories}">
<h2 class="categoryHeader" th:text="${category.name}"></h2>
<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>
<div class="centered">
<h1>Wähle deine Kandidaten:</h1>
<div th:each="category,iter : ${categories}">
<h2 class="categoryHeader" th:text="${category.name}"></h2>
<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>
</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>
<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>
</html>