This commit is contained in:
brausjonas
2023-05-29 21:28:48 +02:00
parent 866dfe9e2b
commit aa790a20d6
41 changed files with 166 additions and 2416027 deletions
+166 -68
View File
@@ -23,9 +23,13 @@ export default function CalenderView(p) {
function readEntries() {
let url = "http://localhost:8080/entries?semesterid=" + localStorage.getItem("currentsid") +
"&daynumber=" + currentWeekStartDay + "&yearnumber=" + currentYear + "&sessionid=" + localStorage.getItem("sessionid");
fetch(url).then(r => r.json()).then(en => {
setEntries(en)
})
try {
fetch(url).then(r => r.json()).then(en => {
setEntries(en)
})
}catch (e) {
}
}
function pushEntry(currentColumnID, row) {
@@ -119,12 +123,51 @@ export default function CalenderView(p) {
let row = Math.floor((y_window - y_target_offset) / cellHeight) + 1;
let currentColumnID = parseInt(e.currentTarget.id)
if (grabbedDown)
if (grabbedDown) {
if (row - 1 > selectedElement.timestart) {
let free = true;
for(let i = 0; i < entries[currentColumnID].length; i++)
{
if(entries[currentColumnID][i] != null && selectedElement !== entries[currentColumnID][i])
{
if(row <= entries[currentColumnID][i].timeend &&
row >= entries[currentColumnID][i].timestart ||
row > entries[currentColumnID][i].timeend &&
selectedElement.timestart < entries[currentColumnID][i].timestart)
{
free = false;
break;
}
}
}
if(free) {
selectedElement.timeend = row + 1;
}
}
} else if (row + 2 < selectedElement.timeend)
{
selectedElement.timeend = row + 1;
}else
{
selectedElement.timestart = row;
let free = true;
for(let i = 0; i < entries[currentColumnID].length; i++)
{
if(entries[currentColumnID][i] != null && selectedElement !== entries[currentColumnID][i])
{
if(row < entries[currentColumnID][i].timeend &&
row >= entries[currentColumnID][i].timestart ||
row < entries[currentColumnID][i].timestart &&
selectedElement.timeend > entries[currentColumnID][i].timestart)
{
free = false;
break;
}
}
}
if(free)
{
selectedElement.timestart = row;
}
}
setUpdate(!update);
}
@@ -136,6 +179,7 @@ export default function CalenderView(p) {
let row = Math.floor((y_window - y_target_offset) / cellHeight) + 1;
let currentColumnID = parseInt(e.currentTarget.id)
let currentId = e.target.id;
let currentUserID = localStorage.getItem("userid");
if (e.button === 0) {
if (!currentId.includes("e")) {
@@ -144,20 +188,16 @@ export default function CalenderView(p) {
pushEntry(currentColumnID, row)
}
} else {
grabbedDown = currentId.includes("down")
/*
if(currentId.includes("up"))
{
grabbedDown = false;
}else grabbedDown = true;
*/
let parentID = parseInt(e.target.parentElement.id.replace("e", ""));
selectedElement = getElementInColumn(parentID, currentColumnID);
if(currentUserID == getElementInColumn(parentID, currentColumnID).usercreatedbyid) {
grabbedDown = currentId.includes("down")
selectedElement = getElementInColumn(parentID, currentColumnID);
}
}
}
} else if (e.button === 2) {
if (currentId.includes("e")) {
let parentID = parseInt(e.target.id.replace("e", ""));
if (currentUserID == getElementInColumn(parentID, currentColumnID).usercreatedbyid && currentId.includes("e")) {
let id = parseInt(currentId.replace("e", ""))
deleteEntry(id)
}
@@ -174,6 +214,31 @@ export default function CalenderView(p) {
readEntries()
}
function getEntryColor(userCreatedByID)
{
let id = localStorage.getItem("userid");
if(id == userCreatedByID)
{
return "#77932b";
}
else
{
return "#a2a2a2";
}
}
function getResizeBarColor(userCreatedByID)
{
let id = localStorage.getItem("userid");
if(id == userCreatedByID)
{
return "#5a6c20";
}
else{
return "#a2a2a2";
}
}
useEffect(() => {
semesterStart = 0;
currentWeekStartDay = 0;
@@ -194,27 +259,25 @@ export default function CalenderView(p) {
window.addEventListener("contextmenu", (e) => (e.preventDefault()))
window.addEventListener("keypress", (e) => {
if(e.key === "+")
{
scrollRef.current.scrollTop = scrollRef.current.scrollTop + 100;
cellHeight += 2
}
else if(e.key === "-")
{
if(cellHeight - 2 >= 8)
{
scrollRef.current.scrollTop = scrollRef.current.scrollTop - 100;
cellHeight -= 2
try {
if (e.key === "+") {
cellHeight += 2
} else if (e.key === "-") {
if (cellHeight - 2 >= 8) {
cellHeight -= 2
}
}
} catch (e) {
}
})
setInterval(function(){
if (selectedElement == null){
setInterval(function () {
if (selectedElement == null) {
readEntries()
}
}, 100);
}, 500);
}, [])
@@ -252,18 +315,29 @@ export default function CalenderView(p) {
justifyContent: "center",
alignItems: "center",
backgroundColor: "white",
gap: 5
gap: 5,
}}>
<div style={{ borderRadius: 10, padding: 10, backgroundColor: "#f1f1f1"}} className={"box-shadow"}>
<div style={{borderRadius: 10, padding: 10, backgroundColor: "#f1f1f1"}} className={"box-shadow"}>
<div>
<div className={"wochen-tag-container"}>
<div className={"wochen-tag font-big"}>Montag {new Date(currentYear, 0, currentWeekStartDay).getDate()}.</div>
<div className={"wochen-tag font-big"}>Dienstag {new Date(currentYear, 0, currentWeekStartDay + 1).getDate()}.</div>
<div className={"wochen-tag font-big"}>Mittwoch {new Date(currentYear, 0, currentWeekStartDay + 2).getDate()}.</div>
<div className={"wochen-tag font-big"}>Donnerstag {new Date(currentYear, 0, currentWeekStartDay + 3).getDate()}.</div>
<div className={"wochen-tag font-big"}>Freitag {new Date(currentYear, 0, currentWeekStartDay + 4).getDate()}.</div>
<div className={"wochen-tag font-big"}>Samstag {new Date(currentYear, 0, currentWeekStartDay + 5).getDate()}.</div>
<div
className={"wochen-tag font-big"}>Montag {new Date(currentYear, 0, currentWeekStartDay).getDate()}.
</div>
<div
className={"wochen-tag font-big"}>Dienstag {new Date(currentYear, 0, currentWeekStartDay + 1).getDate()}.
</div>
<div
className={"wochen-tag font-big"}>Mittwoch {new Date(currentYear, 0, currentWeekStartDay + 2).getDate()}.
</div>
<div
className={"wochen-tag font-big"}>Donnerstag {new Date(currentYear, 0, currentWeekStartDay + 3).getDate()}.
</div>
<div
className={"wochen-tag font-big"}>Freitag {new Date(currentYear, 0, currentWeekStartDay + 4).getDate()}.
</div>
<div
className={"wochen-tag font-big"}>Samstag {new Date(currentYear, 0, currentWeekStartDay + 5).getDate()}.
</div>
</div>
</div>
<div className={"calender-container"} ref={scrollRef}>
@@ -281,14 +355,18 @@ export default function CalenderView(p) {
width: "100%",
gridRowStart: d.timestart,
gridRowEnd: d.timeend,
backgroundColor: "#77932b"
backgroundColor: getEntryColor(d.usercreatedbyid)
}} id={d.id + "e"}>
<div className={"resize-grab"} id={"grabup"}></div>
<div className={"resize-grab"} id={"grabup"} style={{
backgroundColor: getResizeBarColor(d.usercreatedbyid)
}}></div>
<div style={{maxHeight: "60%"}} className={"no-pointer-events"}>
<p>{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}</p>
<p>Modul</p>
</div>
<div className={"resize-grab"} id={"grabdown"}></div>
<div className={"resize-grab"} id={"grabdown"} style={{
backgroundColor: getResizeBarColor(d.usercreatedbyid)
}}></div>
</div>))}
</div>
@@ -303,15 +381,19 @@ export default function CalenderView(p) {
width: "100%",
gridRowStart: d.timestart,
gridRowEnd: d.timeend,
backgroundColor: "#77932b"
backgroundColor: getEntryColor(d.usercreatedbyid)
}} id={d.id + "e"}>
<div className={"resize-grab"} id={"grabup"}></div>
<div className={"resize-grab"} id={"grabup"} style={{
backgroundColor: getResizeBarColor(d.usercreatedbyid)
}}></div>
<div style={{maxHeight: "60%"}} className={"no-pointer-events"}>
<p>{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}</p>
<p>Modul</p>
</div>
<div className={"resize-grab"} id={"grabdown"}></div>
<div className={"resize-grab"} id={"grabdown"} style={{
backgroundColor: getResizeBarColor(d.usercreatedbyid)
}}></div>
</div>))}
</div>
@@ -327,15 +409,19 @@ export default function CalenderView(p) {
width: "100%",
gridRowStart: d.timestart,
gridRowEnd: d.timeend,
backgroundColor: "#77932b"
backgroundColor: getEntryColor(d.usercreatedbyid)
}} id={d.id + "e"}>
<div className={"resize-grab"} id={"grabup"}></div>
<div className={"resize-grab"} id={"grabup"} style={{
backgroundColor: getResizeBarColor(d.usercreatedbyid)
}}></div>
<div style={{maxHeight: "60%"}} className={"no-pointer-events"}>
<p>{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}</p>
<p>Modul</p>
</div>
<div className={"resize-grab"} id={"grabdown"}></div>
<div className={"resize-grab"} id={"grabdown"} style={{
backgroundColor: getResizeBarColor(d.usercreatedbyid)
}}></div>
</div>))}
</div>
@@ -350,15 +436,19 @@ export default function CalenderView(p) {
width: "100%",
gridRowStart: d.timestart,
gridRowEnd: d.timeend,
backgroundColor: "#77932b"
backgroundColor: getEntryColor(d.usercreatedbyid)
}} id={d.id + "e"}>
<div className={"resize-grab"} id={"grabup"}></div>
<div className={"resize-grab"} id={"grabup"} style={{
backgroundColor: getResizeBarColor(d.usercreatedbyid)
}}></div>
<div style={{maxHeight: "60%"}} className={"no-pointer-events"}>
<p>{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}</p>
<p>Moduel etc.</p>
</div>
<div className={"resize-grab"} id={"grabdown"}></div>
<div className={"resize-grab"} id={"grabdown"} style={{
backgroundColor: getResizeBarColor(d.usercreatedbyid)
}}></div>
</div>))}
</div>
@@ -374,14 +464,18 @@ export default function CalenderView(p) {
width: "100%",
gridRowStart: d.timestart,
gridRowEnd: d.timeend,
backgroundColor: "#77932b"
backgroundColor: getEntryColor(d.usercreatedbyid)
}} id={d.id + "e"}>
<div className={"resize-grab"} id={"grabup"}></div>
<div className={"resize-grab"} id={"grabup"} style={{
backgroundColor: getResizeBarColor(d.usercreatedbyid)
}}></div>
<div style={{maxHeight: "60%"}} className={"no-pointer-events"}>
<p>{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}</p>
<p>Modul</p>
</div>
<div className={"resize-grab"} id={"grabdown"}></div>
<div className={"resize-grab"} id={"grabdown"} style={{
backgroundColor: getResizeBarColor(d.usercreatedbyid)
}}></div>
</div>))}
</div>
@@ -397,14 +491,18 @@ export default function CalenderView(p) {
width: "100%",
gridRowStart: d.timestart,
gridRowEnd: d.timeend,
backgroundColor: "#77932b"
backgroundColor: getEntryColor(d.usercreatedbyid)
}} id={d.id + "e"}>
<div className={"resize-grab"} id={"grabup"}></div>
<div className={"resize-grab"} id={"grabup"} style={{
backgroundColor: getResizeBarColor(d.usercreatedbyid)
}}></div>
<div style={{maxHeight: "60%"}} className={"no-pointer-events"}>
<p>{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}</p>
<p>Modul</p>
</div>
<div className={"resize-grab"} id={"grabdown"}></div>
<div className={"resize-grab"} id={"grabdown"} style={{
backgroundColor: getResizeBarColor(d.usercreatedbyid)
}}></div>
</div>))}
</div>
</div>
@@ -420,15 +518,15 @@ export default function CalenderView(p) {
justifyContent: "space-around",
alignItems: "center",
}} className={"no-pointer-events"}>
<div style={{
borderBottom: "1px solid #363636",
}}><p style={{
color: "gray",
marginTop: cellHeight - 3,
marginRight: 120,
fontSize: 12,
textAlign: "center"
}}>{internal_to_time(i + 1)}</p></div>
<div style={{
borderBottom: "1px solid #363636",
}}><p style={{
color: "gray",
marginTop: cellHeight - 3,
marginRight: 120,
fontSize: 12,
textAlign: "center"
}}>{internal_to_time(i + 1)}</p></div>
<div style={{
borderBottom: "1px solid #363636",