code cleanup

This commit is contained in:
Jörg Henke
2024-01-05 11:09:53 +01:00
parent 7fc30ffe48
commit c1b8283dd0
9 changed files with 47 additions and 65 deletions

View File

@ -1,7 +1,11 @@
package de.jottyfan.timetrack.modules; package de.jottyfan.timetrack.modules;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.ModelAttribute;
import de.jottyfan.timetrack.component.OAuth2Provider;
import de.jottyfan.timetrack.modules.profile.ProfileService;
/** /**
* *
* @author jotty * @author jotty
@ -9,6 +13,12 @@ import org.springframework.web.bind.annotation.ModelAttribute;
*/ */
public abstract class CommonController { public abstract class CommonController {
@Autowired
private OAuth2Provider provider;
@Autowired
private ProfileService profileService;
@Value("${server.servlet.context-path}") @Value("${server.servlet.context-path}")
private String contextPath; private String contextPath;
@ -16,4 +26,10 @@ public abstract class CommonController {
public String getBaseUrl() { public String getBaseUrl() {
return contextPath; return contextPath;
} }
@ModelAttribute("theme")
public String getTheme() {
String username = provider.getName();
return profileService.getTheme(username);
}
} }

View File

@ -12,14 +12,12 @@ import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import de.jottyfan.timetrack.component.OAuth2Provider; import de.jottyfan.timetrack.component.OAuth2Provider;
import de.jottyfan.timetrack.modules.done.DoneService; import de.jottyfan.timetrack.modules.done.DoneService;
import de.jottyfan.timetrack.modules.done.model.DoneBean; import de.jottyfan.timetrack.modules.done.model.DoneBean;
import de.jottyfan.timetrack.modules.done.model.DoneModel; import de.jottyfan.timetrack.modules.done.model.DoneModel;
import de.jottyfan.timetrack.modules.done.model.SummaryBean; import de.jottyfan.timetrack.modules.done.model.SummaryBean;
import de.jottyfan.timetrack.modules.profile.ProfileService;
import jakarta.annotation.security.RolesAllowed; import jakarta.annotation.security.RolesAllowed;
import jakarta.servlet.ServletException; import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
@ -38,9 +36,6 @@ public class IndexController extends CommonController {
@Autowired @Autowired
private OAuth2Provider provider; private OAuth2Provider provider;
@Autowired
private ProfileService profileService;
@GetMapping("/logout") @GetMapping("/logout")
public String getLogout(HttpServletRequest request) throws ServletException { public String getLogout(HttpServletRequest request) throws ServletException {
@ -49,14 +44,13 @@ public class IndexController extends CommonController {
} }
@RolesAllowed("timetrack_user") @RolesAllowed("timetrack_user")
@RequestMapping("/") @GetMapping("/")
public String getIndex(@ModelAttribute DoneModel doneModel, Model model, OAuth2AuthenticationToken token) { public String getIndex(@ModelAttribute DoneModel doneModel, Model model, OAuth2AuthenticationToken token) {
String username = provider.getName(); String username = provider.getName();
Duration maxWorkTime = Duration.ofHours(8); // TODO: to the configuration file Duration maxWorkTime = Duration.ofHours(8); // TODO: to the configuration file
LocalDate day = LocalDate.now(); LocalDate day = LocalDate.now();
List<DoneBean> list = doneService.getList(day, username); List<DoneBean> list = doneService.getList(day, username);
model.addAttribute("sum", new SummaryBean(list, day, maxWorkTime)); model.addAttribute("sum", new SummaryBean(list, day, maxWorkTime));
model.addAttribute("theme", profileService.getTheme(username));
LOGGER.debug("sum = {}", model.getAttribute("sum")); LOGGER.debug("sum = {}", model.getAttribute("sum"));
return "public/index"; return "public/index";
} }

View File

@ -5,9 +5,7 @@ import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import de.jottyfan.timetrack.component.OAuth2Provider;
import de.jottyfan.timetrack.modules.CommonController; import de.jottyfan.timetrack.modules.CommonController;
import de.jottyfan.timetrack.modules.profile.ProfileService;
/** /**
* *
@ -17,19 +15,12 @@ import de.jottyfan.timetrack.modules.profile.ProfileService;
@Controller @Controller
public class CalendarController extends CommonController { public class CalendarController extends CommonController {
@Autowired
private OAuth2Provider provider;
@Autowired
private ProfileService profileService;
@Autowired @Autowired
private CalendarService service; private CalendarService service;
@GetMapping("/calendar") @GetMapping("/calendar")
public String getCalendar(Model model) { public String getCalendar(Model model) {
model.addAttribute("events", service.getJsonEvents()); model.addAttribute("events", service.getJsonEvents());
model.addAttribute("theme", profileService.getTheme(provider.getName()));
return "/calendar/calendar"; return "/calendar/calendar";
} }
} }

View File

@ -10,14 +10,11 @@ import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import de.jottyfan.timetrack.component.OAuth2Provider;
import de.jottyfan.timetrack.db.contact.enums.EnumContacttype; import de.jottyfan.timetrack.db.contact.enums.EnumContacttype;
import de.jottyfan.timetrack.modules.CommonController; import de.jottyfan.timetrack.modules.CommonController;
import de.jottyfan.timetrack.modules.profile.ProfileService;
import jakarta.annotation.security.RolesAllowed; import jakarta.annotation.security.RolesAllowed;
/** /**
@ -27,12 +24,6 @@ import jakarta.annotation.security.RolesAllowed;
*/ */
@Controller @Controller
public class ContactController extends CommonController { public class ContactController extends CommonController {
@Autowired
private OAuth2Provider provider;
@Autowired
private ProfileService profileService;
@Autowired @Autowired
private ContactService contactService; private ContactService contactService;
@ -44,16 +35,15 @@ public class ContactController extends CommonController {
} }
@RolesAllowed("timetrack_user") @RolesAllowed("timetrack_user")
@RequestMapping(value = "/contact/list") @GetMapping("/contact/list")
public String getList(Model model) { public String getList(Model model) {
List<ContactBean> list = contactService.getList(); List<ContactBean> list = contactService.getList();
model.addAttribute("contactList", list); model.addAttribute("contactList", list);
model.addAttribute("theme", profileService.getTheme(provider.getName()));
return "contact/list"; return "contact/list";
} }
@RolesAllowed("timetrack_user") @RolesAllowed("timetrack_user")
@RequestMapping(value = "/contact/add", method = RequestMethod.GET) @GetMapping("/contact/add")
public String toAdd(Model model) { public String toAdd(Model model) {
return toItem(null, model); return toItem(null, model);
} }
@ -67,12 +57,11 @@ public class ContactController extends CommonController {
} }
model.addAttribute("contactBean", bean); model.addAttribute("contactBean", bean);
model.addAttribute("types", Arrays.asList(EnumContacttype.values())); model.addAttribute("types", Arrays.asList(EnumContacttype.values()));
model.addAttribute("theme", profileService.getTheme(provider.getName()));
return "contact/item"; return "contact/item";
} }
@RolesAllowed("timetrack_user") @RolesAllowed("timetrack_user")
@RequestMapping(value = "/contact/upsert", method = RequestMethod.POST) @PostMapping("/contact/upsert")
public String doUpsert(Model model, @ModelAttribute ContactBean bean) { public String doUpsert(Model model, @ModelAttribute ContactBean bean) {
Integer amount = contactService.doUpsert(bean); Integer amount = contactService.doUpsert(bean);
return amount.equals(1) ? getList(model) : toItem(bean.getPk(), model); return amount.equals(1) ? getList(model) : toItem(bean.getPk(), model);

View File

@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes; import org.springframework.web.bind.annotation.SessionAttributes;
import de.jottyfan.timetrack.component.OAuth2Provider; import de.jottyfan.timetrack.component.OAuth2Provider;
@ -19,8 +20,8 @@ import de.jottyfan.timetrack.modules.CommonController;
import de.jottyfan.timetrack.modules.done.model.DoneBean; import de.jottyfan.timetrack.modules.done.model.DoneBean;
import de.jottyfan.timetrack.modules.done.model.DoneModel; import de.jottyfan.timetrack.modules.done.model.DoneModel;
import de.jottyfan.timetrack.modules.done.model.OvertimeBean; import de.jottyfan.timetrack.modules.done.model.OvertimeBean;
import de.jottyfan.timetrack.modules.done.model.SlotBean;
import de.jottyfan.timetrack.modules.done.model.SummaryBean; import de.jottyfan.timetrack.modules.done.model.SummaryBean;
import de.jottyfan.timetrack.modules.profile.ProfileService;
import jakarta.annotation.security.RolesAllowed; import jakarta.annotation.security.RolesAllowed;
/** /**
@ -35,9 +36,6 @@ public class DoneController extends CommonController {
@Autowired @Autowired
private OAuth2Provider provider; private OAuth2Provider provider;
@Autowired
private ProfileService profileService;
@Autowired @Autowired
private DoneService doneService; private DoneService doneService;
@ -68,7 +66,6 @@ public class DoneController extends CommonController {
model.addAttribute("moduleList", doneService.getModules(false)); model.addAttribute("moduleList", doneService.getModules(false));
model.addAttribute("jobList", doneService.getJobs(false)); model.addAttribute("jobList", doneService.getJobs(false));
model.addAttribute("billingList", doneService.getBillings(false)); model.addAttribute("billingList", doneService.getBillings(false));
model.addAttribute("theme", profileService.getTheme(username));
model.addAttribute("favorites", doneService.getFavorites(username)); model.addAttribute("favorites", doneService.getFavorites(username));
return "done/list"; return "done/list";
} }
@ -96,13 +93,11 @@ public class DoneController extends CommonController {
} }
private String toItem(DoneBean bean, Model model) { private String toItem(DoneBean bean, Model model) {
String username = provider.getName();
model.addAttribute("doneBean", bean); model.addAttribute("doneBean", bean);
model.addAttribute("projectList", doneService.getProjects(true)); model.addAttribute("projectList", doneService.getProjects(true));
model.addAttribute("moduleList", doneService.getModules(true)); model.addAttribute("moduleList", doneService.getModules(true));
model.addAttribute("jobList", doneService.getJobs(true)); model.addAttribute("jobList", doneService.getJobs(true));
model.addAttribute("billingList", doneService.getBillings(true)); model.addAttribute("billingList", doneService.getBillings(true));
model.addAttribute("theme", profileService.getTheme(username));
return "done/item"; return "done/item";
} }
@ -210,4 +205,11 @@ public class DoneController extends CommonController {
model.addAttribute("bean", doneService.getSlot(id, username)); model.addAttribute("bean", doneService.getSlot(id, username));
return "/done/slot/item"; return "/done/slot/item";
} }
@RolesAllowed("timetrack_user")
@GetMapping("/done/slot/add")
public String addSlot(@RequestParam("day") LocalDate day, Model model) {
model.addAttribute("bean", SlotBean.of(day));
return "/done/slot/item";
}
} }

View File

@ -10,14 +10,11 @@ import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import de.jottyfan.timetrack.component.OAuth2Provider;
import de.jottyfan.timetrack.db.note.enums.EnumCategory; import de.jottyfan.timetrack.db.note.enums.EnumCategory;
import de.jottyfan.timetrack.db.note.enums.EnumNotetype; import de.jottyfan.timetrack.db.note.enums.EnumNotetype;
import de.jottyfan.timetrack.modules.CommonController; import de.jottyfan.timetrack.modules.CommonController;
import de.jottyfan.timetrack.modules.profile.ProfileService;
import jakarta.annotation.security.RolesAllowed; import jakarta.annotation.security.RolesAllowed;
/** /**
@ -28,27 +25,19 @@ import jakarta.annotation.security.RolesAllowed;
@Controller @Controller
public class NoteController extends CommonController { public class NoteController extends CommonController {
@Autowired
private OAuth2Provider provider;
@Autowired
private ProfileService profileService;
@Autowired @Autowired
private NoteService noteService; private NoteService noteService;
@RolesAllowed("timetrack_user") @RolesAllowed("timetrack_user")
@RequestMapping(value = "/note/list") @GetMapping("/note/list")
public String getList(Model model) { public String getList(Model model) {
String username = provider.getName();
List<NoteBean> list = noteService.getList(); List<NoteBean> list = noteService.getList();
model.addAttribute("noteList", list); model.addAttribute("noteList", list);
model.addAttribute("theme", profileService.getTheme(username));
return "note/list"; return "note/list";
} }
@RolesAllowed("timetrack_user") @RolesAllowed("timetrack_user")
@RequestMapping(value = "/note/add", method = RequestMethod.GET) @GetMapping("/note/add")
public String toAdd(Model model, OAuth2AuthenticationToken token) { public String toAdd(Model model, OAuth2AuthenticationToken token) {
return toItem(null, model); return toItem(null, model);
} }
@ -56,7 +45,6 @@ public class NoteController extends CommonController {
@RolesAllowed("timetrack_user") @RolesAllowed("timetrack_user")
@GetMapping("/note/edit/{id}") @GetMapping("/note/edit/{id}")
public String toItem(@PathVariable Integer id, Model model) { public String toItem(@PathVariable Integer id, Model model) {
String username = provider.getName();
NoteBean bean = noteService.getBean(id); NoteBean bean = noteService.getBean(id);
if (bean == null) { if (bean == null) {
bean = new NoteBean(); // the add case bean = new NoteBean(); // the add case
@ -64,12 +52,11 @@ public class NoteController extends CommonController {
model.addAttribute("noteBean", bean); model.addAttribute("noteBean", bean);
model.addAttribute("types", Arrays.asList(EnumNotetype.values())); model.addAttribute("types", Arrays.asList(EnumNotetype.values()));
model.addAttribute("categories", Arrays.asList(EnumCategory.values())); model.addAttribute("categories", Arrays.asList(EnumCategory.values()));
model.addAttribute("theme", profileService.getTheme(username));
return "note/item"; return "note/item";
} }
@RolesAllowed("timetrack_user") @RolesAllowed("timetrack_user")
@RequestMapping(value = "/note/upsert", method = RequestMethod.POST) @PostMapping("/note/upsert")
public String doUpsert(Model model, @ModelAttribute NoteBean bean, OAuth2AuthenticationToken token) { public String doUpsert(Model model, @ModelAttribute NoteBean bean, OAuth2AuthenticationToken token) {
Integer amount = noteService.doUpsert(bean); Integer amount = noteService.doUpsert(bean);
return amount.equals(1) ? getList(model) : toItem(bean.getPk(), model); return amount.equals(1) ? getList(model) : toItem(bean.getPk(), model);

View File

@ -3,9 +3,7 @@ package de.jottyfan.timetrack.modules.profile;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import de.jottyfan.timetrack.component.OAuth2Provider; import de.jottyfan.timetrack.component.OAuth2Provider;
import de.jottyfan.timetrack.modules.CommonController; import de.jottyfan.timetrack.modules.CommonController;
@ -23,7 +21,7 @@ public class ProfileController extends CommonController {
@Autowired @Autowired
private ProfileService service; private ProfileService service;
@RequestMapping(value = "/profile/{theme}", method = RequestMethod.POST) @PostMapping("/profile/{theme}")
public String setTheme(@PathVariable String theme) { public String setTheme(@PathVariable String theme) {
String username = provider.getName(); String username = provider.getName();
service.setTheme(username, theme); service.setTheme(username, theme);

View File

@ -249,11 +249,11 @@
<div class="container"> <div class="container">
<div class="row row-weekday"> <div class="row row-weekday">
<div class="col">Sonntag</div> <div class="col">Sonntag</div>
<div class="col">Montag</div> <div class="col boldy">Montag</div>
<div class="col">Dienstag</div> <div class="col boldy">Dienstag</div>
<div class="col">Mittwoch</div> <div class="col boldy">Mittwoch</div>
<div class="col">Donnerstag</div> <div class="col boldy">Donnerstag</div>
<div class="col">Freitag</div> <div class="col boldy">Freitag</div>
<div class="col">Samstag</div> <div class="col">Samstag</div>
</div> </div>
<div class="row row-weekday"> <div class="row row-weekday">
@ -262,7 +262,7 @@
<span class="slot_badge_left" th:text="${#temporals.format(s.day, 'dd.MM.')}"> <span class="slot_badge_left" th:text="${#temporals.format(s.day, 'dd.MM.')}">
</span><a th:href="@{/done/slot/{id}(id=${s.id})}" class="slot_badge_middle" th:if="${s.id}"> </span><a th:href="@{/done/slot/{id}(id=${s.id})}" class="slot_badge_middle" th:if="${s.id}">
<i class="fas fa-pencil"></i> <i class="fas fa-pencil"></i>
</a><a th:href="@{/done/slot/add?day=${d}(d=${s.day})}" class="slot_badge_middle" th:unless="${s.id}"> </a><a th:href="@{/done/slot/add?day={d}(d=${s.day})}" class="slot_badge_middle" th:unless="${s.id}">
<i class="fas fa-plus"></i> <i class="fas fa-plus"></i>
</a> </a>
<span class="slot_badge_right boldy" th:text="${s.printTime()}" th:if="${s.id}"></span> <span class="slot_badge_right boldy" th:text="${s.printTime()}" th:if="${s.id}"></span>

View File

@ -6,6 +6,9 @@
</head> </head>
<body> <body>
<ul layout:fragment="menu"> <ul layout:fragment="menu">
<li class="nav-item" sec:authorize="hasRole('timetrack_user')">
<a class="nav-link btn btn-outline-primary btn-white-text" th:href="@{/done/list}">zur Arbeitszeit</a>
</li>
</ul> </ul>
<main layout:fragment="content"> <main layout:fragment="content">
<div class="container formpane"> <div class="container formpane">
@ -17,6 +20,8 @@
<div class="col-sm-3">vereinbarte Arbeitszeit</div> <div class="col-sm-3">vereinbarte Arbeitszeit</div>
<div class="col-sm-9" th:text="${bean.printTime()}"></div> <div class="col-sm-9" th:text="${bean.printTime()}"></div>
</div> </div>
TODO: Löschen<br />
TODO: Ersetzen durch Dienstbefreiung, Urlaub, Ausgleichstag/Überstunden, Krankheit oder sonstwas
</div> </div>
</main> </main>
</body> </body>