Test Input Form reload data
This commit is contained in:
@@ -22,26 +22,58 @@ export default function InputForm(p) {
|
||||
const [endDate, setEndDate] = useState(endDateParam);
|
||||
const [courseName, setCourseName] = useState(courseNameParam);
|
||||
const [users, setUsers] = useState([]);
|
||||
const [moduleInfos, setModuleInfos] = useState([])
|
||||
const [checkedSelected, setCheckedSelected] = useState(new Array(100).fill(false))
|
||||
const [activatedSelected, setActivatedSelected] = useState(new Array(100).fill(false))
|
||||
|
||||
async function getAllUsers() {
|
||||
let sessionid = localStorage.getItem("sessionid");
|
||||
let url = "http://localhost:8080/users/all?sessionid=" + sessionid;
|
||||
|
||||
|
||||
try {
|
||||
await fetch(url).then(response => response.json()).then(user => setUsers(user));
|
||||
}
|
||||
catch(e)
|
||||
await fetch(url).then(response => response.json()).then(async user => {
|
||||
setUsers(user)
|
||||
let mURL = "http://localhost:8080/module/suid?sessionid=" + localStorage.getItem("sessionid") + "&semesterid=" + localStorage.getItem("currentsid") + "&userid=";
|
||||
for(let i = 0; i < user.length; i++)
|
||||
{
|
||||
router.push("/")
|
||||
mURL += user[i].id;
|
||||
if(i < user.length - 1)
|
||||
{
|
||||
mURL += "a";
|
||||
}
|
||||
}
|
||||
|
||||
fetch(mURL).then(result => result.json()).then(m => {
|
||||
let temp = []
|
||||
|
||||
for(let i = 0; i < user.length; i++)
|
||||
{
|
||||
temp.push(m[i] != null);
|
||||
}
|
||||
|
||||
setCheckedSelected(temp);
|
||||
|
||||
temp = []
|
||||
|
||||
for(let i = 0; i < user.length; i++)
|
||||
{
|
||||
temp.push(m[i] != null && m[i].activated === 1);
|
||||
}
|
||||
|
||||
setActivatedSelected(temp);
|
||||
|
||||
setModuleInfos(m);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
userModuleMapping.clear()
|
||||
getAllUsers();
|
||||
getAllUsers()
|
||||
userModuleMapping.clear();
|
||||
}, [])
|
||||
|
||||
|
||||
async function onCreateClicked() {
|
||||
let startSplit = startDate.split("-");
|
||||
let endSplit = endDate.split("-");
|
||||
@@ -76,16 +108,16 @@ export default function InputForm(p) {
|
||||
method: method,
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: JSON.stringify(json)
|
||||
}).then(response => response.json()).then(semester => {tempsid = semester.id});
|
||||
}).then(response => response.json()).then(semester => {
|
||||
tempsid = semester.id
|
||||
});
|
||||
|
||||
|
||||
if(method === "POST")
|
||||
{
|
||||
if (method === "POST") {
|
||||
semesterid = tempsid;
|
||||
}
|
||||
|
||||
for(let [key, value] of userModuleMapping)
|
||||
{
|
||||
for (let [key, value] of userModuleMapping) {
|
||||
let json1 = {
|
||||
"id": 0,
|
||||
"userid": value.getUserid(),
|
||||
@@ -94,8 +126,7 @@ export default function InputForm(p) {
|
||||
"activated": value.getActivated()
|
||||
}
|
||||
|
||||
if(value.getChecked())
|
||||
{
|
||||
if (value.getChecked()) {
|
||||
await fetch("http://localhost:8080/module?sessionid=" + localStorage.getItem("sessionid"), {
|
||||
method: method,
|
||||
headers: {"Content-Type": "application/json"},
|
||||
@@ -107,76 +138,109 @@ export default function InputForm(p) {
|
||||
router.back();
|
||||
}
|
||||
|
||||
class UserModuleInfo
|
||||
{
|
||||
constructor()
|
||||
{
|
||||
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}
|
||||
getModuleName() {
|
||||
return this.moduleName
|
||||
}
|
||||
|
||||
function onModuleClicked(user, module) {
|
||||
getUserid() {
|
||||
return this.userid
|
||||
}
|
||||
|
||||
if(userModuleMapping.has(user.id))
|
||||
{
|
||||
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)
|
||||
console.log("test")
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
let temp = new UserModuleInfo()
|
||||
temp.setModuleName(module)
|
||||
temp.setUserid(user.id)
|
||||
userModuleMapping.set(user.id, temp)
|
||||
console.log("test1")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function onSelectedCheckBox(user, state)
|
||||
{
|
||||
if(userModuleMapping.has(user.id))
|
||||
{
|
||||
function onSelectedCheckBox(user, state, index) {
|
||||
if (userModuleMapping.has(user.id)) {
|
||||
userModuleMapping.get(user.id).setChecked(state.target.checked);
|
||||
}
|
||||
else
|
||||
{
|
||||
} 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]);
|
||||
}
|
||||
|
||||
function onActivatedCheckBox(user, state)
|
||||
{
|
||||
if(userModuleMapping.has(user.id))
|
||||
{
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
let temp = new UserModuleInfo()
|
||||
let t = state.target.checked ? 1 : 0;
|
||||
temp.setActivated(t)
|
||||
temp.setUserid(user.id)
|
||||
userModuleMapping.set(user.id, temp)
|
||||
}
|
||||
|
||||
let temp = []
|
||||
|
||||
for(let i = 0; i < checkedSelected.length; i++)
|
||||
{
|
||||
temp.push(activatedSelected[i]);
|
||||
}
|
||||
|
||||
temp[index] = state.target.checked;
|
||||
|
||||
setActivatedSelected(temp);
|
||||
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -247,24 +311,28 @@ export default function InputForm(p) {
|
||||
}}>Modul
|
||||
</th>
|
||||
</tr>
|
||||
{users.map(user => (
|
||||
{users.map((user, i) => (
|
||||
<tr>
|
||||
|
||||
<td><div style={{
|
||||
<td>
|
||||
<div style={{
|
||||
display: "flex",
|
||||
flexDirection: "row",
|
||||
justifyContent: "center",
|
||||
}}><input type="checkbox" onChange={(e) => {
|
||||
onSelectedCheckBox(user, e)
|
||||
}}/></div></td>
|
||||
onSelectedCheckBox(user, e, i)
|
||||
}} checked={checkedSelected[i]}/></div>
|
||||
</td>
|
||||
|
||||
<td><div style={{
|
||||
<td>
|
||||
<div style={{
|
||||
display: "flex",
|
||||
flexDirection: "row",
|
||||
justifyContent: "center",
|
||||
}}><input type="checkbox" onChange={(e) => {
|
||||
onActivatedCheckBox(user, e);
|
||||
}}/></div></td>
|
||||
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={{
|
||||
@@ -272,8 +340,8 @@ export default function InputForm(p) {
|
||||
marginTop: 10,
|
||||
padding: "5px 2px"
|
||||
}} onChange={(e) => {
|
||||
onModuleClicked(user, e.target.value)
|
||||
}}>
|
||||
onModuleClicked(user, e.target.value, i)
|
||||
}} value={moduleInfos[i] != null ? moduleInfos[i].name : "Please Select"}>
|
||||
<option value={"Please Select"}>Please Select</option>
|
||||
<option value={"Programmieren"}>Programmieren</option>
|
||||
<option value={"BWL"}>BWL</option>
|
||||
|
||||
@@ -8,16 +8,6 @@ export default function CreateSemester()
|
||||
const router = useRouter();
|
||||
let {courseName, startDate, endDate} = router.query;
|
||||
|
||||
useEffect(() => {
|
||||
let checkURL = "http://localhost:8080/users/check?sessionid=" + localStorage.getItem("sessionid");
|
||||
try {
|
||||
fetch(checkURL).then(r => console.log(r))
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
router.push("/")
|
||||
}
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className={"normal-centered"}>
|
||||
|
||||
@@ -13,14 +13,11 @@ export default function SemesterOverview(p)
|
||||
{
|
||||
let urlTest = "http://localhost:8080/semester/all?sessionid=" + localStorage.getItem("sessionid");
|
||||
|
||||
try {
|
||||
|
||||
await fetch(urlTest).then(response => response.json()).then(s => {
|
||||
setEntries(s)
|
||||
})
|
||||
} catch(e)
|
||||
{
|
||||
router.push("/")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function onClickSemester(e, m)
|
||||
@@ -33,6 +30,7 @@ export default function SemesterOverview(p)
|
||||
|
||||
function onClickNewSemester()
|
||||
{
|
||||
localStorage.setItem("currentsid", 0);
|
||||
router.push("/createSemester");
|
||||
}
|
||||
|
||||
@@ -89,14 +87,7 @@ export default function SemesterOverview(p)
|
||||
|
||||
useEffect(() => {
|
||||
getSemesters();
|
||||
let checkURL = "http://localhost:8080/users/check?sessionid=" + localStorage.getItem("sessionid");
|
||||
try {
|
||||
fetch(checkURL).then(r => console.log(r))
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
router.push("/")
|
||||
}
|
||||
|
||||
}, [])
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
+134469
File diff suppressed because it is too large
Load Diff
@@ -10,6 +10,7 @@ import com.example.backend.anwprj.Module.Module;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class DataBaseHandler
|
||||
@@ -423,12 +424,35 @@ public class DataBaseHandler
|
||||
}
|
||||
}
|
||||
|
||||
public Module getModulesBySemesterUserID(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)
|
||||
{
|
||||
System.out.println(m.getActivated());
|
||||
|
||||
try {
|
||||
System.out.println(m.getId());
|
||||
Module module = getModule(m.getUserid(), m.getSemesterId(), m.getName());
|
||||
if(module == null)
|
||||
{
|
||||
addModule(m);
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("test");
|
||||
st.executeUpdate("update modules set activated=" + m.getActivated() + " where userid=" + m.getUserid() + " and semesterid=" + m.getSemesterId() + " and name='" + m.getName() + "'");
|
||||
}
|
||||
|
||||
return getModule(m.getUserid(), m.getSemesterId(), m.getName());
|
||||
}
|
||||
catch (SQLException ex) {
|
||||
|
||||
@@ -9,8 +9,12 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
public class ModuleController {
|
||||
public class ModuleController
|
||||
{
|
||||
private final DataBaseHandler db;
|
||||
|
||||
{
|
||||
@@ -40,14 +44,16 @@ public class ModuleController {
|
||||
@CrossOrigin
|
||||
@GetMapping("/module/id")
|
||||
public ResponseEntity<Module[]> getModules(
|
||||
@RequestParam(name="sessionid") String sessionID) {
|
||||
@RequestParam(name = "sessionid") String sessionID)
|
||||
{
|
||||
|
||||
User user = UserSessionIDHandler.getUserBySessionID(sessionID);
|
||||
|
||||
if (user != null)
|
||||
{
|
||||
Module[] modules = db.getModules(user.getId());
|
||||
if (modules != null) {
|
||||
if (modules != null)
|
||||
{
|
||||
return new ResponseEntity<>(modules, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@@ -57,13 +63,43 @@ public class ModuleController {
|
||||
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
|
||||
}
|
||||
|
||||
@CrossOrigin
|
||||
@GetMapping("/module/suid")
|
||||
public ResponseEntity<Module[]> getModulesBySemesterUserID(@RequestParam(name = "sessionid") String sessionid, @RequestParam(name = "userid") String userid, @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]);
|
||||
}
|
||||
|
||||
if(user != null && user.getPermissions() == UserPermissions.admin.getValue())
|
||||
{
|
||||
List<Module> result = new ArrayList<>();
|
||||
|
||||
for(int i = 0; i < userIDS.length; i++)
|
||||
{
|
||||
result.add(db.getModulesBySemesterUserID(userIDS[i], semesterid));
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(result.toArray(new Module[0]), HttpStatus.OK);
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
|
||||
}
|
||||
|
||||
@CrossOrigin
|
||||
@GetMapping("/module/all")
|
||||
public ResponseEntity<Module[]> getModule(@RequestParam(name="sessionid") String sessionid) {
|
||||
public ResponseEntity<Module[]> getModule(@RequestParam(name = "sessionid") String sessionid)
|
||||
{
|
||||
User u = UserSessionIDHandler.getUserBySessionID(sessionid);
|
||||
|
||||
if(u != null) {
|
||||
if(u.getPermissions() == UserPermissions.admin.getValue()) {
|
||||
if (u != null)
|
||||
{
|
||||
if (u.getPermissions() == UserPermissions.admin.getValue())
|
||||
{
|
||||
return new ResponseEntity<>(db.getAllModules(), HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
@@ -73,12 +109,15 @@ public class ModuleController {
|
||||
|
||||
@CrossOrigin
|
||||
@PostMapping("/module")
|
||||
public ResponseEntity<Module> addModule(@RequestBody Module module, @RequestParam(name="sessionid") String sessionID) {
|
||||
public ResponseEntity<Module> addModule(@RequestBody Module module, @RequestParam(name = "sessionid") String sessionID)
|
||||
{
|
||||
User user = UserSessionIDHandler.getUserBySessionID(sessionID);
|
||||
|
||||
if(user.getPermissions() == UserPermissions.admin.getValue()) {
|
||||
if (user.getPermissions() == UserPermissions.admin.getValue())
|
||||
{
|
||||
Module m = db.addModule(module);
|
||||
if(m != null) {
|
||||
if (m != null)
|
||||
{
|
||||
return new ResponseEntity<>(m, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@@ -91,12 +130,15 @@ public class ModuleController {
|
||||
|
||||
@CrossOrigin
|
||||
@PutMapping("/module")
|
||||
public ResponseEntity<Module> updateModule(@RequestBody Module module, @RequestParam(name="sessionid") String sessionID) {
|
||||
public ResponseEntity<Module> updateModule(@RequestBody Module module, @RequestParam(name = "sessionid") String sessionID)
|
||||
{
|
||||
User u = UserSessionIDHandler.getUserBySessionID(sessionID);
|
||||
if(u != null && u.getPermissions() == UserPermissions.admin.getValue()) {
|
||||
if (u != null && u.getPermissions() == UserPermissions.admin.getValue())
|
||||
{
|
||||
Module m = db.updateModule(module);
|
||||
|
||||
if(m != null) {
|
||||
if (m != null)
|
||||
{
|
||||
return new ResponseEntity<>(m, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@@ -108,9 +150,11 @@ public class ModuleController {
|
||||
|
||||
@CrossOrigin
|
||||
@DeleteMapping("/module")
|
||||
public void deleteModule(@RequestParam(name="sessionid") String sessionid, @RequestParam(name="id") int id) {
|
||||
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()) {
|
||||
if (u != null && u.getPermissions() == UserPermissions.admin.getValue())
|
||||
{
|
||||
db.deleteModule(id);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user