fixed bugs

This commit is contained in:
Jottyfan
2025-12-14 21:51:29 +01:00
parent 3726b9172c
commit b048b7c7bc
9 changed files with 64 additions and 30 deletions

View File

@@ -48,6 +48,8 @@ dependencies {
implementation 'org.mnode.ical4j:ical4j:4.2.2'
implementation 'org.jooq:jooq:3.20.10'
implementation 'org.springframework.boot:spring-boot-starter-jooq'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'

View File

@@ -17,7 +17,7 @@ public class SecurityConfig {
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests(
// @formatter:off
r -> r.requestMatchers("/", "/error", "/css/**", "/js/**", "/webjars/**", "/template").permitAll()
r -> r.requestMatchers("/", "/error", "/css/**", "/js/**", "/webjars/**", "/template", "/updateTheme/*").permitAll()
.requestMatchers("/**").authenticated())
.oauth2Login(l -> l.authorizationEndpoint(e -> e.baseUri("/oauth2/authorize-client")));
// @formatter:on

View File

@@ -8,31 +8,33 @@ import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import de.jottyfan.bico.modules.CommonController;
/**
*
*
* @author jotty
*
*
*/
@Controller
public class NextController extends CommonController {
@Autowired
private NextService service;
@GetMapping("/next")
public String getNext(Model model) {
model.addAttribute("list", service.getNext(LocalDate.now()));
public String getNext(@RequestParam(name = "groupname", required = false) String groupname, Model model) {
model.addAttribute("list", service.getNext(LocalDate.now(), groupname));
return "/next";
}
@GetMapping("/next/{date}")
public String getNextForDate(@PathVariable("date") String dateStr, Model model) {
public String getNextForDate(@PathVariable("date") String dateStr,
@RequestParam(name = "groupname", required = false) String groupname, Model model) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate date = LocalDate.parse(dateStr, formatter);
model.addAttribute("list", service.getNext(date));
LocalDate date = LocalDate.parse(dateStr, formatter);
model.addAttribute("list", service.getNext(date, groupname));
return "/next";
}
}

View File

@@ -9,9 +9,11 @@ import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jooq.Condition;
import org.jooq.DSLContext;
import org.jooq.Record4;
import org.jooq.SelectSeekStep1;
import org.jooq.impl.DSL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
@@ -32,15 +34,25 @@ public class NextRepository {
/**
* get the next dates from date on
*
* @param date the date
* @param date the date
* @param classname the classname to filter for
* @return the next dates as beans in a list; an empty list at least
*/
public List<NextBean> getNext(LocalDate date) {
public List<NextBean> getNext(LocalDate date, String classname) {
Condition filter = DSL.trueCondition();
if (classname == null) {
filter = DSL.trueCondition();
} else if (classname.equals("bibleclass")) {
filter = V_CALENDAR.BIBLECLASS.isTrue();
} else if (classname.equals("youthgroup")) {
filter = V_CALENDAR.YOUTHGROUP.isTrue();
}
SelectSeekStep1<Record4<String, LocalDate, Boolean, Boolean>, LocalDate> sql = jooq
// @formatter:off
.selectDistinct(V_CALENDAR.FULLNAME, V_CALENDAR.SLOT_DAY, V_CALENDAR.BIBLECLASS, V_CALENDAR.YOUTHGROUP)
.from(V_CALENDAR)
.where(V_CALENDAR.SLOT_DAY.ge(date))
.and(filter)
.orderBy(V_CALENDAR.SLOT_DAY.asc());
// @formatter:on
LOGGER.trace(sql);
@@ -48,7 +60,8 @@ public class NextRepository {
List<NextBean> list = new ArrayList<>();
while (i.hasNext()) {
Record4<String, LocalDate, Boolean, Boolean> r = i.next();
list.add(NextBean.of(r.get(V_CALENDAR.FULLNAME), r.get(V_CALENDAR.SLOT_DAY), r.get(V_CALENDAR.BIBLECLASS), r.get(V_CALENDAR.YOUTHGROUP)));
list.add(NextBean.of(r.get(V_CALENDAR.FULLNAME), r.get(V_CALENDAR.SLOT_DAY), r.get(V_CALENDAR.BIBLECLASS),
r.get(V_CALENDAR.YOUTHGROUP)));
}
return list;
}

View File

@@ -9,24 +9,25 @@ import org.springframework.stereotype.Service;
import de.jottyfan.bico.modules.next.model.NextBean;
/**
*
*
* @author jotty
*
*
*/
@Service
public class NextService {
@Autowired
private NextRepository repository;
/**
* get the next dates
*
*
* @param date the date
* @param classname the classname to filter for
* @return the list of next dates
*/
public List<NextBean> getNext(LocalDate date) {
return repository.getNext(date);
public List<NextBean> getNext(LocalDate date, String classname) {
return repository.getNext(date, classname);
}
}

View File

@@ -1,7 +1,12 @@
package de.jottyfan.bico.modules.profile;
import java.security.Principal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken;
import org.springframework.security.oauth2.core.user.OAuth2User;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -23,12 +28,20 @@ public class ProfileController extends CommonController {
* update the theme of the current user
*
* @param theme the theme
*
*/
@CrossOrigin(origins = "*")
@PostMapping("/updateTheme/{theme}")
public ResponseEntity<?> updateTheme(@PathVariable("theme") String theme) {
// TODO: add profile's user name
String username = "jotty";
service.updateTheme(username, theme);
public ResponseEntity<?> updateTheme(@PathVariable("theme") String theme, Principal principal) {
String username = null;
OAuth2AuthenticationToken token = (OAuth2AuthenticationToken) principal;
if (token != null) {
OAuth2User user = token.getPrincipal();
username = user.getName();
}
if (username != null) {
service.updateTheme(username, theme);
}
return ResponseEntity.ok(null);
}

View File

@@ -8,7 +8,10 @@ toggleDarkMode = function() {
url: updateUrl,
type: "POST",
contentType: "application/json",
dataType: 'json'
dataType: 'json',
xhrFields: {
withCredentials: true
}
});
}

View File

@@ -4,6 +4,10 @@
<th:block layout:fragment="content">
<div class="borderdist">
<div class="container" th:if="${hasDateRole || hasBUrole}">
<div class="row">
<div class="col-md-6 col-sm-12"><a th:href="@{/next(groupname='bibleclass')}" class="btn btn-outline-secondary">nur Bibelunterricht</a></div>
<div class="col-md-6 col-sm-12"><a th:href="@{/next(groupname='youthgroup')}" class="btn btn-outline-secondary">nur Jungschar</a></div>
</div>
<div class="row">
<div class="col-sm-6 col-md-4 col-lg-2 card p-2 m-1" th:each="s : ${list}">
<div class="tag tagbu" th:if="${s.isBibleclass}">Bibelunt.</div>

View File

@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<html xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security" th:data-bs-theme="${theme}">
<head>
<title>Bible Class Organizer</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
@@ -25,10 +25,6 @@
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent" style="margin-right: 20px">
<ul class="navbar-nav mb-2 mb-lg-0" th:if="${hasAnyRole}">
<!--
<li class="nav-item"><a class="btn btn-outline-secondary" th:href="@{/camp/registration}" style="margin-left: 12px">Anmeldung Gemeindefreizeit</a></li>
<li class="nav-item"><a class="btn btn-outline-secondary" th:href="@{/camp/registration/admin}" style="margin-left: 12px" th:if="${isCampAdmin}">Gemeindefreizeitliste</a></li>
-->
<li class="nav-item"><a class="btn btn-outline-secondary" th:href="@{/next}" style="margin-left: 12px" th:if="${hasDateRole || hasBUrole}">Dienstplan</a></li>
<li class="nav-item"><a class="btn btn-outline-secondary" th:href="@{/sheet}" style="margin-left: 12px" th:if="${hasBUrole}">Einteilung</a></li>
<li class="nav-item"><a class="btn btn-outline-secondary" th:href="@{/subject/list}" style="margin-left: 12px" th:if="${hasBUrole}">Themen</a></li>