From 948a19986af730f9bd9a216419f666136593c23d Mon Sep 17 00:00:00 2001 From: alifyandra <alif@wellmart.id> Date: Sun, 23 May 2021 22:43:57 +0700 Subject: [PATCH] Finish Create Course html and controller & Create schedule and controller --- .idea/gradle.xml | 1 + .idea/misc.xml | 2 +- .../resources/main/application-ci.properties | 3 - .../main/application-heroku.properties | 3 - build/resources/main/application.properties | 6 -- .../compileJava/source-classes-mapping.txt | 51 ------------ gradlew | 0 .../tasc/controller/AddRolesController.java | 1 - .../controller/CreateCoursesController.java | 41 ++++++++++ .../controller/CreateScheduleController.java | 79 +++++++++++++++++++ .../adpro/tasc/repository/SlotRepository.java | 20 +++++ src/main/resources/application.properties | 4 +- .../resources/templates/create_course.html | 51 ++++++++++++ src/main/resources/templates/create_slot.html | 64 +++++++++++++++ .../resources/templates/display_schedule.html | 50 ++++++++++++ 15 files changed, 309 insertions(+), 67 deletions(-) delete mode 100644 build/resources/main/application-ci.properties delete mode 100644 build/resources/main/application-heroku.properties delete mode 100644 build/resources/main/application.properties delete mode 100644 build/tmp/compileJava/source-classes-mapping.txt mode change 100644 => 100755 gradlew create mode 100644 src/main/java/com/adpro/tasc/controller/CreateCoursesController.java create mode 100644 src/main/java/com/adpro/tasc/controller/CreateScheduleController.java create mode 100644 src/main/java/com/adpro/tasc/repository/SlotRepository.java create mode 100644 src/main/resources/templates/create_course.html create mode 100644 src/main/resources/templates/create_slot.html create mode 100644 src/main/resources/templates/display_schedule.html diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 034355e..776914a 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -1,5 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <project version="4"> + <component name="GradleMigrationSettings" migrationVersion="1" /> <component name="GradleSettings"> <option name="linkedExternalProjectsSettings"> <GradleProjectSettings> diff --git a/.idea/misc.xml b/.idea/misc.xml index 6c59112..60de549 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -4,7 +4,7 @@ <component name="FrameworkDetectionExcludesConfiguration"> <file type="web" url="file://$PROJECT_DIR$" /> </component> - <component name="ProjectRootManager" version="2" languageLevel="JDK_15" project-jdk-name="openjdk-15" project-jdk-type="JavaSDK"> + <component name="ProjectRootManager" version="2" languageLevel="JDK_15" default="true" project-jdk-name="openjdk-15" project-jdk-type="JavaSDK"> <output url="file://$PROJECT_DIR$/out" /> </component> </project> \ No newline at end of file diff --git a/build/resources/main/application-ci.properties b/build/resources/main/application-ci.properties deleted file mode 100644 index 8767ec9..0000000 --- a/build/resources/main/application-ci.properties +++ /dev/null @@ -1,3 +0,0 @@ -spring.datasource.url=${SPRING_DATASOURCE_URL} -spring.datasource.username=${SPRING_DATASOURCE_USERNAME} -spring.datasource.password=${SPRING_DATASOURCE_PASSWORD} \ No newline at end of file diff --git a/build/resources/main/application-heroku.properties b/build/resources/main/application-heroku.properties deleted file mode 100644 index f552e6f..0000000 --- a/build/resources/main/application-heroku.properties +++ /dev/null @@ -1,3 +0,0 @@ -spring.datasource.url=${DATABASE_URL} -spring.datasource.username= -spring.datasource.password= \ No newline at end of file diff --git a/build/resources/main/application.properties b/build/resources/main/application.properties deleted file mode 100644 index cd84a22..0000000 --- a/build/resources/main/application.properties +++ /dev/null @@ -1,6 +0,0 @@ -spring.datasource.url=jdbc:postgresql://localhost:5432/tasc -spring.datasource.username=alifyandra -spring.datasource.password=chungalip01 -spring.datasource.currentSchema=tasc - -logging.level.root=info \ No newline at end of file diff --git a/build/tmp/compileJava/source-classes-mapping.txt b/build/tmp/compileJava/source-classes-mapping.txt deleted file mode 100644 index 56466d6..0000000 --- a/build/tmp/compileJava/source-classes-mapping.txt +++ /dev/null @@ -1,51 +0,0 @@ -com/adpro/tasc/appointment/db/model/Course.java - com.adpro.tasc.appointment.db.model.Course -com/adpro/tasc/user/db/model/AcademicUser.java - com.adpro.tasc.user.db.model.AcademicUser -com/adpro/tasc/appointment/db/mapper/SlotMapper.java - com.adpro.tasc.appointment.db.mapper.SlotMapper -com/adpro/tasc/user/db/model/User.java - com.adpro.tasc.user.db.model.User -com/adpro/tasc/appointment/db/template/AppointmentTemplate.java - com.adpro.tasc.appointment.db.template.AppointmentTemplate -com/adpro/tasc/user/db/model/Role.java - com.adpro.tasc.user.db.model.Role - com.adpro.tasc.user.db.model.Role$1 -com/adpro/tasc/appointment/db/mapper/CourseMapper.java - com.adpro.tasc.appointment.db.mapper.CourseMapper -com/adpro/tasc/user/db/template/UserTemplate.java - com.adpro.tasc.user.db.template.UserTemplate -com/adpro/tasc/user/db/mapper/UserMapper.java - com.adpro.tasc.user.db.mapper.UserMapper -com/adpro/tasc/controller/HelloController.java - com.adpro.tasc.controller.HelloController -com/adpro/tasc/appointment/db/dao/AppointmentDAO.java - com.adpro.tasc.appointment.db.dao.AppointmentDAO -com/adpro/tasc/appointment/db/dao/ScheduleDAO.java - com.adpro.tasc.appointment.db.dao.ScheduleDAO -com/adpro/tasc/appointment/db/model/Schedule.java - com.adpro.tasc.appointment.db.model.Schedule -com/adpro/tasc/appointment/db/model/AppointmentRequest.java - com.adpro.tasc.appointment.db.model.AppointmentRequest - com.adpro.tasc.appointment.db.model.AppointmentRequest$Status -com/adpro/tasc/user/db/dao/UserDAO.java - com.adpro.tasc.user.db.dao.UserDAO -com/adpro/tasc/appointment/db/template/CourseTemplate.java - com.adpro.tasc.appointment.db.template.CourseTemplate -com/adpro/tasc/appointment/db/model/Appointment.java - com.adpro.tasc.appointment.db.model.Appointment -com/adpro/tasc/appointment/db/template/ScheduleTemplate.java - com.adpro.tasc.appointment.db.template.ScheduleTemplate -com/adpro/tasc/appointment/db/model/Slot.java - com.adpro.tasc.appointment.db.model.Slot - com.adpro.tasc.appointment.db.model.Slot$Day -com/adpro/tasc/appointment/db/dao/CourseDAO.java - com.adpro.tasc.appointment.db.dao.CourseDAO -com/adpro/tasc/TASCApp.java - com.adpro.tasc.TASCApp -com/adpro/tasc/config/DBConfig.java - com.adpro.tasc.config.DBConfig -com/adpro/tasc/appointment/db/mapper/ScheduleMapper.java - com.adpro.tasc.appointment.db.mapper.ScheduleMapper -com/adpro/tasc/appointment/db/mapper/AppointmentMapper.java - com.adpro.tasc.appointment.db.mapper.AppointmentMapper diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/src/main/java/com/adpro/tasc/controller/AddRolesController.java b/src/main/java/com/adpro/tasc/controller/AddRolesController.java index b4f5e6d..d2de8ca 100644 --- a/src/main/java/com/adpro/tasc/controller/AddRolesController.java +++ b/src/main/java/com/adpro/tasc/controller/AddRolesController.java @@ -4,7 +4,6 @@ import com.adpro.tasc.user.db.dao.UserDAO; import com.adpro.tasc.user.db.model.AcademicUser; import com.adpro.tasc.user.db.model.Role; import com.adpro.tasc.user.db.model.User; -import com.adpro.tasc.user.db.template.UserTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; diff --git a/src/main/java/com/adpro/tasc/controller/CreateCoursesController.java b/src/main/java/com/adpro/tasc/controller/CreateCoursesController.java new file mode 100644 index 0000000..7e0dc97 --- /dev/null +++ b/src/main/java/com/adpro/tasc/controller/CreateCoursesController.java @@ -0,0 +1,41 @@ +package com.adpro.tasc.controller; + +import com.adpro.tasc.appointment.db.model.Course; +import com.adpro.tasc.user.db.dao.UserDAO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; + +import java.util.ArrayList; +import java.util.List; + +@Controller +public class CreateCoursesController { + @Autowired + UserDAO userDAO; + List<Course> courses = new ArrayList<>(); + + @GetMapping(value="/create-course") + public String createCourseForm(Model model) { + System.out.println(); + model.addAttribute("courses",courses); + return "create_course"; + } + + @PostMapping(value="/create-course") + public String createCourse( + @RequestParam("name") String name + ) { + System.out.println(name); + Course newCourse = new Course(); + newCourse.setName(name); + + courses.add(newCourse); + + return "redirect:/create-course"; + } +} \ No newline at end of file diff --git a/src/main/java/com/adpro/tasc/controller/CreateScheduleController.java b/src/main/java/com/adpro/tasc/controller/CreateScheduleController.java new file mode 100644 index 0000000..f45c742 --- /dev/null +++ b/src/main/java/com/adpro/tasc/controller/CreateScheduleController.java @@ -0,0 +1,79 @@ +package com.adpro.tasc.controller; + +import com.adpro.tasc.appointment.db.dao.ScheduleDAO; +import com.adpro.tasc.appointment.db.model.Slot; +import com.adpro.tasc.repository.SlotRepository; +import com.adpro.tasc.user.db.dao.UserDAO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +@Controller +public class CreateScheduleController { + @Autowired + private ScheduleDAO scheduleDAO; + + private String[] daysArr = {"MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY","FRIDAY","SATURDAY","SUNDAY"}; + private List<Slot> slots = new ArrayList<>(); +// private final SlotRepository slots; + + + @GetMapping(value="/create-schedule") + public String displaySchedule(Model model) { + List<String> days = Arrays.asList(daysArr); + +// Slot slot1 = new Slot(); +// slot1.setDay(Slot.Day.MONDAY); +// slot1.setStartTime(System.currentTimeMillis()); +// slot1.setFinishTime(System.currentTimeMillis()+(long)100000000); +// slots.add(slot1); + +// scheduleDAO.addUserScheduleSlot(); + + model.addAttribute("days",days); + model.addAttribute("slots",slots); + + + return "display_schedule"; + } + + @GetMapping(value="/add-slot") + public String addSlotForm(Model model) { + model.addAttribute("days",daysArr); + + return "create_slot"; + } + + @PostMapping(value="/add-slot") + public String createSlot( + @RequestParam("day") int day, + @RequestParam("startHour") int startHour, + @RequestParam("startMinute") int startMinute, + @RequestParam("endHour") int endHour, + @RequestParam("endMinute") int endMinute + ) + { + System.out.println(day+" "+startHour+ " " + startMinute); + + 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(); + + Slot slot1 = new Slot(); + slot1.setDay(Slot.Day.valueOf(daysArr[day])); + slot1.setStartTime(epochStart); + slot1.setFinishTime(epochEnd); + slots.add(slot1); + + return "redirect:/create-schedule"; + } +} diff --git a/src/main/java/com/adpro/tasc/repository/SlotRepository.java b/src/main/java/com/adpro/tasc/repository/SlotRepository.java new file mode 100644 index 0000000..613e49d --- /dev/null +++ b/src/main/java/com/adpro/tasc/repository/SlotRepository.java @@ -0,0 +1,20 @@ +package com.adpro.tasc.repository; + +import com.adpro.tasc.appointment.db.model.Slot; +import org.springframework.stereotype.Repository; + +import java.util.ArrayList; +import java.util.List; + +@Repository +public class SlotRepository { + private List<Slot> slots = new ArrayList<>(); + + public List<Slot> getSlots() { + return slots; + } + + public void addSlot(Slot slot) { + slots.add(slot); + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 7c1305b..cd84a22 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,6 +1,6 @@ spring.datasource.url=jdbc:postgresql://localhost:5432/tasc -spring.datasource.username=postgres -spring.datasource.password=admin +spring.datasource.username=alifyandra +spring.datasource.password=chungalip01 spring.datasource.currentSchema=tasc logging.level.root=info \ No newline at end of file diff --git a/src/main/resources/templates/create_course.html b/src/main/resources/templates/create_course.html new file mode 100644 index 0000000..19cce00 --- /dev/null +++ b/src/main/resources/templates/create_course.html @@ -0,0 +1,51 @@ +<!DOCTYPE html> +<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.w3.org/1999/xhtml"> + <head> + <meta charset="UTF-8"> + <title>Create course</title> + + <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> + <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> + <!-- Bootstrap --> + <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous"> + <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/js/bootstrap.bundle.min.js" integrity="sha384-JEW9xMcG8R+pH31jmWH6WWP0WintQrMb4s7ZOdauHnUtxwoG2vI5DkLtS3qm9Ekf" crossorigin="anonymous"></script> + <!-- Datatables CDN--> + <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.24/css/jquery.dataTables.css"> + <script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.24/js/jquery.dataTables.js"></script> + + </head> +<body> + <div style="padding:2em"> + <div> + <form th:action="@{/home}"> + <button type="submit" class="btn btn-danger">Back</button> + </form> + </div> + <div> + <h2>Create Course</h2> + </div> + <div> + <form method="POST"> + <label for="name">Course Name:</label> + <input id="name" name="name" type="text"/> + <button type="submit" class="btn btn-success">Submit</button> + </form> + </div> + <div> + <table id="courseList" class="table table-striped" style="width:100%"> + <thead> + <tr> + <th>Course Name</th> + </tr> + </thead> + <tbody> + <tr th:each="course: ${courses}"> + <td th:text="${course.name}"></td> + </tr> + </tbody> + </table> + </div> + </div> + <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script> +</body> +</html> \ No newline at end of file diff --git a/src/main/resources/templates/create_slot.html b/src/main/resources/templates/create_slot.html new file mode 100644 index 0000000..406ec93 --- /dev/null +++ b/src/main/resources/templates/create_slot.html @@ -0,0 +1,64 @@ +<!DOCTYPE html> +<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.w3.org/1999/xhtml"> +<head> + <meta charset="UTF-8"> + <title>Create Slot</title> + + <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> + <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> + <!-- Bootstrap --> + <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous"> + <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/js/bootstrap.bundle.min.js" integrity="sha384-JEW9xMcG8R+pH31jmWH6WWP0WintQrMb4s7ZOdauHnUtxwoG2vI5DkLtS3qm9Ekf" crossorigin="anonymous"></script> + <!-- Datatables CDN--> + <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.24/css/jquery.dataTables.css"> + <script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.24/js/jquery.dataTables.js"></script> + +</head> +<body> +<div style="padding:2em; text-align: center"> + <div> + <form th:action="@{/create-schedule}"> + <button type="submit" class="btn btn-danger">Back</button> + </form> + </div> + <div> + <h2>Add a new available slot to your schedule</h2> + </div> + <div> + <form 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> + + <h4>Start time:</h4> + <div> + <label for="startHour">Hours:</label> + <input id = "startHour" name = "startHour" type = "number"/> + </div> + + <div> + <label for="startMinute">Minute:</label> + <input id = "startMinute" name = "startMinute" type = "number"/> + </div> + + <h4>End time:</h4> + <div> + <label for="endHour">Hours:</label> + <input id = "endHour" name = "endHour" type = "number"/> + </div> + + <div> + <label for="endMinute">Minute:</label> + <input id = "endMinute" name = "endMinute" type = "number"/> + </div> + <button type="submit" class="btn btn-success" >Submit</button> + + </form> + </div> +</div> + +</body> +</html> \ No newline at end of file diff --git a/src/main/resources/templates/display_schedule.html b/src/main/resources/templates/display_schedule.html new file mode 100644 index 0000000..c3661b6 --- /dev/null +++ b/src/main/resources/templates/display_schedule.html @@ -0,0 +1,50 @@ +<!DOCTYPE html> +<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.w3.org/1999/xhtml"> +<head> + <meta charset="UTF-8"> + <title>Display Schedule</title> + + <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> + <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> + <!-- Bootstrap --> + <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous"> + <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/js/bootstrap.bundle.min.js" integrity="sha384-JEW9xMcG8R+pH31jmWH6WWP0WintQrMb4s7ZOdauHnUtxwoG2vI5DkLtS3qm9Ekf" crossorigin="anonymous"></script> + <!-- Datatables CDN--> + <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.24/css/jquery.dataTables.css"> + <script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.24/js/jquery.dataTables.js"></script> + +</head> +<body> + <div style="padding:2em;" > + <div> + <form th:action="@{/home}"> + <button type="submit" class="btn btn-danger">Back</button> + </form> + </div> + <div> + <h2>Your schedule</h2> + </div> + <div> + <table id="scheduleList" class="table table-striped" style="width:100%"> + <thead> + <tr> + <th>Day</th> + <th>Available Time Slot</th> + </tr> + </thead> + <tbody> + <tr th:each="slot: ${slots}"> + <td th:text="${days.get(slot.day)}"></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> + </tr> + </tbody> + </table> + </div> + <div> + <form th:action="@{/add-slot}"> + <button type="submit" class="btn btn-success">Add new available slot</button> + </form> + </div> + </div> +</body> +</html> \ No newline at end of file -- GitLab