Added Status Bar for Admins
There are still some minor Bugs to fix, but it works
This commit is contained in:
@@ -3,17 +3,18 @@ import {baseURL} from "@/components/Constants";
|
|||||||
export default function HourCounter(){
|
export default function HourCounter(){
|
||||||
|
|
||||||
function countTimePlanned(){
|
function countTimePlanned(){
|
||||||
const entryurl = baseURL + "/entries/planned?sessionid=" + localStorage.getItem("sessionid");
|
const entryurl = baseURL + "/entries/module?moduleid=" + localStorage.getItem("moduleid") + "&sessionid=" + localStorage.getItem("sessionid");
|
||||||
const moduleid = localStorage.getItem("moduleid")
|
|
||||||
let hoursPlanned = 0
|
let hoursPlanned = 0
|
||||||
|
|
||||||
fetch(entryurl).then(response => response.json()).then(entries => {
|
fetch(entryurl).then(response => response.json()).then(entries => {
|
||||||
entries.forEach(e => {
|
entries.forEach(e => {
|
||||||
hoursPlanned += e.timeend - e.timestart
|
hoursPlanned += (e.timeend - e.timestart)/4;
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(20-countTimePlanned());
|
console.log(20-countTimePlanned());
|
||||||
|
|
||||||
|
return(<p></p>);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,8 +2,9 @@ import React, { useState, useEffect } from "react";
|
|||||||
import { baseURL } from "@/components/Constants";
|
import { baseURL } from "@/components/Constants";
|
||||||
|
|
||||||
export default function StatusBar(p) {
|
export default function StatusBar(p) {
|
||||||
const module = p.module;
|
|
||||||
const [index, setIndex] = useState(-1);
|
const [index, setIndex] = useState(-1);
|
||||||
|
if (p.module != null){
|
||||||
|
const module = p.module;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const url = baseURL + "/entries/planned?sessionid=" + localStorage.getItem("sessionid");
|
const url = baseURL + "/entries/planned?sessionid=" + localStorage.getItem("sessionid");
|
||||||
@@ -17,9 +18,11 @@ export default function StatusBar(p) {
|
|||||||
if (module.activated == 0) {
|
if (module.activated == 0) {
|
||||||
newIndex = 2;
|
newIndex = 2;
|
||||||
} else {
|
} else {
|
||||||
|
if(newIndex < 1) {
|
||||||
newIndex = 1;
|
newIndex = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
if (newIndex === -1) {
|
if (newIndex === -1) {
|
||||||
newIndex = 0;
|
newIndex = 0;
|
||||||
@@ -29,10 +32,100 @@ export default function StatusBar(p) {
|
|||||||
});
|
});
|
||||||
}, [module.id, module.activated]);
|
}, [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;
|
||||||
|
console.log("newIndex: " + 2)
|
||||||
|
} else if (modulesWithEntries.length !== 0 && newIndex < 1 && newIndex <= -1) {
|
||||||
|
newIndex = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newIndex == -1) {
|
||||||
|
newIndex = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
setIndex(newIndex);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}, [semester.id, semester.activated]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
let classNames = ["not-started", "started", "finished"];
|
let classNames = ["not-started", "started", "finished"];
|
||||||
let actives = ["", "", ""];
|
let actives = ["", "", ""];
|
||||||
actives[index] = "active";
|
actives[index] = "active";
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={"step-container"}>
|
<div className={"step-container"}>
|
||||||
<div className={"steps"}>
|
<div className={"steps"}>
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ export default function SemesterOverview(p) {
|
|||||||
localStorage.setItem("currentsid", e.id)
|
localStorage.setItem("currentsid", e.id)
|
||||||
funcButtonEdit(e, m);
|
funcButtonEdit(e, m);
|
||||||
}}/>
|
}}/>
|
||||||
{/*<StatusBar progress={0}/>*/}
|
<StatusBar semester={e} module={null}/>
|
||||||
<div style={
|
<div style={
|
||||||
{
|
{
|
||||||
display:"flex",
|
display:"flex",
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ export default function SemesteroverviewLecturer(p) {
|
|||||||
editable={false} text={semesterNames[index]} text2={e.name}
|
editable={false} text={semesterNames[index]} text2={e.name}
|
||||||
onClick={(f) => onClickSemester(e, f, semesterNames[index])}
|
onClick={(f) => onClickSemester(e, f, semesterNames[index])}
|
||||||
/>
|
/>
|
||||||
<StatusBar progress={0} module={e}/>
|
<StatusBar module={e} semester={null}/>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</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) {
|
public Entry[][] getAllEntrys(int semesterid, int daynumber, int yearnumber, int userid) {
|
||||||
try {
|
try {
|
||||||
@@ -121,8 +136,7 @@ public class DataBaseHandler {
|
|||||||
public Entry[] getAllEntries(int semesterid, int userid) {
|
public Entry[] getAllEntries(int semesterid, int userid) {
|
||||||
try {
|
try {
|
||||||
ResultSet rs = st.executeQuery("select * from entries where " +
|
ResultSet rs = st.executeQuery("select * from entries where " +
|
||||||
"semesterid=" + semesterid +
|
"semesterid=" + semesterid);
|
||||||
" and usercreatedbyid=" + userid);
|
|
||||||
List<Entry> entriestate = new ArrayList<>();
|
List<Entry> entriestate = new ArrayList<>();
|
||||||
Entry current = null;
|
Entry current = null;
|
||||||
while ((current = resultSetToEntry(rs)) != null) {
|
while ((current = resultSetToEntry(rs)) != null) {
|
||||||
|
|||||||
@@ -72,6 +72,32 @@ public class EntriesController
|
|||||||
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
|
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
|
// @CrossOrigin
|
||||||
// @GetMapping("/entries")
|
// @GetMapping("/entries")
|
||||||
// public ResponseEntity<Integer[]> getEntries(@RequestParam(name = "semesterid") int semesterid,
|
// public ResponseEntity<Integer[]> getEntries(@RequestParam(name = "semesterid") int semesterid,
|
||||||
|
|||||||
@@ -33,6 +33,18 @@ public class UserController {
|
|||||||
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
|
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
|
//a user wants to login
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
|
|||||||
Reference in New Issue
Block a user