diff --git a/src/models/rapla-middleware/icalgenerator/icalgenerator.service.ts b/src/models/rapla-middleware/icalgenerator/icalgenerator.service.ts index 2326480..07ad6b5 100644 --- a/src/models/rapla-middleware/icalgenerator/icalgenerator.service.ts +++ b/src/models/rapla-middleware/icalgenerator/icalgenerator.service.ts @@ -20,6 +20,14 @@ export const getiCalFile = async (user: string, file: string, showBlockers: bool iCalFile = removeBlockers(iCalFile); } + if (electiveModule !== '') { + iCalFile = removeElective(iCalFile, electiveModule); + } + + if (profileModule !== '') { + iCalFile = removeProfile(iCalFile, profileModule); + } + // Turn into one file again let resultingFile = serializeIcal(iCalFile); @@ -80,7 +88,75 @@ export const removeBlockers = function (ical: iCalFile): iCalFile { return ical; }; +export const removeElective = function (ical: iCalFile, chosenElective: string): iCalFile { + let remainingEvents: string[] = []; + + let electiveToRemove = electiveModules; + electiveToRemove.splice(parseInt(chosenElective), 1); + + ical.body.forEach((event) => { + let addEvent = true; + electiveToRemove.forEach((module) => { + if (event.includes(module.name)) { + addEvent = false; + } + }); + + if (addEvent) { + remainingEvents.push(event); + } + }); + + ical.body = remainingEvents; + + return ical; +}; + +export const removeProfile = function (ical: iCalFile, chosenProfile: string): iCalFile { + let remainingEvents: string[] = []; + + let profileToRemove = profileModules; + profileToRemove.splice(parseInt(chosenProfile), 1); + + ical.body.forEach((event) => { + let addEvent = true; + profileToRemove.forEach((module) => { + module.names.forEach((name) => { + if (event.includes(name)) { + addEvent = false; + } + }); + }); + + if (addEvent) { + remainingEvents.push(event); + } + }); + + ical.body = remainingEvents; + + return ical; +}; + export interface iCalFile { head: string; body: string[]; } + +let electiveModules = [ + {name: 'ERP-Systeme'}, + {name: 'Ethik für Informatiker'}, + {name: 'Evolutionäre Algorithmen'}, + {name: 'Forensik'}, + {name: 'Kryptographische Verfahren'}, + {name: 'Anwendung der Robotik'}, + {name: 'Web-Services'} +]; + +let profileModules = [ + {names: ['.Grundlagen der KI (KI und BV)', 'Bildverarbeitung (KI und BV)']}, + {names: ['Bildverarbeitung', 'Computergraphik']}, + {names: ['Interaktive Systeme', 'Grundlagen der KI']}, + {names: ['e Business', 'angewandtes Projektmanagement']}, + {names: ['Kommunikations und Netztechnik II']} +];