Modules On Push
This commit is contained in:
@@ -3,26 +3,11 @@ import {useRouter} from "next/router";
|
||||
import {useEffect, useState} from "react";
|
||||
import Background from "@/components/Background";
|
||||
|
||||
let userInfo = []
|
||||
|
||||
let userModuleMapping = new Map()
|
||||
|
||||
export default function InputForm(p) {
|
||||
|
||||
class UserInfo {
|
||||
constructor(userid, modules) {
|
||||
this.userid = userid;
|
||||
this.module = modules;
|
||||
this.checked = false;
|
||||
}
|
||||
|
||||
setChecked(checked) {
|
||||
this.checked = checked;
|
||||
}
|
||||
|
||||
setModule(module) {
|
||||
this.module = module;
|
||||
}
|
||||
}
|
||||
|
||||
let startDateParam = "";
|
||||
let endDateParam = "";
|
||||
let courseNameParam = "";
|
||||
@@ -53,8 +38,7 @@ export default function InputForm(p) {
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
userInfo = [];
|
||||
userModuleMapping.clear()
|
||||
getAllUsers();
|
||||
}, [])
|
||||
|
||||
@@ -86,50 +70,112 @@ export default function InputForm(p) {
|
||||
let method = p.courseName == null ? "POST" : "PUT";
|
||||
|
||||
|
||||
let semesterid = localStorage.getItem("currentsid");
|
||||
let tempsid = 0;
|
||||
await fetch(url, {
|
||||
method: method,
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: JSON.stringify(json)
|
||||
}).then(response => response.json()).then(semester => console.log(semester));
|
||||
}).then(response => response.json()).then(semester => {tempsid = semester.id});
|
||||
|
||||
|
||||
if(method === "POST")
|
||||
{
|
||||
semesterid = tempsid;
|
||||
}
|
||||
|
||||
for(let [key, value] of userModuleMapping)
|
||||
{
|
||||
let json1 = {
|
||||
"id": 0,
|
||||
"userid": value.getUserid(),
|
||||
"semesterid": semesterid,
|
||||
"name": value.getModuleName(),
|
||||
"activated": value.getActivated()
|
||||
}
|
||||
|
||||
if(value.getChecked())
|
||||
{
|
||||
await fetch("http://localhost:8080/module?sessionid=" + localStorage.getItem("sessionid"), {
|
||||
method: method,
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: JSON.stringify(json1)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
router.back();
|
||||
}
|
||||
|
||||
class UserModuleInfo
|
||||
{
|
||||
constructor()
|
||||
{
|
||||
this.moduleName = "";
|
||||
this.userid = 0;
|
||||
this.activated = 0
|
||||
this.checked = false
|
||||
}
|
||||
|
||||
getModuleName() {return this.moduleName}
|
||||
getUserid() {return this.userid}
|
||||
getActivated() {return this.activated}
|
||||
getChecked() {return this.checked}
|
||||
|
||||
setModuleName(name) {this.moduleName = name}
|
||||
setUserid(id) {this.userid = id}
|
||||
setActivated(a) {this.activated = a}
|
||||
setChecked(b) {this.checked = b}
|
||||
}
|
||||
|
||||
function onModuleClicked(user, module) {
|
||||
|
||||
let found = false;
|
||||
|
||||
for (let i = 0; i < userInfo.length; i++) {
|
||||
let current = userInfo[i];
|
||||
if (current !== undefined && current.userid === user.id) {
|
||||
userInfo[i].setModule(module);
|
||||
found = true;
|
||||
if(userModuleMapping.has(user.id))
|
||||
{
|
||||
let temp = userModuleMapping.get(user.id)
|
||||
temp.setModuleName(module)
|
||||
temp.setUserid(user.id)
|
||||
console.log("test")
|
||||
}
|
||||
else
|
||||
{
|
||||
let temp = new UserModuleInfo()
|
||||
temp.setModuleName(module)
|
||||
temp.setUserid(user.id)
|
||||
userModuleMapping.set(user.id, temp)
|
||||
console.log("test1")
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
userInfo.push(new UserInfo(user.id, module));
|
||||
function onSelectedCheckBox(user, state)
|
||||
{
|
||||
if(userModuleMapping.has(user.id))
|
||||
{
|
||||
userModuleMapping.get(user.id).setChecked(state.target.checked);
|
||||
}
|
||||
else
|
||||
{
|
||||
let temp = new UserModuleInfo()
|
||||
temp.setChecked(state.target.checked)
|
||||
temp.setUserid(user.id)
|
||||
userModuleMapping.set(user.id, temp)
|
||||
}
|
||||
}
|
||||
|
||||
function onCheckBoxClicked(user, e) {
|
||||
onModuleClicked(user, "");
|
||||
|
||||
let found = false;
|
||||
|
||||
for (let i = 0; i < userInfo.length; i++) {
|
||||
let current = userInfo[i];
|
||||
if (current !== undefined && current.userid === user.id) {
|
||||
userInfo[i].setChecked(e.target.checked);
|
||||
found = true;
|
||||
function onActivatedCheckBox(user, state)
|
||||
{
|
||||
if(userModuleMapping.has(user.id))
|
||||
{
|
||||
let t = state.target.checked ? 1 : 0;
|
||||
userModuleMapping.get(user.id).setActivated(t);
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
let temp = new UserInfo(user.id, "");
|
||||
temp.setChecked(e.target.checked);
|
||||
userInfo.push(temp);
|
||||
else
|
||||
{
|
||||
let temp = new UserModuleInfo()
|
||||
let t = state.target.checked ? 1 : 0;
|
||||
temp.setActivated(t)
|
||||
temp.setUserid(user.id)
|
||||
userModuleMapping.set(user.id, temp)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,7 +255,7 @@ export default function InputForm(p) {
|
||||
flexDirection: "row",
|
||||
justifyContent: "center",
|
||||
}}><input type="checkbox" onChange={(e) => {
|
||||
onCheckBoxClicked(user, e);
|
||||
onSelectedCheckBox(user, e)
|
||||
}}/></div></td>
|
||||
|
||||
<td><div style={{
|
||||
@@ -217,7 +263,7 @@ export default function InputForm(p) {
|
||||
flexDirection: "row",
|
||||
justifyContent: "center",
|
||||
}}><input type="checkbox" onChange={(e) => {
|
||||
onCheckBoxClicked(user, e);
|
||||
onActivatedCheckBox(user, e);
|
||||
}}/></div></td>
|
||||
<td style={{textAlign: "center"}}>{user.firstName + " " + user.lastName}</td>
|
||||
<select id={"userSelect"} name={"userSelect"} className={"box-shadow selector"}
|
||||
@@ -228,6 +274,7 @@ export default function InputForm(p) {
|
||||
}} onChange={(e) => {
|
||||
onModuleClicked(user, e.target.value)
|
||||
}}>
|
||||
<option value={"Please Select"}>Please Select</option>
|
||||
<option value={"Programmieren"}>Programmieren</option>
|
||||
<option value={"BWL"}>BWL</option>
|
||||
<option value={"Lineare Algebra"}>Lineare Algebra</option>
|
||||
|
||||
@@ -16,7 +16,11 @@ export default function Logout()
|
||||
<div style={{
|
||||
position: "absolute",
|
||||
left: 20,
|
||||
top: 20
|
||||
top: 20,
|
||||
width: 130,
|
||||
height: 60,
|
||||
borderBottomRightRadius: 10,
|
||||
|
||||
}}>
|
||||
<Button onClick={() => logout()} text={"Logout"} color={"#77932b"} width={100} height={40}/>
|
||||
</div>
|
||||
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@@ -312,7 +312,7 @@ public class DataBaseHandler
|
||||
{
|
||||
try
|
||||
{
|
||||
st.executeUpdate("DELETE FROM modules WHERE semesterId = " + id);
|
||||
st.executeUpdate("DELETE FROM modules WHERE semesterid=" + id);
|
||||
|
||||
st.executeUpdate("delete from semester where id=" + id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user