Skip to content

Commit

Permalink
CSCEXAM-1195 Change some dropdowns to typeaheads with reservation sea…
Browse files Browse the repository at this point in the history
…rchy

- also refactor the admin/teacher reservation components into one
  • Loading branch information
Matti Lupari committed Nov 17, 2023
1 parent a88753d commit f9f6c64
Show file tree
Hide file tree
Showing 16 changed files with 335 additions and 355 deletions.
28 changes: 20 additions & 8 deletions app/controllers/ReservationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> filter) {
User user = request.attrs().get(Attrs.AUTHENTICATED_USER);
PathProperties props = PathProperties.parse("(id, name)");
Query<Exam> q = DB.createQuery(Exam.class);
Expand All @@ -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
Expand All @@ -91,7 +94,8 @@ public Result getExams(Http.Request request) {
.eq("shared", true)
.endJunction();
}
return ok(el.findList(), props);
List<Exam> exams = el.findList();
return ok(exams, props);
}

@Restrict({ @Group("ADMIN") })
Expand Down Expand Up @@ -119,15 +123,23 @@ private ArrayNode asJson(List<User> users) {
}

@Restrict({ @Group("ADMIN"), @Group("TEACHER") })
public Result getStudents() {
List<User> students = DB.find(User.class).where().eq("roles.name", "STUDENT").findList();
public Result getStudents(Optional<String> filter) {
ExpressionList<User> 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<User> students = el.findList();
return ok(Json.toJson(asJson(students)));
}

@Restrict({ @Group("ADMIN") })
public Result getTeachers() {
List<User> teachers = DB.find(User.class).where().eq("roles.name", "TEACHER").findList();

public Result getTeachers(Optional<String> filter) {
ExpressionList<User> el = DB.find(User.class).where().eq("roles.name", "TEACHER");
if (filter.isPresent()) {
el = applyUserFilter(null, el.or(), filter.get()).endOr();
}
List<User> teachers = el.findList();
return ok(Json.toJson(asJson(teachers)));
}

Expand Down Expand Up @@ -155,7 +167,7 @@ public CompletionStage<Result> 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);
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/base/BaseController.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ protected <T> ExpressionList<T> applyUserFilter(String prefix, ExpressionList<T>
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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -71,10 +73,13 @@ Optional<URL> 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();
Expand Down
6 changes: 3 additions & 3 deletions conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ import { Component } from '@angular/core';

@Component({
selector: 'xm-admin-dashboard',
template: '<xm-admin-reservations></xm-admin-reservations>',
template: '<xm-reservations></xm-reservations>',
})
export class AdminDashboardComponent {}
1 change: 1 addition & 0 deletions ui/src/app/dashboard/staff/admin/admin-dashboard.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and limitations under the Licence.
*/
// TODO: maybe this module is redundant. Let's keep it anyway in case we want to lazy load admin stuff in the future
import { NgModule } from '@angular/core';
import { ReservationModule } from '../../../reservation/reservation.module';
import { SharedModule } from '../../../shared/shared.module';
Expand Down
6 changes: 3 additions & 3 deletions ui/src/app/dashboard/staff/staff-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { LanguageInspectionsComponent } from '../../maturity/language-inspection
import { MaturityReportingComponent } from '../../maturity/reporting/maturity-reporting.component';
import { QuestionComponent } from '../../question/basequestion/question.component';
import { LibraryComponent } from '../../question/library/library.component';
import { TeacherReservationComponent } from '../../reservation/teacher/teacher-reservations.component';
import { ReservationsComponent } from '../../reservation/reservations.component';
import { AssessmentComponent } from '../../review/assessment/assessment.component';
import { PrintedAssessmentComponent } from '../../review/assessment/print/printed-assessment.component';
import { SpeedReviewComponent } from '../../review/listing/speed-review.component';
Expand Down Expand Up @@ -152,8 +152,8 @@ const routes: Route[] = [
{ path: 'inspections', component: LanguageInspectionsComponent },
{ path: 'inspections/reports', component: MaturityReportingComponent },
{ path: 'adminexams', component: ExamListingComponent },
{ path: 'reservations', component: TeacherReservationComponent },
{ path: 'reservations/:eid', component: TeacherReservationComponent },
{ path: 'reservations', component: ReservationsComponent },
{ path: 'reservations/:eid', component: ReservationsComponent },
{ path: 'rooms', component: FacilityComponent },
{ path: 'rooms/:id', component: RoomComponent },
{ path: 'rooms/:id/availability', component: AvailabilityComponent },
Expand Down
118 changes: 0 additions & 118 deletions ui/src/app/reservation/admin/admin-reservations.component.html

This file was deleted.

22 changes: 0 additions & 22 deletions ui/src/app/reservation/admin/admin-reservations.component.ts

This file was deleted.

2 changes: 1 addition & 1 deletion ui/src/app/reservation/reservation-details.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import { Component, Input, OnChanges } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { ToastrService } from 'ngx-toastr';
import { ExamEnrolment } from '../enrolment/enrolment.model';
import { AnyReservation } from './reservation-base.component';
import type { Reservation } from './reservation.model';
import { ReservationService } from './reservation.service';
import { AnyReservation } from './reservations.component';

type ReservationDetail = Reservation & { org: { name: string; code: string }; userAggregate: string };

Expand Down
8 changes: 3 additions & 5 deletions ui/src/app/reservation/reservation.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,20 @@ import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { SharedModule } from '../shared/shared.module';
import { AdminReservationComponent } from './admin/admin-reservations.component';
import { ChangeMachineDialogComponent } from './admin/change-machine-dialog.component';
import { RemoveReservationDialogComponent } from './admin/remove-reservation-dialog.component';
import { ReservationDetailsComponent } from './reservation-details.component';
import { ReservationService } from './reservation.service';
import { TeacherReservationComponent } from './teacher/teacher-reservations.component';
import { ReservationsComponent } from './reservations.component';

@NgModule({
imports: [NgbModule, SharedModule, RouterModule],
exports: [AdminReservationComponent],
exports: [ReservationsComponent],
declarations: [
ChangeMachineDialogComponent,
RemoveReservationDialogComponent,
ReservationDetailsComponent,
AdminReservationComponent,
TeacherReservationComponent,
ReservationsComponent,
],
bootstrap: [ChangeMachineDialogComponent, RemoveReservationDialogComponent],
providers: [ReservationService],
Expand Down
Loading

0 comments on commit f9f6c64

Please sign in to comment.