diff --git a/anwendung/src/components/InputForm.jsx b/anwendung/src/components/InputForm.jsx
index ab3a494..0eacbeb 100644
--- a/anwendung/src/components/InputForm.jsx
+++ b/anwendung/src/components/InputForm.jsx
@@ -3,26 +3,11 @@ import {useRouter} from "next/router";
import {useEffect, useState} from "react";
import Background from "@/components/Background";
-let userInfo = []
+
+let userModuleMapping = new Map()
export default function InputForm(p) {
- class UserInfo {
- constructor(userid, modules) {
- this.userid = userid;
- this.module = modules;
- this.checked = false;
- }
-
- setChecked(checked) {
- this.checked = checked;
- }
-
- setModule(module) {
- this.module = module;
- }
- }
-
let startDateParam = "";
let endDateParam = "";
let courseNameParam = "";
@@ -53,8 +38,7 @@ export default function InputForm(p) {
}
useEffect(() => {
-
- userInfo = [];
+ userModuleMapping.clear()
getAllUsers();
}, [])
@@ -86,50 +70,112 @@ export default function InputForm(p) {
let method = p.courseName == null ? "POST" : "PUT";
+ let semesterid = localStorage.getItem("currentsid");
+ let tempsid = 0;
await fetch(url, {
method: method,
headers: {"Content-Type": "application/json"},
body: JSON.stringify(json)
- }).then(response => response.json()).then(semester => console.log(semester));
+ }).then(response => response.json()).then(semester => {tempsid = semester.id});
+ if(method === "POST")
+ {
+ semesterid = tempsid;
+ }
+
+ for(let [key, value] of userModuleMapping)
+ {
+ let json1 = {
+ "id": 0,
+ "userid": value.getUserid(),
+ "semesterid": semesterid,
+ "name": value.getModuleName(),
+ "activated": value.getActivated()
+ }
+
+ if(value.getChecked())
+ {
+ await fetch("http://localhost:8080/module?sessionid=" + localStorage.getItem("sessionid"), {
+ method: method,
+ headers: {"Content-Type": "application/json"},
+ body: JSON.stringify(json1)
+ })
+ }
+ }
+
router.back();
}
- function onModuleClicked(user, module) {
-
- let found = false;
-
- for (let i = 0; i < userInfo.length; i++) {
- let current = userInfo[i];
- if (current !== undefined && current.userid === user.id) {
- userInfo[i].setModule(module);
- found = true;
- }
+ class UserModuleInfo
+ {
+ constructor()
+ {
+ this.moduleName = "";
+ this.userid = 0;
+ this.activated = 0
+ this.checked = false
}
- if (!found) {
- userInfo.push(new UserInfo(user.id, module));
+ getModuleName() {return this.moduleName}
+ getUserid() {return this.userid}
+ getActivated() {return this.activated}
+ getChecked() {return this.checked}
+
+ setModuleName(name) {this.moduleName = name}
+ setUserid(id) {this.userid = id}
+ setActivated(a) {this.activated = a}
+ setChecked(b) {this.checked = b}
+ }
+
+ function onModuleClicked(user, module) {
+
+ if(userModuleMapping.has(user.id))
+ {
+ let temp = userModuleMapping.get(user.id)
+ temp.setModuleName(module)
+ temp.setUserid(user.id)
+ console.log("test")
+ }
+ else
+ {
+ let temp = new UserModuleInfo()
+ temp.setModuleName(module)
+ temp.setUserid(user.id)
+ userModuleMapping.set(user.id, temp)
+ console.log("test1")
}
}
- function onCheckBoxClicked(user, e) {
- onModuleClicked(user, "");
-
- let found = false;
-
- for (let i = 0; i < userInfo.length; i++) {
- let current = userInfo[i];
- if (current !== undefined && current.userid === user.id) {
- userInfo[i].setChecked(e.target.checked);
- found = true;
- }
+ function onSelectedCheckBox(user, state)
+ {
+ if(userModuleMapping.has(user.id))
+ {
+ userModuleMapping.get(user.id).setChecked(state.target.checked);
}
+ else
+ {
+ let temp = new UserModuleInfo()
+ temp.setChecked(state.target.checked)
+ temp.setUserid(user.id)
+ userModuleMapping.set(user.id, temp)
+ }
+ }
- if (!found) {
- let temp = new UserInfo(user.id, "");
- temp.setChecked(e.target.checked);
- userInfo.push(temp);
+ function onActivatedCheckBox(user, state)
+ {
+ if(userModuleMapping.has(user.id))
+ {
+ let t = state.target.checked ? 1 : 0;
+ userModuleMapping.get(user.id).setActivated(t);
+ }
+ else
+ {
+ let temp = new UserModuleInfo()
+ let t = state.target.checked ? 1 : 0;
+ temp.setActivated(t)
+ temp.setUserid(user.id)
+ userModuleMapping.set(user.id, temp)
}
}
@@ -209,7 +255,7 @@ export default function InputForm(p) {
flexDirection: "row",
justifyContent: "center",
}}> {
- onCheckBoxClicked(user, e);
+ onSelectedCheckBox(user, e)
}}/>
{
- onCheckBoxClicked(user, e);
+ onActivatedCheckBox(user, e);
}}/> |
{user.firstName + " " + user.lastName} |