diff --git a/app/controllers/ReservationController.java b/app/controllers/ReservationController.java index 41720d3f82..6a46340f1f 100644 --- a/app/controllers/ReservationController.java +++ b/app/controllers/ReservationController.java @@ -71,7 +71,7 @@ public class ReservationController extends BaseController { @Authenticated @Restrict({ @Group("ADMIN"), @Group("TEACHER") }) - public Result getExams(Http.Request request) { + public Result getExams(Http.Request request, Optional filter) { User user = request.attrs().get(Attrs.AUTHENTICATED_USER); PathProperties props = PathProperties.parse("(id, name)"); Query q = DB.createQuery(Exam.class); @@ -80,6 +80,9 @@ public Result getExams(Http.Request request) { .where() .isNull("parent") // only Exam prototypes .eq("state", Exam.State.PUBLISHED); + if (filter.isPresent()) { + el = el.ilike("name", String.format("%%%s%%", filter.get())); + } if (user.hasRole(Role.Name.TEACHER)) { el = el @@ -91,7 +94,8 @@ public Result getExams(Http.Request request) { .eq("shared", true) .endJunction(); } - return ok(el.findList(), props); + List exams = el.findList(); + return ok(exams, props); } @Restrict({ @Group("ADMIN") }) @@ -119,15 +123,23 @@ private ArrayNode asJson(List users) { } @Restrict({ @Group("ADMIN"), @Group("TEACHER") }) - public Result getStudents() { - List students = DB.find(User.class).where().eq("roles.name", "STUDENT").findList(); + public Result getStudents(Optional filter) { + ExpressionList el = DB.find(User.class).where().eq("roles.name", "STUDENT"); + if (filter.isPresent()) { + el = el.or().ilike("userIdentifier", String.format("%%%s%%", filter.get())); + el = applyUserFilter(null, el, filter.get()).endOr(); + } + List students = el.findList(); return ok(Json.toJson(asJson(students))); } @Restrict({ @Group("ADMIN") }) - public Result getTeachers() { - List teachers = DB.find(User.class).where().eq("roles.name", "TEACHER").findList(); - + public Result getTeachers(Optional filter) { + ExpressionList el = DB.find(User.class).where().eq("roles.name", "TEACHER"); + if (filter.isPresent()) { + el = applyUserFilter(null, el.or(), filter.get()).endOr(); + } + List teachers = el.findList(); return ok(Json.toJson(asJson(teachers))); } @@ -155,7 +167,7 @@ public CompletionStage removeReservation(long id, Http.Request request) } Reservation reservation = enrolment.getReservation(); - // Lets not send emails about historical reservations + // Let's not send emails about historical reservations if (reservation.getEndAt().isAfter(DateTime.now())) { User student = enrolment.getUser(); emailComposer.composeReservationCancellationNotification(student, reservation, msg, false, enrolment); diff --git a/app/controllers/base/BaseController.java b/app/controllers/base/BaseController.java index c16b79b125..c8e50779c0 100644 --- a/app/controllers/base/BaseController.java +++ b/app/controllers/base/BaseController.java @@ -95,7 +95,7 @@ protected ExpressionList applyUserFilter(String prefix, ExpressionList String fnField = prefix == null ? "firstName" : String.format("%s.firstName", prefix); String lnField = prefix == null ? "lastName" : String.format("%s.lastName", prefix); if (rawFilter.contains(" ")) { - // Possible that user provided us two names. Lets try out some combinations of first and last names + // Possible that user provided us two names. Let's try out some combinations of first and last names String name1 = rawFilter.split(" ")[0]; String name2 = rawFilter.split(" ")[1]; result = diff --git a/app/controllers/iop/collaboration/impl/CollaborationController.java b/app/controllers/iop/collaboration/impl/CollaborationController.java index 1d981d8689..c3526e4b04 100644 --- a/app/controllers/iop/collaboration/impl/CollaborationController.java +++ b/app/controllers/iop/collaboration/impl/CollaborationController.java @@ -13,6 +13,8 @@ import java.net.MalformedURLException; import java.net.URI; import java.net.URL; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Map; import java.util.Optional; @@ -71,10 +73,13 @@ Optional parseUrlWithSearchParam(String filter, boolean anonymous) { if (filter == null) { return Optional.empty(); } - - String paramStr = String.format("?filter=%s&anonymous=%s", filter, anonymous); - String url = String.format("%s/api/exams/search%s", configReader.getIopHost(), paramStr); - return Optional.of(URI.create(url).toURL()); + String paramStr = String.format( + "filter=%s&anonymous=%s", + URLEncoder.encode(filter, StandardCharsets.UTF_8), + anonymous + ); + URI uri = URI.create(String.format("%s/api/exams/search?%s", configReader.getIopHost(), paramStr)); + return Optional.of(uri.toURL()); } catch (MalformedURLException e) { logger.error("Malformed URL", e); return Optional.empty(); diff --git a/conf/routes b/conf/routes index a20e7c42bd..f2ad8db502 100644 --- a/conf/routes +++ b/conf/routes @@ -221,10 +221,10 @@ GET /app/accessibility controlle GET /app/draft/rooms controllers.RoomController.createExamRoomDraft -GET /app/reservations/students controllers.ReservationController.getStudents -GET /app/reservations/teachers controllers.ReservationController.getTeachers +GET /app/reservations/students controllers.ReservationController.getStudents(filter: java.util.Optional[String]) +GET /app/reservations/teachers controllers.ReservationController.getTeachers(filter: java.util.Optional[String]) GET /app/reservations/examrooms controllers.ReservationController.getExamRooms -GET /app/reservations/exams controllers.ReservationController.getExams(request: Request) +GET /app/reservations/exams controllers.ReservationController.getExams(request: Request, filter: java.util.Optional[String]) GET /app/reservations controllers.ReservationController.getReservations(state: java.util.Optional[String], ownerId: java.util.Optional[java.lang.Long], studentId: java.util.Optional[java.lang.Long], roomId: java.util.Optional[java.lang.Long], machineId: java.util.Optional[java.lang.Long], examId: java.util.Optional[java.lang.Long], start: java.util.Optional[String], end: java.util.Optional[String], externalRef: java.util.Optional[String], request: Request) GET /app/events controllers.ReservationController.getExaminationEvents(state: java.util.Optional[String], ownerId: java.util.Optional[java.lang.Long], studentId: java.util.Optional[java.lang.Long], examId: java.util.Optional[java.lang.Long], start: java.util.Optional[String], end: java.util.Optional[String], request: Request) DELETE /app/reservations/:id controllers.ReservationController.removeReservation(id: Long, request: Request) diff --git a/ui/src/app/reservation/admin/admin-reservations.component.html b/ui/src/app/reservation/admin/admin-reservations.component.html index 701614e687..42fc52cd39 100644 --- a/ui/src/app/reservation/admin/admin-reservations.component.html +++ b/ui/src/app/reservation/admin/admin-reservations.component.html @@ -8,53 +8,93 @@
-
+
- {{ 'sitnet_student' | translate }} - - + +
+ + +
- {{ 'sitnet_exam' | translate }} - - + +
+ + +
- {{ 'sitnet_begin' | translate }} - + +
- {{ 'sitnet_end' | translate }} - + +
-
+
- {{ 'sitnet_exam_owners' | translate }} - - + +
+ + +
- {{ 'sitnet_room' | translate }} +
- {{ 'sitnet_exam_machine' | translate }} +
- {{ 'sitnet_exam_state' | translate }} +
-
+
- {{ 'sitnet_begin' | translate }} - + +
- {{ 'sitnet_end' | translate }} - + +
- {{ 'sitnet_student' | translate }} - - + +
+ + +
- {{ 'sitnet_exam' | translate }} - - + +
+ + +
- {{ 'sitnet_exam_state' | translate }} + { {{ selected?.label || placeholder | translate }}