Merge Of Branches Multiselect
This commit is contained in:
@@ -796,7 +796,7 @@ export default function CalenderView(p) {
|
||||
width: "90%",
|
||||
backgroundColor: e === ErrorType.Okay ? "white" : "#e5a10e",
|
||||
borderRadius: 15,
|
||||
display: "flex",
|
||||
display: e === ErrorType.Okay ? "none" : "flex",
|
||||
flexDirection: "column",
|
||||
justifyContent: "center",
|
||||
gap: 10,
|
||||
|
||||
@@ -3,407 +3,357 @@ import {useRouter} from "next/router";
|
||||
import {useEffect, useState} from "react";
|
||||
import Background from "@/components/Background";
|
||||
import {baseURL} from "@/components/Constants";
|
||||
import Back from "@/components/Back";
|
||||
|
||||
let modulesDummy = [
|
||||
["Analysis", "Theo Inf 1"],
|
||||
["Lineare Algebra", "Anwendungsprojekt"],
|
||||
["Theo Inf 3", "Software Eng"],
|
||||
["Security", "BWL"],
|
||||
["Software Eng", "Security"],
|
||||
["Studienarbeit", "Bachelor"]
|
||||
]
|
||||
|
||||
let userModuleMapping = new Map()
|
||||
let tempSemesterNumber = 0
|
||||
let update = false
|
||||
|
||||
let baseMapping = []
|
||||
|
||||
export default function InputForm(p) {
|
||||
|
||||
let startDateParam = "";
|
||||
let endDateParam = "";
|
||||
let courseNameParam = "";
|
||||
const [startDate, setStartDate] = useState("0000-00-00")
|
||||
const [endDate, setEndDate] = useState("0000-00-00")
|
||||
const [courseName, setCourseName] = useState("")
|
||||
const [semesterNumber, setSemesterNumber] = useState(0)
|
||||
const [users, setUsers] = useState([])
|
||||
const [modulesSelectorValues, setModulesSelectorValues] = useState(["nothing", "nothing"])
|
||||
const [userModulesMapping, setUserModulesMapping] = useState({})
|
||||
const [isChecked, setIsChecked] = useState([])
|
||||
const [isActivated, setIsActivated] = useState([])
|
||||
const router = useRouter()
|
||||
|
||||
if (p.startDate != null) startDateParam = p.startDate;
|
||||
if (p.endDate != null) endDateParam = p.endDate;
|
||||
if (p.courseName != null) courseNameParam = p.courseName;
|
||||
useEffect(() => {
|
||||
|
||||
const router = useRouter();
|
||||
let base = baseURL + "/semester/id?sessionid=" + localStorage.getItem("sessionid") + "&id=" + localStorage.getItem("currentsid")
|
||||
fetch(base).then(r => r.json()).then(j => {
|
||||
setCourseName(j.name)
|
||||
|
||||
const [startDate, setStartDate] = useState(startDateParam);
|
||||
const [endDate, setEndDate] = useState(endDateParam);
|
||||
const [courseName, setCourseName] = useState(courseNameParam);
|
||||
const [users, setUsers] = useState([]);
|
||||
const [checkedSelected, setCheckedSelected] = useState(new Array(100).fill(false))
|
||||
const [activatedSelected, setActivatedSelected] = useState(new Array(100).fill(false))
|
||||
const [modulesNames, setModulesNames] = useState(new Array(100).fill("Please Select"))
|
||||
let tempStartDate = new Date(parseInt(j.startyear), 0, parseInt(j.startday))
|
||||
let tempEndDate = new Date(parseInt(j.endyear), 0, parseInt(j.endday))
|
||||
|
||||
async function getAllUsers() {
|
||||
let sessionid = localStorage.getItem("sessionid");
|
||||
let url = baseURL + "/users/all?sessionid=" + sessionid;
|
||||
setStartDate(tempStartDate.getFullYear() + "-" + ((tempStartDate.getMonth() + 1).toString().padStart(2, "0")) + "-" + tempStartDate.getDate().toString().padStart(2, "0"))
|
||||
setEndDate(tempEndDate.getFullYear() + "-" + ((tempEndDate.getMonth() + 1).toString().padStart(2, "0")) + "-" + tempEndDate.getDate().toString().padStart(2, "0"))
|
||||
|
||||
await fetch(url).then(response => response.json()).then(async user => {
|
||||
setUsers(user)
|
||||
let mURL = baseURL + "/module/suid?sessionid=" + localStorage.getItem("sessionid") + "&semesterid=" + localStorage.getItem("currentsid") + "&userid=";
|
||||
for(let i = 0; i < user.length; i++)
|
||||
{
|
||||
mURL += user[i].id;
|
||||
if(i < user.length - 1)
|
||||
{
|
||||
mURL += "a";
|
||||
}
|
||||
setSemesterNumber(j.number)
|
||||
tempSemesterNumber = j.number
|
||||
|
||||
}).then(() => {
|
||||
readModules()
|
||||
update = true
|
||||
}).catch(() => readModules())
|
||||
|
||||
|
||||
}, [])
|
||||
|
||||
function readModules() {
|
||||
let usersTemp = []
|
||||
|
||||
let userURL = baseURL + "/users/all?sessionid=" + localStorage.getItem("sessionid")
|
||||
fetch(userURL).then(r => r.json()).then(j => {
|
||||
setUsers(j)
|
||||
usersTemp = j
|
||||
let temp = [false, false, false]
|
||||
let temp2 = []
|
||||
for (let i = 0; i < j.length; i++) {
|
||||
temp.push(false)
|
||||
temp2.push(false)
|
||||
}
|
||||
setIsChecked(temp)
|
||||
setIsActivated(temp2)
|
||||
}).then(() => {
|
||||
let modulesURL = baseURL + "/module/bysemesterid?sessionid=" + localStorage.getItem("sessionid") + "&semesterid=" + localStorage.getItem("currentsid");
|
||||
fetch(modulesURL).then(r => r.json()).then(j => {
|
||||
|
||||
fetch(mURL).then(result => result.json()).then(m => {
|
||||
let temp = []
|
||||
setUserModulesMapping(j)
|
||||
baseMapping = j
|
||||
|
||||
for(let i = 0; i < user.length; i++)
|
||||
{
|
||||
temp.push(m[i] != null);
|
||||
}
|
||||
let temp = isChecked.slice()
|
||||
let temp2 = isActivated.slice()
|
||||
|
||||
setCheckedSelected(temp);
|
||||
for (let i = 0; i < usersTemp.length; i++) {
|
||||
let currentUser = usersTemp[i]
|
||||
|
||||
temp = []
|
||||
let found = false
|
||||
let foundModuleLast = null
|
||||
for (let f = 0; f < j.length; f++) {
|
||||
let currentModule = j[f]
|
||||
|
||||
for(let i = 0; i < user.length; i++)
|
||||
{
|
||||
temp.push(m[i] != null && m[i].activated === 1);
|
||||
if (currentModule.userid === currentUser.id) {
|
||||
found = true
|
||||
foundModuleLast = currentModule
|
||||
}
|
||||
}
|
||||
|
||||
if(m[i] != null) {
|
||||
let tempModuleInfo = new UserModuleInfo();
|
||||
tempModuleInfo.setModuleName(m[i].name);
|
||||
tempModuleInfo.setActivated(m[i].activated);
|
||||
tempModuleInfo.setChecked(true);
|
||||
tempModuleInfo.setUserid(user[i].id)
|
||||
userModuleMapping.set(user[i].id, tempModuleInfo)
|
||||
if (found) {
|
||||
temp[i] = true
|
||||
|
||||
temp2[i] = foundModuleLast.activated === 1
|
||||
}
|
||||
}
|
||||
|
||||
setActivatedSelected(temp);
|
||||
|
||||
temp = []
|
||||
|
||||
for(let i = 0; i < user.length; i++)
|
||||
{
|
||||
temp.push(m[i] == null ? "Please Select" : m[i].name);
|
||||
}
|
||||
|
||||
setModulesNames(temp);
|
||||
|
||||
});
|
||||
|
||||
for(let i = 0; i < user.length; i++)
|
||||
{
|
||||
if(!userModuleMapping.has(user[i].id)) {
|
||||
let tempModuleInfo = new UserModuleInfo();
|
||||
tempModuleInfo.setModuleName("Please Select");
|
||||
tempModuleInfo.setActivated(0);
|
||||
tempModuleInfo.setChecked(false);
|
||||
tempModuleInfo.setUserid(user[i].id)
|
||||
userModuleMapping.set(user[i].id, tempModuleInfo)
|
||||
}
|
||||
}
|
||||
});
|
||||
setIsChecked(temp)
|
||||
setIsActivated(temp2)
|
||||
})
|
||||
}).then(() => {
|
||||
setModulesSelectorValues(modulesDummy[tempSemesterNumber])
|
||||
})
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
getAllUsers()
|
||||
userModuleMapping.clear();
|
||||
}, [])
|
||||
function onCourseNameChange(e) {
|
||||
setCourseName(e.target.value)
|
||||
}
|
||||
|
||||
function onStartDateChange(e) {
|
||||
setStartDate(e.target.value)
|
||||
}
|
||||
|
||||
function onEndDateChange(e) {
|
||||
setEndDate(e.target.value)
|
||||
}
|
||||
|
||||
function onSemesterNumberChange(e) {
|
||||
setSemesterNumber(e.target.value)
|
||||
setModulesSelectorValues(modulesDummy[e.target.value])
|
||||
}
|
||||
|
||||
function isOptionSelected(e, userid) {
|
||||
let found = false;
|
||||
|
||||
for (let i = 0; i < userModulesMapping.length; i++) {
|
||||
let current = userModulesMapping[i]
|
||||
if (current.name === e && current.userid === userid) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function onCreateClicked() {
|
||||
let startSplit = startDate.split("-");
|
||||
let endSplit = endDate.split("-");
|
||||
let startYear = parseInt(startSplit[0]);
|
||||
let endYear = parseInt(endSplit[0]);
|
||||
return found;
|
||||
}
|
||||
|
||||
//month - 1 because jan = 0, day like month... but because of next lines 3 to 4 not - 1
|
||||
let startInternalDate = new Date(startYear, parseInt(startSplit[1]) - 1, parseInt(startSplit[2]))
|
||||
let endInternalDate = new Date(endYear, parseInt(endSplit[1]) - 1, parseInt(endSplit[2]))
|
||||
function onCheckedChange(e, index) {
|
||||
let temp = isChecked.slice()
|
||||
temp[index] = e.target.checked
|
||||
setIsChecked(temp)
|
||||
|
||||
let startDayInYear = Math.round((startInternalDate - new Date(startYear, 0, 0)) / (1000 * 60 * 60 * 24));
|
||||
let endDayInYear = Math.round((endInternalDate - new Date(endYear, 0, 0)) / (1000 * 60 * 60 * 24));
|
||||
if (!e.target.checked) {
|
||||
let temp = []
|
||||
let currentUser = users[index]
|
||||
for (let j = 0; j < userModulesMapping.length; j++) {
|
||||
if (userModulesMapping[j].userid !== currentUser.id) {
|
||||
temp.push(userModulesMapping[j])
|
||||
}
|
||||
}
|
||||
|
||||
let id = p.courseName == null ? 0 : localStorage.getItem("currentsid");
|
||||
setUserModulesMapping(temp)
|
||||
}
|
||||
}
|
||||
|
||||
let json = {
|
||||
"id": id,
|
||||
function onActivatedChange(e, index) {
|
||||
|
||||
let temp = isActivated.slice()
|
||||
temp[index] = e.target.checked
|
||||
setIsActivated(temp)
|
||||
|
||||
let userid = users[index].id
|
||||
|
||||
for (let j = 0; j < userModulesMapping.length; j++) {
|
||||
if (userModulesMapping[j].userid === userid) {
|
||||
userModulesMapping[j].activated = e.target.checked ? 1 : 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function onModuleSelectionChange(e, index) {
|
||||
let userid = users[index].id
|
||||
|
||||
let newMapping = []
|
||||
let oldNamesIds = new Map()
|
||||
|
||||
for (let j = 0; j < userModulesMapping.length; j++) {
|
||||
let currentModuleMapping = userModulesMapping[j]
|
||||
if (currentModuleMapping.userid != userid) {
|
||||
newMapping.push(currentModuleMapping)
|
||||
} else {
|
||||
oldNamesIds.set(currentModuleMapping.name, currentModuleMapping.id)
|
||||
}
|
||||
}
|
||||
|
||||
let found = false
|
||||
for (let i = 0; i < e.target.options.length; i++) {
|
||||
|
||||
let currentOption = e.target.options[i]
|
||||
if (currentOption.selected) {
|
||||
found = true
|
||||
|
||||
newMapping.push({
|
||||
"id": oldNamesIds.has(currentOption.value) ? oldNamesIds.get(currentOption.value) : -1,
|
||||
"userid": userid,
|
||||
"semesterid": -1,
|
||||
"name": currentOption.value,
|
||||
"activated": isActivated[index] ? 1 : 0
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
let temp = isChecked.slice()
|
||||
temp[index] = found
|
||||
setIsChecked(temp)
|
||||
|
||||
setUserModulesMapping(newMapping)
|
||||
}
|
||||
|
||||
function onButtonAbort() {
|
||||
router.back()
|
||||
}
|
||||
|
||||
function onButtonSave() {
|
||||
let tempDateStart = new Date(parseInt(startDate.split("-")[0]), parseInt(startDate.split("-")[1]) - 1, parseInt(startDate.split("-")[2]))
|
||||
let tempDateEnd = new Date(parseInt(endDate.split("-")[0]), parseInt(endDate.split("-")[1]) - 1, parseInt(endDate.split("-")[2]))
|
||||
|
||||
let startDayInYear = Math.round((tempDateStart - new Date(tempDateStart.getFullYear(), 0, 0)) / (1000 * 60 * 60 * 24))
|
||||
let endDayInYear = Math.round((tempDateEnd - new Date(tempDateEnd.getFullYear(), 0, 0)) / (1000 * 60 * 60 * 24))
|
||||
|
||||
|
||||
let semesterJson = {
|
||||
"id": update ? localStorage.getItem("currentsid") : 0,
|
||||
"startday": startDayInYear,
|
||||
"endday": endDayInYear,
|
||||
"name": courseName,
|
||||
"startyear": startYear,
|
||||
"endyear": endYear
|
||||
"startyear": tempDateStart.getFullYear(),
|
||||
"endyear": tempDateEnd.getFullYear(),
|
||||
"number": semesterNumber
|
||||
}
|
||||
|
||||
let url = baseURL + "/semester?sessionid=" + localStorage.getItem("sessionid");
|
||||
let method = p.courseName == null ? "POST" : "PUT";
|
||||
|
||||
|
||||
let semesterid = localStorage.getItem("currentsid");
|
||||
let tempsid = 0;
|
||||
await fetch(url, {
|
||||
method: method,
|
||||
fetch(baseURL + "/semester?sessionid=" + localStorage.getItem("sessionid"), {
|
||||
method: update ? "PUT" : "POST",
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: JSON.stringify(json)
|
||||
}).then(response => response.json()).then(semester => {
|
||||
tempsid = semester.id
|
||||
});
|
||||
body: JSON.stringify(semesterJson)
|
||||
}).then(r => r.json()).then(async sem => {
|
||||
let semesterID = sem.id
|
||||
|
||||
for (let i = 0; i < baseMapping.length; i++) {
|
||||
let found = false
|
||||
for (let j = 0; j < userModulesMapping.length; j++) {
|
||||
if (baseMapping[i].name === userModulesMapping[j].name) {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
|
||||
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 (!found) {
|
||||
fetch(baseURL + "/module?sessionid=" + localStorage.getItem("sessionid") + "&id=" + baseMapping[i].id, {
|
||||
method: "DELETE"
|
||||
})
|
||||
}
|
||||
}
|
||||
if (value.getChecked()) {
|
||||
let updateURL = baseURL + "/module?sessionid=" + localStorage.getItem("sessionid");
|
||||
await fetch(updateURL, {
|
||||
method: method,
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: JSON.stringify(json1)
|
||||
})
|
||||
|
||||
for (let i = 0; i < userModulesMapping.length; i++) {
|
||||
|
||||
userModulesMapping[i].semesterid = semesterID
|
||||
setTimeout(() => {
|
||||
console.log(userModulesMapping[i])
|
||||
fetch(baseURL + "/module?sessionid=" + localStorage.getItem("sessionid"), {
|
||||
method: userModulesMapping[i].id === -1 ? "POST" : "PUT",
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: JSON.stringify(userModulesMapping[i])
|
||||
})
|
||||
}, i * 100)
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
let deleteURL = baseURL + "/module?sessionid=" + localStorage.getItem("sessionid") +
|
||||
"&semesterid=" + semesterid +
|
||||
"&userid=" + value.getUserid();
|
||||
await fetch(deleteURL, {
|
||||
method: "DELETE"
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
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, index) {
|
||||
|
||||
if (userModuleMapping.has(user.id)) {
|
||||
let temp = userModuleMapping.get(user.id)
|
||||
temp.setModuleName(module)
|
||||
temp.setUserid(user.id)
|
||||
}
|
||||
|
||||
let temp = [];
|
||||
|
||||
for(let i = 0; i < modulesNames.length; i++)
|
||||
{
|
||||
temp.push(modulesNames[i]);
|
||||
}
|
||||
|
||||
temp[index] = module;
|
||||
|
||||
setModulesNames(temp);
|
||||
}
|
||||
|
||||
function onSelectedCheckBox(user, state, index) {
|
||||
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)
|
||||
}
|
||||
let temp = []
|
||||
|
||||
for(let i = 0; i < checkedSelected.length; i++)
|
||||
{
|
||||
temp.push(checkedSelected[i]);
|
||||
}
|
||||
|
||||
temp[index] = state.target.checked;
|
||||
|
||||
setCheckedSelected(temp);
|
||||
|
||||
}
|
||||
|
||||
function onActivatedCheckBox(user, state, index) {
|
||||
if (userModuleMapping.has(user.id)) {
|
||||
let t = state.target.checked ? 1 : 0;
|
||||
userModuleMapping.get(user.id).setActivated(t);
|
||||
}
|
||||
|
||||
let temp = []
|
||||
|
||||
for(let i = 0; i < checkedSelected.length; i++)
|
||||
{
|
||||
temp.push(activatedSelected[i]);
|
||||
}
|
||||
|
||||
temp[index] = state.target.checked;
|
||||
|
||||
setActivatedSelected(temp);
|
||||
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
<Background/>
|
||||
<div className="inputForm box-shadow">
|
||||
<p style={{
|
||||
fontSize: "18px",
|
||||
color: "#777777",
|
||||
fontWeight: 500,
|
||||
width: 150
|
||||
}}>Kursname</p>
|
||||
<input className="courseNameInput box-shadow" value={courseName}
|
||||
onChange={(e) => setCourseName(e.target.value)}/>
|
||||
<div className="semesterRangeInput">
|
||||
<div className="semesterDateLables">
|
||||
<p className="semesterDateLable" style={{
|
||||
fontSize: " 18px",
|
||||
color: "#777777",
|
||||
fontWeight: 500,
|
||||
width: 150
|
||||
}}>Theorie Anfang</p>
|
||||
<p className="semesterDateLable" style={{
|
||||
fontSize: " 18px",
|
||||
color: "#777777",
|
||||
fontWeight: 500,
|
||||
width: 150
|
||||
}}>Theorie Ende</p>
|
||||
</div>
|
||||
<div className={"MeinTest"}>
|
||||
<div className="semesterDateInputPair">
|
||||
<input type="date" id="start" className={"box-shadow selector"} value={startDate}
|
||||
style={{
|
||||
padding: 5,
|
||||
backgroundColor: (startDate == "" || startDate >= endDate) ? "#E44747" : "white"
|
||||
}}
|
||||
onChange={(e) => setStartDate(e.target.value)}/>
|
||||
<p className="inputFieldSeperator">-</p>
|
||||
<input type="date" id="start" className={"box-shadow selector"} value={endDate}
|
||||
style={{
|
||||
padding: 5,
|
||||
backgroundColor: (endDate == "" || startDate >= endDate) ? "#E44747" : "white"
|
||||
}}
|
||||
onChange={(e) => setEndDate(e.target.value)}/>
|
||||
</div>
|
||||
</div>
|
||||
<div className={"box-shadow input-form round-border"}>
|
||||
|
||||
<p>Kursname</p>
|
||||
<input type={"text"} className={"box-shadow round-border"} style={{padding: 8, width: "100%"}}
|
||||
onChange={e => onCourseNameChange(e)} value={courseName}/>
|
||||
|
||||
<div style={{display: "flex", justifyContent: "flex-start", gap: 40}}>
|
||||
<p>Theorie Anfang</p>
|
||||
<p>Theorie Ende</p>
|
||||
</div>
|
||||
<div className="round-border dozentSelector">
|
||||
<div style={{display: "flex", justifyContent: "flex-start", gap: 20}}>
|
||||
<input type={"date"} className={"box-shadow round-border"} style={{padding: 8}}
|
||||
onChange={e => onStartDateChange(e)} value={startDate}/>
|
||||
<input type={"date"} className={"box-shadow round-border"} style={{padding: 8}}
|
||||
onChange={e => onEndDateChange(e)} value={endDate}/>
|
||||
</div>
|
||||
|
||||
<p>Semester Wählen</p>
|
||||
<select className={"round-border box-shadow"} style={{padding: 5, width: "100%"}} value={semesterNumber}
|
||||
onChange={e => onSemesterNumberChange(e)}>
|
||||
<option value={0}>1. Semester</option>
|
||||
<option value={1}>2. Semester</option>
|
||||
<option value={2}>3. Semester</option>
|
||||
<option value={3}>4. Semester</option>
|
||||
<option value={4}>5. Semester</option>
|
||||
<option value={5}>6. Semester</option>
|
||||
</select>
|
||||
|
||||
<div className={"table-wrapper"}>
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th style={{
|
||||
fontSize: " 18px",
|
||||
color: "#777777",
|
||||
fontWeight: 500,
|
||||
}}>Wählen
|
||||
</th>
|
||||
<th style={{
|
||||
fontSize: " 18px",
|
||||
color: "#777777",
|
||||
fontWeight: 500,
|
||||
}}>Freischalten
|
||||
</th>
|
||||
<th style={{
|
||||
fontSize: " 18px",
|
||||
color: "#777777",
|
||||
fontWeight: 500,
|
||||
textAlign: "center"
|
||||
}}>Dozent
|
||||
</th>
|
||||
<th style={{
|
||||
fontSize: " 18px",
|
||||
color: "#777777",
|
||||
fontWeight: 500,
|
||||
textAlign: "center",
|
||||
}}>Modul
|
||||
</th>
|
||||
<th>Wählen</th>
|
||||
<th>Freischalten</th>
|
||||
<th>Dozent</th>
|
||||
<th>Modul</th>
|
||||
</tr>
|
||||
{users.map((user, i) => (
|
||||
<tr>
|
||||
|
||||
<td>
|
||||
<div style={{
|
||||
display: "flex",
|
||||
flexDirection: "row",
|
||||
justifyContent: "center",
|
||||
}}><input type="checkbox" onChange={(e) => {
|
||||
onSelectedCheckBox(user, e, i)
|
||||
}} checked={checkedSelected[i]}/></div>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<div style={{
|
||||
display: "flex",
|
||||
flexDirection: "row",
|
||||
justifyContent: "center",
|
||||
}}><input type="checkbox" onChange={(e) => {
|
||||
onActivatedCheckBox(user, e, i);
|
||||
}} checked={activatedSelected[i]}/></div>
|
||||
</td>
|
||||
<td style={{textAlign: "center"}}>{user.firstName + " " + user.lastName}</td>
|
||||
<select id={"userSelect"} name={"userSelect"} className={"box-shadow selector"}
|
||||
multiple={false} style={{
|
||||
maxHeight: 80,
|
||||
marginTop: 10,
|
||||
padding: "5px 2px"
|
||||
}} onChange={(e) => {
|
||||
onModuleClicked(user, e.target.value, i)
|
||||
}} value={modulesNames[i]}>
|
||||
<option value={"Please Select"}>Please Select</option>
|
||||
<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>
|
||||
))}
|
||||
{
|
||||
users.map((user, index) => (
|
||||
<tr>
|
||||
<td>
|
||||
<input type={"checkbox"} checked={isChecked[index]}
|
||||
onChange={e => onCheckedChange(e, index)}/>
|
||||
</td>
|
||||
<td>
|
||||
<input type={"checkbox"} checked={isActivated[index]}
|
||||
onChange={e => onActivatedChange(e, index)}/>
|
||||
</td>
|
||||
<td>
|
||||
{user.firstName + " " + user.lastName}
|
||||
</td>
|
||||
<td>
|
||||
<select multiple={true} className={"box-shadow round-border"}
|
||||
style={{padding: 5}}
|
||||
onChange={e => onModuleSelectionChange(e, index)}>
|
||||
{modulesSelectorValues.map(msv => (
|
||||
<option value={msv}
|
||||
selected={isOptionSelected(msv, user.id)}>{msv}</option>
|
||||
))}
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
))
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div id="buttons">
|
||||
<Button color="rgba(54,54,54,0.64)" width="100px" height="30px" text="Abbrechen" onClick={() => {
|
||||
router.back()
|
||||
}}/>
|
||||
<Button color="#77932b" width="100px" height="30px" text="Speichern" onClick={() => { (startDate == "" || endDate == ""|| startDate >= endDate) ? () => {} : onCreateClicked()}
|
||||
}/>
|
||||
|
||||
<div style={{
|
||||
display: "flex",
|
||||
justifyContent: "flex-end",
|
||||
alignItems: "center",
|
||||
width: "100%",
|
||||
gap: 10
|
||||
}}>
|
||||
<Button text={"Abbrechen"} onClick={onButtonAbort}/>
|
||||
<Button text={"Speichern"} color={"#77932b"} onClick={onButtonSave}/>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
|
||||
@@ -101,7 +101,7 @@ export default function SemesterOverview(p) {
|
||||
<Background/>
|
||||
{
|
||||
entries.map(e => (
|
||||
<div className={"semester-tile box-shadow"}>
|
||||
<div className={"semester-tile box-shadow"} onClick={(f) => onClickSemester(e, f)}>
|
||||
<SemesterTile text={e.name} onClick={(f) => onClickSemester(e, f)} onButtonDeleteClick={() => {
|
||||
localStorage.setItem("currentsid", e.id)
|
||||
setModalHint(e.name + " Löschen?");
|
||||
|
||||
@@ -62,7 +62,7 @@ export default function SemesteroverviewLecturer(p) {
|
||||
{entries.map((e, index) => (
|
||||
<div className={"semester-tile box-shadow"} style={{
|
||||
backgroundColor: e.activated == 1 ? "#ffffff" : "#aaaaaa"
|
||||
}}>
|
||||
}} onClick={(f) => onClickSemester(e, f)}>
|
||||
<SemesterTile
|
||||
editable={false} text={semesterNames[index]} text2={e.name}
|
||||
onClick={(f) => onClickSemester(e, f)}
|
||||
|
||||
@@ -73,6 +73,48 @@ body {
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0,1);
|
||||
}
|
||||
|
||||
/*
|
||||
Input Form
|
||||
*/
|
||||
|
||||
.input-form
|
||||
{
|
||||
width: 600px;
|
||||
background-color: white;
|
||||
padding: 30px;
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-around;
|
||||
align-items: flex-start;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
|
||||
table
|
||||
{
|
||||
width: 550px;
|
||||
}
|
||||
|
||||
.table-wrapper
|
||||
{
|
||||
max-height: 40%;
|
||||
overflow-y: scroll;
|
||||
}
|
||||
|
||||
td
|
||||
{
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.input-form p, .input-form th
|
||||
{
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
color: #5e5e5e;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Button
|
||||
*/
|
||||
@@ -117,6 +159,7 @@ Step Progress Bar
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
max-width: 400px;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.steps {
|
||||
@@ -127,6 +170,7 @@ Step Progress Bar
|
||||
gap: 20px;
|
||||
width: 100%;
|
||||
position: relative;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.step {
|
||||
@@ -138,6 +182,7 @@ Step Progress Bar
|
||||
justify-content: center;
|
||||
color: white;
|
||||
font-weight: bold;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.steps .not-started {
|
||||
@@ -391,99 +436,6 @@ Calender View
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/*
|
||||
inputForm
|
||||
*/
|
||||
|
||||
input {
|
||||
border-width: 2px;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.courseNameInput {
|
||||
width: 300px;
|
||||
padding: 5px;
|
||||
border: none;
|
||||
background-color: white;
|
||||
border-radius: 5px;
|
||||
font-family: Arial, serif;
|
||||
}
|
||||
|
||||
.selector
|
||||
{
|
||||
border-width: 0;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.semesterDateInput {
|
||||
width: 150px;
|
||||
padding: 5px;
|
||||
border: none;
|
||||
background-color: white;
|
||||
border-radius: 5px;
|
||||
font-family: Arial, serif;
|
||||
}
|
||||
|
||||
.semesterDateLables, .semesterDateInputPair {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: left;
|
||||
padding: 0;
|
||||
border: none;
|
||||
background-color: white;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.inputFieldSeperator {
|
||||
width: 40px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.semesterDateLable {
|
||||
margin-right: 32px;
|
||||
}
|
||||
|
||||
.semesterRangeInput {
|
||||
margin-top: 50px;
|
||||
}
|
||||
|
||||
.inputForm {
|
||||
width: 600px;
|
||||
height: 600px;
|
||||
padding: 20px;
|
||||
/*border: solid;*/
|
||||
border-radius: 10px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
#buttons {
|
||||
align-self: flex-end;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: flex-end;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.dozentSelector {
|
||||
height: 350px;
|
||||
/*border: solid;*/
|
||||
margin-top: 20px;
|
||||
width: 500px;
|
||||
padding: 10px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
th {
|
||||
text-align: left;
|
||||
padding: 0 10px;
|
||||
}
|
||||
|
||||
td {
|
||||
padding: 0 10px;
|
||||
}
|
||||
|
||||
/*
|
||||
Login
|
||||
*/
|
||||
@@ -574,9 +526,6 @@ SemesterTile
|
||||
font-size: 23px;
|
||||
}
|
||||
|
||||
.semester-tile .step-container {
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.Error
|
||||
{
|
||||
|
||||
@@ -10,15 +10,12 @@ import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DataBaseHandler
|
||||
{
|
||||
public class DataBaseHandler {
|
||||
//singleton instance of database handler
|
||||
private static DataBaseHandler instance = null;
|
||||
|
||||
public static DataBaseHandler getInstance()
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
public static DataBaseHandler getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new DataBaseHandler();
|
||||
}
|
||||
|
||||
@@ -31,22 +28,19 @@ public class DataBaseHandler
|
||||
private Statement st;
|
||||
private boolean encrypted = false;
|
||||
|
||||
public DataBaseHandler()
|
||||
{
|
||||
try
|
||||
{
|
||||
public DataBaseHandler() {
|
||||
try {
|
||||
//connect to the local database
|
||||
connection = DriverManager.getConnection("jdbc:h2:./database", "adm", "73bgjfdsfJ!934");
|
||||
st = connection.createStatement();
|
||||
} catch (SQLException e)
|
||||
{
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
ENTRIES
|
||||
* ENTRIES
|
||||
*/
|
||||
public void addEntry(Entry entry)
|
||||
{
|
||||
@@ -55,7 +49,7 @@ public class DataBaseHandler
|
||||
st.executeUpdate("insert into entries (daynumber, yearnumber, semesterid, usercreatedbyid, timestart, timeend, moduleid, info) values (" +
|
||||
entry.getDaynumber() + ", " + entry.getYearnumber() + ", " + entry.getSemesterid() + ", " +
|
||||
entry.getUsercreatedbyid() + ", " + entry.getTimestart() + ", " + entry.getTimeend() + ", " + entry.getModuleid() + " ,'" + entry.getInfo() + "')"
|
||||
);
|
||||
);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
@@ -63,10 +57,8 @@ public class DataBaseHandler
|
||||
}
|
||||
}
|
||||
|
||||
public Entry[][] getEntries(int semesterid, int daynumber, int yearnumber)
|
||||
{
|
||||
try
|
||||
{
|
||||
public Entry[][] getEntries(int semesterid, int daynumber, int yearnumber) {
|
||||
try {
|
||||
ResultSet rs = st.executeQuery("select * from entries where " +
|
||||
"semesterid=" + semesterid +
|
||||
" and yearnumber=" + yearnumber +
|
||||
@@ -74,20 +66,16 @@ public class DataBaseHandler
|
||||
|
||||
List<Entry> entryList = new ArrayList<>();
|
||||
Entry current = null;
|
||||
while((current = resultSetToEntry(rs)) != null)
|
||||
{
|
||||
while ((current = resultSetToEntry(rs)) != null) {
|
||||
entryList.add(current);
|
||||
}
|
||||
|
||||
Entry[][] entries = new Entry[6][20];
|
||||
for(int i = 0; i < 6; i++)
|
||||
{
|
||||
for (int i = 0; i < 6; i++) {
|
||||
int f = 0;
|
||||
|
||||
for(int j = 0; j < entryList.size(); j++)
|
||||
{
|
||||
if(entryList.get(j).getDaynumber() == i + daynumber)
|
||||
{
|
||||
for (int j = 0; j < entryList.size(); j++) {
|
||||
if (entryList.get(j).getDaynumber() == i + daynumber) {
|
||||
entries[i][f] = entryList.get(j);
|
||||
f++;
|
||||
}
|
||||
@@ -95,16 +83,13 @@ public class DataBaseHandler
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
} 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 {
|
||||
ResultSet rs = st.executeQuery("select * from entries where " +
|
||||
"semesterid<>" + semesterid +
|
||||
@@ -113,45 +98,38 @@ public class DataBaseHandler
|
||||
" and daynumber between " + daynumber + " and " + daynumber + 6);
|
||||
List<Entry> entryList = new ArrayList<>();
|
||||
Entry current = null;
|
||||
while((current = resultSetToEntry(rs)) != null)
|
||||
{
|
||||
while ((current = resultSetToEntry(rs)) != null) {
|
||||
entryList.add(current);
|
||||
}
|
||||
Entry[][] entries = new Entry[6][20];
|
||||
for(int i = 0; i < 6; i++)
|
||||
{
|
||||
for (int i = 0; i < 6; i++) {
|
||||
int f = 0;
|
||||
|
||||
for(int j = 0; j < entryList.size(); j++)
|
||||
{
|
||||
if(entryList.get(j).getDaynumber() == i + daynumber)
|
||||
{
|
||||
for (int j = 0; j < entryList.size(); j++) {
|
||||
if (entryList.get(j).getDaynumber() == i + daynumber) {
|
||||
entries[i][f] = entryList.get(j);
|
||||
f++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return entries;
|
||||
}catch(Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Entry[] getAllEntries(int semesterid, int userid)
|
||||
{
|
||||
public Entry[] getAllEntries(int semesterid, int userid) {
|
||||
try {
|
||||
ResultSet rs = st.executeQuery("select * from entries where " +
|
||||
"semesterid=" + semesterid +
|
||||
" and usercreatedbyid=" + userid);
|
||||
List<Entry> entriestate = new ArrayList<>();
|
||||
Entry current = null;
|
||||
while((current = resultSetToEntry(rs)) != null)
|
||||
{
|
||||
Entry current = null;
|
||||
while ((current = resultSetToEntry(rs)) != null) {
|
||||
entriestate.add(current);
|
||||
}
|
||||
return entriestate.toArray(new Entry[0]);
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -175,26 +153,18 @@ public class DataBaseHandler
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteEntry(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
public void deleteEntry(int id) {
|
||||
try {
|
||||
st.executeUpdate("delete from entries where id=" + id);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void updateEntry(Entry entry)
|
||||
{
|
||||
try
|
||||
{
|
||||
public void updateEntry(Entry entry) {
|
||||
try {
|
||||
st.executeUpdate("update entries set timeend=" + entry.getTimeend() + ", timestart=" + entry.getTimestart() + " where id=" + entry.getId());
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -224,105 +194,81 @@ public class DataBaseHandler
|
||||
|
||||
|
||||
/**
|
||||
SEMESTER
|
||||
* SEMESTER
|
||||
*/
|
||||
//get a semester object by its name
|
||||
public Semester getSemester(String name)
|
||||
{
|
||||
try
|
||||
{
|
||||
public Semester getSemester(String name) {
|
||||
try {
|
||||
ResultSet rs = st.executeQuery("select * from SEMESTER where name = '" + name + "'");
|
||||
return resultSetToSemester(rs);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Semester getSemester(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
public Semester getSemester(int id) {
|
||||
try {
|
||||
ResultSet rs = st.executeQuery("select * from semester where id=" + id);
|
||||
return resultSetToSemester(rs);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//write a new semester to the database returns if process was successful
|
||||
public Semester addSemester(Semester s)
|
||||
{
|
||||
try
|
||||
{
|
||||
st.executeUpdate("insert into SEMESTER (startday, endday, name, startyear, endyear) values (" + s.getStartday() + ", " + s.getEndday() + ", '" + s.getName() + "', " + s.getStartyear() + ", " + s.getEndyear() + ")");
|
||||
public Semester addSemester(Semester s) {
|
||||
try {
|
||||
st.executeUpdate("insert into SEMESTER (startday, endday, name, startyear, endyear, number) values (" + s.getStartday() + ", " + s.getEndday() + ", '" + s.getName() + "', " + s.getStartyear() + ", " + s.getEndyear() + ", " + s.getNumber() + ")");
|
||||
return getSemester(s.getName());
|
||||
|
||||
} catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Semester[] getAllSemesters()
|
||||
{
|
||||
try
|
||||
{
|
||||
public Semester[] getAllSemesters() {
|
||||
try {
|
||||
ResultSet rs = st.executeQuery("select * from semester");
|
||||
List<Semester> semestersList = new ArrayList<>();
|
||||
Semester s = null;
|
||||
while((s = resultSetToSemester(rs)) != null)
|
||||
{
|
||||
while ((s = resultSetToSemester(rs)) != null) {
|
||||
semestersList.add(s);
|
||||
}
|
||||
|
||||
return semestersList.toArray(new Semester[0]);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Semester updateSemester(Semester semester)
|
||||
{
|
||||
try
|
||||
{
|
||||
public Semester updateSemester(Semester semester) {
|
||||
try {
|
||||
st.executeUpdate("update semester set startday=" + semester.getStartday() + ", " +
|
||||
"endday=" + semester.getEndday() + ", " +
|
||||
"name='" + semester.getName() + "', " +
|
||||
"startyear=" + semester.getStartyear() + ", " +
|
||||
"number=" + semester.getNumber() + ", " +
|
||||
"endyear=" + semester.getEndyear() + " where id=" + semester.getId());
|
||||
|
||||
return getSemester(semester.getId());
|
||||
} catch (SQLException e)
|
||||
{
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteSemester(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
public void deleteSemester(int id) {
|
||||
try {
|
||||
st.executeUpdate("DELETE FROM modules WHERE semesterid=" + id);
|
||||
|
||||
st.executeUpdate("delete from semester where id=" + id);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public Semester resultSetToSemester(ResultSet rs)
|
||||
{
|
||||
try
|
||||
{
|
||||
public Semester resultSetToSemester(ResultSet rs) {
|
||||
try {
|
||||
rs.next();
|
||||
return new Semester(
|
||||
rs.getInt("id"),
|
||||
@@ -330,40 +276,34 @@ public class DataBaseHandler
|
||||
rs.getInt("endday"),
|
||||
rs.getString("name"),
|
||||
rs.getInt("startyear"),
|
||||
rs.getInt("endyear")
|
||||
rs.getInt("endyear"),
|
||||
rs.getInt("number")
|
||||
);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
MODULE
|
||||
* MODULE
|
||||
*/
|
||||
|
||||
//get a module object by its id
|
||||
public Module getModule(int id) {
|
||||
try {
|
||||
ResultSet rs = st.executeQuery("SELECT * FROM modules WHERE id=" + id);
|
||||
return resultSetToModule(rs);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return resultSetToModule(rs);
|
||||
} catch (Exception ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Module getModule(int userid, int semesterid)
|
||||
{
|
||||
try
|
||||
{
|
||||
public Module getModule(int userid, int semesterid) {
|
||||
try {
|
||||
ResultSet rs = st.executeQuery("select * from modules where userid=" + userid + " and semesterid=" + semesterid);
|
||||
|
||||
return resultSetToModule(rs);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -374,96 +314,64 @@ public class DataBaseHandler
|
||||
ResultSet rs = st.executeQuery("SELECT * FROM modules WHERE userid = " + userid);
|
||||
List<Module> moduleList = new ArrayList<>();
|
||||
Module m = null;
|
||||
while((m = resultSetToModule(rs)) != null)
|
||||
{
|
||||
while ((m = resultSetToModule(rs)) != null) {
|
||||
moduleList.add(m);
|
||||
}
|
||||
|
||||
return moduleList.toArray(new Module[0]);
|
||||
|
||||
}
|
||||
catch (Exception ex){
|
||||
} catch (Exception ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Module addModule(Module m)
|
||||
{
|
||||
public Module addModule(Module m) {
|
||||
try {
|
||||
st.executeUpdate("insert into modules (userid, semesterid, name, activated) " +
|
||||
"Values (" + m.getUserid() + ", " + m.getsemesterid() + ", '" + m.getName() + "', " + m.getActivated() + ")");
|
||||
return getModule(m.getUserid(), m.getsemesterid());
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Module[] getAllModules() {
|
||||
try
|
||||
{
|
||||
try {
|
||||
ResultSet rs = st.executeQuery("SELECT * FROM modules");
|
||||
List<Module> moduleList = new ArrayList<>();
|
||||
Module m = null;
|
||||
while((m = resultSetToModule(rs)) != null)
|
||||
{
|
||||
while ((m = resultSetToModule(rs)) != null) {
|
||||
moduleList.add(m);
|
||||
}
|
||||
|
||||
return moduleList.toArray(new Module[0]);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Module getModuleBySemesterUserID(int userid, int semesterid)
|
||||
{
|
||||
try
|
||||
{
|
||||
ResultSet rs = st.executeQuery("select * from modules where userid=" + userid + " and semesterid=" + semesterid);
|
||||
return resultSetToModule(rs);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
return new Module(-1, 0, 0, "", 0);
|
||||
}
|
||||
}
|
||||
|
||||
public Module updateModule(Module m)
|
||||
{
|
||||
public Module updateModule(Module m) {
|
||||
|
||||
try {
|
||||
Module module = getModule(m.getUserid(), m.getsemesterid());
|
||||
if(module == null)
|
||||
{
|
||||
addModule(m);
|
||||
}
|
||||
else
|
||||
{
|
||||
st.executeUpdate("update modules set activated=" + m.getActivated() + ", semesterid=" + m.getsemesterid() + ", name='" + m.getName() + "' where id=" + module.getid());
|
||||
}
|
||||
|
||||
Module test = getModule(m.getUserid(), m.getsemesterid());
|
||||
System.out.println(test.getActivated());
|
||||
return test;
|
||||
}
|
||||
catch (SQLException ex) {
|
||||
|
||||
st.executeUpdate("update modules set activated=" + m.getActivated() + ", semesterid=" + m.getsemesterid() + ", name='" + m.getName() + "' where id=" + m.getid());
|
||||
|
||||
|
||||
return null;
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean deleteModule(int semesterid, int userid)
|
||||
{
|
||||
public boolean deleteModule(int id) {
|
||||
try {
|
||||
st.executeUpdate("delete from modules where semesterid=" + semesterid + " and userid=" + userid);
|
||||
st.executeUpdate("delete from modules where id=" + id);
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -477,89 +385,72 @@ public class DataBaseHandler
|
||||
rs.getInt("semesterid"),
|
||||
rs.getString("name"),
|
||||
rs.getInt("activated"));
|
||||
}
|
||||
catch (Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
USER
|
||||
* USER
|
||||
*/
|
||||
|
||||
//Alle User, die nicht admin sind
|
||||
public User[] getAllUsers()
|
||||
{
|
||||
try
|
||||
{
|
||||
public User[] getAllUsers() {
|
||||
try {
|
||||
ResultSet rs = st.executeQuery("select * from users where permission=0");
|
||||
|
||||
User u = null;
|
||||
|
||||
List<User> output = new ArrayList<>();
|
||||
|
||||
while((u = resultSetToUser(rs)) != null)
|
||||
{
|
||||
while ((u = resultSetToUser(rs)) != null) {
|
||||
u.clearOutPassword();
|
||||
output.add(u);
|
||||
}
|
||||
|
||||
return output.toArray(new User[0]);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//einen User
|
||||
public User getUser(String mail, String password)
|
||||
{
|
||||
public User getUser(String mail, String password) {
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
ResultSet rs = st.executeQuery("select * from users where mail = '" + mail + "' and password = '" + password + "'");
|
||||
return resultSetToUser(rs);
|
||||
} catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public User getUser(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
public User getUser(int id) {
|
||||
try {
|
||||
ResultSet rs = st.executeQuery("select * from users where id=" + id);
|
||||
return resultSetToUser(rs);
|
||||
} catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public User getUser(String mail)
|
||||
{
|
||||
try
|
||||
{
|
||||
public User getUser(String mail) {
|
||||
try {
|
||||
ResultSet rs = st.executeQuery("select * from users where mail='" + mail + "'");
|
||||
User u = resultSetToUser(rs);
|
||||
if(u != null) u.clearOutPassword();
|
||||
if (u != null) u.clearOutPassword();
|
||||
|
||||
return u;
|
||||
} catch (SQLException e)
|
||||
{
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public User resultSetToUser(ResultSet rs)
|
||||
{
|
||||
try
|
||||
{
|
||||
public User resultSetToUser(ResultSet rs) {
|
||||
try {
|
||||
rs.next();
|
||||
return new User(
|
||||
rs.getInt("id"),
|
||||
@@ -569,27 +460,21 @@ public class DataBaseHandler
|
||||
rs.getString("password"),
|
||||
rs.getInt("permission")
|
||||
);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//add a new user object to the database returns if process was successful
|
||||
public User addUser(User user)
|
||||
{
|
||||
public User addUser(User user) {
|
||||
//check if mail and passwort (key user information) is given
|
||||
if (user.getMail() == null || user.getPassword() == null)
|
||||
{
|
||||
if (user.getMail() == null || user.getPassword() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
String password = user.getPassword();
|
||||
if(encrypted)
|
||||
{
|
||||
if (encrypted) {
|
||||
RSA rsa = RSA.getInstance();
|
||||
byte[] psw = rsa.loadByteArray(password);
|
||||
try {
|
||||
@@ -600,20 +485,16 @@ public class DataBaseHandler
|
||||
}
|
||||
st.executeUpdate("insert into users (firstname, lastname, mail, password, permission) values (" + "'" + user.getFirstName() + "', '" + user.getLastName() + "', '" + user.getMail() + "', '" + password + "', " + 0 + ")");
|
||||
return getUser(user.getMail(), user.getPassword());
|
||||
} catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public User updateUser(User user, int id, boolean elevationRequestByAdmin)
|
||||
{
|
||||
try
|
||||
{
|
||||
public User updateUser(User user, int id, boolean elevationRequestByAdmin) {
|
||||
try {
|
||||
String password = user.getPassword();
|
||||
if(encrypted)
|
||||
{
|
||||
if (encrypted) {
|
||||
RSA rsa = RSA.getInstance();
|
||||
byte[] psw = rsa.loadByteArray(password);
|
||||
try {
|
||||
@@ -623,17 +504,14 @@ public class DataBaseHandler
|
||||
}
|
||||
}
|
||||
|
||||
if(!elevationRequestByAdmin)
|
||||
{
|
||||
if (!elevationRequestByAdmin) {
|
||||
st.executeUpdate("update users set " +
|
||||
"firstname='" + user.getFirstName() + "', " +
|
||||
"lastname='" + user.getLastName() + "', " +
|
||||
"mail='" + user.getMail() + "', " +
|
||||
"password='" + password + "' " +
|
||||
"where id=" + id);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
st.executeUpdate("update users set " +
|
||||
"firstname='" + user.getFirstName() + "', " +
|
||||
"lastname='" + user.getLastName() + "', " +
|
||||
@@ -644,17 +522,14 @@ public class DataBaseHandler
|
||||
}
|
||||
|
||||
return getUser(id);
|
||||
} catch (SQLException e)
|
||||
{
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean deleteUser(String mail)
|
||||
{
|
||||
try
|
||||
{
|
||||
public boolean deleteUser(String mail) {
|
||||
try {
|
||||
ResultSet rs = st.executeQuery("SELECT id FROM user WHERE mail='" + mail + "'");
|
||||
rs.next();
|
||||
int id = rs.getInt("id");
|
||||
@@ -662,9 +537,7 @@ public class DataBaseHandler
|
||||
|
||||
st.executeUpdate("delete from users where mail='" + mail + "'");
|
||||
return true;
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -9,14 +9,16 @@ public class Semester
|
||||
private String name;
|
||||
private int startyear;
|
||||
private int endyear;
|
||||
private int number;
|
||||
|
||||
public Semester(int id, int startday, int endday, String name, int startyear, int endyear) {
|
||||
public Semester(int id, int startday, int endday, String name, int startyear, int endyear, int number) {
|
||||
this.id = id;
|
||||
this.startday = startday;
|
||||
this.endday = endday;
|
||||
this.name = name;
|
||||
this.startyear = startyear;
|
||||
this.endyear = endyear;
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
@@ -42,4 +44,6 @@ public class Semester
|
||||
public int getEndyear() {
|
||||
return endyear;
|
||||
}
|
||||
|
||||
public int getNumber(){return number; }
|
||||
}
|
||||
|
||||
@@ -40,11 +40,11 @@ public class EntriesController
|
||||
for (int i = 0; i < 6; i++) {
|
||||
var idx = 0;
|
||||
for (int j = 0; j < 20; j++) {
|
||||
if (lonelyEntry[i][j] != null){
|
||||
if (lonelyEntry != null && lonelyEntry[i][j] != null){
|
||||
combinedEntry[i][idx] = lonelyEntry[i][j];
|
||||
idx++;
|
||||
}
|
||||
if (happyEntry[i][j] != null){
|
||||
if (happyEntry != null && happyEntry[i][j] != null){
|
||||
combinedEntry[i][idx] = happyEntry[i][j];
|
||||
idx++;
|
||||
}
|
||||
|
||||
@@ -53,29 +53,23 @@ public class ModuleController
|
||||
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
|
||||
}
|
||||
|
||||
/**
|
||||
GET
|
||||
Get A Module by the matching semester and user id (important for edit function in frontend)
|
||||
*/
|
||||
@CrossOrigin
|
||||
@GetMapping("/module/suid")
|
||||
public ResponseEntity<Module[]> getModulesBySemesterUserID(@RequestParam(name = "sessionid") String sessionid, @RequestParam(name = "userid") String userid, @RequestParam(name = "semesterid") int semesterid)
|
||||
@GetMapping("/module/bysemesterid")
|
||||
public ResponseEntity<Module[]> getModulesBySemesterID(@RequestParam(name="sessionid") String sessionID, @RequestParam(name="semesterid") int semesterid)
|
||||
{
|
||||
User user = UserSessionIDHandler.getUserBySessionID(sessionid);
|
||||
String[] userIDSSplit = userid.split("a");
|
||||
int[] userIDS = new int[userIDSSplit.length];
|
||||
for(int i = 0; i < userIDS.length; i++)
|
||||
{
|
||||
userIDS[i] = Integer.parseInt(userIDSSplit[i]);
|
||||
}
|
||||
User user = UserSessionIDHandler.getUserBySessionID(sessionID);
|
||||
|
||||
if(user != null && user.getPermissions() == UserPermissions.admin.getValue())
|
||||
{
|
||||
Module[] tempModuleArray = db.getAllModules();
|
||||
List<Module> result = new ArrayList<>();
|
||||
|
||||
for(int i = 0; i < userIDS.length; i++)
|
||||
for(int i = 0; i < tempModuleArray.length; i++)
|
||||
{
|
||||
result.add(db.getModuleBySemesterUserID(userIDS[i], semesterid));
|
||||
if(tempModuleArray[i].getsemesterid() == semesterid)
|
||||
{
|
||||
result.add(tempModuleArray[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(result.toArray(new Module[0]), HttpStatus.OK);
|
||||
@@ -114,7 +108,6 @@ public class ModuleController
|
||||
public ResponseEntity<Module> addModule(@RequestBody Module module, @RequestParam(name = "sessionid") String sessionID)
|
||||
{
|
||||
|
||||
System.out.println("test1");
|
||||
User user = UserSessionIDHandler.getUserBySessionID(sessionID);
|
||||
|
||||
if (user.getPermissions() == UserPermissions.admin.getValue())
|
||||
@@ -163,12 +156,12 @@ public class ModuleController
|
||||
*/
|
||||
@CrossOrigin
|
||||
@DeleteMapping("/module")
|
||||
public void deleteModule(@RequestParam(name = "sessionid") String sessionid, @RequestParam(name = "semesterid") int semesterid, @RequestParam(name = "userid") int userid)
|
||||
public void deleteModule(@RequestParam(name = "sessionid") String sessionid, @RequestParam(name="id") int id)
|
||||
{
|
||||
User u = UserSessionIDHandler.getUserBySessionID(sessionid);
|
||||
if (u != null && u.getPermissions() == UserPermissions.admin.getValue())
|
||||
{
|
||||
db.deleteModule(semesterid, userid);
|
||||
db.deleteModule(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public class SemesterController
|
||||
return new ResponseEntity<>(s, HttpStatus.OK);
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
return new ResponseEntity<>(null, HttpStatus.OK);
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
|
||||
|
||||
Reference in New Issue
Block a user