diff --git a/anwendung/src/components/HourCounter.jsx b/anwendung/src/components/HourCounter.jsx index e3c5619..bf00f75 100644 --- a/anwendung/src/components/HourCounter.jsx +++ b/anwendung/src/components/HourCounter.jsx @@ -3,17 +3,18 @@ import {baseURL} from "@/components/Constants"; export default function HourCounter(){ function countTimePlanned(){ - const entryurl = baseURL + "/entries/planned?sessionid=" + localStorage.getItem("sessionid"); - const moduleid = localStorage.getItem("moduleid") + const entryurl = baseURL + "/entries/module?moduleid=" + localStorage.getItem("moduleid") + "&sessionid=" + localStorage.getItem("sessionid"); let hoursPlanned = 0 fetch(entryurl).then(response => response.json()).then(entries => { entries.forEach(e => { - hoursPlanned += e.timeend - e.timestart + hoursPlanned += (e.timeend - e.timestart)/4; }) }) } console.log(20-countTimePlanned()); + return(

); + } \ No newline at end of file diff --git a/anwendung/src/components/StatusBar.jsx b/anwendung/src/components/StatusBar.jsx index 12415a2..4c492ed 100644 --- a/anwendung/src/components/StatusBar.jsx +++ b/anwendung/src/components/StatusBar.jsx @@ -1,38 +1,131 @@ -import React, { useState, useEffect } from "react"; +import React, {useState, useEffect} from "react"; import { baseURL } from "@/components/Constants"; export default function StatusBar(p) { - const module = p.module; const [index, setIndex] = useState(-1); + if (p.module != null){ + const module = p.module; - useEffect(() => { - const url = baseURL + "/entries/planned?sessionid=" + localStorage.getItem("sessionid"); - fetch(url) - .then((response) => response.json()) - .then((entries) => { - let newIndex = -1; - if (entries !== null) { - entries.forEach((e) => { - if (e.moduleid == module.id) { - if (module.activated == 0) { + useEffect(() => { + const url = baseURL + "/entries/planned?sessionid=" + localStorage.getItem("sessionid"); + fetch(url) + .then((response) => response.json()) + .then((entries) => { + let newIndex = -1; + if (entries !== null) { + entries.forEach((e) => { + if (e.moduleid == module.id) { + if (module.activated == 0) { + newIndex = 2; + } else { + if(newIndex < 1) { + newIndex = 1; + } + } + } + }); + if (newIndex === -1) { + newIndex = 0; + } + } + setIndex(newIndex); + }); + }, [module.id, module.activated]); + + } + else if(p.semester != null){ + const semester = p.semester; + // const [newIndex, setNewIndex] = useState(-1) + const url = baseURL + "/entries/semester?semesterid=" + semester.id + "&sessionid=" + localStorage.getItem("sessionid"); + const moduleurl = baseURL + "/module/bysemesterid?sessionid=" + localStorage.getItem("sessionid") + "&semesterid=" + localStorage.getItem("currentsid"); + + useEffect(() => { + + fetch(url) + .then((response) => response.json()) + .then((entries) => { + // let newIndex = -1 + if (entries !== null) { + const moduleurl = baseURL + "/module/bysemesterid?sessionid=" + localStorage.getItem("sessionid") + "&semesterid=" + localStorage.getItem("currentsid"); + fetch(moduleurl).then(response => response.json()).then(modules => { + // let newIndex = -1 + let modulesWithEntries = []; + let isSubmitted = true; + modules.forEach(m => { + entries.forEach(e => { + if (e.moduleid === m.id) { + if (!modulesWithEntries.includes(m)) { + modulesWithEntries.push(m) + } + } + if (m.activated === 1) { + isSubmitted = false; + } + }) + }) + + // entries.forEach(e => { + // + // const moduleurl = baseURL + "/module/bysemesterid?sessionid=" + localStorage.getItem("sessionid") + "&semesterid=" + localStorage.getItem("currentsid"); + // fetch(moduleurl).then(response => response.json()).then(modules => { + // // let newIndex = -1 + // let modulesWithEntries = []; + // let isSubmitted = true; + // modules.forEach(m => { + // if (e.moduleid === m.id){ + // if (!modulesWithEntries.includes(m)) { + // modulesWithEntries.push(m) + // } + // } + // if (m.activated === 1){ + // isSubmitted = false; + // } + // }) + // // const modulesWithoutEntries = modules.filter(element => !modulesWithEntries.includes(element)); + // // console.log(modulesWithoutEntries); + // // if (modulesWithoutEntries.length === 0 && isSubmitted){ + // // newIndex = 2; + // // console.log("newIndex: "+2) + // // } + // // else if(modulesWithEntries.length !== 0 && newIndex < 1 && newIndex <= -1){ + // // newIndex = 1; + // // } + // // + // // if (newIndex == -1) { + // // newIndex = 0; + // // } + // // + // // setIndex(newIndex); + // }) + // }); + let newIndex = -1 + const modulesWithoutEntries = modules.filter(element => !modulesWithEntries.includes(element)); + console.log(modulesWithoutEntries); + if (modulesWithoutEntries.length === 0 && isSubmitted) { newIndex = 2; - } else { + console.log("newIndex: " + 2) + } else if (modulesWithEntries.length !== 0 && newIndex < 1 && newIndex <= -1) { newIndex = 1; } - } - }); - if (newIndex === -1) { - newIndex = 0; + + if (newIndex == -1) { + newIndex = 0; + } + + setIndex(newIndex); + }); } - } - setIndex(newIndex); - }); - }, [module.id, module.activated]); + + }); + }, [semester.id, semester.activated]); + + } let classNames = ["not-started", "started", "finished"]; let actives = ["", "", ""]; actives[index] = "active"; + return (
diff --git a/anwendung/src/pages/semesteroverview.js b/anwendung/src/pages/semesteroverview.js index bd23a0e..dcc56f3 100644 --- a/anwendung/src/pages/semesteroverview.js +++ b/anwendung/src/pages/semesteroverview.js @@ -110,7 +110,7 @@ export default function SemesterOverview(p) { localStorage.setItem("currentsid", e.id) funcButtonEdit(e, m); }}/> - {/**/} +
onClickSemester(e, f, semesterNames[index])} /> - +
))}
diff --git a/backend/src/main/java/com/example/backend/anwprj/Database/DataBaseHandler.java b/backend/src/main/java/com/example/backend/anwprj/Database/DataBaseHandler.java index cda73da..d80d419 100644 --- a/backend/src/main/java/com/example/backend/anwprj/Database/DataBaseHandler.java +++ b/backend/src/main/java/com/example/backend/anwprj/Database/DataBaseHandler.java @@ -88,6 +88,21 @@ public class DataBaseHandler { } } + public Entry[] getEntries(int userid, int moduleid){ + try{ + ResultSet rs = st.executeQuery("select * from entries where moduleid=" + moduleid); + List entryList = new ArrayList<>(); + Entry current = null; + while ((current = resultSetToEntry(rs)) != null){ + entryList.add(current); + } + return entryList.toArray(new Entry[0]); + } + catch (Exception e){ + return null; + } + } + public Entry[][] getAllEntrys(int semesterid, int daynumber, int yearnumber, int userid) { try { @@ -121,8 +136,7 @@ public class DataBaseHandler { public Entry[] getAllEntries(int semesterid, int userid) { try { ResultSet rs = st.executeQuery("select * from entries where " + - "semesterid=" + semesterid + - " and usercreatedbyid=" + userid); + "semesterid=" + semesterid); List entriestate = new ArrayList<>(); Entry current = null; while ((current = resultSetToEntry(rs)) != null) { diff --git a/backend/src/main/java/com/example/backend/anwprj/controller/EntriesController.java b/backend/src/main/java/com/example/backend/anwprj/controller/EntriesController.java index 06e213b..fb32685 100644 --- a/backend/src/main/java/com/example/backend/anwprj/controller/EntriesController.java +++ b/backend/src/main/java/com/example/backend/anwprj/controller/EntriesController.java @@ -72,6 +72,32 @@ public class EntriesController return new ResponseEntity<>(HttpStatus.FORBIDDEN); } + @CrossOrigin + @GetMapping("/entries/semester") + public ResponseEntity getEntriesInSemester(@RequestParam(name = "semesterid") int semesterid, + @RequestParam(name = "sessionid") String sessionid){ + User sessionUser = UserSessionIDHandler.getUserBySessionID(sessionid); + if (sessionUser != null){ + Entry[] entries = db.getAllEntries(semesterid, sessionUser.getId()); + + return new ResponseEntity<>(entries, HttpStatus.OK); + } + return new ResponseEntity<>(HttpStatus.FORBIDDEN); + } + + @CrossOrigin + @GetMapping("/entries/module") + public ResponseEntity getEntries(@RequestParam(name = "moduleid") int moduleid, + @RequestParam(name = "sessionid") String sessionid){ + User sessionUser = UserSessionIDHandler.getUserBySessionID(sessionid); + if (sessionUser != null){ + Entry[] entries = db.getEntries(sessionUser.getId(), moduleid); + + return new ResponseEntity<>(entries, HttpStatus.OK); + } + return new ResponseEntity<>(HttpStatus.FORBIDDEN); + } + // @CrossOrigin // @GetMapping("/entries") // public ResponseEntity getEntries(@RequestParam(name = "semesterid") int semesterid, diff --git a/backend/src/main/java/com/example/backend/anwprj/controller/UserController.java b/backend/src/main/java/com/example/backend/anwprj/controller/UserController.java index 1647821..f0f6577 100644 --- a/backend/src/main/java/com/example/backend/anwprj/controller/UserController.java +++ b/backend/src/main/java/com/example/backend/anwprj/controller/UserController.java @@ -33,6 +33,18 @@ public class UserController { return new ResponseEntity<>(HttpStatus.FORBIDDEN); } + @CrossOrigin + @GetMapping("/user") + public ResponseEntity getUser(@RequestParam(name = "sessionid") String sessionid){ + User u = UserSessionIDHandler.getUserBySessionID(sessionid); + + if (u != null){ + return new ResponseEntity<>(u, HttpStatus.OK); + } + + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + //a user wants to login @CrossOrigin