Added Status Bar for Admins

There are still some minor Bugs to fix, but it works
This commit is contained in:
AlexE030
2023-06-16 22:38:19 +02:00
parent dc20f35fb8
commit b3fb3b1b8f
7 changed files with 174 additions and 28 deletions
+4 -3
View File
@@ -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(<p></p>);
}
+114 -21
View File
@@ -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 (
<div className={"step-container"}>
<div className={"steps"}>
+1 -1
View File
@@ -110,7 +110,7 @@ export default function SemesterOverview(p) {
localStorage.setItem("currentsid", e.id)
funcButtonEdit(e, m);
}}/>
{/*<StatusBar progress={0}/>*/}
<StatusBar semester={e} module={null}/>
<div style={
{
display:"flex",
@@ -68,7 +68,7 @@ export default function SemesteroverviewLecturer(p) {
editable={false} text={semesterNames[index]} text2={e.name}
onClick={(f) => onClickSemester(e, f, semesterNames[index])}
/>
<StatusBar progress={0} module={e}/>
<StatusBar module={e} semester={null}/>
</div>
))}
</div>
@@ -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<Entry> 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<Entry> entriestate = new ArrayList<>();
Entry current = null;
while ((current = resultSetToEntry(rs)) != null) {
@@ -72,6 +72,32 @@ public class EntriesController
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
}
@CrossOrigin
@GetMapping("/entries/semester")
public ResponseEntity<Entry[]> 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<Entry[]> 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<Integer[]> getEntries(@RequestParam(name = "semesterid") int semesterid,
@@ -33,6 +33,18 @@ public class UserController {
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
}
@CrossOrigin
@GetMapping("/user")
public ResponseEntity<User> 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