diff --git a/src/main/java/mops/gruppen2/controller/Gruppen2Controller.java b/src/main/java/mops/gruppen2/controller/Gruppen2Controller.java index 6946481..bea3010 100644 --- a/src/main/java/mops/gruppen2/controller/Gruppen2Controller.java +++ b/src/main/java/mops/gruppen2/controller/Gruppen2Controller.java @@ -75,7 +75,9 @@ public class Gruppen2Controller { @RolesAllowed({"ROLE_orga", "ROLE_actuator)"}) @GetMapping("/createOrga") public String createOrga(KeycloakAuthenticationToken token, Model model) { - model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token)); + Account account = keyCloakService.createAccountFromPrincipal(token); + model.addAttribute("account", account); + model.addAttribute("lectures", groupService.getAllLecturesWithVisibilityPublic()); return "createOrga"; } @@ -87,6 +89,7 @@ public class Gruppen2Controller { @RequestParam(value = "visibility", required = false) Boolean visibility, @RequestParam(value = "lecture", required = false) Boolean lecture, @RequestParam("userMaximum") Long userMaximum, + @RequestParam(value = "parent", required = false) Long parent, @RequestParam(value = "file", required = false) MultipartFile file) throws IOException, EventException { Account account = keyCloakService.createAccountFromPrincipal(token); @@ -99,9 +102,11 @@ public class Gruppen2Controller { } } visibility = visibility == null; - lecture = lecture == null; + lecture = lecture != null; - controllerService.createOrga(account, title, description, visibility, lecture, userMaximum, userList); + if (lecture) parent = null; + + controllerService.createOrga(account, title, description, visibility, lecture, userMaximum, parent, userList); return "redirect:/gruppen2/"; } @@ -109,7 +114,9 @@ public class Gruppen2Controller { @RolesAllowed({"ROLE_studentin"}) @GetMapping("/createStudent") public String createStudent(KeycloakAuthenticationToken token, Model model) { - model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token)); + Account account = keyCloakService.createAccountFromPrincipal(token); + model.addAttribute("account", account); + model.addAttribute("lectures", groupService.getAllLecturesWithVisibilityPublic()); return "createStudent"; } @@ -119,11 +126,12 @@ public class Gruppen2Controller { @RequestParam("title") String title, @RequestParam("description") String description, @RequestParam(value = "visibility", required = false) Boolean visibility, - @RequestParam("userMaximum") Long userMaximum) throws EventException { + @RequestParam("userMaximum") Long userMaximum, + @RequestParam(value = "parent", required = false) Long parent) throws EventException { Account account = keyCloakService.createAccountFromPrincipal(token); visibility = visibility == null; - controllerService.createGroup(account, title, description, visibility, userMaximum); + controllerService.createGroup(account, title, description, visibility, userMaximum, parent); return "redirect:/gruppen2/"; } @@ -164,7 +172,14 @@ public class Gruppen2Controller { Group group = userService.getGroupById(groupId); Account account = keyCloakService.createAccountFromPrincipal(token); User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()); + Long parentId = group.getParent(); + Group parent = new Group(); + if (parentId != null) { + parent = userService.getGroupById(parentId); + } if (group != null) { + model.addAttribute("parentId", parentId); + model.addAttribute("parent", parent); model.addAttribute("group", group); model.addAttribute("roles", group.getRoles()); model.addAttribute("user", user); @@ -196,8 +211,15 @@ public class Gruppen2Controller { public String showGroupDetailsNoMember(KeycloakAuthenticationToken token, Model model, @RequestParam("id") Long groupId) throws EventException { model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token)); Group group = userService.getGroupById(groupId); + Long parentId = group.getParent(); + Group parent = new Group(); + if (parentId != null) { + parent = userService.getGroupById(parentId); + } if (group != null && group.getUserMaximum() > group.getMembers().size()) { model.addAttribute("group", group); + model.addAttribute("parentId", parentId); + model.addAttribute("parent", parent); return "detailsNoMember"; } throw new GroupNotFoundException(this.getClass().toString()); diff --git a/src/main/java/mops/gruppen2/service/ControllerService.java b/src/main/java/mops/gruppen2/service/ControllerService.java index d46e708..4d651d4 100644 --- a/src/main/java/mops/gruppen2/service/ControllerService.java +++ b/src/main/java/mops/gruppen2/service/ControllerService.java @@ -46,7 +46,7 @@ public class ControllerService { * @param title Gruppentitel * @param description Gruppenbeschreibung */ - public void createGroup(Account account, String title, String description, Boolean visibility, Long userMaximum) throws EventException { + public void createGroup(Account account, String title, String description, Boolean visibility, Long userMaximum, Long parent) throws EventException { Visibility visibility1; Long groupId = eventService.checkGroup(); @@ -57,7 +57,7 @@ public class ControllerService { createInviteLink(groupId); } - CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), null, GroupType.SIMPLE, visibility1, userMaximum); + CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), parent, GroupType.SIMPLE, visibility1, userMaximum); eventService.saveEvent(createGroupEvent); addUser(account, groupId); @@ -66,7 +66,7 @@ public class ControllerService { updateRole(account.getName(), groupId); } - public void createOrga(Account account, String title, String description, Boolean visibility, Boolean lecture, Long maximmum, List users) throws EventException { + public void createOrga(Account account, String title, String description, Boolean visibility, Boolean lecture, Long userMaximum, Long parent, List users) throws EventException { Visibility visibility1; Long groupId = eventService.checkGroup(); @@ -78,12 +78,12 @@ public class ControllerService { GroupType groupType; if (lecture) { - groupType = GroupType.SIMPLE; - } else { groupType = GroupType.LECTURE; + } else { + groupType = GroupType.SIMPLE; } - CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), null, groupType, visibility1, maximmum); + CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), parent, groupType, visibility1, userMaximum); eventService.saveEvent(createGroupEvent); addUser(account, groupId); diff --git a/src/main/java/mops/gruppen2/service/GroupService.java b/src/main/java/mops/gruppen2/service/GroupService.java index f7b5d62..fc9362c 100644 --- a/src/main/java/mops/gruppen2/service/GroupService.java +++ b/src/main/java/mops/gruppen2/service/GroupService.java @@ -1,6 +1,7 @@ package mops.gruppen2.service; import mops.gruppen2.domain.Group; +import mops.gruppen2.domain.GroupType; import mops.gruppen2.domain.User; import mops.gruppen2.domain.dto.EventDTO; import mops.gruppen2.domain.event.Event; @@ -96,6 +97,18 @@ public class GroupService { return removeUserGroups(visibleGroups, newGroups); } + public List getAllLecturesWithVisibilityPublic() throws EventException { + List eventsVisible = eventService.translateEventDTOs(eventRepository.findAllEventsOfGroups(eventRepository.findGroup_idsWhereVisibility(Boolean.TRUE))); + List visibleGroups = projectEventList(eventsVisible); + List visibleLectures = new ArrayList<>(); + for (Group group : visibleGroups) { + if (group.getType().equals(GroupType.LECTURE)) { + visibleLectures.add(group); + } + } + return visibleLectures; + } + /** * Filtert alle öffentliche Gruppen nach dem Suchbegriff und gibt diese als Liste von Gruppen zurück. diff --git a/src/main/resources/templates/createOrga.html b/src/main/resources/templates/createOrga.html index 35b06a9..d06692a 100644 --- a/src/main/resources/templates/createOrga.html +++ b/src/main/resources/templates/createOrga.html @@ -67,15 +67,12 @@ type="checkbox"> -
- - + + - - - -
@@ -107,6 +104,13 @@ var fileName = $(this).val().split("\\").pop(); $(this).siblings(".custom-file-label").addClass("selected").html(fileName); }); + + // Collapsing lectureParent if lecture is checked + $(document).ready(function () { + $('#lecture').change(function () { + $('#lectureParent').fadeToggle(); + }); + }); diff --git a/src/main/resources/templates/createStudent.html b/src/main/resources/templates/createStudent.html index 90777bc..ab750ea 100644 --- a/src/main/resources/templates/createStudent.html +++ b/src/main/resources/templates/createStudent.html @@ -57,15 +57,12 @@
-
- - + + - - - -
diff --git a/src/main/resources/templates/detailsMember.html b/src/main/resources/templates/detailsMember.html index 5d833de..ec34e6a 100644 --- a/src/main/resources/templates/detailsMember.html +++ b/src/main/resources/templates/detailsMember.html @@ -39,7 +39,9 @@ Öffentliche Gruppe Veranstaltung + th:if='${group.getType() == group.getType().LECTURE}'>Veranstaltung + Parent
diff --git a/src/main/resources/templates/detailsNoMember.html b/src/main/resources/templates/detailsNoMember.html index ece315e..be65b7f 100644 --- a/src/main/resources/templates/detailsNoMember.html +++ b/src/main/resources/templates/detailsNoMember.html @@ -41,6 +41,8 @@ Veranstaltung + Parent