diff --git a/anwendung/src/components/InputForm.jsx b/anwendung/src/components/InputForm.jsx
index 0eacbeb..2f0c9be 100644
--- a/anwendung/src/components/InputForm.jsx
+++ b/anwendung/src/components/InputForm.jsx
@@ -22,26 +22,58 @@ export default function InputForm(p) {
const [endDate, setEndDate] = useState(endDateParam);
const [courseName, setCourseName] = useState(courseNameParam);
const [users, setUsers] = useState([]);
+ const [moduleInfos, setModuleInfos] = useState([])
+ const [checkedSelected, setCheckedSelected] = useState(new Array(100).fill(false))
+ const [activatedSelected, setActivatedSelected] = useState(new Array(100).fill(false))
async function getAllUsers() {
let sessionid = localStorage.getItem("sessionid");
let url = "http://localhost:8080/users/all?sessionid=" + sessionid;
- try {
- await fetch(url).then(response => response.json()).then(user => setUsers(user));
- }
- catch(e)
- {
- router.push("/")
- }
+ await fetch(url).then(response => response.json()).then(async user => {
+ setUsers(user)
+ let mURL = "http://localhost:8080/module/suid?sessionid=" + localStorage.getItem("sessionid") + "&semesterid=" + localStorage.getItem("currentsid") + "&userid=";
+ for(let i = 0; i < user.length; i++)
+ {
+ mURL += user[i].id;
+ if(i < user.length - 1)
+ {
+ mURL += "a";
+ }
+ }
+
+ fetch(mURL).then(result => result.json()).then(m => {
+ let temp = []
+
+ for(let i = 0; i < user.length; i++)
+ {
+ temp.push(m[i] != null);
+ }
+
+ setCheckedSelected(temp);
+
+ temp = []
+
+ for(let i = 0; i < user.length; i++)
+ {
+ temp.push(m[i] != null && m[i].activated === 1);
+ }
+
+ setActivatedSelected(temp);
+
+ setModuleInfos(m);
+ });
+ });
+
}
useEffect(() => {
- userModuleMapping.clear()
- getAllUsers();
+ getAllUsers()
+ userModuleMapping.clear();
}, [])
+
async function onCreateClicked() {
let startSplit = startDate.split("-");
let endSplit = endDate.split("-");
@@ -76,16 +108,16 @@ export default function InputForm(p) {
method: method,
headers: {"Content-Type": "application/json"},
body: JSON.stringify(json)
- }).then(response => response.json()).then(semester => {tempsid = semester.id});
+ }).then(response => response.json()).then(semester => {
+ tempsid = semester.id
+ });
- if(method === "POST")
- {
+ if (method === "POST") {
semesterid = tempsid;
}
- for(let [key, value] of userModuleMapping)
- {
+ for (let [key, value] of userModuleMapping) {
let json1 = {
"id": 0,
"userid": value.getUserid(),
@@ -94,8 +126,7 @@ export default function InputForm(p) {
"activated": value.getActivated()
}
- if(value.getChecked())
- {
+ if (value.getChecked()) {
await fetch("http://localhost:8080/module?sessionid=" + localStorage.getItem("sessionid"), {
method: method,
headers: {"Content-Type": "application/json"},
@@ -107,76 +138,109 @@ export default function InputForm(p) {
router.back();
}
- class UserModuleInfo
- {
- constructor()
- {
+ class UserModuleInfo {
+ constructor() {
this.moduleName = "";
this.userid = 0;
this.activated = 0
this.checked = false
}
- getModuleName() {return this.moduleName}
- getUserid() {return this.userid}
- getActivated() {return this.activated}
- getChecked() {return this.checked}
+ getModuleName() {
+ return this.moduleName
+ }
- setModuleName(name) {this.moduleName = name}
- setUserid(id) {this.userid = id}
- setActivated(a) {this.activated = a}
- setChecked(b) {this.checked = b}
+ 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) {
+ function onModuleClicked(user, module, index) {
- if(userModuleMapping.has(user.id))
- {
+ if (userModuleMapping.has(user.id)) {
let temp = userModuleMapping.get(user.id)
temp.setModuleName(module)
temp.setUserid(user.id)
console.log("test")
- }
- else
- {
+ } else {
let temp = new UserModuleInfo()
temp.setModuleName(module)
temp.setUserid(user.id)
userModuleMapping.set(user.id, temp)
console.log("test1")
}
+
}
- function onSelectedCheckBox(user, state)
- {
- if(userModuleMapping.has(user.id))
- {
+ function onSelectedCheckBox(user, state, index) {
+ if (userModuleMapping.has(user.id)) {
userModuleMapping.get(user.id).setChecked(state.target.checked);
- }
- else
- {
+ } else {
let temp = new UserModuleInfo()
temp.setChecked(state.target.checked)
temp.setUserid(user.id)
userModuleMapping.set(user.id, temp)
}
+ let temp = []
+
+ for(let i = 0; i < checkedSelected.length; i++)
+ {
+ temp.push(checkedSelected[i]);
+ }
+
+ temp[index] = state.target.checked;
+
+ setCheckedSelected(temp);
+
}
- function onActivatedCheckBox(user, state)
- {
- if(userModuleMapping.has(user.id))
- {
+ function onActivatedCheckBox(user, state, index) {
+ if (userModuleMapping.has(user.id)) {
let t = state.target.checked ? 1 : 0;
userModuleMapping.get(user.id).setActivated(t);
- }
- else
- {
+ } else {
let temp = new UserModuleInfo()
let t = state.target.checked ? 1 : 0;
temp.setActivated(t)
temp.setUserid(user.id)
userModuleMapping.set(user.id, temp)
}
+
+ let temp = []
+
+ for(let i = 0; i < checkedSelected.length; i++)
+ {
+ temp.push(activatedSelected[i]);
+ }
+
+ temp[index] = state.target.checked;
+
+ setActivatedSelected(temp);
+
}
return (
@@ -247,24 +311,28 @@ export default function InputForm(p) {
}}>Modul
- {users.map(user => (
+ {users.map((user, i) => (
- {
- onSelectedCheckBox(user, e)
- }}/> |
+
+ {
+ onSelectedCheckBox(user, e, i)
+ }} checked={checkedSelected[i]}/>
+ |
- {
- onActivatedCheckBox(user, e);
- }}/> |
+
+ {
+ onActivatedCheckBox(user, e, i);
+ }} checked={activatedSelected[i]}/>
+ |
{user.firstName + " " + user.lastName} |