Archived
Private
Public Access
1
0

finished schedule page + added substitution functions

This commit is contained in:
2023-04-29 14:01:27 +02:00
parent 20660cd746
commit 227af36c05
18 changed files with 584 additions and 11 deletions

View File

@@ -12,6 +12,27 @@ export class IServService {
public keys?: AuthKeys;
public backend: string = "http://localhost:5273";
public courseNames: {[id: string]: string} = {
["Bi"]: "Biologie",
["Ch"]: "Chemie",
["Ma"]: "Mathe",
["Ph"]: "Physik",
["De"]: "Deutsch",
["Ek"]: "Erdkunde",
["En"]: "Englisch",
["PW"]: "Politik",
["Sn"]: "Spanisch",
["If"]: "Informatik",
["Sp"]: "Sport",
["WN"]: "Werte und Normen",
["La"]: "Latein",
["Re"]: "Religion",
["Ge"]: "Geschichte",
["Ku"]: "Kunst",
["Sf"]: "Seminarfach",
["DS"]: "Darstellendes Spiel",
};
constructor(private client: HttpClient) {
const data = localStorage.getItem("userdata");
if (data != null) {
@@ -42,6 +63,11 @@ export class IServService {
}
}
public logout() {
delete this.userdata;
delete this.keys;
}
public async getKeys(): Promise<AuthKeys> {
const keys = await firstValueFrom(this.client.post<AuthKeys>(this.backend + "/iserv/login", this.userdata));
localStorage.setItem("keys", JSON.stringify(keys));
@@ -52,9 +78,34 @@ export class IServService {
try {
return (await firstValueFrom(this.client.post<{value: string[]}>(this.backend + "/iserv/groups?domain=" + this.userdata.domain, this.keys))).value;
} catch {
await this.getKeys();
return (await firstValueFrom(this.client.post<{value: string[]}>(this.backend + "/iserv/groups?domain=" + this.userdata.domain, this.keys))).value;
const keys = await this.getKeys();
return (await firstValueFrom(this.client.post<{value: string[]}>(this.backend + "/iserv/groups?domain=" + this.userdata.domain, keys))).value;
}
}
public async getCoursesAndClass(groups?: string[]): Promise<{class: string, courses: string[]}> {
if (groups == undefined) {
groups = await this.getGroups();
}
const result: {class: string, courses: string[]} = {class: undefined, courses: []};
const classNames = groups.filter(group => group.startsWith("Klasse ") && !group.includes("."));
if (classNames.length != 0) {
result.class = classNames[0].replace("Klasse ", "");
}else {
const grades = groups.filter(group => group.startsWith("Jahrgang ") && !group.includes("."));
if (grades.length != 0) {
result.class = grades[0].replace("Jahrgang ", "").toUpperCase();
}
}
for (let group of groups) {
if (!group.includes(".") || !group.toLowerCase().startsWith("q")) continue;
result.courses.push(group.split(".")[1]);
}
return result;
}
}