Fakultas Ilmu Komputer UI

Commit e3029a06 authored by Ahmad Izzudin Alifyandra's avatar Ahmad Izzudin Alifyandra
Browse files

Merge branch 'alif' into 'master'

Alif

See merge request AdvProg/KKI-2021/1906315821/tasc-raja-singa!47
parents e8aa1e4a 630cbd6f
Pipeline #81840 passed with stages
in 25 minutes and 51 seconds
......@@ -8,6 +8,7 @@ import com.adpro.tasc.user.db.dao.UserDAO;
import com.adpro.tasc.user.db.model.AcademicUser;
import com.adpro.tasc.user.db.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
......@@ -21,6 +22,7 @@ import java.time.YearMonth;
import java.util.*;
@Controller
@PreAuthorize("hasRole('STUDENT')")
public class BookAppointmentController {
@Autowired
AppointmentDAO appointmentDAO;
......@@ -98,8 +100,8 @@ public class BookAppointmentController {
public String bookAppointment(
Model model,
Principal principal,
@RequestParam("startTime") int startTime,
@RequestParam("finishTime") int finishTime,
@RequestParam("startTime") long startTime,
@RequestParam("finishTime") long finishTime,
@RequestParam("day") String day,
@RequestParam("taUserName") String taUserName,
@RequestParam("courseName") String courseName,
......@@ -180,57 +182,63 @@ public class BookAppointmentController {
@RequestParam("slotStartTime") long slotStartTime,
@RequestParam("slotFinishTime") long slotFinishTime,
@RequestParam("bookDateWeekOffset") int bookDateWeekOffset,
@RequestParam("startHourForm") int startHour,
@RequestParam("endHourForm") int endHour,
@RequestParam("startMinuteForm") int startMinute,
@RequestParam("endMinuteForm") int endMinute,
@RequestParam("startTimeForm") String startTime,
@RequestParam("endTimeForm") String endTime,
@RequestParam("targetBookDate") long targetBookMillis,
@RequestParam("taUserName") String taUserName,
@RequestParam("courseName") String courseName
) {
boolean valid =true;
long targetBookEpochStart = java.time.Duration.ofMinutes(startMinute).toMillis() +
java.time.Duration.ofHours(startHour).toMillis();
long targetBookEpochEnd = java.time.Duration.ofMinutes(endMinute).toMillis() +
java.time.Duration.ofHours(endHour).toMillis();
if (
!(
targetBookEpochStart < targetBookEpochEnd &&
targetBookEpochStart >= slotStartTime &&
targetBookEpochStart < slotFinishTime &&
targetBookEpochEnd <= slotFinishTime &&
targetBookEpochEnd > slotStartTime
) ||
!(
startHour >= 0 && startHour < 24 &&
startMinute >= 0 && startMinute < 60 &&
endHour >= 0 && endHour < 24 &&
endMinute >= 0 && endMinute < 60
)
) {
valid = false;
}
if (!valid) {
System.out.println("invalid");
String referer = request.getHeader("Referer").replaceAll("false","true");
System.out.println(referer);
return "redirect:"+referer;
} else {
try {
String[] splittedStartTime = startTime.split("\\.");
String[] splittedEndTime = endTime.split("\\.");
if (splittedStartTime.length != 2 || splittedEndTime.length != 2) {
throw new Exception("");
}
int startHour = Integer.parseInt(splittedStartTime[0]);
int startMinute = Integer.parseInt(splittedStartTime[1]);
int endHour = Integer.parseInt(splittedEndTime[0]);
int endMinute = Integer.parseInt(splittedEndTime[1]);
long targetBookEpochStart = java.time.Duration.ofMinutes(startMinute).toMillis() +
java.time.Duration.ofHours(startHour).toMillis();
long targetBookEpochEnd = java.time.Duration.ofMinutes(endMinute).toMillis() +
java.time.Duration.ofHours(endHour).toMillis();
if (
!(
targetBookEpochStart < targetBookEpochEnd &&
targetBookEpochStart >= slotStartTime &&
targetBookEpochStart < slotFinishTime &&
targetBookEpochEnd <= slotFinishTime &&
targetBookEpochEnd > slotStartTime
) ||
!(
startHour >= 0 && startHour < 24 &&
startMinute >= 0 && startMinute < 60 &&
endHour >= 0 && endHour < 24 &&
endMinute >= 0 && endMinute < 60
)
) {
throw new Exception("");
}
System.out.println("valid");
Calendar calendarBookDate = Calendar.getInstance();
calendarBookDate.setTimeInMillis(targetBookMillis);
int targetBookDate = calendarBookDate.get(Calendar.DATE);
int targetBookMonth = calendarBookDate.get(Calendar.MONTH)+1;
int targetBookMonth = calendarBookDate.get(Calendar.MONTH);
int targetBookYear = calendarBookDate.get(Calendar.YEAR);
long duration = targetBookEpochEnd - targetBookEpochStart;
calendarBookDate.set(targetBookYear,targetBookMonth,targetBookDate,startHour,startMinute);
calendarBookDate.add(Calendar.DATE,bookDateWeekOffset*7);
calendarBookDate.set(targetBookYear, targetBookMonth, targetBookDate, startHour, startMinute);
calendarBookDate.add(Calendar.DATE, bookDateWeekOffset * 7);
long targetBookEpochDate = calendarBookDate.getTimeInMillis();
Appointment appointment = new Appointment();
......@@ -249,6 +257,12 @@ public class BookAppointmentController {
appointmentDAO.createAppointment(appointmentRequest);
return "redirect:/see-appointment-student";
} catch (Exception e) {
System.out.println("invalid");
String referer = request.getHeader("Referer").replaceAll("false", "true");
System.out.println(referer);
return "redirect:" + referer;
}
}
}
......@@ -73,32 +73,60 @@ public class CreateScheduleController {
@PostMapping(value="/add-slot/post")
public String createSlot(
@RequestParam("day") int day,
@RequestParam("startHour") int startHour,
@RequestParam("startMinute") int startMinute,
@RequestParam("endHour") int endHour,
@RequestParam("endMinute") int endMinute,
@RequestParam("startTime") String startTime,
@RequestParam("endTime") String endTime,
Principal principal
)
{
System.out.println(day+" "+startHour+ " " + startMinute);
try {
String[] splittedStartTime = startTime.split("\\.");
String[] splittedEndTime = endTime.split("\\.");
if (splittedStartTime.length != 2 || splittedEndTime.length != 2) {
throw new Exception("");
}
int startHour = Integer.parseInt(splittedStartTime[0]);
int startMinute = Integer.parseInt(splittedStartTime[1]);
int endHour = Integer.parseInt(splittedEndTime[0]);
int endMinute = Integer.parseInt(splittedEndTime[1]);
long epochStart = java.time.Duration.ofMinutes(startMinute).toMillis() +
java.time.Duration.ofHours(startHour).toMillis();
long epochEnd = java.time.Duration.ofMinutes(endMinute).toMillis() +
java.time.Duration.ofHours(endHour).toMillis();
if (
!(
startHour >= 0 && startHour < 24 &&
startMinute >= 0 && startMinute < 60 &&
endHour >= 0 && endHour < 24 &&
endMinute >= 0 && endMinute < 60 &&
epochStart < epochEnd
)
) {
throw new Exception("");
}
long epochStart = java.time.Duration.ofMinutes(startMinute).toMillis() +
java.time.Duration.ofHours(startHour).toMillis();
Slot slot1 = new Slot();
slot1.setDay(Slot.Day.valueOf(daysArr[day]));
slot1.setStartTime(epochStart);
slot1.setFinishTime(epochEnd);
long epochEnd = java.time.Duration.ofMinutes(endMinute).toMillis() +
java.time.Duration.ofHours(endHour).toMillis();
User currentUser = userDAO.getUser(principal.getName());
Schedule schedule = scheduleDAO.getUserSchedule((AcademicUser) currentUser);
slot1.setSchedule(schedule.getId());
Slot slot1 = new Slot();
slot1.setDay(Slot.Day.valueOf(daysArr[day]));
slot1.setStartTime(epochStart);
slot1.setFinishTime(epochEnd);
// slots.add(slot1);
User currentUser = userDAO.getUser(principal.getName());
Schedule schedule = scheduleDAO.getUserSchedule((AcademicUser) currentUser);
slot1.setSchedule(schedule.getId());
slotDAO.addSlot(slot1);
return "redirect:/create-schedule";
} catch (Exception e) {
return "redirect:/add-slot";
}
slotDAO.addSlot(slot1);
return "redirect:/create-schedule";
}
}
......@@ -30,6 +30,7 @@ public class UserListCoursesController {
List<Course> courseList = courseDAO.getAllCourse();
List<Course> userCourseList = courseDAO.getUserCourseList((AcademicUser) currentUser);
model.addAttribute("currentUser", currentUser);
model.addAttribute("courseList", courseList);
model.addAttribute("userCourseList",userCourseList);
......
......@@ -18,7 +18,9 @@
<nav th:replace="${currentUser.getRole().toString() == 'ROLE_STUDENT'} ? ~{fragments/navbar_student :: navbar}"></nav>
<div style="padding:2em;" >
<div>
<form th:action="${currentUser.getRole().toString() == 'ROLE_STUDENT'} ? @{/book-appointment/pick-ta}">
<form th:action="@{/book-appointment/see-ta-schedule}">
<input id = "courseNameBackTrack" name = "courseName" type = "hidden" th:value = "${courseName}"/>
<input id = "taUserNameBackTrack" name = "taUserName" type = "hidden" th:value = "${taUserName}"/>
<button type="submit" class="btn btn-danger">Back</button>
</form>
</div>
......@@ -26,10 +28,10 @@
<h2>Book an appointment</h2>
</div>
<div>
<div style="border-width: 1px; border-radius: 10px; border-color:grey; border-style: solid;padding:3em">
<h5>
<div style="border-width: 1px; border-radius: 10px; border-color:grey; border-style: solid;padding:2em; margin: 1em 20vw">
<h4>
For slot:
</h5>
</h4>
<div>
<h6>TA:</h6>
<p th:text="${taUserName}"></p>
......@@ -43,48 +45,61 @@
<p th:text="${day}"></p>
</div>
<div>
<h6>Start time:</h6>
<p th:text="${(startTime / (1000 * 60 * 60))%24}+'.'+${(startTime / 60000) % 60}"></p>
<h6>Time:</h6>
<p th:text="${#dates.format(startTime-25200000, 'HH:mm')}+' - '+${#dates.format(finishTime-25200000,'HH:mm')}"></p>
</div>
<div>
<h6>Finish time:</h6>
<p th:text="${(finishTime / (1000 * 60 * 60))%24}+'.'+${(finishTime / 60000) % 60}"></p>
<!-- <div style="flex-direction: row; display: flex">-->
<!-- <div style="margin-right: 0.5em">-->
<!-- <h6>Start time:</h6>-->
<!-- <p th:text="${(startTime / (1000 * 60 * 60))%24}+'.'+${(startTime / 60000) % 60}"></p>-->
<!-- </div>-->
<!-- <div>-->
<!-- <h6>Finish time:</h6>-->
<!-- <p th:text="${(finishTime / (1000 * 60 * 60))%24}+'.'+${(finishTime / 60000) % 60}"></p>-->
<!-- </div>-->
</div>
</div>
<div>
<div style="padding: 0.5em 3em; text-align: center">
<h5>Enter values within above time slot range:</h5>
<form th:action="@{/book-appointment/validate-book}" id="bookAppointment" method="post">
<div th:if="${error == 'true'}" class="alert alert-danger" role="alert">
Invalid start and end time!
</div>
<div>
<label for="bookDates">Date:</label>
<select id="bookDates" name="bookDateWeekOffset">
<option th:each="date,iStat: ${targetBookDates}" th:text="${date}" th:value="${iStat.index}"></option>
</select>
</div>
<h6>Start time:</h6>
<div>
<label for="startHour">Hours:</label>
<input id = "startHour" name = "startHourForm" type = "number" min="0" max="23" value="0"/>
</div>
<div>
<label for="startMinute">Minute:</label>
<input id = "startMinute" name = "startMinuteForm" type = "number" min="0" max="59" value="0"/>
<!-- <div>-->
<!-- <label for="bookDates">Date:</label>-->
<!-- <select id="bookDates" name="bookDateWeekOffset">-->
<!-- <option th:each="date,iStat: ${targetBookDates}" th:text="${date}" th:value="${iStat.index}"></option>-->
<!-- </select>-->
<!-- </div>-->
<div class="form-group" style="flex-direction: row; display: flex;justify-content: center; align-items: center">
<div style="margin-right: 1em">
<h6>Pick a date:</h6>
</div>
<div>
<select id="bookDates" name="bookDateWeekOffset" class="form-control">
<option th:each="date,iStat: ${targetBookDates}" th:text="${date}" th:value="${iStat.index}"></option>
</select>
</div>
</div>
<h6>End time:</h6>
<div>
<label for="endHour">Hours:</label>
<input id = "endHour" name = "endHourForm" type = "number" min="0" max="23" value="0"/>
<br/>
<div style="flex-direction: row; display: flex; justify-content: center; align-items: center">
<div>
<h6>Start time:</h6>
</div>
<div style="padding: 0em 0.5em">
<input class="form-control" id = "startTime" name = "startTimeForm" type = "text" placeholder="11.59"/>
</div>
</div>
<div>
<label for="endMinute">Minute:</label>
<input id = "endMinute" name = "endMinuteForm" type = "number" min="0" max="59" value="0"/>
<br/>
<div style="flex-direction: row; display: flex; justify-content: center; align-items: center">
<div>
<h6>End time:</h6>
</div>
<div style="padding: 0em 0.5em">
<input class="form-control" id = "endTime" name = "endTimeForm" type = "text" placeholder="13.05"/>
</div>
</div>
<p th:value="${error}"></p>
......
......@@ -39,7 +39,7 @@
<tbody>
<tr th:each="slot: ${slots}">
<td th:text="${slot.day.toString()}"></td>
<td th:text="${(slot.startTime / (1000 * 60 * 60))%24}+'.'+${(slot.startTime / 60000) % 60}+' - '+${(slot.finishTime / (1000 * 60 * 60))%24}+'.'+${(slot.finishTime / 60000) % 60}"></td>
<td th:text="${#dates.format(slot.startTime-25200000, 'HH:mm')}+' - '+${#dates.format(slot.finishTime-25200000,'HH:mm')}"></td>
<td>
<form th:action="@{/book-appointment/book}">
<input id = "startTime" name = "startTime" type = "hidden" th:value = "${slot.startTime}"/>
......
......@@ -16,7 +16,7 @@
</head>
<body>
<nav th:replace="${currentUser.getRole().toString() == 'ROLE_TEACHING_ASSISTANT'} ? ~{fragments/navbar_TA :: navbar}"></nav>
<div style="padding:2em; text-align: center">
<div style="padding:2em 4em;">
<div>
<form th:action="${currentUser.getRole().toString() == 'ROLE_TEACHING_ASSISTANT'} ? @{/create-schedule}">
<button type="submit" class="btn btn-danger">Back</button>
......@@ -27,34 +27,57 @@
</div>
<div>
<form th:action="@{/add-slot/post}" method="POST" >
<div>
<label for="day">Day:</label>
<select id="day" name="day">
<option th:each="day,iStat: ${days}" th:text="${day}" th:value="${iStat.index}"></option>
</select>
<div class="form-group" style="flex-direction: row; display: flex">
<div style="margin-right: 1em">
<h5>Pick a day:</h5>
</div>
<div>
<select id="day" name="day" class="form-control">
<option th:each="day,iStat: ${days}" th:text="${day}" th:value="${iStat.index}"></option>
</select>
</div>
</div>
<h4>Start time:</h4>
<div>
<label for="startHour">Hours:</label>
<input id = "startHour" name = "startHour" type = "number" min="0" max="23" value="0"/>
<div class="form-group" style="flex-direction: row; display: flex;">
<div>
<h5>Start time:</h5>
</div>
<div style="padding: 0em 0.5em">
<input class="form-control" id = "startTime" name = "startTime" type = "text" placeholder="11.59"/>
</div>
</div>
<div>
<label for="startMinute">Minute:</label>
<input id = "startMinute" name = "startMinute" type = "number" min="0" max="59" value="0"/>
<br/>
<div class="form-group" style="flex-direction: row; display: flex">
<div>
<h5>End time:</h5>
</div>
<div style="padding: 0em 0.5em">
<input class="form-control" id = "endTime" name = "endTime" type = "text" placeholder="13.05"/>
</div>
</div>
<h4>End time:</h4>
<div>
<label for="endHour">Hours:</label>
<input id = "endHour" name = "endHour" type = "number" min="0" max="23" value="0"/>
</div>
<!-- <h4>Start time:</h4>-->
<!-- <div>-->
<!-- <label for="startHour">Hours:</label>-->
<!-- <input id = "startHour" name = "startHour" type = "number" min="0" max="23" value="0"/>-->
<!-- </div>-->
<div>
<label for="endMinute">Minute:</label>
<input id = "endMinute" name = "endMinute" type = "number" min="0" max="59" value="0"/>
</div>
<!-- <div>-->
<!-- <label for="startMinute">Minute:</label>-->
<!-- <input id = "startMinute" name = "startMinute" type = "number" min="0" max="59" value="0"/>-->
<!-- </div>-->
<!-- <h4>End time:</h4>-->
<!-- <div>-->
<!-- <label for="endHour">Hours:</label>-->
<!-- <input id = "endHour" name = "endHour" type = "number" min="0" max="23" value="0"/>-->
<!-- </div>-->
<!-- <div>-->
<!-- <label for="endMinute">Minute:</label>-->
<!-- <input id = "endMinute" name = "endMinute" type = "number" min="0" max="59" value="0"/>-->
<!-- </div>-->
<button type="submit" class="btn btn-success" >Submit</button>
</form>
......
......@@ -36,7 +36,7 @@
<tbody>
<tr th:each="slot: ${slots}">
<td th:text="${slot.day.toString()}"></td>
<td th:text="${(slot.startTime / (1000 * 60 * 60))%24}+'.'+${(slot.startTime / 60000) % 60}+' - '+${(slot.finishTime / (1000 * 60 * 60))%24}+'.'+${(slot.finishTime / 60000) % 60}"></td>
<td th:text="${#dates.format(slot.startTime-25200000, 'HH:mm')}+' - '+${#dates.format(slot.finishTime-25200000,'HH:mm')}"></td>
</tr>
</tbody>
</table>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment