1

Merge pull request #111 from hhu-propra2/lecture-parent-in-create

Lecture parent in create
This commit is contained in:
Talha Caliskan
2020-03-20 12:53:26 +01:00
committed by GitHub
7 changed files with 69 additions and 29 deletions

View File

@ -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());

View File

@ -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<User> users) throws EventException {
public void createOrga(Account account, String title, String description, Boolean visibility, Boolean lecture, Long userMaximum, Long parent, List<User> 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);

View File

@ -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<Group> getAllLecturesWithVisibilityPublic() throws EventException {
List<Event> eventsVisible = eventService.translateEventDTOs(eventRepository.findAllEventsOfGroups(eventRepository.findGroup_idsWhereVisibility(Boolean.TRUE)));
List<Group> visibleGroups = projectEventList(eventsVisible);
List<Group> 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.

View File

@ -67,15 +67,12 @@
type="checkbox">
<label class="custom-control-label" for="lecture">Veranstaltung</label>
</div>
<div class="form-group">
<label for="sel1"></label>
<select class="form-control" id="sel1">
<option disabled selected="true">--Bitte Veranstaltung auswählen--
<div class="form-group" id="lectureParent">
<label for="parent"></label>
<select class="form-control" id="parent" name="parent">
<option disabled selected="true">--Bitte Veranstaltung auswählen--</option>
<option th:each="lecture : ${lectures}" th:name="parent" th:value="${lecture.getId()}" th:text="${lecture.getTitle()}">
</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
</div>
<div class="form-group pt-4">
@ -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();
});
});
</script>
</main>
</body>

View File

@ -57,15 +57,12 @@
<label class="custom-control-label" for="visibility">Private
Gruppe</label>
</div>
<div class="form-group">
<label for="sel1"></label>
<select class="form-control" id="sel1">
<option disabled selected="true">--Bitte Veranstaltung auswählen--
<div class="form-group" id="lectureParent">
<label for="parent"></label>
<select class="form-control" id="parent" name="parent">
<option disabled selected="true">--Bitte Veranstaltung auswählen--</option>
<option th:each="lecture : ${lectures}" th:name="parent" th:value="${lecture.getId()}" th:text="${lecture.getTitle()}">
</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
</div>
<div class="form-group pt-4">

View File

@ -40,6 +40,8 @@
th:if="${group.getVisibility() == group.getVisibility().PUBLIC}">Öffentliche Gruppe</span>
<span class="badge badge-pill badge-success" style="background: lightseagreen"
th:if='${group.getType() == group.getType().LECTURE}'>Veranstaltung</span>
<span class="badge badge-pill badge-info" style="background: mediumorchid"
th:text="${parent.getTitle()}">Parent</span>
</h3>
<br>
<div class="shadow-sm p-4" style="background: white">

View File

@ -41,6 +41,8 @@
<span class="badge badge-pill badge-success"
style="background: lightseagreen"
th:if='${group.getType() == group.getType().LECTURE}'> Veranstaltung</span>
<span class="badge badge-pill badge-info" style="background: mediumorchid"
th:text="${parent.getTitle()}">Parent</span>
</h3>
<div class="shadow-sm p-4" style="background: white">
<p style="overflow-wrap: break-word"