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