Skip to content

Commit

Permalink
Duplicate the events students route for tests & dashboard #712 #713
Browse files Browse the repository at this point in the history
  • Loading branch information
hupf committed Dec 17, 2024
1 parent e356872 commit 6015591
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ describe("DashboardTimetableComponent", () => {
let link = rows[0].querySelector("td.subject a");
expect(link?.textContent?.trim()).toBe("Mathematik, 9a");
expect(link?.getAttribute("href")).toBe(
"/events/current/10?returnlink=%252Fdashboard",
"/dashboard/students/10?returnlink=%252Fdashboard",
);

expect(rows[0].querySelector("td.study-class")?.textContent).toContain(
Expand All @@ -192,7 +192,7 @@ describe("DashboardTimetableComponent", () => {
link = rows[1].querySelector("td.subject a");
expect(link?.textContent?.trim()).toBe("Zeichnen, 8c");
expect(link?.getAttribute("href")).toBe(
"/events/current/20?returnlink=%252Fdashboard",
"/dashboard/students/20?returnlink=%252Fdashboard",
);

expect(rows[1].querySelector("td.study-class")?.textContent).toContain(
Expand Down
7 changes: 6 additions & 1 deletion src/app/dashboard/dashboard.routes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Routes } from "@angular/router";
import { getStudentsRoute } from "../events/events.routes";
import { dossierRoute } from "../shared/components/student-dossier/dossier-route";
import { DashboardLayoutComponent } from "./components/dashboard-layout/dashboard-layout.component";
import { DashboardComponent } from "./components/dashboard/dashboard.component";
Expand All @@ -7,6 +8,10 @@ export const DASHBOARD_ROUTES: Routes = [
{
path: "",
component: DashboardComponent,
children: [{ path: "", component: DashboardLayoutComponent }, dossierRoute],
children: [
{ path: "", component: DashboardLayoutComponent },
dossierRoute,
getStudentsRoute("students/:id"),
],
},
];
23 changes: 14 additions & 9 deletions src/app/events/events.routes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Routes } from "@angular/router";
import { Route, Routes } from "@angular/router";
import { dossierRoute } from "../shared/components/student-dossier/dossier-route";
import { EventsCurrentListComponent } from "./components/events-current-list/events-current-list.component";
import { EventsCurrentComponent } from "./components/events-current/events-current.component";
Expand All @@ -11,6 +11,17 @@ import { TestsEditComponent } from "./components/tests-edit/tests-edit.component
import { TestsListComponent } from "./components/tests-list/tests-list.component";
import { TestsComponent } from "./components/tests/tests.component";

export function getStudentsRoute(path: string): Route {
return {
path,
component: EventsStudentsComponent,
children: [
{ path: "", component: EventsStudentsListComponent },
dossierRoute,
],
};
}

export const EVENTS_ROUTES: Routes = [
{
path: "",
Expand All @@ -25,14 +36,7 @@ export const EVENTS_ROUTES: Routes = [
component: EventsCurrentComponent,
children: [
{ path: "", component: EventsCurrentListComponent },
{
path: ":id",
component: EventsStudentsComponent,
children: [
{ path: "", component: EventsStudentsListComponent },
dossierRoute,
],
},
getStudentsRoute(":id"),
],
},
{
Expand All @@ -43,6 +47,7 @@ export const EVENTS_ROUTES: Routes = [
path: "tests",
component: TestsListComponent,
},
getStudentsRoute("students"),
],
},
{
Expand Down
14 changes: 7 additions & 7 deletions src/app/events/services/events-state.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe("EventsStateService", () => {
{
id: 5,
designation: "22a",
detailLink: "/events/current/5?returnlink=%2F",
detailLink: "/events/5/students?returnlink=%2F",
studentCount: 0,
state: null,
},
Expand All @@ -92,7 +92,7 @@ describe("EventsStateService", () => {
{
id: 6,
designation: "22b",
detailLink: "/events/current/6?returnlink=%2F",
detailLink: "/events/6/students?returnlink=%2F",
studentCount: 0,
state: EventState.Rating,
evaluationText: "events.state.rating",
Expand Down Expand Up @@ -156,7 +156,7 @@ describe("EventsStateService", () => {
const courseEvent: EventEntry = {
id: 1,
designation: "Physik, 22a, 22b",
detailLink: "/events/current/1?returnlink=%2F",
detailLink: "/events/1/students?returnlink=%2F",
dateFrom: new Date("2022-02-09T00:00:00"),
dateTo: new Date("2022-06-30T00:00:00"),
studentCount: 20,
Expand All @@ -170,7 +170,7 @@ describe("EventsStateService", () => {
...courseEvent,
id: 2,
designation: "Bio, 22a",
detailLink: "/events/current/2?returnlink=%2F",
detailLink: "/events/2/students?returnlink=%2F",
state: EventState.RatingUntil,
evaluationText: "events.state.rating-until 03.06.2022",
evaluationLink: "link-to-evaluation-module/2",
Expand All @@ -179,7 +179,7 @@ describe("EventsStateService", () => {
...courseEvent,
id: 4,
designation: "Franz, 22a, 22b",
detailLink: "/events/current/4?returnlink=%2F",
detailLink: "/events/4/students?returnlink=%2F",
state: EventState.Tests,
evaluationText: "events.state.add-tests",
},
Expand All @@ -188,7 +188,7 @@ describe("EventsStateService", () => {
...courseEvent,
id: 3,
designation: "Zeichnen, 22b",
detailLink: "/events/current/3?returnlink=%2F",
detailLink: "/events/3/students?returnlink=%2F",
state: EventState.IntermediateRating,
evaluationText: "events.state.intermediate-rating",
evaluationLink: "link-to-evaluation-module/3",
Expand All @@ -214,7 +214,7 @@ describe("EventsStateService", () => {
id: 10,
designation: "Zentraler Gymnasialer Bildungsgang",
studentCount: 3,
detailLink: "/events/current/10?returnlink=%2F",
detailLink: "/events/10/students?returnlink=%2F",
state: null,
},
];
Expand Down
11 changes: 9 additions & 2 deletions src/app/events/services/events-students-state.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,15 @@ export type PrimarySortKey = "name";
providedIn: "root",
})
export class EventsStudentsStateService {
private eventId$ = this.route.paramMap.pipe(
map((params) => Number(params.get("id"))),
private eventId$ = combineLatest([
this.route.paramMap,
this.route.parent?.paramMap ?? of(null),
]).pipe(
map(([params, parentParams]) =>
// In the tests module, we have to look at the parent route's params to
// get the ID
Number(params.get("id") || parentParams?.get("id")),
),
);
private eventTypeId = toSignal(
this.eventId$.pipe(switchMap(this.loadEventTypeId.bind(this))),
Expand Down
13 changes: 8 additions & 5 deletions src/app/events/utils/events-students.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ import {

export function getEventsStudentsLink(
eventId: number,
returnLink?: string,
returnLink: string,
): string {
const query = new URLSearchParams(
returnLink ? { returnlink: returnLink } : {},
);
return `/events/current/${eventId}?${query}`;
const query = new URLSearchParams({ returnlink: returnLink });
if (returnLink.startsWith("/dashboard")) {
return `/dashboard/students/${eventId}?${query}`;
} else if (returnLink.startsWith("/events/current")) {
return `/events/current/${eventId}?${query}`;
}
return `/events/${eventId}/students?${query}`;
}

export function convertCourseToStudentEntries(course: Course): StudentEntries {
Expand Down

0 comments on commit 6015591

Please sign in to comment.