Calender View Angepasst auf die Module ID eines Entries

This commit is contained in:
brausjonas
2023-06-16 11:33:36 +02:00
parent 53ac8ff0bf
commit 8205b7d9d9
+40 -46
View File
@@ -43,9 +43,8 @@ export default function CalenderView(p) {
function readEntries() { function readEntries() {
let url = baseURL + "/entries?semesterid=" + localStorage.getItem("currentsid") + let url = baseURL + "/entries?semesterid=" + localStorage.getItem("currentsid") +
"&daynumber=" + currentWeekStartDay + "&yearnumber=" + currentYear + "&sessionid=" + localStorage.getItem("sessionid"); "&daynumber=" + currentWeekStartDay + "&yearnumber=" + currentYear + "&sessionid=" + localStorage.getItem("sessionid");
// let currentsid = localStorage.getItem("currentsid") let currentsid = localStorage.getItem("currentsid")
// let userid = localStorage.getItem("userid") let userid = localStorage.getItem("userid")
let moduleid = localStorage.getItem("moduleid");
try { try {
fetch(url).then(r => r.json()).then(en => { fetch(url).then(r => r.json()).then(en => {
@@ -56,8 +55,7 @@ export default function CalenderView(p) {
let maxLunchBreak = 0 let maxLunchBreak = 0
let daySum = 0 let daySum = 0
for (let j = 0; j < en[i].length; j++) { for (let j = 0; j < en[i].length; j++) {
// if (en[i][j] != null && currentsid == (en[i][j]).semesterid) { if (en[i][j] != null && currentsid == (en[i][j]).semesterid) {
if (en[i][j] != null && moduleid == (en[i][j]).moduleid) {
let elem = en[i][j] let elem = en[i][j]
if ((elem.timestart - 1) / 4 < 8) { if ((elem.timestart - 1) / 4 < 8) {
@@ -82,8 +80,7 @@ export default function CalenderView(p) {
let min = 24 * 3 let min = 24 * 3
for (let j2 = 0; j2 < en[i].length; j2++) { 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 && 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].timestart < min && en[i][j2].timestart >= elem.timeend) { if (en[i][j2].timestart < min && en[i][j2].timestart >= elem.timeend) {
min = en[i][j2].timestart min = en[i][j2].timestart
} }
@@ -114,12 +111,10 @@ export default function CalenderView(p) {
for (let k = 0; k < 20; k++) { for (let k = 0; k < 20; k++) {
if (en[i][k] != null){ if (en[i][k] != null){
// if (en[i][k].semesterid != currentsid) if (en[i][k].semesterid != currentsid)
if (en[i][k].moduleid != moduleid)
{ {
for (let l = 0; l < 20; l++) { 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].usercreatedbyid != userid) {
if (en[i][l] != null && en[i][l].moduleid != moduleid) {
if (en[i][l].timestart <= en[i][k].timestart && en[i][l].timeend >= en[i][k].timeend) { if (en[i][l].timestart <= en[i][k].timestart && en[i][l].timeend >= en[i][k].timeend) {
en[i][k] = null; en[i][k] = null;
break 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].usercreatedbyid != userid) {
if (en[i][k] != null && en[i][k].moduleid != moduleid) {
for (let l = 0; l < 20; l++) { 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].semesterid != currentsid) {
if (en[i][l] != null && en[i][l].moduleid != moduleid) {
if (en[i][l].timestart <= en[i][k].timestart && en[i][l].timeend >= en[i][k].timeend) { if (en[i][l].timestart <= en[i][k].timestart && en[i][l].timeend >= en[i][k].timeend) {
en[i][k] = null; en[i][k] = null;
break break
@@ -178,8 +171,8 @@ export default function CalenderView(p) {
"usercreatedbyid": localStorage.getItem("userid"), "usercreatedbyid": localStorage.getItem("userid"),
"timestart": row, "timestart": row,
"timeend": row + 3, "timeend": row + 3,
"moduleid": localStorage.getItem("moduleid"), "info": localStorage.getItem("currentmodulename"),
"info": localStorage.getItem("currentmodulename") "moduleid": localStorage.getItem("moduleid")
} }
fetch(url, { fetch(url, {
method: "POST", method: "POST",
@@ -244,10 +237,10 @@ export default function CalenderView(p) {
"yearnumber": 0, "yearnumber": 0,
"semesterid": 0, "semesterid": 0,
"usercreatedbyid": 0, "usercreatedbyid": 0,
"moduleid": 0,
"timestart": selectedElement.timestart, "timestart": selectedElement.timestart,
"timeend": selectedElement.timeend, "timeend": selectedElement.timeend,
"info": "" "info": "",
"moduleid": localStorage.getItem("moduleid")
} }
fetch(url, { fetch(url, {
method: "PUT", method: "PUT",
@@ -332,7 +325,7 @@ export default function CalenderView(p) {
} }
} else { } else {
let parentID = parseInt(e.target.parentElement.id.replace("e", "")); 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") grabbedDown = currentId.includes("down")
selectedElement = getElementInColumn(parentID, currentColumnID); selectedElement = getElementInColumn(parentID, currentColumnID);
} }
@@ -340,7 +333,7 @@ export default function CalenderView(p) {
} }
} else if (e.button === 2) { } else if (e.button === 2) {
let parentID = parseInt(e.target.id.replace("e", "")); 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", "")) let id = parseInt(currentId.replace("e", ""))
errorState[currentColumnID] = ErrorType.Okay errorState[currentColumnID] = ErrorType.Okay
deleteEntry(id) deleteEntry(id)
@@ -376,13 +369,14 @@ export default function CalenderView(p) {
readEntries() readEntries()
} }
function getEntryColor(userCreatedByID, columnID, semesterid) { function getEntryColor(userCreatedByID, columnID, semesterid, moduleid) {
console.log(moduleid)
let id = localStorage.getItem("userid"); let id = localStorage.getItem("userid");
let currentsid = localStorage.getItem("currentsid") let currentsid = localStorage.getItem("currentsid")
if (id == userCreatedByID) { if (id == userCreatedByID) {
if (isDayOkay[columnID] && semesterid == currentsid) { if (isDayOkay[columnID] && moduleid == localStorage.getItem("moduleid")) {
return "#77932b"; return "#77932b";
}else if(semesterid != currentsid){ }else if(moduleid != localStorage.getItem("moduleid")){
return "#346991"; return "#346991";
}else { }else {
return "#e5a10e"; 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 id = localStorage.getItem("userid");
let currentsid = localStorage.getItem("currentsid") let currentsid = localStorage.getItem("currentsid")
if (id == userCreatedByID) { if (id == userCreatedByID) {
if (isDayOkay[columnID] && currentsid == semesterid) { if (isDayOkay[columnID] && moduleid == localStorage.getItem("moduleid")) {
return "#5a6c20"; return "#5a6c20";
} else if(currentsid != semesterid) } else if(moduleid != localStorage.getItem("moduleid"))
{ {
return "#346991" return "#346991"
} }
@@ -566,17 +560,17 @@ export default function CalenderView(p) {
width: "100%", width: "100%",
gridRowStart: d.timestart, gridRowStart: d.timestart,
gridRowEnd: d.timeend, gridRowEnd: d.timeend,
backgroundColor: getEntryColor(d.usercreatedbyid, 0, d.semesterid) backgroundColor: getEntryColor(d.usercreatedbyid, 0, d.semesterid, d.moduleid)
}} id={d.id + "e"}> }} id={d.id + "e"}>
<div className={"resize-grab"} id={"grabup"} style={{ <div className={"resize-grab"} id={"grabup"} style={{
backgroundColor: getResizeBarColor(d.usercreatedbyid, 0, d.semesterid) backgroundColor: getResizeBarColor(d.usercreatedbyid, 0, d.semesterid, d.moduleid)
}}></div> }}></div>
<div style={{maxHeight: "60%"}} className={"no-pointer-events"}> <div style={{maxHeight: "60%"}} className={"no-pointer-events"}>
<p>{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}</p> <p>{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}</p>
<p>{d.info}</p> <p>{d.info}</p>
</div> </div>
<div className={"resize-grab"} id={"grabdown"} style={{ <div className={"resize-grab"} id={"grabdown"} style={{
backgroundColor: getResizeBarColor(d.usercreatedbyid, 0, d.semesterid) backgroundColor: getResizeBarColor(d.usercreatedbyid, 0, d.semesterid, d.moduleid)
}}></div> }}></div>
</div>))} </div>))}
</div> </div>
@@ -592,18 +586,18 @@ export default function CalenderView(p) {
width: "100%", width: "100%",
gridRowStart: d.timestart, gridRowStart: d.timestart,
gridRowEnd: d.timeend, gridRowEnd: d.timeend,
backgroundColor: getEntryColor(d.usercreatedbyid, 1, d.semesterid) backgroundColor: getEntryColor(d.usercreatedbyid, 1, d.semesterid, d.moduleid)
}} id={d.id + "e"}> }} id={d.id + "e"}>
<div className={"resize-grab"} id={"grabup"} style={{ <div className={"resize-grab"} id={"grabup"} style={{
backgroundColor: getResizeBarColor(d.usercreatedbyid, 1, d.semesterid) backgroundColor: getResizeBarColor(d.usercreatedbyid, 1, d.semesterid, d.moduleid)
}}></div> }}></div>
<div style={{maxHeight: "60%"}} className={"no-pointer-events"}> <div style={{maxHeight: "60%"}} className={"no-pointer-events"}>
<p>{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}</p> <p>{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}</p>
<p>{d.info}</p> <p>{d.info}</p>
</div> </div>
<div className={"resize-grab"} id={"grabdown"} style={{ <div className={"resize-grab"} id={"grabdown"} style={{
backgroundColor: getResizeBarColor(d.usercreatedbyid, 1, d.semesterid) backgroundColor: getResizeBarColor(d.usercreatedbyid, 1, d.semesterid, d.moduleid)
}}></div> }}></div>
</div>))} </div>))}
</div> </div>
@@ -620,18 +614,18 @@ export default function CalenderView(p) {
width: "100%", width: "100%",
gridRowStart: d.timestart, gridRowStart: d.timestart,
gridRowEnd: d.timeend, gridRowEnd: d.timeend,
backgroundColor: getEntryColor(d.usercreatedbyid, 2, d.semesterid) backgroundColor: getEntryColor(d.usercreatedbyid, 2, d.semesterid, d.moduleid)
}} id={d.id + "e"}> }} id={d.id + "e"}>
<div className={"resize-grab"} id={"grabup"} style={{ <div className={"resize-grab"} id={"grabup"} style={{
backgroundColor: getResizeBarColor(d.usercreatedbyid, 2, d.semesterid) backgroundColor: getResizeBarColor(d.usercreatedbyid, 2, d.semesterid, d.moduleid)
}}></div> }}></div>
<div style={{maxHeight: "60%"}} className={"no-pointer-events"}> <div style={{maxHeight: "60%"}} className={"no-pointer-events"}>
<p>{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}</p> <p>{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}</p>
<p>{d.info}</p> <p>{d.info}</p>
</div> </div>
<div className={"resize-grab"} id={"grabdown"} style={{ <div className={"resize-grab"} id={"grabdown"} style={{
backgroundColor: getResizeBarColor(d.usercreatedbyid, 2, d.semesterid) backgroundColor: getResizeBarColor(d.usercreatedbyid, 2, d.semesterid, d.moduleid)
}}></div> }}></div>
</div>))} </div>))}
</div> </div>
@@ -647,18 +641,18 @@ export default function CalenderView(p) {
width: "100%", width: "100%",
gridRowStart: d.timestart, gridRowStart: d.timestart,
gridRowEnd: d.timeend, gridRowEnd: d.timeend,
backgroundColor: getEntryColor(d.usercreatedbyid, 3, d.semesterid) backgroundColor: getEntryColor(d.usercreatedbyid, 3, d.semesterid, d.moduleid)
}} id={d.id + "e"}> }} id={d.id + "e"}>
<div className={"resize-grab"} id={"grabup"} style={{ <div className={"resize-grab"} id={"grabup"} style={{
backgroundColor: getResizeBarColor(d.usercreatedbyid, 3, d.semesterid) backgroundColor: getResizeBarColor(d.usercreatedbyid, 3, d.semesterid, d.moduleid)
}}></div> }}></div>
<div style={{maxHeight: "60%"}} className={"no-pointer-events"}> <div style={{maxHeight: "60%"}} className={"no-pointer-events"}>
<p>{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}</p> <p>{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}</p>
<p>{d.info}</p> <p>{d.info}</p>
</div> </div>
<div className={"resize-grab"} id={"grabdown"} style={{ <div className={"resize-grab"} id={"grabdown"} style={{
backgroundColor: getResizeBarColor(d.usercreatedbyid, 3, d.semesterid) backgroundColor: getResizeBarColor(d.usercreatedbyid, 3, d.semesterid, d.moduleid)
}}></div> }}></div>
</div>))} </div>))}
</div> </div>
@@ -675,17 +669,17 @@ export default function CalenderView(p) {
width: "100%", width: "100%",
gridRowStart: d.timestart, gridRowStart: d.timestart,
gridRowEnd: d.timeend, gridRowEnd: d.timeend,
backgroundColor: getEntryColor(d.usercreatedbyid, 4, d.semesterid) backgroundColor: getEntryColor(d.usercreatedbyid, 4, d.semesterid, d.moduleid)
}} id={d.id + "e"}> }} id={d.id + "e"}>
<div className={"resize-grab"} id={"grabup"} style={{ <div className={"resize-grab"} id={"grabup"} style={{
backgroundColor: getResizeBarColor(d.usercreatedbyid, 4, d.semesterid) backgroundColor: getResizeBarColor(d.usercreatedbyid, 4, d.semesterid, d.moduleid)
}}></div> }}></div>
<div style={{maxHeight: "60%"}} className={"no-pointer-events"}> <div style={{maxHeight: "60%"}} className={"no-pointer-events"}>
<p>{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}</p> <p>{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}</p>
<p>{d.info}</p> <p>{d.info}</p>
</div> </div>
<div className={"resize-grab"} id={"grabdown"} style={{ <div className={"resize-grab"} id={"grabdown"} style={{
backgroundColor: getResizeBarColor(d.usercreatedbyid, 4, d.semesterid) backgroundColor: getResizeBarColor(d.usercreatedbyid, 4, d.semesterid, d.moduleid)
}}></div> }}></div>
</div>))} </div>))}
</div> </div>
@@ -702,17 +696,17 @@ export default function CalenderView(p) {
width: "100%", width: "100%",
gridRowStart: d.timestart, gridRowStart: d.timestart,
gridRowEnd: d.timeend, gridRowEnd: d.timeend,
backgroundColor: getEntryColor(d.usercreatedbyid, 5, d.semesterid) backgroundColor: getEntryColor(d.usercreatedbyid, 5, d.semesterid, d.moduleid)
}} id={d.id + "e"}> }} id={d.id + "e"}>
<div className={"resize-grab"} id={"grabup"} style={{ <div className={"resize-grab"} id={"grabup"} style={{
backgroundColor: getResizeBarColor(d.usercreatedbyid, 5, d.semesterid) backgroundColor: getResizeBarColor(d.usercreatedbyid, 5, d.semesterid, d.moduleid)
}}></div> }}></div>
<div style={{maxHeight: "60%"}} className={"no-pointer-events"}> <div style={{maxHeight: "60%"}} className={"no-pointer-events"}>
<p>{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}</p> <p>{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}</p>
<p>{d.info}</p> <p>{d.info}</p>
</div> </div>
<div className={"resize-grab"} id={"grabdown"} style={{ <div className={"resize-grab"} id={"grabdown"} style={{
backgroundColor: getResizeBarColor(d.usercreatedbyid, 5, d.semesterid) backgroundColor: getResizeBarColor(d.usercreatedbyid, 5, d.semesterid, d.moduleid)
}}></div> }}></div>
</div>))} </div>))}
</div> </div>
@@ -793,10 +787,10 @@ export default function CalenderView(p) {
<div className={"error-bar"}> <div className={"error-bar"}>
{errorState.map((e, index) => ( {errorState.map((e, index) => (
<div style={{ <div style={{
display: e === ErrorType.Okay ? "none" : "flex",
width: "90%", width: "90%",
backgroundColor: e === ErrorType.Okay ? "white" : "#e5a10e", backgroundColor: e === ErrorType.Okay ? "white" : "#e5a10e",
borderRadius: 15, borderRadius: 15,
display: e === ErrorType.Okay ? "none" : "flex",
flexDirection: "column", flexDirection: "column",
justifyContent: "center", justifyContent: "center",
gap: 10, gap: 10,