In Semester Edit and Create there are real users to select now
And dummy data of modules to select from a list
This commit is contained in:
@@ -1,10 +1,29 @@
|
||||
import DozentSelector from "@/components/DozentSelector";
|
||||
import Button from "@/components/Button";
|
||||
import {useRouter} from "next/router";
|
||||
import {useState} from "react";
|
||||
import {useEffect, useState} from "react";
|
||||
|
||||
let userInfo = []
|
||||
|
||||
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 = "";
|
||||
@@ -18,6 +37,21 @@ export default function InputForm(p) {
|
||||
const [startDate, setStartDate] = useState(startDateParam);
|
||||
const [endDate, setEndDate] = useState(endDateParam);
|
||||
const [courseName, setCourseName] = useState(courseNameParam);
|
||||
const [users, setUsers] = useState([]);
|
||||
|
||||
async function getAllUsers() {
|
||||
let sessionid = localStorage.getItem("sessionid");
|
||||
let url = "http://localhost:8080/users/all?sessionid=" + sessionid;
|
||||
|
||||
|
||||
await fetch(url).then(response => response.json()).then(user => setUsers(user));
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
userInfo = [];
|
||||
getAllUsers();
|
||||
}, [])
|
||||
|
||||
async function onCreateClicked() {
|
||||
let startSplit = startDate.split("-");
|
||||
@@ -57,10 +91,48 @@ export default function InputForm(p) {
|
||||
router.back();
|
||||
}
|
||||
|
||||
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(!found) {
|
||||
userInfo.push(new UserInfo(user.id, module));
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
if(!found) {
|
||||
let temp = new UserInfo(user.id, "");
|
||||
temp.setChecked(e.target.checked);
|
||||
userInfo.push(temp);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="inputForm round-border">
|
||||
<h3>Kursname</h3>
|
||||
<h3>SemesterName</h3>
|
||||
<input className="courseNameInput" value={courseName} onChange={(e) => setCourseName(e.target.value)}/>
|
||||
<div className="semesterRangeInput">
|
||||
<div className="semesterDateLables">
|
||||
@@ -75,7 +147,37 @@ export default function InputForm(p) {
|
||||
onChange={(e) => setEndDate(e.target.value)}/>
|
||||
</div>
|
||||
</div>
|
||||
<DozentSelector/>
|
||||
<div className="round-border dozentSelector">
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>Dozent</th>
|
||||
<th>Modul</th>
|
||||
</tr>
|
||||
{users.map(user => (
|
||||
<tr>
|
||||
<td><input type="checkbox" onChange={(e) => {
|
||||
onCheckBoxClicked(user, e);
|
||||
}}/></td>
|
||||
<td>{user.firstName + " " + user.lastName}</td>
|
||||
<select id={"userSelect"} name={"userSelect"} multiple={false} style={{
|
||||
maxHeight: 80,
|
||||
border: "1px solid black"
|
||||
}} onChange={(e) => {
|
||||
onModuleClicked(user, e.target.value)
|
||||
}}>
|
||||
<option value={"Programmieren"}>Programmieren</option>
|
||||
<option value={"BWL"}>BWL</option>
|
||||
<option value={"Lineare Algebra"}>Lineare Algebra</option>
|
||||
<option value={"Analysis"}>Analysis</option>
|
||||
<option value={"AnwendungsProjekt"}>AnwendungsProjekt</option>
|
||||
</select>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div id="buttons">
|
||||
<Button color="red" width="100px" height="30px" text="Abbrechen" onClick={() => {
|
||||
router.back()
|
||||
|
||||
Reference in New Issue
Block a user