From 972d08a54d234ce6871a9bc56adc597908e7e769 Mon Sep 17 00:00:00 2001 From: Wawilski Date: Sun, 24 Mar 2024 13:37:27 +0100 Subject: [PATCH 01/15] added temporary fix to docker issue --- backend/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/build.gradle.kts b/backend/build.gradle.kts index b7cabcd..e0abc58 100644 --- a/backend/build.gradle.kts +++ b/backend/build.gradle.kts @@ -25,7 +25,7 @@ dependencies { implementation("com.kohlschutter.junixsocket:junixsocket-core:2.9.0") // implementation("org.springframework.session:spring-session-jdbc") developmentOnly("org.springframework.boot:spring-boot-devtools") - developmentOnly("org.springframework.boot:spring-boot-docker-compose") + // developmentOnly("org.springframework.boot:spring-boot-docker-compose") runtimeOnly("org.postgresql:postgresql") testImplementation("org.springframework.boot:spring-boot-starter-test") testImplementation("org.springframework.boot:spring-boot-testcontainers") From 2b9493422d352f2693711714509c47cba4d158c6 Mon Sep 17 00:00:00 2001 From: Wawilski Date: Mon, 1 Apr 2024 16:51:18 +0200 Subject: [PATCH 02/15] setup grid to display courses --- backend/build.gradle.kts | 1 - .../EndPoints/ApplicationsController.java | 1 + .../herisson/Clyde/Tables/Applications.java | 1 + frontend/src/App.vue | 1 - frontend/src/Apps/Schedule.vue | 211 ++++++++++++++++++ frontend/src/rest/apps.js | 2 + 6 files changed, 215 insertions(+), 2 deletions(-) create mode 100644 frontend/src/Apps/Schedule.vue diff --git a/backend/build.gradle.kts b/backend/build.gradle.kts index e0abc58..2551f2a 100644 --- a/backend/build.gradle.kts +++ b/backend/build.gradle.kts @@ -25,7 +25,6 @@ dependencies { implementation("com.kohlschutter.junixsocket:junixsocket-core:2.9.0") // implementation("org.springframework.session:spring-session-jdbc") developmentOnly("org.springframework.boot:spring-boot-devtools") - // developmentOnly("org.springframework.boot:spring-boot-docker-compose") runtimeOnly("org.postgresql:postgresql") testImplementation("org.springframework.boot:spring-boot-starter-test") testImplementation("org.springframework.boot:spring-boot-testcontainers") diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ApplicationsController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ApplicationsController.java index 8d1f1ca..83c5050 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ApplicationsController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ApplicationsController.java @@ -47,6 +47,7 @@ public class ApplicationsController { //if unAuthed authorizedApps.add(Applications.Login); + authorizedApps.add(Applications.Schedule); User user = authServ.getUserFromToken(token); if(user == null) diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Applications.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Applications.java index 3dadcec..684441a 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Applications.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Applications.java @@ -3,6 +3,7 @@ package ovh.herisson.Clyde.Tables; public enum Applications { // without any token Login, + Schedule, // with any token Profile, diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 6dcad67..83f753b 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -25,7 +25,6 @@ window.addEventListener('hashchange', () => { const login=ref(i18n("app.login")) const active=ref(false) - const apps = ref([]) appList().then(e => apps.value = e) diff --git a/frontend/src/Apps/Schedule.vue b/frontend/src/Apps/Schedule.vue new file mode 100644 index 0000000..490cf9b --- /dev/null +++ b/frontend/src/Apps/Schedule.vue @@ -0,0 +1,211 @@ + + + diff --git a/frontend/src/rest/apps.js b/frontend/src/rest/apps.js index 99cbc10..2672686 100644 --- a/frontend/src/rest/apps.js +++ b/frontend/src/rest/apps.js @@ -9,8 +9,10 @@ import Profil from "@/Apps/Profil.vue" import Courses from "@/Apps/ManageCourses.vue" import Users from "@/Apps/UsersList.vue" import Students from "@/Apps/StudentsList.vue" +import Schedule from "@/Apps/Schedule.vue" const apps = { + '/schedule': Schedule, '/login': LoginPage, '/inscription': Inscription, '/profil': Profil, From 443cf557849c8a01faecd6374544b1523b4e20be Mon Sep 17 00:00:00 2001 From: Wawilski Date: Tue, 2 Apr 2024 16:52:40 +0200 Subject: [PATCH 03/15] weekly set up, end --- frontend/src/Apps/ManageCourses.vue | 2 +- frontend/src/Apps/Schedule.vue | 77 +++++++++++++++++++++-------- 2 files changed, 58 insertions(+), 21 deletions(-) diff --git a/frontend/src/Apps/ManageCourses.vue b/frontend/src/Apps/ManageCourses.vue index 7337633..96bd35b 100644 --- a/frontend/src/Apps/ManageCourses.vue +++ b/frontend/src/Apps/ManageCourses.vue @@ -17,7 +17,7 @@ const editElementID = ref("") function editItem(id){ - editElementID = id; + editElementID.value = id; } //Juste pour montrer le Create Mode diff --git a/frontend/src/Apps/Schedule.vue b/frontend/src/Apps/Schedule.vue index 490cf9b..1fab1bc 100644 --- a/frontend/src/Apps/Schedule.vue +++ b/frontend/src/Apps/Schedule.vue @@ -3,23 +3,26 @@ const schedule = [ {course:"Math Pour L'info", - start:"Wed Mar 27 2024 10:15 GMT+0100", - end:"Wed Mar 27 2024 12:15 GMT+0100"}, + start:"Tue Mar 26 2024 08:15 GMT+0100", + end:"Tue Mar 26 2024 10:15 GMT+0100", + color:"rgb(0,50,100)"}, { course:"Calculus", - start:"Wed Mar 27 2024 08:00 GMT+0100", - end:"Wed Mar 27 2024 10:00 GMT+0100" - + start:"Wed Mar 27 2024 08:15 GMT+0100", + end:"Wed Mar 27 2024 09:15 GMT+0100", + color:"rgb(100,50,0)" }, { course:"Physique II", - start:"Tue Mar 26 2024 10:15 GMT+0100", - end:"Tue Mar 26 2024 12:15 GMT+0100" + start:"Tue Mar 26 2024 10:30 GMT+0100", + end:"Tue Mar 26 2024 12:30 GMT+0100", + color:"rgb(100,50,100)" }, { course:"Math Pour L'info", - start:"Thu Mar 28 2024 10:15 GMT+0100", - end:"Thu Mar 28 2024 12:15 GMT+0100" + start:"Tue Mar 26 2024 13:30 GMT+0100", + end:"Tue Mar 26 2024 15:30 GMT+0100", + color:"rgb(100,0,50)" }] function formatDate(date) { var d = new Date(date), @@ -97,10 +100,28 @@ return matrix; } - - const schedule2 = matrixFromList(schedule); - const scheduleByWeek = transpose(schedule2); - + function sundayToTheEnd(list){ + const newlist = list; + const sunday = newlist.shift(); + newlist.push(sunday); + return newlist; + } + + function getDifferenceTime(date1,date2){ + return Math.abs((new Date(date2).getTime() - new Date(date1).getTime())/60000); + } + + function getMarginTop(list, index1, index2){ + if(index2 < 0){ + const temp = new Date(list[index1].start); + temp.setHours(8,0,0); + return Math.abs((new Date(list[index1].start).getTime()- temp.getTime())/60000); + } + return Math.abs((new Date(list[index1].start).getTime()- new Date(list[index2].end).getTime())/60000)+getMarginTop(list,index2,index2-1); + } + + + const scheduleByWeek = sundayToTheEnd(matrixFromList(schedule)); console.log(scheduleByWeek) @@ -126,8 +147,15 @@
-
- Test +
+
@@ -201,11 +229,20 @@ } - .course{ - width:100%; - height:100%; - background-color:rgb(100,0,100); - } + .course{ + position:relative; + border: 1px solid black; + border-radius:10px; + width:90%; + margin-left:auto; + margin-right:auto; + display:grid; + grid-template-rows:1fr 1fr 1fr; + } + + .dayCourse{ + display:block; + } From 9937a7db39ac84de5bce4bdfe2c37555d11ad46d Mon Sep 17 00:00:00 2001 From: Wawilski Date: Thu, 4 Apr 2024 14:44:35 +0200 Subject: [PATCH 04/15] Display Week and Month End --- frontend/src/Apps/Schedule.vue | 350 ++++++++++++++++++++++----------- frontend/src/schedule.js | 114 +++++++++++ 2 files changed, 351 insertions(+), 113 deletions(-) create mode 100644 frontend/src/schedule.js diff --git a/frontend/src/Apps/Schedule.vue b/frontend/src/Apps/Schedule.vue index 1fab1bc..0c3f640 100644 --- a/frontend/src/Apps/Schedule.vue +++ b/frontend/src/Apps/Schedule.vue @@ -1,145 +1,152 @@ @@ -167,13 +242,14 @@ margin-top:2%; align-items:center; justify-content:center; - grid-template-columns:15vw 70vw; - column-gap:2.5vw; - - grid-template-areas:"options schedule"; + grid-template-columns:72vw 14.5vw; + column-gap:2vw; + overflow:hidden; + grid-template-areas:"schedule options"; } .schedule{ - position:relative; + position:relative; + overflow-y:scroll; border-radius:20px; grid-area:schedule; width:100%; @@ -181,6 +257,8 @@ background-color:rgba(255,255,255,0.1); } .options{ + display:flex; + flex-direction:column; border-radius:20px; grid-area:options; background-color:rgba(255,255,255,0.1); @@ -203,9 +281,17 @@ } .header{ - align-items:center; width:12.5%; color:#FFFFFF; + position:relative; + } + + + .childHeader{ + margin-top:0; + margin-bottom:0; + max-height:14.28% + } table th:not(:last-child), table td:not(:last-child) { @@ -228,8 +314,7 @@ grid-template-columns:repeat(7,1fr); } - - + .course{ position:relative; border: 1px solid black; @@ -244,5 +329,44 @@ .dayCourse{ display:block; } + + .infos{ + height:100%; + width:100%; + font-size:0.85em; + display:flex; + flex-direction:column; + align-items:center; + justify-content:center; + position:absolute; + } + .childInfos{ + text-align:center; + margin-top:0%; + margin-bottom:0%; + overflow:hidden; + } + + .hourStart{ + background-color:rgb(200,200,200); + border-radius:5px; + position:absolute; + top:2%; + left:2%; + font-size:0.75em; + + border: 1px solid black; + } + + .hourEnd{ + background-color:rgb(200,200,200); + border-radius:3px; + position:absolute; + bottom:2%; + left:2%; + font-size:0.7em; + } + + diff --git a/frontend/src/schedule.js b/frontend/src/schedule.js new file mode 100644 index 0000000..4c80099 --- /dev/null +++ b/frontend/src/schedule.js @@ -0,0 +1,114 @@ + import {ref} from 'vue' + export function formatDate(date) { + var d = new Date(date), + month = '' + (d.getMonth() + 1), + day = '' + d.getDate(), + year = d.getFullYear(); + + if (month.length < 2) + month = '0' + month; + if (day.length < 2) + day = '0' + day; + + return [day, month, year].join('-'); + } + + + + export function durationCourse(element){ + const hour = element.end.substring(3,5) -element.start.substring(3,5); + + + return (element.end - element.start)%2; + } + + export function sortByDate(a, b) { + const nameA = a.start; // ignore upper and lowercase + const nameB = b.start; // ignore upper and lowercase + + if (nameA < nameB) { + return -1; + } + if (nameA > nameB) { + return 1; + } + return 0; + } + + + export function getFirstDay(d){ + var date = new Date(d); + return new Date(date.getFullYear(), date.getMonth(), 1); + } + + + + export function matrixFromList(list,weekMonday){ + const weekStart = new Date(weekMonday); + const matrix = new Array(7); + for (let i = 0; i < matrix.length; i++) { + matrix[i] = []; + } + for(let key in list){ + const temp = list[key]; + const day = new Date(list[key].start); + if((((day.getTime()-weekStart.getTime())/60000)<10080) && (((day.getTime()-weekStart.getTime())/60000)>0)){ + matrix[day.getDay()].push(temp); + matrix[day.getDay()].sort((a,b) => sortByDate(a,b)); + } + } + return matrix; + } + + export function lastDateOfMonth(d){ + const date = new Date(d); + const temp = new Date(date.getFullYear(), date.getMonth() + 1, 0); + return temp.getDate(); + } + + export function monthFromList(list,month){ + const beginning = getFirstDay(month); + const matrix = new Array(lastDateOfMonth(month)) + for (let i = 0; i < matrix.length; i++) { + matrix[i] = []; + + } + for(let key in list){ + const temp = list[key]; + const day = new Date(list[key].start); + if(day.getMonth()==month){ + matrix[day.getDate()].push(temp); + matrix[day.getDay()].sort((a,b) => sortByDate(a,b)); + }} + + + return matrix; + } + + + + export function sundayToTheEnd(list){ + const newlist = list; + const sunday = newlist.shift(); + newlist.push(sunday); + return newlist; + } + + export function getDifferenceTime(date1,date2){ + return Math.abs((new Date(date2).getTime() - new Date(date1).getTime())/60000); + } + + export function getMarginTop(list, index1, index2){ + if(index2 < 0){ + const temp = new Date(list[index1].start); + temp.setHours(8,0,0); + return Math.abs((new Date(list[index1].start).getTime()- temp.getTime())/60000); + } + return Math.abs((new Date(list[index1].start).getTime()- new Date(list[index2].end).getTime())/60000)+getMarginTop(list,index2,index2-1); + } + + export function getHoursMinutes(date){ + const d = new Date(date); + return d.getHours()+ ":" + d.getMinutes(); + } + From aa3e1cb8684716c8413f38c39f8163802a61661d Mon Sep 17 00:00:00 2001 From: Wawilski Date: Sun, 7 Apr 2024 14:33:51 +0200 Subject: [PATCH 05/15] backend Schedule --- .../Clyde/EndPoints/CourseController.java | 2 - .../Clyde/EndPoints/LessonController.java | 75 ++++++++++++++++++ .../Clyde/EndPoints/MockController.java | 45 ++++++++++- .../Clyde/EndPoints/ScheduleController.java | 66 ++++++++++++++++ .../Clyde/Repositories/LessonRepository.java | 14 ++++ .../ScheduleLessonRepository.java | 23 ++++++ .../Repositories/ScheduleRepository.java | 9 +++ .../Clyde/Services/LessonService.java | 59 ++++++++++++++ .../Clyde/Services/ProtectionService.java | 26 +++++++ .../Clyde/Services/ScheduleLessonService.java | 75 ++++++++++++++++++ .../Clyde/Services/ScheduleService.java | 24 ++++++ .../ovh/herisson/Clyde/Tables/Lesson.java | 77 +++++++++++++++++++ .../ovh/herisson/Clyde/Tables/Schedule.java | 33 ++++++++ .../herisson/Clyde/Tables/ScheduleLesson.java | 53 +++++++++++++ frontend/src/Apps/Schedule.vue | 9 ++- frontend/src/rest/courses.js | 2 - frontend/src/rest/lessonSchedule.js | 65 ++++++++++++++++ frontend/src/rest/scheduleRest.js | 13 ++++ .../src/{schedule.js => scheduleFunctions.js} | 0 19 files changed, 662 insertions(+), 8 deletions(-) create mode 100644 backend/src/main/java/ovh/herisson/Clyde/EndPoints/LessonController.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/EndPoints/ScheduleController.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Repositories/LessonRepository.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Repositories/ScheduleLessonRepository.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Repositories/ScheduleRepository.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Services/LessonService.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Services/ScheduleLessonService.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Services/ScheduleService.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Tables/Lesson.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Tables/Schedule.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Tables/ScheduleLesson.java create mode 100644 frontend/src/rest/lessonSchedule.js create mode 100644 frontend/src/rest/scheduleRest.js rename frontend/src/{schedule.js => scheduleFunctions.js} (100%) diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CourseController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CourseController.java index d5e87a8..40b1e0f 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CourseController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CourseController.java @@ -74,8 +74,6 @@ public class CourseController { public ResponseEntity> postCourse(@RequestHeader("Authorization") String token, @RequestBody Course course) { - System.out.println(course); - System.out.println(token); if (authServ.isNotIn(new Role[]{Role.Secretary,Role.Admin},token)) return new UnauthorizedResponse<>(null); diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LessonController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LessonController.java new file mode 100644 index 0000000..bd8bfb5 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LessonController.java @@ -0,0 +1,75 @@ +package ovh.herisson.Clyde.EndPoints; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import ovh.herisson.Clyde.Responses.UnauthorizedResponse; +import ovh.herisson.Clyde.Services.AuthenticatorService; +import ovh.herisson.Clyde.Services.LessonService; +import ovh.herisson.Clyde.Services.ProtectionService; +import ovh.herisson.Clyde.Tables.Lesson; +import ovh.herisson.Clyde.Tables.Role; + +import java.util.HashMap; +import java.util.Map; + +@RestController +@CrossOrigin(originPatterns = "*", allowCredentials = "true") +public class LessonController { + private final LessonService lessonServ; + + private final AuthenticatorService authServ; + + public LessonController(LessonService lessonServ, AuthenticatorService authServ) { + this.lessonServ = lessonServ; + this.authServ = authServ; + } + + @GetMapping("/lesson/{id}") + public ResponseEntity> getLesson(@PathVariable long id){ + Lesson lesson = lessonServ.findById(id); + + if(lesson == null) + return new ResponseEntity<>(HttpStatus.BAD_REQUEST); + + return new ResponseEntity<>(ProtectionService.lessonWithoutPassword(lesson),HttpStatus.OK); + } + + @GetMapping("/lessons") + public ResponseEntity>> getAllLessons(@RequestHeader("Authorization") String token){ + if(authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary},token)) + return new UnauthorizedResponse<>(null); + return new ResponseEntity<>(ProtectionService.lessonsWithoutPassword(lessonServ.findAll()),HttpStatus.OK); + } + + @GetMapping("/lessons/owned") + public ResponseEntity>> getOwnedLessons(@RequestHeader("Authorization") String token){ + if (authServ.isNotIn(new Role[]{Role.Admin,Role.Teacher},token)) + return new UnauthorizedResponse<>(null); + return new ResponseEntity<>(ProtectionService.lessonsWithoutPassword(lessonServ.findAllOwnedLesson(authServ.getUserFromToken(token))),HttpStatus.OK); + } + + + @PostMapping("/lesson") + public ResponseEntity> postLesson(@RequestHeader("Authorization")String token, + @RequestBody Lesson lesson){ + if(authServ.isNotIn(new Role[]{Role.Secretary,Role.Admin},token)) + return new UnauthorizedResponse<>(null); + Lesson createdLesson = lessonServ.save(lesson); + + if(createdLesson==null) + return new ResponseEntity<>(null,HttpStatus.BAD_REQUEST); + return new ResponseEntity<>(ProtectionService.lessonWithoutPassword(createdLesson), HttpStatus.OK); + } + + @PatchMapping("/lesson/{id}") + public ResponseEntity patchLesson(@RequestHeader("Authorization") String token, + @RequestBody Map updates, + @PathVariable long id){ + if(authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary},token)) + return new UnauthorizedResponse<>(null); + if(!lessonServ.modifyData(id, updates, authServ.getUserFromToken(token).getRole())) + return new ResponseEntity<>(HttpStatus.BAD_REQUEST); + return new ResponseEntity<>(HttpStatus.OK); + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java index 0b7a1b4..779a1f0 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java @@ -24,10 +24,15 @@ public class MockController { public final CourseService courseService; public final InscriptionService inscriptionService; + + public final LessonService lessonService; + public final ScheduleService scheduleService; + public final ScheduleLessonService scheduleLessonService; + ArrayList mockUsers; - public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CurriculumCourseService CurriculumCourseService, CurriculumService curriculumService, CourseService courseService, InscriptionService inscriptionService){ + public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CurriculumCourseService CurriculumCourseService, CurriculumService curriculumService, CourseService courseService, InscriptionService inscriptionService, LessonService lessonService, ScheduleService scheduleService, ScheduleLessonService scheduleLessonService){ this.tokenRepo = tokenRepo; this.userRepo = userRepo; this.tokenService = tokenService; @@ -35,6 +40,9 @@ public class MockController { this.curriculumService = curriculumService; this.courseService = courseService; this.inscriptionService = inscriptionService; + this.lessonService = lessonService; + this.scheduleService = scheduleService; + this.scheduleLessonService = scheduleLessonService; } /** Saves an example of each user type by : @@ -95,7 +103,40 @@ public class MockController { InscriptionRequest inscriptionRequest = new InscriptionRequest("helen","prenom","non","helen@gmail.com","america",new Date(),(long) 1,RequestState.Pending,"yes.png","password"); inscriptionService.save(inscriptionRequest); - + + + //Schedule part + + Lesson lesson_0_progra1 = new Lesson(progra1, "Mon Apr 01 2024 08:15", "Mon Apr 01 2024 10:15","rgb(0,50,100)","A0B2"); + Lesson lesson_0_chemistry1 = new Lesson(chemistry1, "Wed Mar 27 2024 08:15", "Wed Mar 27 2024 09:15","rgb(100,50,0)","A0B2"); + Lesson lesson_0_psycho1 = new Lesson(psycho1, "Sun Mar 24 2024 10:30 ","Sun Mar 24 2024 12:30 ","rgb(100,50,100)", "A0B2"); + Lesson lesson_1_progra1 = new Lesson(progra1, "Mon Apr 02 2024 13:30", "Mon Apr 02 2024 15:30","rgb(0,50,100)","A0B2"); + Lesson lesson_0_commun = new Lesson(commun, "Mon Apr 01 2024 10:30", "Mon Apr 01 2024 12:30","rgb(0,50,100)","A0B2"); + + Schedule infoBab1Schedule = new Schedule(infoBab1); + Schedule chemistryBab1Schedule = new Schedule(chemistryBab1); + Schedule psychoBab1Schedule = new Schedule(psychologyBab1); + + scheduleService.save(infoBab1Schedule); + scheduleService.save(chemistryBab1Schedule); + scheduleService.save(psychoBab1Schedule); + + lessonService.save(lesson_0_progra1); + lessonService.save(lesson_0_chemistry1); + lessonService.save(lesson_0_commun); + lessonService.save(lesson_0_psycho1); + lessonService.save(lesson_1_progra1); + + scheduleLessonService.save(new ScheduleLesson(infoBab1Schedule,lesson_0_progra1)); + scheduleLessonService.save(new ScheduleLesson(infoBab1Schedule,lesson_1_progra1)); + scheduleLessonService.save(new ScheduleLesson(infoBab1Schedule,lesson_0_commun)); + + scheduleLessonService.save(new ScheduleLesson(chemistryBab1Schedule,lesson_0_chemistry1)); + scheduleLessonService.save(new ScheduleLesson(chemistryBab1Schedule,lesson_0_commun)); + + scheduleLessonService.save(new ScheduleLesson(psychoBab1Schedule,lesson_0_psycho1)); + scheduleLessonService.save(new ScheduleLesson(psychoBab1Schedule,lesson_0_commun)); + } } diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ScheduleController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ScheduleController.java new file mode 100644 index 0000000..51cbcc1 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ScheduleController.java @@ -0,0 +1,66 @@ +package ovh.herisson.Clyde.EndPoints; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import ovh.herisson.Clyde.Responses.UnauthorizedResponse; +import ovh.herisson.Clyde.Services.AuthenticatorService; +import ovh.herisson.Clyde.Services.ScheduleLessonService; +import ovh.herisson.Clyde.Services.ScheduleService; +import ovh.herisson.Clyde.Services.UserCurriculumService; +import ovh.herisson.Clyde.Tables.Role; +import ovh.herisson.Clyde.Tables.Schedule; + +import java.util.Map; + +@RestController +@CrossOrigin(originPatterns = "*", allowCredentials = "true") +public class ScheduleController { + + private final ScheduleService scheduleServ; + + private final UserCurriculumService userCurriculumService; + private final AuthenticatorService authServ; + + private final ScheduleLessonService scheduleLessonServ; + + public ScheduleController(ScheduleService scheduleServ, UserCurriculumService userCurriculumService, AuthenticatorService authServ, ScheduleLessonService scheduleLessonServ) { + this.scheduleServ = scheduleServ; + this.userCurriculumService = userCurriculumService; + this.authServ = authServ; + this.scheduleLessonServ = scheduleLessonServ; + } + + @GetMapping("/schedule/{id}") + public ResponseEntity> findById(@PathVariable long id){ + Schedule schedule = scheduleServ.findById(id); + + if(schedule == null) + return new ResponseEntity<>(HttpStatus.BAD_REQUEST); + return new ResponseEntity<>(scheduleLessonServ.getDepthScheduleBySchedule(schedule),HttpStatus.OK); + } + + + @GetMapping("/schedule") + public ResponseEntity> findSelfSchedule(@RequestHeader("Authorization") String token){ + if(authServ.getUserFromToken(token) == null) + return new UnauthorizedResponse<>(null); + Schedule schedule = scheduleLessonServ.getScheduleByCurriculum(userCurriculumService.findByUser(authServ.getUserFromToken(token))); + if(schedule == null) + return new ResponseEntity<>(HttpStatus.BAD_REQUEST); + return new ResponseEntity<>(scheduleLessonServ.getDepthScheduleBySchedule(schedule),HttpStatus.OK); + } + + @GetMapping("/schedules") + public ResponseEntity>> findAllSchedule(){ + return new ResponseEntity<>(scheduleLessonServ.getAllSchedule(),HttpStatus.OK); + } + + @PostMapping("/schedule") + public ResponseEntity postSchedule(@RequestHeader("Authorization") String token, + @RequestBody Schedule schedule){ + if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary},token)) + return new UnauthorizedResponse<>(null); + return new ResponseEntity<>(scheduleServ.save(schedule),HttpStatus.OK); + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/LessonRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/LessonRepository.java new file mode 100644 index 0000000..eae64da --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/LessonRepository.java @@ -0,0 +1,14 @@ +package ovh.herisson.Clyde.Repositories; + +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.CrudRepository; +import ovh.herisson.Clyde.Tables.Lesson; +import ovh.herisson.Clyde.Tables.User; + +public interface LessonRepository extends CrudRepository { + + Lesson findById(long id); + + @Query("select l from Lesson l where l.course.owner = ?1") + Iterable findAllOwnedLesson(User teacher); +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/ScheduleLessonRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/ScheduleLessonRepository.java new file mode 100644 index 0000000..81fec17 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/ScheduleLessonRepository.java @@ -0,0 +1,23 @@ +package ovh.herisson.Clyde.Repositories; + +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.CrudRepository; +import ovh.herisson.Clyde.Tables.Curriculum; +import ovh.herisson.Clyde.Tables.Lesson; +import ovh.herisson.Clyde.Tables.Schedule; +import ovh.herisson.Clyde.Tables.ScheduleLesson; + +public interface ScheduleLessonRepository extends CrudRepository { + + @Query("select distinct sl.lesson from ScheduleLesson sl where sl.schedule.curriculum = ?1") + Iterable findLessonByCurriculum(Curriculum curriculum); + + @Query("select distinct sl.schedule from ScheduleLesson sl") + Iterable findDistinctSchedule(); + + @Query("select distinct sl.schedule from ScheduleLesson sl where sl.schedule.curriculum = ?1") + Schedule findScheduleByCurriculum(Curriculum curriculum); + + @Query("select distinct sl.lesson from ScheduleLesson sl where sl.schedule = ?1") + Iterable findLessonBySchedule(Schedule schedule); +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/ScheduleRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/ScheduleRepository.java new file mode 100644 index 0000000..192fb05 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/ScheduleRepository.java @@ -0,0 +1,9 @@ +package ovh.herisson.Clyde.Repositories; + +import org.springframework.data.repository.CrudRepository; +import ovh.herisson.Clyde.Tables.Schedule; + +public interface ScheduleRepository extends CrudRepository { + + Schedule findById(long id); +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/LessonService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/LessonService.java new file mode 100644 index 0000000..5b3c13d --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/LessonService.java @@ -0,0 +1,59 @@ +package ovh.herisson.Clyde.Services; + +import org.springframework.stereotype.Service; +import ovh.herisson.Clyde.Repositories.LessonRepository; +import ovh.herisson.Clyde.Tables.Lesson; +import ovh.herisson.Clyde.Tables.Role; +import ovh.herisson.Clyde.Tables.User; +import java.util.Map; + +@Service +public class LessonService { + private final LessonRepository lessonRepo; + public LessonService(LessonRepository lessonRepo){ + this.lessonRepo = lessonRepo; + } + + public Lesson save(Lesson lesson){ + return lessonRepo.save(lesson); + } + public Lesson findById(long id){ + return lessonRepo.findById(id); + } + public Iterable findAll(){return lessonRepo.findAll();} + + public Iterable findAllOwnedLesson(User teacher){ + return lessonRepo.findAllOwnedLesson(teacher); + } + + public boolean modifyData(long id, Map updates, Role role){ + Lesson target = lessonRepo.findById(id); + + if(target == null || role != Role.Secretary) + return false; + + + for (Map.Entry entry: updates.entrySet()){ + switch (entry.getKey()){ + case "lessonStart": + target.setLessonStart((String) entry.getValue()); + break; + case "lessonEnd": + target.setLessonEnd((String) entry.getValue()); + case "color": + target.setColor((String) entry.getValue()); + break; + case "local": + target.setLocal((String) entry.getValue()); + } + } + lessonRepo.save(target); + return true; + } + + public void delete(Lesson lesson){ + lessonRepo.delete(lesson); + } + + +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/ProtectionService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/ProtectionService.java index 44e53a7..1f25dfe 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/ProtectionService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/ProtectionService.java @@ -2,6 +2,7 @@ package ovh.herisson.Clyde.Services; import ovh.herisson.Clyde.Tables.Course; import ovh.herisson.Clyde.Tables.InscriptionRequest; +import ovh.herisson.Clyde.Tables.Lesson; import ovh.herisson.Clyde.Tables.User; import java.util.ArrayList; @@ -69,6 +70,31 @@ public class ProtectionService { } + public static HashMap lessonWithoutPassword(Lesson lesson){ + if(lesson == null) + return null; + + HashMap toReturn = new HashMap<>(); + + toReturn.put("lessonID", lesson.getLessonID()); + toReturn.put("lessonStart", lesson.getLessonStart()); + toReturn.put("lessonEnd", lesson.getLessonEnd()); + toReturn.put("course",courseWithoutPassword(lesson.getCourse())); + toReturn.put("local",lesson.getLocal()); + return toReturn; + } + + public static Iterable> lessonsWithoutPassword(Iterable lessons){ + ArrayList> toReturn = new ArrayList<>(); + + for (Lesson l: lessons){ + toReturn.add(ProtectionService.lessonWithoutPassword(l)); + } + + return toReturn; + + } + public static Map requestWithoutPassword(InscriptionRequest inscriptionRequest) { diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/ScheduleLessonService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/ScheduleLessonService.java new file mode 100644 index 0000000..53e15ba --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/ScheduleLessonService.java @@ -0,0 +1,75 @@ +package ovh.herisson.Clyde.Services; + +import org.springframework.stereotype.Service; +import ovh.herisson.Clyde.Repositories.LessonRepository; +import ovh.herisson.Clyde.Repositories.ScheduleLessonRepository; +import ovh.herisson.Clyde.Repositories.ScheduleRepository; +import ovh.herisson.Clyde.Tables.*; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +@Service +public class ScheduleLessonService { + + private final ScheduleLessonRepository scheduleLessonRepo; + + private final LessonRepository lessonRepo; + private final ScheduleRepository scheduleRepo; + public ScheduleLessonService(ScheduleLessonRepository scheduleLessonRepo, LessonRepository lessonRepo, ScheduleRepository scheduleRepo) { + this.scheduleLessonRepo = scheduleLessonRepo; + this.lessonRepo = lessonRepo; + this.scheduleRepo = scheduleRepo; + } + + public void save(ScheduleLesson scheduleLesson){ + scheduleLessonRepo.save(scheduleLesson); + } + + public Schedule getScheduleByCurriculum(Curriculum curriculum){ + return scheduleLessonRepo.findScheduleByCurriculum(curriculum); + } + + public Map getDepthScheduleByCurriculum(Curriculum curriculum){ + if(curriculum == null) + return null; + + HashMap toReturn = new HashMap<>(); + ArrayList> lessons = new ArrayList<>(); + Iterable foundLessons = scheduleLessonRepo.findLessonByCurriculum(curriculum); + + for (Lesson l: foundLessons){ + lessons.add(ProtectionService.lessonWithoutPassword(l)); + } + toReturn.put("lessons",lessons); + toReturn.put("scheduleId" , scheduleLessonRepo.findScheduleByCurriculum(curriculum).getScheduleID()); + return toReturn; + } + + public Map getDepthScheduleBySchedule(Schedule schedule){ + if(schedule == null) + return null; + + HashMap toReturn = new HashMap<>(); + ArrayList> lessons = new ArrayList<>(); + Iterable foundLessons = scheduleLessonRepo.findLessonByCurriculum(schedule.getCurriculum()); + + for (Lesson l: foundLessons){ + lessons.add(ProtectionService.lessonWithoutPassword(l)); + } + toReturn.put("lessons",lessons); + toReturn.put("scheduleId" , schedule.getScheduleID()); + return toReturn; + } + + public Iterable> getAllSchedule(){ + ArrayList> toReturn = new ArrayList<>(); + + for (Schedule schedule: scheduleRepo.findAll()){ + toReturn.add(getDepthScheduleBySchedule(schedule)); + } + return toReturn; + } + +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/ScheduleService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/ScheduleService.java new file mode 100644 index 0000000..950261c --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/ScheduleService.java @@ -0,0 +1,24 @@ +package ovh.herisson.Clyde.Services; + +import org.springframework.stereotype.Service; +import ovh.herisson.Clyde.Repositories.ScheduleRepository; +import ovh.herisson.Clyde.Tables.Schedule; + +@Service +public class ScheduleService { + private final ScheduleRepository scheduleRepo; + public ScheduleService(ScheduleRepository scheduleRepo) { + this.scheduleRepo = scheduleRepo; + } + public Schedule save(Schedule schedule){ + return scheduleRepo.save(schedule); + } + public Schedule findById(long id){ + return scheduleRepo.findById(id); + } + public void delete(Schedule schedule){ + scheduleRepo.delete(schedule); + } + +} + diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Lesson.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Lesson.java new file mode 100644 index 0000000..00a693c --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Lesson.java @@ -0,0 +1,77 @@ +package ovh.herisson.Clyde.Tables; + +import jakarta.persistence.*; + + +@Entity +public class Lesson { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int lessonID; + + @ManyToOne + @JoinColumn(name= "Course") + private Course course; + + private String lessonStart; + + private String lessonEnd; + private String color; + + private String local; + + public Lesson(Course course,String start, String end ,String color,String local){ + this.lessonEnd = end; + this.course = course; + this.lessonStart = start; + this.color = color; + this.local = local; + } + + public Lesson() { + } + + public int getLessonID(){ + return lessonID; + } + + public void setCourse(Course course) { + this.course = course; + } + + public Course getCourse(){ + return course; + } + + public String getLessonStart(){ + return lessonStart; + } + + public String getLessonEnd() { + return lessonEnd; + } + + public String getColor(){ + return color; + } + + public String getLocal() { + return local; + } + + public void setLessonStart(String start){ + this.lessonStart = start; + } + + public void setLessonEnd(String lessonEnd) { + this.lessonEnd = lessonEnd; + } + + public void setColor(String color){ + this.color = color; + } + + public void setLocal(String local){ + this.local = local; + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Schedule.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Schedule.java new file mode 100644 index 0000000..993c38c --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Schedule.java @@ -0,0 +1,33 @@ + +package ovh.herisson.Clyde.Tables; + +import jakarta.persistence.*; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; + +@Entity +public class Schedule { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int scheduleID; + + @OneToOne + @JoinColumn(name = "Curriculum") + private Curriculum curriculum; + + public Schedule(Curriculum curriculum){ + this.curriculum = curriculum; + } + + public Schedule() {} + + + public int getScheduleID(){ + return scheduleID; +} + + public Curriculum getCurriculum(){ + return curriculum; +} + +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/ScheduleLesson.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/ScheduleLesson.java new file mode 100644 index 0000000..3b7b6a4 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/ScheduleLesson.java @@ -0,0 +1,53 @@ +package ovh.herisson.Clyde.Tables; + +import jakarta.persistence.*; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; + + + +@Entity +public class ScheduleLesson{ + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "Schedule") + private Schedule schedule; + + + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "Lesson") + private Lesson lesson; + + public ScheduleLesson(Schedule schedule,Lesson lesson){ + this.schedule = schedule; + this.lesson = lesson; + } + + public ScheduleLesson() { + } + + public int getID(){ + return id; + } + + public Lesson getLesson(){ + return lesson; + } + + public Schedule getSchedule(){ + return schedule; + } + + public void setLesson(Lesson lesson){ + this.lesson = lesson; + } + + public void setSchedule(Schedule schedule){ + this.schedule = schedule; + } + + +} diff --git a/frontend/src/Apps/Schedule.vue b/frontend/src/Apps/Schedule.vue index 0c3f640..0722d91 100644 --- a/frontend/src/Apps/Schedule.vue +++ b/frontend/src/Apps/Schedule.vue @@ -1,7 +1,12 @@ diff --git a/frontend/src/rest/lessonSchedule.js b/frontend/src/rest/lessonSchedule.js index ec6cb56..154b0df 100644 --- a/frontend/src/rest/lessonSchedule.js +++ b/frontend/src/rest/lessonSchedule.js @@ -39,13 +39,14 @@ export async function getLesson(id){ * - teacher * - Assistants */ -export async function getLessons(role){ - if(role==="Teacher"){ - return restGet("/lessons/owned") - } +export async function getLessons(){ return restGet("/lessons") } +export async function getOwnedLessons(){ + return restGet("/lessons/owned") + +} /** * Change the options of a course diff --git a/frontend/src/rest/scheduleRest.js b/frontend/src/rest/scheduleRest.js index c3783d0..d7abca8 100644 --- a/frontend/src/rest/scheduleRest.js +++ b/frontend/src/rest/scheduleRest.js @@ -11,3 +11,7 @@ export async function getOwnSchedule(){ export async function createSchedule(curriculum) { return restPost('/schedule',{curriculum : curriculum}) } + +export async function getCurriculumSchedule(id){ + return restGet('/schedule/curriculum/' + id) +} diff --git a/frontend/src/scheduleFunctions.js b/frontend/src/scheduleFunctions.js index 02c9539..0db5e75 100644 --- a/frontend/src/scheduleFunctions.js +++ b/frontend/src/scheduleFunctions.js @@ -67,11 +67,12 @@ } export function monthFromList(list,month){ + console.log(month) + console.log(list) const beginning = getFirstDay(month); const matrix = new Array(lastDateOfMonth(month)) for (let i = 0; i < matrix.length; i++) { matrix[i] = []; - } for(let key in list){ const temp = list[key]; From adaa828810517b12f4e9ec8fdcf354c11b151af1 Mon Sep 17 00:00:00 2001 From: Wawilski Date: Thu, 11 Apr 2024 15:47:56 +0200 Subject: [PATCH 08/15] Filter and lists --- .../Clyde/EndPoints/MockController.java | 10 +- .../Clyde/EndPoints/UserController.java | 3 - .../Clyde/Services/LessonService.java | 4 + .../Clyde/Services/ProtectionService.java | 1 + .../ovh/herisson/Clyde/Tables/Lesson.java | 14 +- frontend/src/Apps/Schedule.vue | 273 ++++++++++++++++-- 6 files changed, 273 insertions(+), 32 deletions(-) diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java index 779a1f0..835ddfe 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java @@ -107,11 +107,11 @@ public class MockController { //Schedule part - Lesson lesson_0_progra1 = new Lesson(progra1, "Mon Apr 01 2024 08:15", "Mon Apr 01 2024 10:15","rgb(0,50,100)","A0B2"); - Lesson lesson_0_chemistry1 = new Lesson(chemistry1, "Wed Mar 27 2024 08:15", "Wed Mar 27 2024 09:15","rgb(100,50,0)","A0B2"); - Lesson lesson_0_psycho1 = new Lesson(psycho1, "Sun Mar 24 2024 10:30 ","Sun Mar 24 2024 12:30 ","rgb(100,50,100)", "A0B2"); - Lesson lesson_1_progra1 = new Lesson(progra1, "Mon Apr 02 2024 13:30", "Mon Apr 02 2024 15:30","rgb(0,50,100)","A0B2"); - Lesson lesson_0_commun = new Lesson(commun, "Mon Apr 01 2024 10:30", "Mon Apr 01 2024 12:30","rgb(0,50,100)","A0B2"); + Lesson lesson_0_progra1 = new Lesson(progra1, "Mon Apr 01 2024 08:15", "Mon Apr 01 2024 10:15","rgb(0,50,100)","A0B2","Course"); + Lesson lesson_0_chemistry1 = new Lesson(chemistry1, "Wed Mar 27 2024 08:15", "Wed Mar 27 2024 09:15","rgb(100,50,0)","A0B2","TP"); + Lesson lesson_0_psycho1 = new Lesson(psycho1, "Sun Mar 24 2024 10:30 ","Sun Mar 24 2024 12:30 ","rgb(100,50,100)", "A0B2","TD"); + Lesson lesson_1_progra1 = new Lesson(progra1, "Mon Apr 02 2024 13:30", "Mon Apr 02 2024 15:30","rgb(0,50,100)","A0B2","TP"); + Lesson lesson_0_commun = new Lesson(commun, "Mon Apr 01 2024 10:30", "Mon Apr 01 2024 12:30","rgb(0,50,100)","A0B2","Course"); Schedule infoBab1Schedule = new Schedule(infoBab1); Schedule chemistryBab1Schedule = new Schedule(chemistryBab1); diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/UserController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/UserController.java index 20ca9ee..2835b60 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/UserController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/UserController.java @@ -103,9 +103,6 @@ public class UserController { @GetMapping("/teachers") public ResponseEntity>> getAllTeachers(@RequestHeader("Authorization") String token){ - if (authServ.getUserFromToken(token) == null) - return new UnauthorizedResponse<>(null); - Iterable teachers = userService.getAllTeachers(); return new ResponseEntity<>(ProtectionService.usersWithoutPasswords(teachers), HttpStatus.OK); diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/LessonService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/LessonService.java index 0eceb43..8637a45 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/LessonService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/LessonService.java @@ -57,6 +57,10 @@ public class LessonService { break; case "local": target.setLocal((String) entry.getValue()); + break; + case "lessonType": + target.setLessonType((String) entry.getValue()); + break; } } lessonRepo.save(target); diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/ProtectionService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/ProtectionService.java index aca1f0a..6c7f06f 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/ProtectionService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/ProtectionService.java @@ -82,6 +82,7 @@ public class ProtectionService { toReturn.put("course",courseWithoutPassword(lesson.getCourse())); toReturn.put("local",lesson.getLocal()); toReturn.put("color", lesson.getColor()); + toReturn.put("lessonType",lesson.getLessonType()); return toReturn; } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Lesson.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Lesson.java index 00a693c..8370324 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Lesson.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Lesson.java @@ -16,16 +16,20 @@ public class Lesson { private String lessonStart; private String lessonEnd; + private String color; + + private String lessonType; private String local; - public Lesson(Course course,String start, String end ,String color,String local){ + public Lesson(Course course,String start, String end ,String color,String local,String lessonType){ this.lessonEnd = end; this.course = course; this.lessonStart = start; this.color = color; this.local = local; + this.lessonType = lessonType; } public Lesson() { @@ -59,6 +63,10 @@ public class Lesson { return local; } + public String getLessonType(){ + return lessonType; + } + public void setLessonStart(String start){ this.lessonStart = start; } @@ -74,4 +82,8 @@ public class Lesson { public void setLocal(String local){ this.local = local; } + + public void setLessonType(String lessonType){ + this.lessonType = lessonType; + } } diff --git a/frontend/src/Apps/Schedule.vue b/frontend/src/Apps/Schedule.vue index 6b788e8..8d14c15 100644 --- a/frontend/src/Apps/Schedule.vue +++ b/frontend/src/Apps/Schedule.vue @@ -3,11 +3,13 @@ import {getDifferenceTime,lastDateOfMonth,formatDate,getFirstDay,sortByDate,matrixFromList,sundayToTheEnd,getMarginTop,getHoursMinutes, monthFromList} from '../scheduleFunctions.js' import {getAllSchedule, getOwnSchedule, getCurriculumSchedule} from "@/rest/scheduleRest.js"; import {getLessons, getOwnedLessons } from "@/rest/lessonSchedule.js" - import {isLogged, getSelf} from "@/rest/Users.js" - import {getAllCurriculums} from "@/rest/curriculum.js" - + import {isLogged, getSelf,getTeachers} from "@/rest/Users.js" + import {getAllCurriculums, getcurriculum} from "@/rest/curriculum.js" + + const trueSchedule = ref() const log = await isLogged(); const schedule = ref(); + const curriculum = ref(); const shift = ref(getFirstDay(new Date()).getDay()); let value = 1; const len = ref(lastDateOfMonth(new Date())); @@ -18,8 +20,8 @@ const allSchedules = await getAllSchedule(); let counter = 0; const ownSchedule = ref(); - console.log(allSchedules) - + const filter = ref("null"); + const subFilter = ref("null"); let user; if(log){ @@ -34,8 +36,9 @@ } if(user.role == "Student"){ - const trueSchedule = await getOwnSchedule(); - ownSchedule.value = trueSchedule.lessons;} + trueSchedule.value = await getOwnSchedule(); + ownSchedule.value = trueSchedule.value.lessons; + curriculum.value = trueSchedule.value.curriculum;} schedule.value = ownSchedule.value; scheduleByWeek.value = sundayToTheEnd(matrixFromList(schedule.value,mondayOfWeek.value)); @@ -46,8 +49,16 @@ - const display =ref("Month") - + const display =ref("Week"); + const format = ref("Grid"); + + const filters = ["Type","Teacher","Course"]; + const types = ["TP","TD","Course","Exam"]; + const teachers = await getTeachers() ; + const courses = ref(); + if(curriculum.value != null){ + courses.value = curriculum.value.courses; + } const days = ["Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi","Dimanche"]; const months = ["Janvier","Fevrier","Mars","Avril",'Mai',"Juin","Juillet","Aout","Septembre","Octobre","Novembre","Decembre"] const firstDayOfMonth = ref(getFirstDay(new Date())) @@ -91,12 +102,97 @@ } + function dateOfMonth(i){ - async function changeSchedule(){ + return new Date(currentDate.value.getFullYear(),currentDate.value.getMonth(),i); + } + + function sortSchedule(){ + schedule.value =trueSchedule.value.lessons; + console.log(filter.value) + if(filter.value =="Teacher"){ + schedule.value = sortByTeacher(schedule.value,subFilter.value); scheduleByWeek.value = sundayToTheEnd(matrixFromList(schedule.value,mondayOfWeek.value)); month.value = monthFromList(schedule.value,currentDate.value.getMonth()); value = 1; counter=0; + + + } + else if(filter.value =="Type"){ + schedule.value = sortByType(schedule.value,subFilter.value); + scheduleByWeek.value = sundayToTheEnd(matrixFromList(schedule.value,mondayOfWeek.value)); + month.value = monthFromList(schedule.value,currentDate.value.getMonth()); + value = 1; + counter=0; + + + + } + else if(filter.value =="Course"){ + schedule.value = sortByCourse(schedule.value,subFilter.value); + scheduleByWeek.value = sundayToTheEnd(matrixFromList(schedule.value,mondayOfWeek.value)); + month.value = monthFromList(schedule.value,currentDate.value.getMonth()); + value = 1; + counter=0; + } + } + + function sortByType(lessons,type){ + if(type == null){ + return lessons; + } + const matrix = []; + for (let element in lessons){ + console.log(lessons[element].lessonType) + if(lessons[element].lessonType == type){ + matrix.push(lessons[element]) + } + } + return matrix + } + + + + + function sortByCourse(lessons,course){ + if(course == null){ + return lessons; + } + const matrix = []; + for (let element in lessons){ + if(lessons[element].course.title == course.title){ + matrix.push(lessons[element]) + } + } + return matrix + } + + function sortByTeacher(lessons, teacher){ + if(teacher == null){ + return lessons; + } + const matrix = []; + for (let element in lessons){ + if(lessons[element].course.owner.regNo == teacher.regNo){ + matrix.push(lessons[element]) + } + } + return matrix + } + + + async function changeSchedule(){ + schedule.value =trueSchedule.value.lessons; + curriculum.value = trueSchedule.value.curriculum; + + scheduleByWeek.value = sundayToTheEnd(matrixFromList(schedule.value,mondayOfWeek.value)); + month.value = monthFromList(schedule.value,currentDate.value.getMonth()); + value = 1; + counter=0; + courses.value = (await getcurriculum(curriculum.value.curriculumId)).courses; + filter.value = "null"; + subFilter.value = "null" } function changeWeek(i){ @@ -145,7 +241,7 @@