From adaa828810517b12f4e9ec8fdcf354c11b151af1 Mon Sep 17 00:00:00 2001 From: Wawilski Date: Thu, 11 Apr 2024 15:47:56 +0200 Subject: [PATCH] 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 @@