From a0451c0d610213575e426bb4ef805566a113c7ea Mon Sep 17 00:00:00 2001 From: Samuele Musiani Date: Fri, 7 Jun 2024 14:40:42 +0200 Subject: [PATCH] chore: new degrees config format (#285) --- src/config | 2 +- src/lib/const.ts | 1 + src/lib/teachings.ts | 32 ++++++++++++-------- src/routes/+page.svelte | 2 +- src/routes/[...dir]/[zfile=dir]/+page.svelte | 27 ++++++----------- src/routes/build/+page.svelte | 13 ++++---- src/routes/dash/[course]/+page.svelte | 19 ++++++------ src/routes/dash/[course]/ListTeaching.svelte | 3 +- 8 files changed, 51 insertions(+), 48 deletions(-) diff --git a/src/config b/src/config index 4c736544..7884d1b4 160000 --- a/src/config +++ b/src/config @@ -1 +1 @@ -Subproject commit 4c736544471b1f6d855e29db61a08509b0a9b237 +Subproject commit 7884d1b4a727672cbe45b1e6828bf2cb30380a9f diff --git a/src/lib/const.ts b/src/lib/const.ts index d978257f..2d2be50a 100644 --- a/src/lib/const.ts +++ b/src/lib/const.ts @@ -17,3 +17,4 @@ export const EDIT_URLS = (path: string) => { github_dev: `${GH_DEV_BASE_URL}/${repo}/blob/main/${filePath}` }; }; +export const MAX_YEARS_FOR_DEGREE = 3; diff --git a/src/lib/teachings.ts b/src/lib/teachings.ts index 09419c3c..a659af85 100644 --- a/src/lib/teachings.ts +++ b/src/lib/teachings.ts @@ -10,21 +10,22 @@ export type Teaching = { degree?: string; }; -export type YearStudyDiagram = { - mandatory?: string[]; - electives?: string[]; -}; - export type Year = { year: number; chat?: string; - teachings: YearStudyDiagram; +}; + +export type DegreeTeaching = { + name: string; + year?: number; + mandatory: boolean; }; export type Degree = { id: string; name: string; icon: string; + teachings?: DegreeTeaching[]; years?: Year[]; chat?: string; }; @@ -42,11 +43,18 @@ export async function isTeachingActive(fetch: typeof window.fetch, teaching: Tea return isTeachingActiveFromName(fetch, teaching.url); } -export function yearToFlatTeachings(y: Year): string[] { +export function teachingsFilter(d: Degree, year?: number, mandatory?: boolean): string[] { let res: string[] = []; - const studyDiagram = y.teachings; - if (studyDiagram.mandatory) res = res.concat(studyDiagram.mandatory); - if (studyDiagram.electives) res = res.concat(studyDiagram.electives); + + d.teachings?.forEach((x) => { + if ( + (year == undefined || (x.year && x.year == year) || (!x.year && year == 0)) && + (mandatory == undefined || x.mandatory == mandatory) + ) { + res = res.concat(x.name); + } + }); + return res; } @@ -54,9 +62,9 @@ export async function getActiveTeachings( fetch: typeof window.fetch, degree: Degree ): Promise { - const years = degree.years; + const years = degree.teachings; if (!years) return []; - const allTeachings = years.flatMap(yearToFlatTeachings); + const allTeachings = teachingsFilter(degree); const activeTeachings = await filterAsync(allTeachings, (t) => isTeachingActiveFromName(fetch, t) ); diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 5f9dbe5b..d4b4bcc9 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -57,7 +57,7 @@