Skip to content

Commit fb7511b

Browse files
committed
Calendar Popup fix, enabled Cache
1 parent 181e184 commit fb7511b

File tree

5 files changed

+58
-19
lines changed

5 files changed

+58
-19
lines changed

src/main/java/de/jadenk/springcloud/controller/CalendarController.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,30 @@ public String viewCalendar(@RequestParam(defaultValue = "#{T(java.time.Year).now
7878
return "calendar";
7979
}
8080

81-
81+
@PostMapping("/toggle-visibility")
82+
public String toggleVisibility(@RequestParam Long id) {
83+
Optional<CalendarEntry> entryOpt = entryRepo.findById(id);
84+
if (entryOpt.isPresent()) {
85+
CalendarEntry entry = entryOpt.get();
86+
User currentUser = getCurrentUser();
87+
88+
boolean isCreator = entry.getUser().equals(currentUser);
89+
boolean isAdmin = SecurityContextHolder.getContext().getAuthentication()
90+
.getAuthorities().stream()
91+
.anyMatch(auth -> auth.getAuthority().endsWith("ADMIN"));
92+
93+
if (isCreator || isAdmin) {
94+
if (entry.getVisibility() == CalendarEntry.Visibility.PUBLIC) {
95+
entry.setVisibility(CalendarEntry.Visibility.PRIVATE);
96+
} else {
97+
entry.setVisibility(CalendarEntry.Visibility.PUBLIC);
98+
}
99+
entryRepo.save(entry);
100+
}
101+
}
102+
// zurück zum Kalender (aktuelles Jahr/Monat)
103+
return "redirect:/calendar";
104+
}
82105

83106
@GetMapping("/entry/{id}")
84107
@ResponseBody

src/main/java/de/jadenk/springcloud/service/VersionService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
@Service
66
public class VersionService {
7-
private final String currentVersion = "2.2";
7+
private final String currentVersion = "3.0";
88

99
public String getCurrentVersion() {
1010
return currentVersion;

src/main/resources/application.properties

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ spring.datasource.username=${SPRING_DATASOURCE_USERNAME}
55
spring.datasource.password=${SPRING_DATASOURCE_PASSWORD}
66
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
77

8-
#logging.level.org.springframework.security=DEBUG
8+
logging.level.org.springframework=INFO
9+
logging.level.org.hibernate.SQL=WARN
10+
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=ERROR
911
spring.thymeleaf.extras.springsecurity.enabled=true
12+
spring.thymeleaf.cache=true
1013

1114

1215
spring.servlet.multipart.enabled=true

src/main/resources/templates/calendar.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ <h2 class="text-2xl font-bold text-[var(--color-primary)] text-center mb-2">New
142142
</div>
143143
</div>
144144

145-
<div id="viewModal" class="modal hidden fixed inset-0 z-50 flex items-center justify-center bg-[rgba(15,15,30,0.9)]"></div>
145+
<div id="viewModal" class="hidden popup-overlay">
146+
147+
</div>
146148

147149

148150
<!-- Scripts -->
Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,34 @@
1-
<div class="modal-content" th:fragment="modal-content">
2-
<h2 th:text="${entry.title}">Entry</h2>
3-
<p th:text="${entry.description}"></p>
4-
<p><strong>Creator:</strong> <span th:text="${entry.user.username}"></span></p>
5-
<p><strong>Time:</strong> <span th:text="${entry.time}"></span></p>
6-
<p><strong>Date:</strong> <span th:text="${entry.date}"></span></p>
7-
<p><strong>Visibility:</strong> <span th:text="${entry.visibility}"></span></p>
1+
<div class="popup-container" th:fragment="modal-content">
2+
<!-- Titel -->
3+
<h2 class="text-xl font-bold text-[var(--color-primary)] mb-4" th:text="${entry.title}">Entry</h2>
84

9-
<div class="button-row" th:if="${canEdit}">
10-
<form method="post" th:action="@{/calendar/toggle-visibility}">
5+
<!-- Details -->
6+
<p class="mb-2 text-[var(--color-text-light)]" th:text="${entry.description}">Description</p>
7+
<p class="mb-1"><strong>Creator:</strong> <span th:text="${entry.user.username}">User</span></p>
8+
<p class="mb-1"><strong>Time:</strong> <span th:text="${entry.time}">12:00</span></p>
9+
<p class="mb-1"><strong>Date:</strong> <span th:text="${entry.date}">01.01.2025</span></p>
10+
<p class="mb-4"><strong>Visibility:</strong> <span th:text="${entry.visibility}">PUBLIC</span></p>
11+
12+
<!-- Buttons nur wenn editierbar -->
13+
<div class="flex gap-2 mb-3" th:if="${canEdit}">
14+
<form method="post" th:action="@{/calendar/toggle-visibility}" class="flex-1">
1115
<input type="hidden" name="id" th:value="${entry.id}">
12-
<button type="submit">Change Visibility</button>
16+
<button type="submit" class="w-full py-2 bg-blue-600 text-white rounded hover:bg-blue-700 transition">
17+
Change Visibility
18+
</button>
1319
</form>
1420

15-
<form method="get" th:action="@{'/calendar/delete/' + ${entry.id}}">
16-
<button type="submit">Delete</button>
21+
<form method="get" th:action="@{'/calendar/delete/' + ${entry.id}}" class="flex-1">
22+
<button type="submit" class="w-full py-2 bg-red-600 text-white rounded hover:bg-red-700 transition">
23+
Delete
24+
</button>
1725
</form>
26+
<input type="hidden" name="id" th:value="${entry.id}">
1827
</div>
1928

20-
<div class="button-row">
21-
<button onclick="closeModal('viewModal')" class="close-btn">Close</button>
22-
</div>
29+
<!-- Close -->
30+
<button onclick="closeModal('viewModal')"
31+
class="w-full py-2 bg-gray-600 text-white rounded hover:bg-gray-700 transition">
32+
Close
33+
</button>
2334
</div>

0 commit comments

Comments
 (0)