Skip to content

Commit 5dd0930

Browse files
committed
fix close, add colors, add titles
1 parent 236bd4e commit 5dd0930

File tree

9 files changed

+37
-18
lines changed

9 files changed

+37
-18
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ FROM eclipse-temurin:21-jre-alpine
33
RUN addgroup -S spring && adduser -S spring -G spring
44
USER spring:spring
55

6-
ARG JAR_FILE=build/libs/unipoll-1.0.5.jar
6+
ARG JAR_FILE=build/libs/unipoll-1.0.6.jar
77
COPY ${JAR_FILE} app.jar
88

99
EXPOSE 8080

build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
plugins {
22
id 'java'
3-
id 'org.springframework.boot' version '3.3.2'
3+
id 'org.springframework.boot' version '3.3.3'
44
id 'io.spring.dependency-management' version '1.1.5'
55
}
66

77
group = 'de.cwansart'
8-
version = '1.0.5'
8+
version = '1.0.6'
99

1010
java {
1111
toolchain {
@@ -26,10 +26,10 @@ dependencies {
2626
//runtimeOnly 'com.h2database:h2'
2727
runtimeOnly 'org.postgresql:postgresql'
2828
testImplementation 'org.springframework.boot:spring-boot-starter-test'
29-
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
29+
//testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
3030
}
3131

32-
tasks.named('test') {
33-
useJUnitPlatform()
34-
}
32+
//tasks.named('test') {
33+
// useJUnitPlatform()
34+
//}
3535

src/main/java/de/cwansart/unipoll/controller/ClosePollController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ public String confirm(@RequestParam(name = "id", required = true) long id, Model
3939
}
4040

4141
model.addAttribute("id", id);
42+
model.addAttribute("name", poll.get().getName());
4243
return "confirm_close";
4344
}
4445

4546
@PostMapping("/close")
46-
public String delete(@RequestParam(name = "id", required = true) long id, Model model) {
47+
public String close(@RequestParam(name = "id", required = true) long id, Model model) {
4748
if (!auth.isAuthenticated()) {
4849
return "redirect:/login?p=list";
4950
}

src/main/java/de/cwansart/unipoll/controller/ResultController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public String show(@RequestParam(name = "id", required = true) Long id, Model mo
4747
model.addAttribute("results", results);
4848
model.addAttribute("id", id);
4949
model.addAttribute("name", poll.get().getName());
50+
model.addAttribute("closed", poll.get().isDeleted());
5051
return "result";
5152
}
5253
}

src/main/java/de/cwansart/unipoll/controller/VoteController.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ public String show(@RequestParam(name = "id", required = true) long id, Model mo
4040
if (poll.isEmpty()) {
4141
throw new ResponseStatusException(HttpStatusCode.valueOf(404), "poll does not exist");
4242
}
43+
44+
if (poll.get().isDeleted()) {
45+
return "redirect:/results?id=" + id + "&c=1";
46+
}
4347

4448
Optional<Cookie> userIdCookie = request.getCookies() != null ? Arrays.asList(request.getCookies()).stream()
4549
.filter(c -> c.getName().equals("unipoll-user-id")).findFirst() : Optional.empty();
@@ -50,6 +54,7 @@ public String show(@RequestParam(name = "id", required = true) long id, Model mo
5054
model.addAttribute("choices", poll.get().getChoices());
5155
model.addAttribute("voteForm", new VoteForm());
5256
model.addAttribute("id", id);
57+
model.addAttribute("name", poll.get().getName());
5358
return "vote";
5459
}
5560

@@ -60,6 +65,10 @@ public String save(@RequestParam(name = "id", required = true) long id,
6065
if (poll.isEmpty()) {
6166
throw new ResponseStatusException(HttpStatusCode.valueOf(404), "poll does not exist");
6267
}
68+
69+
if (poll.get().isDeleted()) {
70+
return "redirect:/results?id=" + id + "&c=1";
71+
}
6372

6473
String userId = UUID.randomUUID().toString();
6574

src/main/resources/templates/confirm_close.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010

1111
<body>
1212
<div class="container">
13-
<form class="form-create" method="POST" th:action="@{/delete(id=${id})}">
13+
<form class="form-create" method="POST" th:action="@{/close(id=${id})}">
1414
<h2 class="form-heading">Confirm Close</h2>
1515

1616
<div class="form-group">
1717
<h3 th:text="${'Are you sure you want to close poll #' + id + '?'}" />
18+
<h4 th:text="${name}"></h4>
1819

1920
<button class="btn btn-lg btn-primary btn-block" type="submit">Close</button>
2021
</div>

src/main/resources/templates/list.html

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
<h2 class="form-heading">List of all polls</h2>
1414
<h3 th:text="${'Total of ' + totalNum + ' polls.'}" />
1515

16+
<div class="float-right">
17+
<a href="/create" class="text-primary">Create a new poll</a>
18+
</div>
19+
1620
<div class="container mb-3">
1721
<div class="row align-items-start">
1822
<div class="col border border-info bg-info bg-opacity-10">Name</div>
@@ -25,22 +29,22 @@ <h3 th:text="${'Total of ' + totalNum + ' polls.'}" />
2529
<div class="col border" th:text="${poll.participants}" />
2630
<div class="col border" th:text="${{poll.deleted}}" />
2731
<div class="col border">
28-
<a th:href="@{/delete(id=${poll.id})}">Close</a>
29-
<a th:href="@{/vote(id=${poll.id})}">Participate</a>
30-
<a th:href="@{/results(id=${poll.id})}">Show results</a>
32+
<a th:href="@{/vote(id=${poll.id})}" class="text-primary">Participate</a>
33+
<a th:href="@{/results(id=${poll.id})}" class="text-secondary">Show results</a>
34+
<a th:unless="${poll.deleted}" th:href="@{/close(id=${poll.id})}" class="text-danger">Close</a>
3135
</div>
3236
</div>
3337
</div>
3438

35-
<div class="container mb-3">
39+
<div class="container mb-3" th:if="${totalPages > 1}">
3640
<div class="row align-items-start"></div>
3741
<nav aria-label="Page navigation">
3842
<ul class="pagination">
3943
<li th:class="${currentPage == 1} ? 'page-item disabled' : 'page-item'"><a class="page-link"
40-
th:href="${currentPage == 1} ? '#' : '@{/list(p=${currentPage-1})}'">Previous</a></li>
41-
<li th:class="${currentPage == totalPages} ? 'page-item disabled' : 'page-item'"><a
44+
th:href="${currentPage == 1} ? '#' : @{/list(p=${currentPage-1})}">Previous</a></li>
45+
<li th:class="${totalPages > 1 && currentPage == totalPages} ? 'page-item disabled' : 'page-item'"><a
4246
class="page-link"
43-
th:href="${currentPage == totalPages} ? '#' : '@{/list(p=${currentPage+1})}'">Next</a></li>
47+
th:href="${totalPages > 1 && currentPage == totalPages} ? '#' : @{/list(p=${currentPage+1})}">Next</a></li>
4448
</ul>
4549
</nav>
4650
</div>

src/main/resources/templates/result.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
<div class="container">
1313
<h2 class="form-heading" th:text="${'Results for poll #' + id}"></h2>
1414
<h3 th:text="${name}"></h3>
15+
<div th:if="${closed}" class="alert alert-info" role="alert">
16+
This poll has been closed.
17+
</div>
1518

1619
<div class="container mb-3">
1720
<table class="table table-striped table-bordered">

src/main/resources/templates/vote.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html xmlns:th="http://www.thymeleaf.org">
33

44
<head>
5-
<title>Vote</title>
5+
<title th:text="${'Vote for ' + name}" />
66
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
77
<link href="/css/bootstrap.min.css" rel="stylesheet">
88
<script src="/js/bootstrap.bundle.min.js"></script>
@@ -11,7 +11,7 @@
1111
<body>
1212
<div class="container">
1313
<form class="form-vote" method="POST" th:action="@{/vote(id=${id})}" th:object="${voteForm}">
14-
<h2 class="form-heading">Please select your choices and vote!</h2>
14+
<h2 class="form-heading" th:text="${name}"/>
1515
<div class="form-group">
1616
<div class="form-check" th:each="choice: ${choices}">
1717
<input class="form-check-input" type="checkbox" th:value="${choice.id}" th:field="*{selected}" />

0 commit comments

Comments
 (0)