From 8205b7d9d98c5ca57d4fa74b90dd5594ac5a54f4 Mon Sep 17 00:00:00 2001 From: brausjonas Date: Fri, 16 Jun 2023 11:33:36 +0200 Subject: [PATCH] Calender View Angepasst auf die Module ID eines Entries --- anwendung/src/components/CalenderView.jsx | 86 +++++++++++------------ 1 file changed, 40 insertions(+), 46 deletions(-) diff --git a/anwendung/src/components/CalenderView.jsx b/anwendung/src/components/CalenderView.jsx index 1fac085..12a34d5 100644 --- a/anwendung/src/components/CalenderView.jsx +++ b/anwendung/src/components/CalenderView.jsx @@ -43,9 +43,8 @@ export default function CalenderView(p) { function readEntries() { let url = baseURL + "/entries?semesterid=" + localStorage.getItem("currentsid") + "&daynumber=" + currentWeekStartDay + "&yearnumber=" + currentYear + "&sessionid=" + localStorage.getItem("sessionid"); - // let currentsid = localStorage.getItem("currentsid") - // let userid = localStorage.getItem("userid") - let moduleid = localStorage.getItem("moduleid"); + let currentsid = localStorage.getItem("currentsid") + let userid = localStorage.getItem("userid") try { fetch(url).then(r => r.json()).then(en => { @@ -56,8 +55,7 @@ export default function CalenderView(p) { let maxLunchBreak = 0 let daySum = 0 for (let j = 0; j < en[i].length; j++) { - // if (en[i][j] != null && currentsid == (en[i][j]).semesterid) { - if (en[i][j] != null && moduleid == (en[i][j]).moduleid) { + if (en[i][j] != null && currentsid == (en[i][j]).semesterid) { let elem = en[i][j] if ((elem.timestart - 1) / 4 < 8) { @@ -82,8 +80,7 @@ export default function CalenderView(p) { let min = 24 * 3 for (let j2 = 0; j2 < en[i].length; j2++) { - // if (en[i][j2] != null && (en[i][j2].timestart - 1) / 4 >= 11 && (en[i][j2].timestart - 1) / 4 <= 14 && currentsid == (en[i][j2]).semesterid) { - if (en[i][j2] != null && (en[i][j2].timestart - 1) / 4 >= 11 && (en[i][j2].timestart - 1) / 4 <= 14 && moduleid == (en[i][j2]).moduleid) { + if (en[i][j2] != null && (en[i][j2].timestart - 1) / 4 >= 11 && (en[i][j2].timestart - 1) / 4 <= 14 && currentsid == (en[i][j2]).semesterid) { if (en[i][j2].timestart < min && en[i][j2].timestart >= elem.timeend) { min = en[i][j2].timestart } @@ -114,12 +111,10 @@ export default function CalenderView(p) { for (let k = 0; k < 20; k++) { if (en[i][k] != null){ - // if (en[i][k].semesterid != currentsid) - if (en[i][k].moduleid != moduleid) + if (en[i][k].semesterid != currentsid) { for (let l = 0; l < 20; l++) { - // if (en[i][l] != null && en[i][l].usercreatedbyid != userid) { - if (en[i][l] != null && en[i][l].moduleid != moduleid) { + if (en[i][l] != null && en[i][l].usercreatedbyid != userid) { if (en[i][l].timestart <= en[i][k].timestart && en[i][l].timeend >= en[i][k].timeend) { en[i][k] = null; break @@ -133,11 +128,9 @@ export default function CalenderView(p) { } } } - // if (en[i][k] != null && en[i][k].usercreatedbyid != userid) { - if (en[i][k] != null && en[i][k].moduleid != moduleid) { + if (en[i][k] != null && en[i][k].usercreatedbyid != userid) { for (let l = 0; l < 20; l++) { - // if (en[i][l] != null && en[i][l].semesterid != currentsid) { - if (en[i][l] != null && en[i][l].moduleid != moduleid) { + if (en[i][l] != null && en[i][l].semesterid != currentsid) { if (en[i][l].timestart <= en[i][k].timestart && en[i][l].timeend >= en[i][k].timeend) { en[i][k] = null; break @@ -178,8 +171,8 @@ export default function CalenderView(p) { "usercreatedbyid": localStorage.getItem("userid"), "timestart": row, "timeend": row + 3, - "moduleid": localStorage.getItem("moduleid"), - "info": localStorage.getItem("currentmodulename") + "info": localStorage.getItem("currentmodulename"), + "moduleid": localStorage.getItem("moduleid") } fetch(url, { method: "POST", @@ -244,10 +237,10 @@ export default function CalenderView(p) { "yearnumber": 0, "semesterid": 0, "usercreatedbyid": 0, - "moduleid": 0, "timestart": selectedElement.timestart, "timeend": selectedElement.timeend, - "info": "" + "info": "", + "moduleid": localStorage.getItem("moduleid") } fetch(url, { method: "PUT", @@ -332,7 +325,7 @@ export default function CalenderView(p) { } } else { let parentID = parseInt(e.target.parentElement.id.replace("e", "")); - if (currentUserID == getElementInColumn(parentID, currentColumnID).usercreatedbyid && getElementInColumn(parentID, currentColumnID).semesterid == currentsid) { + if (currentUserID == getElementInColumn(parentID, currentColumnID).usercreatedbyid && getElementInColumn(parentID, currentColumnID).moduleid == localStorage.getItem("moduleid")) { grabbedDown = currentId.includes("down") selectedElement = getElementInColumn(parentID, currentColumnID); } @@ -340,7 +333,7 @@ export default function CalenderView(p) { } } else if (e.button === 2) { let parentID = parseInt(e.target.id.replace("e", "")); - if (currentUserID == getElementInColumn(parentID, currentColumnID).usercreatedbyid && currentId.includes("e") && getElementInColumn(parentID, currentColumnID).semesterid == currentsid) { + if (currentUserID == getElementInColumn(parentID, currentColumnID).usercreatedbyid && currentId.includes("e") && getElementInColumn(parentID, currentColumnID).moduleid == localStorage.getItem("moduleid")) { let id = parseInt(currentId.replace("e", "")) errorState[currentColumnID] = ErrorType.Okay deleteEntry(id) @@ -376,13 +369,14 @@ export default function CalenderView(p) { readEntries() } - function getEntryColor(userCreatedByID, columnID, semesterid) { + function getEntryColor(userCreatedByID, columnID, semesterid, moduleid) { + console.log(moduleid) let id = localStorage.getItem("userid"); let currentsid = localStorage.getItem("currentsid") if (id == userCreatedByID) { - if (isDayOkay[columnID] && semesterid == currentsid) { + if (isDayOkay[columnID] && moduleid == localStorage.getItem("moduleid")) { return "#77932b"; - }else if(semesterid != currentsid){ + }else if(moduleid != localStorage.getItem("moduleid")){ return "#346991"; }else { return "#e5a10e"; @@ -393,13 +387,13 @@ export default function CalenderView(p) { } } - function getResizeBarColor(userCreatedByID, columnID, semesterid) { + function getResizeBarColor(userCreatedByID, columnID, semesterid, moduleid) { let id = localStorage.getItem("userid"); let currentsid = localStorage.getItem("currentsid") if (id == userCreatedByID) { - if (isDayOkay[columnID] && currentsid == semesterid) { + if (isDayOkay[columnID] && moduleid == localStorage.getItem("moduleid")) { return "#5a6c20"; - } else if(currentsid != semesterid) + } else if(moduleid != localStorage.getItem("moduleid")) { return "#346991" } @@ -566,17 +560,17 @@ export default function CalenderView(p) { width: "100%", gridRowStart: d.timestart, gridRowEnd: d.timeend, - backgroundColor: getEntryColor(d.usercreatedbyid, 0, d.semesterid) + backgroundColor: getEntryColor(d.usercreatedbyid, 0, d.semesterid, d.moduleid) }} id={d.id + "e"}>

{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}

{d.info}

))} @@ -592,18 +586,18 @@ export default function CalenderView(p) { width: "100%", gridRowStart: d.timestart, gridRowEnd: d.timeend, - backgroundColor: getEntryColor(d.usercreatedbyid, 1, d.semesterid) + backgroundColor: getEntryColor(d.usercreatedbyid, 1, d.semesterid, d.moduleid) }} id={d.id + "e"}>

{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}

{d.info}

))} @@ -620,18 +614,18 @@ export default function CalenderView(p) { width: "100%", gridRowStart: d.timestart, gridRowEnd: d.timeend, - backgroundColor: getEntryColor(d.usercreatedbyid, 2, d.semesterid) + backgroundColor: getEntryColor(d.usercreatedbyid, 2, d.semesterid, d.moduleid) }} id={d.id + "e"}>

{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}

{d.info}

))} @@ -647,18 +641,18 @@ export default function CalenderView(p) { width: "100%", gridRowStart: d.timestart, gridRowEnd: d.timeend, - backgroundColor: getEntryColor(d.usercreatedbyid, 3, d.semesterid) + backgroundColor: getEntryColor(d.usercreatedbyid, 3, d.semesterid, d.moduleid) }} id={d.id + "e"}>

{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}

{d.info}

))} @@ -675,17 +669,17 @@ export default function CalenderView(p) { width: "100%", gridRowStart: d.timestart, gridRowEnd: d.timeend, - backgroundColor: getEntryColor(d.usercreatedbyid, 4, d.semesterid) + backgroundColor: getEntryColor(d.usercreatedbyid, 4, d.semesterid, d.moduleid) }} id={d.id + "e"}>

{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}

{d.info}

))} @@ -702,17 +696,17 @@ export default function CalenderView(p) { width: "100%", gridRowStart: d.timestart, gridRowEnd: d.timeend, - backgroundColor: getEntryColor(d.usercreatedbyid, 5, d.semesterid) + backgroundColor: getEntryColor(d.usercreatedbyid, 5, d.semesterid, d.moduleid) }} id={d.id + "e"}>

{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}

{d.info}

))} @@ -793,10 +787,10 @@ export default function CalenderView(p) {
{errorState.map((e, index) => (