Skip to content
Snippets Groups Projects
Commit 2b4a0711 authored by Chris Lemaire's avatar Chris Lemaire
Browse files

Fix model for rooms and assistants on request table

- Fixes rooms by only showing rooms used in the list of current labs.
- Fixes courses by only showing courses from current labs.
- Fixes assistants in the model by adding them to the model.
parent ef42adbf
No related branches found
No related tags found
No related merge requests found
......@@ -184,6 +184,13 @@ public class Course implements Serializable {
.collect(Collectors.toList());
}
public List<User> getRequestHandlers() {
return roles.stream()
.filter(r -> r instanceof Assistant || r instanceof Manager || r instanceof Teacher)
.map(Role::getUser)
.collect(Collectors.toList());
}
public List<User> getAssistants() {
return roles.stream()
.filter(r -> r instanceof Assistant)
......
......@@ -172,7 +172,7 @@ public class RequestTableService {
}));
// Add the created model attributes
addToModel(model, courses, activeLabs, filteredRequests, filters);
addToModel(model, activeLabs, filteredRequests, filters);
model.addAttribute("queued", queueCount);
}
......@@ -203,7 +203,8 @@ public class RequestTableService {
List<Course> courses = user.getParticipates();
List<Lab> labs = labs(courses);
List<Group> groups = courses.stream().filter(Course::getHasGroups)
List<Group> groups = courses.stream()
.filter(Course::getHasGroups)
.flatMap(c -> c.getGroups().stream())
.filter(g -> g.hasMember(user))
.collect(Collectors.toList());
......@@ -217,30 +218,47 @@ public class RequestTableService {
(currentGroup.or(currentUser)).and(predicate), pageable);
// Add the created model attributes
addToModel(model, courses, labs, filteredRequests, filters);
addToModel(model, labs, filteredRequests, filters);
}
/**
* Adds the given information to the model using the variable names used in the "request/list.html" page.
*
* @param model The model to The model to add attributes to.
* @param courses The courses that should be displayed in filters.
* @param labs The labs that should be displayed in filters.
* @param requests The requests that should be displayed on the page.
* @param filters The state of the page.
* @param filters The state of the filters.
*/
private void addToModel(Model model,
List<Course> courses,
List<Lab> labs,
Page<Request> requests,
Object filters) {
addDefaultModelAttributes(model);
List<Room> rooms = labs.stream()
.flatMap(lab -> lab.getRooms().stream())
.distinct()
.collect(Collectors.toList());
// Fetch the courses from the given list of labs to make sure only currently active
// or relevant courses are shown.
List<Course> courses = labs.stream()
.map(Lab::getCourse)
.distinct()
.collect(Collectors.toList());
List<User> assistants = courses.stream()
.flatMap(course -> course.getRequestHandlers().stream())
.distinct()
.collect(Collectors.toList());
model
.addAttribute("rooms", rooms)
.addAttribute("requestTypes", requestTypeRepository.findAll())
.addAttribute("courses", courses)
.addAttribute("activeLabs", labs)
.addAttribute("requests", requests)
.addAttribute("state", filters)
.addAttribute("assignments", assignments(labs));
.addAttribute("assignments", assignments(labs))
.addAttribute("assistants", assistants);
}
/**
......@@ -265,17 +283,6 @@ public class RequestTableService {
.orElse(new LinkedMultiValueMap<>());
}
/**
* Adds the attributes that can be filled in without context of the request table view to the given Model.
* These attributes can be rooms and requestTypes because we simply select all of them.
*
* @param model The model to add attributes to.
*/
private void addDefaultModelAttributes(Model model) {
model.addAttribute("rooms", roomRepository.findAllByOrderByNameAsc());
model.addAttribute("requestTypes", requestTypeRepository.findAll());
}
/**
* Flatmaps a list of courses to a list of labs.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment