diff --git a/anwendung/src/components/CalenderView.jsx b/anwendung/src/components/CalenderView.jsx
index e3c7b75..1fac085 100644
--- a/anwendung/src/components/CalenderView.jsx
+++ b/anwendung/src/components/CalenderView.jsx
@@ -796,7 +796,7 @@ export default function CalenderView(p) {
width: "90%",
backgroundColor: e === ErrorType.Okay ? "white" : "#e5a10e",
borderRadius: 15,
- display: "flex",
+ display: e === ErrorType.Okay ? "none" : "flex",
flexDirection: "column",
justifyContent: "center",
gap: 10,
diff --git a/anwendung/src/components/InputForm.jsx b/anwendung/src/components/InputForm.jsx
index b2fe53e..c0168f3 100644
--- a/anwendung/src/components/InputForm.jsx
+++ b/anwendung/src/components/InputForm.jsx
@@ -3,407 +3,357 @@ import {useRouter} from "next/router";
import {useEffect, useState} from "react";
import Background from "@/components/Background";
import {baseURL} from "@/components/Constants";
+import Back from "@/components/Back";
+let modulesDummy = [
+ ["Analysis", "Theo Inf 1"],
+ ["Lineare Algebra", "Anwendungsprojekt"],
+ ["Theo Inf 3", "Software Eng"],
+ ["Security", "BWL"],
+ ["Software Eng", "Security"],
+ ["Studienarbeit", "Bachelor"]
+]
-let userModuleMapping = new Map()
+let tempSemesterNumber = 0
+let update = false
+
+let baseMapping = []
export default function InputForm(p) {
- let startDateParam = "";
- let endDateParam = "";
- let courseNameParam = "";
+ const [startDate, setStartDate] = useState("0000-00-00")
+ const [endDate, setEndDate] = useState("0000-00-00")
+ const [courseName, setCourseName] = useState("")
+ const [semesterNumber, setSemesterNumber] = useState(0)
+ const [users, setUsers] = useState([])
+ const [modulesSelectorValues, setModulesSelectorValues] = useState(["nothing", "nothing"])
+ const [userModulesMapping, setUserModulesMapping] = useState({})
+ const [isChecked, setIsChecked] = useState([])
+ const [isActivated, setIsActivated] = useState([])
+ const router = useRouter()
- if (p.startDate != null) startDateParam = p.startDate;
- if (p.endDate != null) endDateParam = p.endDate;
- if (p.courseName != null) courseNameParam = p.courseName;
+ useEffect(() => {
- const router = useRouter();
+ let base = baseURL + "/semester/id?sessionid=" + localStorage.getItem("sessionid") + "&id=" + localStorage.getItem("currentsid")
+ fetch(base).then(r => r.json()).then(j => {
+ setCourseName(j.name)
- const [startDate, setStartDate] = useState(startDateParam);
- const [endDate, setEndDate] = useState(endDateParam);
- const [courseName, setCourseName] = useState(courseNameParam);
- const [users, setUsers] = useState([]);
- const [checkedSelected, setCheckedSelected] = useState(new Array(100).fill(false))
- const [activatedSelected, setActivatedSelected] = useState(new Array(100).fill(false))
- const [modulesNames, setModulesNames] = useState(new Array(100).fill("Please Select"))
+ let tempStartDate = new Date(parseInt(j.startyear), 0, parseInt(j.startday))
+ let tempEndDate = new Date(parseInt(j.endyear), 0, parseInt(j.endday))
- async function getAllUsers() {
- let sessionid = localStorage.getItem("sessionid");
- let url = baseURL + "/users/all?sessionid=" + sessionid;
+ setStartDate(tempStartDate.getFullYear() + "-" + ((tempStartDate.getMonth() + 1).toString().padStart(2, "0")) + "-" + tempStartDate.getDate().toString().padStart(2, "0"))
+ setEndDate(tempEndDate.getFullYear() + "-" + ((tempEndDate.getMonth() + 1).toString().padStart(2, "0")) + "-" + tempEndDate.getDate().toString().padStart(2, "0"))
- await fetch(url).then(response => response.json()).then(async user => {
- setUsers(user)
- let mURL = baseURL + "/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";
- }
+ setSemesterNumber(j.number)
+ tempSemesterNumber = j.number
+
+ }).then(() => {
+ readModules()
+ update = true
+ }).catch(() => readModules())
+
+
+ }, [])
+
+ function readModules() {
+ let usersTemp = []
+
+ let userURL = baseURL + "/users/all?sessionid=" + localStorage.getItem("sessionid")
+ fetch(userURL).then(r => r.json()).then(j => {
+ setUsers(j)
+ usersTemp = j
+ let temp = [false, false, false]
+ let temp2 = []
+ for (let i = 0; i < j.length; i++) {
+ temp.push(false)
+ temp2.push(false)
}
+ setIsChecked(temp)
+ setIsActivated(temp2)
+ }).then(() => {
+ let modulesURL = baseURL + "/module/bysemesterid?sessionid=" + localStorage.getItem("sessionid") + "&semesterid=" + localStorage.getItem("currentsid");
+ fetch(modulesURL).then(r => r.json()).then(j => {
- fetch(mURL).then(result => result.json()).then(m => {
- let temp = []
+ setUserModulesMapping(j)
+ baseMapping = j
- for(let i = 0; i < user.length; i++)
- {
- temp.push(m[i] != null);
- }
+ let temp = isChecked.slice()
+ let temp2 = isActivated.slice()
- setCheckedSelected(temp);
+ for (let i = 0; i < usersTemp.length; i++) {
+ let currentUser = usersTemp[i]
- temp = []
+ let found = false
+ let foundModuleLast = null
+ for (let f = 0; f < j.length; f++) {
+ let currentModule = j[f]
- for(let i = 0; i < user.length; i++)
- {
- temp.push(m[i] != null && m[i].activated === 1);
+ if (currentModule.userid === currentUser.id) {
+ found = true
+ foundModuleLast = currentModule
+ }
+ }
- if(m[i] != null) {
- let tempModuleInfo = new UserModuleInfo();
- tempModuleInfo.setModuleName(m[i].name);
- tempModuleInfo.setActivated(m[i].activated);
- tempModuleInfo.setChecked(true);
- tempModuleInfo.setUserid(user[i].id)
- userModuleMapping.set(user[i].id, tempModuleInfo)
+ if (found) {
+ temp[i] = true
+
+ temp2[i] = foundModuleLast.activated === 1
}
}
- setActivatedSelected(temp);
-
- temp = []
-
- for(let i = 0; i < user.length; i++)
- {
- temp.push(m[i] == null ? "Please Select" : m[i].name);
- }
-
- setModulesNames(temp);
-
- });
-
- for(let i = 0; i < user.length; i++)
- {
- if(!userModuleMapping.has(user[i].id)) {
- let tempModuleInfo = new UserModuleInfo();
- tempModuleInfo.setModuleName("Please Select");
- tempModuleInfo.setActivated(0);
- tempModuleInfo.setChecked(false);
- tempModuleInfo.setUserid(user[i].id)
- userModuleMapping.set(user[i].id, tempModuleInfo)
- }
- }
- });
+ setIsChecked(temp)
+ setIsActivated(temp2)
+ })
+ }).then(() => {
+ setModulesSelectorValues(modulesDummy[tempSemesterNumber])
+ })
}
- useEffect(() => {
- getAllUsers()
- userModuleMapping.clear();
- }, [])
+ function onCourseNameChange(e) {
+ setCourseName(e.target.value)
+ }
+
+ function onStartDateChange(e) {
+ setStartDate(e.target.value)
+ }
+
+ function onEndDateChange(e) {
+ setEndDate(e.target.value)
+ }
+
+ function onSemesterNumberChange(e) {
+ setSemesterNumber(e.target.value)
+ setModulesSelectorValues(modulesDummy[e.target.value])
+ }
+
+ function isOptionSelected(e, userid) {
+ let found = false;
+
+ for (let i = 0; i < userModulesMapping.length; i++) {
+ let current = userModulesMapping[i]
+ if (current.name === e && current.userid === userid) {
+ found = true;
+ }
+ }
- async function onCreateClicked() {
- let startSplit = startDate.split("-");
- let endSplit = endDate.split("-");
- let startYear = parseInt(startSplit[0]);
- let endYear = parseInt(endSplit[0]);
+ return found;
+ }
- //month - 1 because jan = 0, day like month... but because of next lines 3 to 4 not - 1
- let startInternalDate = new Date(startYear, parseInt(startSplit[1]) - 1, parseInt(startSplit[2]))
- let endInternalDate = new Date(endYear, parseInt(endSplit[1]) - 1, parseInt(endSplit[2]))
+ function onCheckedChange(e, index) {
+ let temp = isChecked.slice()
+ temp[index] = e.target.checked
+ setIsChecked(temp)
- let startDayInYear = Math.round((startInternalDate - new Date(startYear, 0, 0)) / (1000 * 60 * 60 * 24));
- let endDayInYear = Math.round((endInternalDate - new Date(endYear, 0, 0)) / (1000 * 60 * 60 * 24));
+ if (!e.target.checked) {
+ let temp = []
+ let currentUser = users[index]
+ for (let j = 0; j < userModulesMapping.length; j++) {
+ if (userModulesMapping[j].userid !== currentUser.id) {
+ temp.push(userModulesMapping[j])
+ }
+ }
- let id = p.courseName == null ? 0 : localStorage.getItem("currentsid");
+ setUserModulesMapping(temp)
+ }
+ }
- let json = {
- "id": id,
+ function onActivatedChange(e, index) {
+
+ let temp = isActivated.slice()
+ temp[index] = e.target.checked
+ setIsActivated(temp)
+
+ let userid = users[index].id
+
+ for (let j = 0; j < userModulesMapping.length; j++) {
+ if (userModulesMapping[j].userid === userid) {
+ userModulesMapping[j].activated = e.target.checked ? 1 : 0
+ }
+ }
+ }
+
+ function onModuleSelectionChange(e, index) {
+ let userid = users[index].id
+
+ let newMapping = []
+ let oldNamesIds = new Map()
+
+ for (let j = 0; j < userModulesMapping.length; j++) {
+ let currentModuleMapping = userModulesMapping[j]
+ if (currentModuleMapping.userid != userid) {
+ newMapping.push(currentModuleMapping)
+ } else {
+ oldNamesIds.set(currentModuleMapping.name, currentModuleMapping.id)
+ }
+ }
+
+ let found = false
+ for (let i = 0; i < e.target.options.length; i++) {
+
+ let currentOption = e.target.options[i]
+ if (currentOption.selected) {
+ found = true
+
+ newMapping.push({
+ "id": oldNamesIds.has(currentOption.value) ? oldNamesIds.get(currentOption.value) : -1,
+ "userid": userid,
+ "semesterid": -1,
+ "name": currentOption.value,
+ "activated": isActivated[index] ? 1 : 0
+ })
+ }
+ }
+
+ let temp = isChecked.slice()
+ temp[index] = found
+ setIsChecked(temp)
+
+ setUserModulesMapping(newMapping)
+ }
+
+ function onButtonAbort() {
+ router.back()
+ }
+
+ function onButtonSave() {
+ let tempDateStart = new Date(parseInt(startDate.split("-")[0]), parseInt(startDate.split("-")[1]) - 1, parseInt(startDate.split("-")[2]))
+ let tempDateEnd = new Date(parseInt(endDate.split("-")[0]), parseInt(endDate.split("-")[1]) - 1, parseInt(endDate.split("-")[2]))
+
+ let startDayInYear = Math.round((tempDateStart - new Date(tempDateStart.getFullYear(), 0, 0)) / (1000 * 60 * 60 * 24))
+ let endDayInYear = Math.round((tempDateEnd - new Date(tempDateEnd.getFullYear(), 0, 0)) / (1000 * 60 * 60 * 24))
+
+
+ let semesterJson = {
+ "id": update ? localStorage.getItem("currentsid") : 0,
"startday": startDayInYear,
"endday": endDayInYear,
"name": courseName,
- "startyear": startYear,
- "endyear": endYear
+ "startyear": tempDateStart.getFullYear(),
+ "endyear": tempDateEnd.getFullYear(),
+ "number": semesterNumber
}
- let url = baseURL + "/semester?sessionid=" + localStorage.getItem("sessionid");
- let method = p.courseName == null ? "POST" : "PUT";
-
-
- let semesterid = localStorage.getItem("currentsid");
- let tempsid = 0;
- await fetch(url, {
- method: method,
+ fetch(baseURL + "/semester?sessionid=" + localStorage.getItem("sessionid"), {
+ method: update ? "PUT" : "POST",
headers: {"Content-Type": "application/json"},
- body: JSON.stringify(json)
- }).then(response => response.json()).then(semester => {
- tempsid = semester.id
- });
+ body: JSON.stringify(semesterJson)
+ }).then(r => r.json()).then(async sem => {
+ let semesterID = sem.id
+ for (let i = 0; i < baseMapping.length; i++) {
+ let found = false
+ for (let j = 0; j < userModulesMapping.length; j++) {
+ if (baseMapping[i].name === userModulesMapping[j].name) {
+ found = true
+ }
+ }
- 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 (!found) {
+ fetch(baseURL + "/module?sessionid=" + localStorage.getItem("sessionid") + "&id=" + baseMapping[i].id, {
+ method: "DELETE"
+ })
+ }
}
- if (value.getChecked()) {
- let updateURL = baseURL + "/module?sessionid=" + localStorage.getItem("sessionid");
- await fetch(updateURL, {
- method: method,
- headers: {"Content-Type": "application/json"},
- body: JSON.stringify(json1)
- })
+
+ for (let i = 0; i < userModulesMapping.length; i++) {
+
+ userModulesMapping[i].semesterid = semesterID
+ setTimeout(() => {
+ console.log(userModulesMapping[i])
+ fetch(baseURL + "/module?sessionid=" + localStorage.getItem("sessionid"), {
+ method: userModulesMapping[i].id === -1 ? "POST" : "PUT",
+ headers: {"Content-Type": "application/json"},
+ body: JSON.stringify(userModulesMapping[i])
+ })
+ }, i * 100)
+
}
- else
- {
- let deleteURL = baseURL + "/module?sessionid=" + localStorage.getItem("sessionid") +
- "&semesterid=" + semesterid +
- "&userid=" + value.getUserid();
- await fetch(deleteURL, {
- method: "DELETE"
- })
- }
- }
+ })
- router.back();
+ router.back()
}
- 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
- }
-
- setModuleName(name) {
- this.moduleName = name
- }
-
- setUserid(id) {
- this.userid = id
- }
-
- setActivated(a) {
- this.activated = a
- }
-
- setChecked(b) {
- this.checked = b
- }
- }
-
- function onModuleClicked(user, module, index) {
-
- if (userModuleMapping.has(user.id)) {
- let temp = userModuleMapping.get(user.id)
- temp.setModuleName(module)
- temp.setUserid(user.id)
- }
-
- let temp = [];
-
- for(let i = 0; i < modulesNames.length; i++)
- {
- temp.push(modulesNames[i]);
- }
-
- temp[index] = module;
-
- setModulesNames(temp);
- }
-
- function onSelectedCheckBox(user, state, index) {
- 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)
- }
- 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, index) {
- if (userModuleMapping.has(user.id)) {
- let t = state.target.checked ? 1 : 0;
- userModuleMapping.get(user.id).setActivated(t);
- }
-
- let temp = []
-
- for(let i = 0; i < checkedSelected.length; i++)
- {
- temp.push(activatedSelected[i]);
- }
-
- temp[index] = state.target.checked;
-
- setActivatedSelected(temp);
-
- }
-
-
return (
<>
Kursname
- setCourseName(e.target.value)}/> -Theorie Anfang
-Theorie Ende
--
- = endDate) ? "#E44747" : "white" - }} - onChange={(e) => setEndDate(e.target.value)}/> -Kursname
+ onCourseNameChange(e)} value={courseName}/> + +Theorie Anfang
+Theorie Ende
Semester Wählen
+ + +| Wählen - | -Freischalten - | -Dozent - | -Modul - | +Wählen | +Freischalten | +Dozent | +Modul |
|---|---|---|---|---|---|---|---|
|
- {
- onSelectedCheckBox(user, e, i)
- }} checked={checkedSelected[i]}/>
- |
-
-
- {
- onActivatedCheckBox(user, e, i);
- }} checked={activatedSelected[i]}/>
- |
- {user.firstName + " " + user.lastName} | - -|||||
| + onCheckedChange(e, index)}/> + | ++ onActivatedChange(e, index)}/> + | ++ {user.firstName + " " + user.lastName} + | ++ + | +