Candidates get sorted descending by their votes within their categories
This commit is contained in:
@@ -4,7 +4,7 @@ import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "candidates")
|
||||
public class Candidate {
|
||||
public class Candidate implements Comparable<Candidate>{
|
||||
|
||||
public Candidate() {
|
||||
super();
|
||||
@@ -41,4 +41,16 @@ public class Candidate {
|
||||
}
|
||||
|
||||
public Category getCategory() {return category;}
|
||||
|
||||
public void votedFor() {
|
||||
this.votes += 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Candidate c) {
|
||||
if (getVotes() == null || c.getVotes() == null) {
|
||||
return 0;
|
||||
}
|
||||
return c.getVotes().compareTo(getVotes());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.github.cato447.AbizeitungVotingSystem.entities;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@@ -34,6 +35,11 @@ public class Category {
|
||||
}
|
||||
|
||||
public List<Candidate> getCandidateList() {
|
||||
Collections.sort(candidateList);
|
||||
return candidateList;
|
||||
}
|
||||
|
||||
public int getCandidateListSize(){
|
||||
return candidateList.size();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,50 +8,56 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Wähler Liste</h1>
|
||||
|
||||
<div class="voterTable">
|
||||
<table class="tableVoters" border="5">
|
||||
<tr>
|
||||
<th>Id</th>
|
||||
<th>E-Mail</th>
|
||||
<th>Vote status</th>
|
||||
</tr>
|
||||
<ul>
|
||||
<li>
|
||||
<h1>Wähler Liste</h1>
|
||||
<div class="voterTable">
|
||||
|
||||
<tr th:each="voter : ${voters}">
|
||||
<!-- If voter has voted -->
|
||||
<div th:if="${voter.vote_status}">
|
||||
<td class="voted" th:text="${voter.id}"></td>
|
||||
<td class="voted" th:text="${voter.email}"></td>
|
||||
<td class="voted" th:text="${voter.vote_status}"></td>
|
||||
<table class="tableVoters" border="5">
|
||||
<tr>
|
||||
<th>Id</th>
|
||||
<th>E-Mail</th>
|
||||
<th>Vote status</th>
|
||||
</tr>
|
||||
|
||||
<tr th:each="voter : ${voters}">
|
||||
<!-- If voter has voted -->
|
||||
<div th:if="${voter.vote_status}">
|
||||
<td class="voted" th:text="${voter.id}"></td>
|
||||
<td class="voted" th:text="${voter.email}"></td>
|
||||
<td class="voted" th:text="${voter.vote_status}"></td>
|
||||
</div>
|
||||
|
||||
<!-- ELSE -->
|
||||
<div th:unless="${voter.vote_status}">
|
||||
<td class="notVoted" th:text="${voter.id}"></td>
|
||||
<td class="notVoted" th:text="${voter.email}"></td>
|
||||
<td class="notVoted" th:text="${voter.vote_status}"></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</li>
|
||||
<li>
|
||||
<h1>Kandidaten Liste</h1>
|
||||
<div th:each="category : ${categories}" th:id="${category.id}">
|
||||
<h2 th:text="${category.name}"></h2>
|
||||
<table class="tableCandidates" border="5">
|
||||
<tr>
|
||||
<th>Id</th>
|
||||
<th>Name</th>
|
||||
<th>Votes</th>
|
||||
</tr>
|
||||
|
||||
<!-- ELSE -->
|
||||
<div th:unless="${voter.vote_status}">
|
||||
<td class="notVoted" th:text="${voter.id}"></td>
|
||||
<td class="notVoted" th:text="${voter.email}"></td>
|
||||
<td class="notVoted" th:text="${voter.vote_status}"></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<h1>Kandidaten Liste</h1>
|
||||
<div th:each="category : ${categories}" th:id="${category.id}">
|
||||
<h2 th:text="${category.name}"></h2>
|
||||
<table class="tableCandidates" border="5">
|
||||
<tr>
|
||||
<th>Id</th>
|
||||
<th>Name</th>
|
||||
<th>Votes</th>
|
||||
</tr>
|
||||
|
||||
<tr th:each="candidate: ${category.candidateList}" th:id="${category.id} + '_' + ${candidate.id}">
|
||||
<td th:text="${candidate.id}"></td>
|
||||
<td th:text="${candidate.name}"></td>
|
||||
<td th:text="${candidate.votes}"></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<tr th:each="candidate: ${category.candidateList}" th:id="${category.id} + '_' + ${candidate.id}">
|
||||
<td th:text="${candidate.id}"></td>
|
||||
<td th:text="${candidate.name}"></td>
|
||||
<td th:text="${candidate.votes}"></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user