link backend Post Patch Delete Lesson
This commit is contained in:
		| @ -76,7 +76,7 @@ public class CourseController { | |||||||
|     { |     { | ||||||
|         if (authServ.isNotIn(new Role[]{Role.Secretary,Role.Admin},token)) |         if (authServ.isNotIn(new Role[]{Role.Secretary,Role.Admin},token)) | ||||||
|             return new UnauthorizedResponse<>(null); |             return new UnauthorizedResponse<>(null); | ||||||
|  |         System.out.println(course.getOwner().getRegNo()); | ||||||
|         Course createdCourse = courseServ.save(course); |         Course createdCourse = courseServ.save(course); | ||||||
|         if (createdCourse == null) |         if (createdCourse == null) | ||||||
|             return new ResponseEntity<>(null,HttpStatus.BAD_REQUEST); |             return new ResponseEntity<>(null,HttpStatus.BAD_REQUEST); | ||||||
|  | |||||||
| @ -52,11 +52,14 @@ public class LessonController { | |||||||
|  |  | ||||||
|  |  | ||||||
|     @PostMapping("/lesson") |     @PostMapping("/lesson") | ||||||
|     public ResponseEntity<HashMap<String, Object>> postLesson(@RequestHeader("Authorization")String token, |     public ResponseEntity<HashMap<String, Object>> postLesson(@RequestHeader("Authorization") String token, | ||||||
|                                                               @RequestBody Lesson lesson){ |                                                               @RequestBody Map<String, Object> lessonInfos){ | ||||||
|         if(authServ.isNotIn(new Role[]{Role.Secretary,Role.Admin},token)) |         if(authServ.isNotIn(new Role[]{Role.Secretary,Role.Admin},token)) | ||||||
|             return new UnauthorizedResponse<>(null); |             return new UnauthorizedResponse<>(null); | ||||||
|         Lesson createdLesson = lessonServ.save(lesson); |  | ||||||
|  |  | ||||||
|  |           Lesson lesson = lessonServ.createLesson(lessonInfos); | ||||||
|  |           Lesson createdLesson = lessonServ.save(lesson); | ||||||
|         if(createdLesson==null) |         if(createdLesson==null) | ||||||
|             return new ResponseEntity<>(null,HttpStatus.BAD_REQUEST); |             return new ResponseEntity<>(null,HttpStatus.BAD_REQUEST); | ||||||
|         return new ResponseEntity<>(ProtectionService.lessonWithoutPassword(createdLesson), HttpStatus.OK); |         return new ResponseEntity<>(ProtectionService.lessonWithoutPassword(createdLesson), HttpStatus.OK); | ||||||
| @ -68,8 +71,22 @@ public class LessonController { | |||||||
|                                               @PathVariable long id){ |                                               @PathVariable long id){ | ||||||
|         if(authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary},token)) |         if(authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary},token)) | ||||||
|             return new UnauthorizedResponse<>(null); |             return new UnauthorizedResponse<>(null); | ||||||
|         if(!lessonServ.modifyData(id, updates, authServ.getUserFromToken(token).getRole())) |         if(!lessonServ.modifyData(id, updates)){ | ||||||
|             return new ResponseEntity<>(HttpStatus.BAD_REQUEST); |             return new ResponseEntity<>(HttpStatus.BAD_REQUEST); | ||||||
|  |           } | ||||||
|         return new ResponseEntity<>(HttpStatus.OK); |         return new ResponseEntity<>(HttpStatus.OK); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @DeleteMapping("lesson/{id}") | ||||||
|  |     public ResponseEntity<String> deleteLesson(@RequestHeader("Authorization") String token, | ||||||
|  |                                                @PathVariable Long id){ | ||||||
|  |         if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary},token)) | ||||||
|  |             return new UnauthorizedResponse<>(null); | ||||||
|  |         Lesson toDelete = lessonServ.findById(id); | ||||||
|  |         if(toDelete == null) | ||||||
|  |             return new ResponseEntity<>(HttpStatus.BAD_REQUEST); | ||||||
|  |         lessonServ.delete(toDelete); | ||||||
|  |         return new ResponseEntity<>(HttpStatus.OK); | ||||||
|  |  | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -107,7 +107,7 @@ public class MockController { | |||||||
|  |  | ||||||
|         //Schedule part |         //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","Course"); |         Lesson lesson_0_progra1 = new Lesson(progra1, "Mon Apr 22 2024 08:15", "Mon Apr 22 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_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_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_1_progra1 = new Lesson(progra1, "Mon Apr 02 2024 13:30", "Mon Apr 02 2024 15:30","rgb(0,50,100)","A0B2","TP"); | ||||||
|  | |||||||
| @ -1,5 +1,6 @@ | |||||||
| package ovh.herisson.Clyde.EndPoints; | package ovh.herisson.Clyde.EndPoints; | ||||||
|  |  | ||||||
|  | import ch.qos.logback.core.net.SyslogOutputStream; | ||||||
| import org.springframework.http.HttpStatus; | import org.springframework.http.HttpStatus; | ||||||
| import org.springframework.http.ResponseEntity; | import org.springframework.http.ResponseEntity; | ||||||
| import org.springframework.web.bind.annotation.*; | import org.springframework.web.bind.annotation.*; | ||||||
| @ -9,10 +10,7 @@ import ovh.herisson.Clyde.Services.ScheduleLessonService; | |||||||
| import ovh.herisson.Clyde.Services.ScheduleService; | import ovh.herisson.Clyde.Services.ScheduleService; | ||||||
| import ovh.herisson.Clyde.Services.UserCurriculumService; | import ovh.herisson.Clyde.Services.UserCurriculumService; | ||||||
| import ovh.herisson.Clyde.Services.CurriculumService; | import ovh.herisson.Clyde.Services.CurriculumService; | ||||||
| import ovh.herisson.Clyde.Tables.Curriculum; | import ovh.herisson.Clyde.Tables.*; | ||||||
| import ovh.herisson.Clyde.Tables.Role; |  | ||||||
| import ovh.herisson.Clyde.Tables.Schedule; |  | ||||||
| import ovh.herisson.Clyde.Tables.ScheduleLesson; |  | ||||||
| import ovh.herisson.Clyde.Services.LessonService; | import ovh.herisson.Clyde.Services.LessonService; | ||||||
|  |  | ||||||
| import java.util.Map; | import java.util.Map; | ||||||
| @ -94,4 +92,16 @@ public class ScheduleController { | |||||||
|  |  | ||||||
|         return new ResponseEntity<>(HttpStatus.OK); |         return new ResponseEntity<>(HttpStatus.OK); | ||||||
|     } |     } | ||||||
|  |     @DeleteMapping("/schedule/lesson/{id}") | ||||||
|  |     public ResponseEntity<String> deleteLessonFromSchedule(@RequestHeader("Authorization") String token, | ||||||
|  |                                                           @RequestBody Long lessonId, | ||||||
|  |                                                           @PathVariable Long id) | ||||||
|  |     { | ||||||
|  |         if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary},token)) | ||||||
|  |             return new UnauthorizedResponse<>(null); | ||||||
|  |         if (!scheduleLessonServ.delete(lessonId)) | ||||||
|  |             return new ResponseEntity<>(HttpStatus.BAD_REQUEST); | ||||||
|  |  | ||||||
|  |         return new ResponseEntity<>(HttpStatus.OK); | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,5 +1,7 @@ | |||||||
| package ovh.herisson.Clyde.Repositories; | package ovh.herisson.Clyde.Repositories; | ||||||
|  |  | ||||||
|  | import jakarta.transaction.Transactional; | ||||||
|  | import org.springframework.data.jpa.repository.Modifying; | ||||||
| import org.springframework.data.jpa.repository.Query; | import org.springframework.data.jpa.repository.Query; | ||||||
| import org.springframework.data.repository.CrudRepository; | import org.springframework.data.repository.CrudRepository; | ||||||
| import ovh.herisson.Clyde.Tables.Curriculum; | import ovh.herisson.Clyde.Tables.Curriculum; | ||||||
| @ -20,4 +22,10 @@ public interface ScheduleLessonRepository extends CrudRepository<ScheduleLesson, | |||||||
|  |  | ||||||
|     @Query("select distinct sl.lesson from ScheduleLesson sl where sl.schedule = ?1") |     @Query("select distinct sl.lesson from ScheduleLesson sl where sl.schedule = ?1") | ||||||
|     Iterable<Lesson> findLessonBySchedule(Schedule schedule); |     Iterable<Lesson> findLessonBySchedule(Schedule schedule); | ||||||
|  |  | ||||||
|  |     @Modifying | ||||||
|  |     @Transactional | ||||||
|  |     @Query("delete from ScheduleLesson sl where sl.lesson =?1") | ||||||
|  |     void delete(Lesson lesson); | ||||||
|  |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -8,6 +8,7 @@ import ovh.herisson.Clyde.Tables.Lesson; | |||||||
| import ovh.herisson.Clyde.Tables.Role; | import ovh.herisson.Clyde.Tables.Role; | ||||||
| import ovh.herisson.Clyde.Tables.User; | import ovh.herisson.Clyde.Tables.User; | ||||||
|  |  | ||||||
|  | import java.lang.reflect.GenericSignatureFormatError; | ||||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||||
| import java.util.Map; | import java.util.Map; | ||||||
|  |  | ||||||
| @ -38,15 +39,11 @@ public class LessonService { | |||||||
|         return toReturn; |         return toReturn; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean modifyData(long id, Map<String ,Object> updates, Role role){ |     public Lesson createLesson(Map<String,Object> lessonInfos) { | ||||||
|         Lesson target = lessonRepo.findById(id); |         Lesson target = new Lesson(); | ||||||
|  |  | ||||||
|         if(target == null || role != Role.Secretary) |         for (Map.Entry<String, Object> entry : lessonInfos.entrySet()) { | ||||||
|             return false; |             switch (entry.getKey()) { | ||||||
|  |  | ||||||
|  |  | ||||||
|         for (Map.Entry<String , Object> entry: updates.entrySet()){ |  | ||||||
|             switch (entry.getKey()){ |  | ||||||
|                 case "lessonStart": |                 case "lessonStart": | ||||||
|                     target.setLessonStart((String) entry.getValue()); |                     target.setLessonStart((String) entry.getValue()); | ||||||
|                     break; |                     break; | ||||||
| @ -61,6 +58,40 @@ public class LessonService { | |||||||
|                 case "lessonType": |                 case "lessonType": | ||||||
|                     target.setLessonType((String) entry.getValue()); |                     target.setLessonType((String) entry.getValue()); | ||||||
|                     break; |                     break; | ||||||
|  |                 case "courseId": | ||||||
|  |                     target.setCourse(courseRepo.findById((int) entry.getValue())); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |         } | ||||||
|  |         return target; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public boolean modifyData(long id, Map<String ,Object> updates){ | ||||||
|  |         Lesson target = lessonRepo.findById(id); | ||||||
|  |         System.out.println(target); | ||||||
|  |  | ||||||
|  |         if(target == null) | ||||||
|  |             return false; | ||||||
|  |  | ||||||
|  |  | ||||||
|  |         System.out.println("test"); | ||||||
|  |         System.out.println(updates.entrySet()); | ||||||
|  |  | ||||||
|  |         for (Map.Entry<String , Object> entry: updates.entrySet()){ | ||||||
|  |             System.out.println(entry); | ||||||
|  |             switch (entry.getKey()){ | ||||||
|  |                 case "lessonStart": | ||||||
|  |                     target.setLessonStart((String) entry.getValue()); | ||||||
|  |                     break; | ||||||
|  |                 case "lessonEnd": | ||||||
|  |                     target.setLessonEnd((String) entry.getValue()); | ||||||
|  |                     break;             | ||||||
|  |                 case "local": | ||||||
|  |                     target.setLocal((String) entry.getValue()); | ||||||
|  |                     break; | ||||||
|  |                 case "lessonType": | ||||||
|  |                     target.setLessonType((String) entry.getValue()); | ||||||
|  |                     break; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         lessonRepo.save(target); |         lessonRepo.save(target); | ||||||
|  | |||||||
| @ -30,6 +30,14 @@ public class ScheduleLessonService { | |||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public boolean delete(long lessonId){ | ||||||
|  |         if(lessonId == 0) | ||||||
|  |             return false; | ||||||
|  |         scheduleLessonRepo.delete(lessonRepo.findById(lessonId)); | ||||||
|  |         return true; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|     public Schedule getScheduleByCurriculum(Curriculum curriculum){ |     public Schedule getScheduleByCurriculum(Curriculum curriculum){ | ||||||
|         return scheduleLessonRepo.findScheduleByCurriculum(curriculum); |         return scheduleLessonRepo.findScheduleByCurriculum(curriculum); | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -8,7 +8,7 @@ import org.hibernate.annotations.OnDeleteAction; | |||||||
| public class Course { | public class Course { | ||||||
|     @Id |     @Id | ||||||
|     @GeneratedValue(strategy = GenerationType.AUTO) |     @GeneratedValue(strategy = GenerationType.AUTO) | ||||||
|     private int courseID; |     private int courseId; | ||||||
|     private int credits; |     private int credits; | ||||||
|     private String title; |     private String title; | ||||||
|  |  | ||||||
| @ -26,8 +26,11 @@ public class Course { | |||||||
|     public Course() {} |     public Course() {} | ||||||
|  |  | ||||||
|     public int getCourseID() { |     public int getCourseID() { | ||||||
|         return courseID; |         return courseId; | ||||||
|     } |     } | ||||||
|  |     public void setCourseID(int courseId){ | ||||||
|  |       this.courseId = courseId; | ||||||
|  |   } | ||||||
|  |  | ||||||
|     public int getCredits() { |     public int getCredits() { | ||||||
|         return credits; |         return credits; | ||||||
|  | |||||||
| @ -1,6 +1,8 @@ | |||||||
| package ovh.herisson.Clyde.Tables; | package ovh.herisson.Clyde.Tables; | ||||||
|  |  | ||||||
| import jakarta.persistence.*; | import jakarta.persistence.*; | ||||||
|  | import org.hibernate.annotations.OnDelete; | ||||||
|  | import org.hibernate.annotations.OnDeleteAction; | ||||||
|  |  | ||||||
|  |  | ||||||
| @Entity | @Entity | ||||||
| @ -10,7 +12,8 @@ public class Lesson { | |||||||
|   private int lessonID; |   private int lessonID; | ||||||
|  |  | ||||||
|   @ManyToOne(fetch = FetchType.EAGER) |   @ManyToOne(fetch = FetchType.EAGER) | ||||||
|   @JoinColumn(name= "Course") |   @OnDelete(action = OnDeleteAction.SET_NULL) | ||||||
|  |   @JoinColumn(name = "Course") | ||||||
|   private Course course; |   private Course course; | ||||||
|  |  | ||||||
|   private String lessonStart; |   private String lessonStart; | ||||||
|  | |||||||
| @ -13,6 +13,7 @@ public class Schedule { | |||||||
|  |  | ||||||
|   @OneToOne |   @OneToOne | ||||||
|   @JoinColumn(name = "Curriculum") |   @JoinColumn(name = "Curriculum") | ||||||
|  |   @OnDelete(action = OnDeleteAction.SET_NULL) | ||||||
|   private Curriculum curriculum; |   private Curriculum curriculum; | ||||||
|  |  | ||||||
|   public Schedule(Curriculum curriculum){ |   public Schedule(Curriculum curriculum){ | ||||||
|  | |||||||
| @ -14,10 +14,12 @@ public class ScheduleLesson{ | |||||||
|    |    | ||||||
|   @ManyToOne(fetch = FetchType.EAGER) |   @ManyToOne(fetch = FetchType.EAGER) | ||||||
|   @JoinColumn(name = "Schedule") |   @JoinColumn(name = "Schedule") | ||||||
|  |   @OnDelete(action = OnDeleteAction.SET_NULL) | ||||||
|   private Schedule schedule; |   private Schedule schedule; | ||||||
|  |  | ||||||
|  |  | ||||||
|   @ManyToOne(fetch = FetchType.EAGER) |   @ManyToOne(fetch = FetchType.EAGER) | ||||||
|  |   @OnDelete(action = OnDeleteAction.SET_NULL) | ||||||
|   @JoinColumn(name = "Lesson") |   @JoinColumn(name = "Lesson") | ||||||
|   private Lesson lesson; |   private Lesson lesson; | ||||||
|  |  | ||||||
|  | |||||||
| @ -155,11 +155,11 @@ | |||||||
|       </div> |       </div> | ||||||
|       <div class="containerElement"v-else> |       <div class="containerElement"v-else> | ||||||
|         <input style="max-width:200px;" class="name" v-model="toModify.title"> |         <input style="max-width:200px;" class="name" v-model="toModify.title"> | ||||||
|         <select v-if="self.role === 'Secretary'" style="max-width:200px;" class="teacher" v-model="toModify.owner"> |         <select v-if="self.role != 'Secretary'" style="max-width:200px;" class="teacher" v-model="toModify.owner"> | ||||||
|           <option v-for="(item,index) in profList" :value='item'>{{item.lastName}}</option> |           <option v-for="(item,index) in profList" :value='item'>{{item.lastName}}</option> | ||||||
|         </select> |         </select> | ||||||
|         <div v-else class="teacher">{{item.owner.lastName}}</div>  |         <div v-else class="teacher">{{item.owner.lastName}}</div>  | ||||||
|         <input v-if="self.role==='Secretary'"style="max-width:100px;"class="credits" v-model="toModify.credits">   |         <input v-if="self.role !='Secretary'"style="max-width:100px;"class="credits" v-model="toModify.credits">   | ||||||
|         <div v-else class="credits">{{i18n("Credits")}}:{{item.credits}}</div>   |         <div v-else class="credits">{{i18n("Credits")}}:{{item.credits}}</div>   | ||||||
|       </div> |       </div> | ||||||
|     </div> |     </div> | ||||||
|  | |||||||
| @ -1,18 +1,17 @@ | |||||||
| <script setup> | <script setup> | ||||||
| import { ref } from 'vue' | import { ref } from 'vue' | ||||||
| import i18n from '@/i18n.js' | import i18n from '@/i18n.js' | ||||||
|   import {getDifferenceTime,lastDateOfMonth,formatDate,getFirstDay,sortByDate,matrixFromList,sundayToTheEnd,getMarginTop,getHoursMinutes, monthFromList} from '../scheduleFunctions.js' |   import {formatDate,getHoursMinutes} from '../scheduleFunctions.js' | ||||||
|   import {getAllSchedule, getOwnSchedule, getCurriculumSchedule,addLessonToSchedule} from "@/rest/scheduleRest.js"; |   import {getAllSchedule, deleteLessonFromSchedule ,getSchedule, getCurriculumSchedule,addLessonToSchedule} from "@/rest/scheduleRest.js"; | ||||||
|   import {getLessons, getOwnedLessons, createLesson } from "@/rest/lessonSchedule.js" |   import {getLessons , createLesson, alterLesson , deleteLesson} from "@/rest/lessonSchedule.js" | ||||||
|   import {isLogged, getSelf,getTeachers} from "@/rest/Users.js" |   import {getTeachers} from "@/rest/Users.js" | ||||||
|   import {getAllCurriculums, getcurriculum} from "@/rest/curriculum.js" |   import { getcurriculum} from "@/rest/curriculum.js" | ||||||
|   import {getCourse} from "@/rest/courses.js" |  | ||||||
|  |  | ||||||
|   const trueSchedule = ref() |   const trueSchedule = ref() | ||||||
|   const schedule = ref(); |   const schedule = ref(); | ||||||
|   const lessonFinder = ref(); |   const lessonFinder = ref(); | ||||||
|   const curriculum = ref(); |   const curriculum = ref(); | ||||||
|   const allSchedules = await getAllSchedule(); |   const allSchedules = ref(await getAllSchedule()); | ||||||
|   const filter = ref("null"); |   const filter = ref("null"); | ||||||
|   const subFilter = ref("null"); |   const subFilter = ref("null"); | ||||||
|   const lesson = ref(); |   const lesson = ref(); | ||||||
| @ -28,7 +27,11 @@ import i18n from '@/i18n.js' | |||||||
| const colors = {"TP":"rgb(36,175,255)","TD":"rgb(255,36,175)","Exam":"rgb(175,255,36)","Course":"rgb(255,36,175)"} | const colors = {"TP":"rgb(36,175,255)","TD":"rgb(255,36,175)","Exam":"rgb(175,255,36)","Course":"rgb(255,36,175)"} | ||||||
| const currentDate = new Date(); | const currentDate = new Date(); | ||||||
|  |  | ||||||
|  | const editElementID = ref() | ||||||
|  |  | ||||||
|  | function editItem(id){ | ||||||
|  |   editElementID.value = id; | ||||||
|  | } | ||||||
|  |  | ||||||
| function invertedFormatDate(date) { | function invertedFormatDate(date) { | ||||||
|     var d = new Date(date), |     var d = new Date(date), | ||||||
| @ -47,7 +50,6 @@ function invertedFormatDate(date) { | |||||||
| const maxDate = ref(invertedFormatDate(new Date([currentDate.getMonth()<7 ? currentDate.getFullYear() : (currentDate.getFullYear())+1],7,31))); | const maxDate = ref(invertedFormatDate(new Date([currentDate.getMonth()<7 ? currentDate.getFullYear() : (currentDate.getFullYear())+1],7,31))); | ||||||
|  |  | ||||||
| const minDate = ref(invertedFormatDate((new Date()).setDate(currentDate.getDate()+1))) | const minDate = ref(invertedFormatDate((new Date()).setDate(currentDate.getDate()+1))) | ||||||
| console.log(minDate.value) |  | ||||||
|  |  | ||||||
| function createLessonEvent(date,hour){ | function createLessonEvent(date,hour){ | ||||||
|     const str = date.concat(' ',hour); |     const str = date.concat(' ',hour); | ||||||
| @ -66,7 +68,41 @@ function createLessonEvent(date,hour){ | |||||||
|     "color": null, |     "color": null, | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   const lessonCreator = { | ||||||
|  |     "courseId" : null, | ||||||
|  |     "lessonStart":null, | ||||||
|  |     "lessonEnd":null, | ||||||
|  |     "lessonType":null, | ||||||
|  |     "local":null, | ||||||
|  |     "color":null, | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   const patternModify = { | ||||||
|  |     "day": null, | ||||||
|  |     "lessonStart": null, | ||||||
|  |     "lesssonEnd": null, | ||||||
|  |     "local":null, | ||||||
|  |     "lessonType":null, | ||||||
|  |   } | ||||||
|  |    | ||||||
|  | const toModify = ref(Object.assign({}, pattern)); | ||||||
|   const lessonBuffer = ref(Object.assign({}, pattern)); |   const lessonBuffer = ref(Object.assign({}, pattern)); | ||||||
|  |   const lessonCreatorBuffer = ref(Object.assign({},lessonCreator)); | ||||||
|  |  | ||||||
|  |  | ||||||
|  |   function setModify(lesson){ | ||||||
|  |     toModify.value.day = invertedFormatDate(new Date(lesson.lessonStart)); | ||||||
|  |     toModify.value.lessonStart = getHoursMinutes(lesson.lessonStart); | ||||||
|  |     toModify.value.lessonEnd = getHoursMinutes(lesson.lessonEnd); | ||||||
|  |     toModify.value.local = lesson.local | ||||||
|  |     toModify.value.lessonType = lesson.lessonType | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   function inFuture(lesson){ | ||||||
|  |     let toCompare = new Date(lesson.lessonStart); | ||||||
|  |     let current = new Date(); | ||||||
|  |     return (current < toCompare) | ||||||
|  | } | ||||||
|  |  | ||||||
| async function setCourses(){ | async function setCourses(){ | ||||||
|   courses.value = (await getcurriculum(curriculum.value.curriculumId)).courses |   courses.value = (await getcurriculum(curriculum.value.curriculumId)).courses | ||||||
| @ -136,12 +172,7 @@ async function setCourses(){ | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   function findCreatedLesson(){ |   function findCreatedLesson(){ | ||||||
|   console.log(lessonFinder.value); |  | ||||||
|   for(let element in lessonFinder.value){ |   for(let element in lessonFinder.value){ | ||||||
|     console.log(lessonFinder.value[element].course.courseId, lessonFinder.value[element].local); |  | ||||||
|      |  | ||||||
|     console.log(lessonBuffer.value.course.courseId, lessonBuffer.value.local) |  | ||||||
|  |  | ||||||
|       if((lessonFinder.value[element].course.courseId ==lessonBuffer.value.course.courseId) && (lessonFinder.value[element].local == lessonBuffer.value.local) ){ |       if((lessonFinder.value[element].course.courseId ==lessonBuffer.value.course.courseId) && (lessonFinder.value[element].local == lessonBuffer.value.local) ){ | ||||||
|         return lessonFinder.value[element]; |         return lessonFinder.value[element]; | ||||||
|      } |      } | ||||||
| @ -160,35 +191,86 @@ async function setCourses(){ | |||||||
|         } |         } | ||||||
|         } |         } | ||||||
|       if(!isnull){ |       if(!isnull){ | ||||||
|         let course = await getCourse(lessonBuffer.value.course.courseId); |  | ||||||
|         console.log(course) |  | ||||||
|         let start = createLessonEvent(lessonBuffer.value.day,lessonBuffer.value.lessonStart) |         let start = createLessonEvent(lessonBuffer.value.day,lessonBuffer.value.lessonStart) | ||||||
|         let end = createLessonEvent(lessonBuffer.value.day,lessonBuffer.value.lessonEnd) |         let end = createLessonEvent(lessonBuffer.value.day,lessonBuffer.value.lessonEnd) | ||||||
|         await createLesson(course, |  | ||||||
|         start, |         lessonCreatorBuffer.value.lessonStart = start; | ||||||
|         end, |         lessonCreatorBuffer.value.lessonEnd = end; | ||||||
|         lessonBuffer.value.lessonType, |         lessonCreatorBuffer.value.color = lessonBuffer.value.color; | ||||||
|         lessonBuffer.value.color,lessonBuffer.value.local) |         lessonCreatorBuffer.value.lessonType =lessonBuffer.value.lessonType; | ||||||
|  |         lessonCreatorBuffer.value.local = lessonBuffer.value.local; | ||||||
|  |         lessonCreatorBuffer.value.courseId = lessonBuffer.value.course.courseId; | ||||||
|  |          | ||||||
|  |        await createLesson(lessonCreatorBuffer.value); | ||||||
|  |  | ||||||
|         lessonFinder.value = await getLessons(); |         lessonFinder.value = await getLessons(); | ||||||
|         lesson.value = findCreatedLesson(); |         lesson.value = findCreatedLesson(); | ||||||
|  |          | ||||||
|         trueSchedule.value = await getCurriculumSchedule(curriculum.value.curriculumId)  |         trueSchedule.value = await getCurriculumSchedule(curriculum.value.curriculumId)  | ||||||
|         await addLessonToSchedule(trueSchedule.value.scheduleId,lesson.value.lessonID) |         await addLessonToSchedule(trueSchedule.value.scheduleId,lesson.value.lessonID) | ||||||
|  |  | ||||||
|     } |     } | ||||||
|     } |     } | ||||||
|     lessonBuffer.value = Object.assign({}, pattern); |     lessonBuffer.value = Object.assign({}, pattern); | ||||||
|  |     lessonFinder.value = null; | ||||||
|  |     lessonCreatorBuffer.value = Object.assign({},lessonCreator) | ||||||
|     trueSchedule.value = null; |     trueSchedule.value = null; | ||||||
|  |  | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | async function patchLesson(lesson){ | ||||||
|  |    | ||||||
|  |   for (let element in toModify.value){ | ||||||
|  |       if (element =="lessonType" && (toModify.value[element] != lesson[element])){ | ||||||
|  |         await alterLesson(lesson.lessonID,{lessonType:toModify.value[element]}); | ||||||
|  |       } | ||||||
|  |       if (element =="local" && (toModify.value[element] != lesson[element])){ | ||||||
|  |         await alterLesson(lesson.lessonID,{local:toModify.value[element]}); | ||||||
|  |       } | ||||||
|  |       if (element =="lessonStart" && (toModify.value[element] != lesson[element])){ | ||||||
|  |         await alterLesson(lesson.lessonID,{lessonStart:createLessonEvent(toModify.value.day,toModify.value[element]) | ||||||
|  | }); | ||||||
|  |       } | ||||||
|  |       if (element =="lessonEnd" && (toModify.value[element] != lesson[element])){ | ||||||
|  |         await alterLesson(lesson.lessonID,{lessonEnd:createLessonEvent(toModify.value.day,toModify.value[element]) | ||||||
|  | }); | ||||||
|  |       } | ||||||
|  |       if(element == "day" && (toModify.value[element] != invertedFormatDate(new Date(lesson.lessonStart))) ){ | ||||||
|  |          | ||||||
|  |        if(toModify.value.lessonStart == lesson.lessonStart){ | ||||||
|  |         await alterLesson(lesson.lessonID,{lessonStart:createLessonEvent(toModify.value.day,lesson.lessonStart) | ||||||
|  |       });} | ||||||
|  |        if(toModify.value.lessonEnd == lesson.lessonEnd){ | ||||||
|  |           await alterLesson(lesson.lessonID,{lessonStart:createLessonEvent(toModify.value.day,lesson.lessonStart)}); | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |        } | ||||||
|  |     toModify.value= Object.assign({},patternModify); | ||||||
|  |     trueSchedule.value = await getSchedule(trueSchedule.value.scheduleId); | ||||||
|  |     schedule.value =trueSchedule.value.lessons; | ||||||
|  |     editElementID.value= ''; | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |   async function removeLesson() { | ||||||
|  |       await deleteLessonFromSchedule(trueSchedule.value.scheduleId, editElementID.value) | ||||||
|  |       await deleteLesson(editElementID.value); | ||||||
|  |       trueSchedule.value = await getSchedule(trueSchedule.value.scheduleId); | ||||||
|  |       schedule.value =trueSchedule.value.lessons; | ||||||
|  |       editElementID.value= ''; | ||||||
|  |  | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
| </script> | </script> | ||||||
| <template> | <template> | ||||||
|   <div class="body"> |   <div class="body"> | ||||||
|     <div class="listTitle buttonGrid"v-if="!deleteMod && !createMod" > |     <div class="listTitle buttonGrid"v-if="!createMod" > | ||||||
|       <button class="create" @click="createMod = true;">Create</button> |       <button class="create" @click="createMod = true;">Create</button> | ||||||
|       <button class="delete" @click="deleteMod = true;">Delete</button> |       <button class="delete" @click="deleteMod = !deleteMod;">{{!deleteMod ? "Delete" : "Remove Delete"}}</button> | ||||||
|  |  | ||||||
|     </div> |     </div> | ||||||
|     <div v-if="createMod"> |     <div v-if="createMod"> | ||||||
|       <form class="listElement" style="width:40%; margin:0 auto 0 auto;"> |       <form class="listElement" style="width:40%; margin:0 auto 0 auto;"> | ||||||
| @ -241,7 +323,7 @@ async function setCourses(){ | |||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|     <div v-if="!deleteMod && !createMod"> |     <div v-if="!createMod"> | ||||||
|       <select @change="changeSchedule()" v-model="trueSchedule"> |       <select @change="changeSchedule()" v-model="trueSchedule"> | ||||||
|         <option v-for="item in allSchedules" :value='item'>{{item.curriculum.option}}</option> |         <option v-for="item in allSchedules" :value='item'>{{item.curriculum.option}}</option> | ||||||
|       </select> |       </select> | ||||||
| @ -263,14 +345,58 @@ async function setCourses(){ | |||||||
|       </select> |       </select> | ||||||
|  |  | ||||||
|     </div> |     </div> | ||||||
|     <div v-for="element in schedule" style="width:50%;margin-left:auto; margin-right:auto;" > |     <div v-if="!createMod " :key="element.lessonID" v-for="element in schedule" style="width:50%;margin-left:auto; margin-right:auto;" > | ||||||
|  |         <div  v-if="editElementID !== element.lessonID" style ="padding:15px 15px 15px 15px;"> | ||||||
|  |         <button  v-if="inFuture(element)" @click="editElementID = element.lessonID;setModify(element);"> | ||||||
|  |         {{i18n("courses.modify")}} | ||||||
|  |         </button> | ||||||
|  |       </div> | ||||||
|  |       <div v-else> | ||||||
|  |         <button @click="patchLesson(element);"> {{i18n("courses.confirm")}} </button> | ||||||
|  |         <button @click="editElementID= '';"> {{i18n("courses.back")}} </button> | ||||||
|  |       </div> | ||||||
|       <div class="listElement"> |       <div class="listElement"> | ||||||
|         <div class="containerElement"> |         <div  v-if="editElementID != element.lessonID"> | ||||||
|           <div> |           <div> | ||||||
|           {{element.course.title}} |           {{element.course.title}} | ||||||
|           </div> |           </div> | ||||||
|           <div>{{formatDate(element.lessonStart)}}</div> |           <div>{{formatDate(element.lessonStart)}}</div> | ||||||
|           <div>{{getHoursMinutes(element.lessonStart)}}-{{getHoursMinutes(element.lessonEnd)}}</div> |           <div>{{getHoursMinutes(element.lessonStart)}}-{{getHoursMinutes(element.lessonEnd)}} | ||||||
|  |           </div> | ||||||
|  |           <div>{{element.local}}</div> | ||||||
|  |           <div>{{element.lessonType}}</div> | ||||||
|  |         </div> | ||||||
|  |  | ||||||
|  |         <div v-else> | ||||||
|  |          <div>{{element.course.title}}</div> | ||||||
|  |         <div style="margin-bottom:20px;"> | ||||||
|  |           Day: | ||||||
|  |           <input type="date" :min="minDate" :max="maxDate" v-model="toModify.day"> | ||||||
|  |         </div> | ||||||
|  |         <div style="margin-bottom:20px;"> | ||||||
|  |           Start:  | ||||||
|  |           <input v-model="toModify.lessonStart" type="time" min="8:00" max="20:00"/> | ||||||
|  |         </div> | ||||||
|  |         <div style="margin-bottom:20px;"> | ||||||
|  |           End:  | ||||||
|  |           <input v-model="toModify.lessonEnd" type="time" min="10:00" max="20:00" required /> | ||||||
|  |         </div> | ||||||
|  |         <div style="margin-bottom:20px;"> | ||||||
|  |           Type:  | ||||||
|  |           <select v-model="toModify.lessonType"> | ||||||
|  |            <option v-for="item in types" :value='item'>{{item}}</option> | ||||||
|  |           </select> | ||||||
|  |         </div> | ||||||
|  |         <div style="margin-bottom:20px;"> | ||||||
|  |           Local:  | ||||||
|  |           <select v-model="toModify.local"> | ||||||
|  |            <option v-for="item in locals" :value='item'>{{item}}</option> | ||||||
|  |           </select> | ||||||
|  |         <div v-if="deleteMod" style="float:right;"> | ||||||
|  |             <button class="delete" @click="removeLesson(element);"> {{i18n("courses.deleteCourse")}} </button> | ||||||
|  |         </div> | ||||||
|  |          | ||||||
|  |         </div> | ||||||
|         </div> |         </div> | ||||||
|       </div> |       </div> | ||||||
|     </div> |     </div> | ||||||
| @ -286,6 +412,7 @@ async function setCourses(){ | |||||||
|  |  | ||||||
| .infosContainer { | .infosContainer { | ||||||
|   min-width:350px; |   min-width:350px; | ||||||
|  |   width:70%; | ||||||
|   padding-bottom:50px; |   padding-bottom:50px; | ||||||
|   border:2px solid black; |   border:2px solid black; | ||||||
|   font-size:25px; |   font-size:25px; | ||||||
| @ -295,29 +422,6 @@ async function setCourses(){ | |||||||
|   border-radius:20px; |   border-radius:20px; | ||||||
| } | } | ||||||
|  |  | ||||||
|  .containerElement{  |  | ||||||
|     justify-content:center; |  | ||||||
|     display:grid; |  | ||||||
|     grid-template-columns:38.8% 38.8% 22.4%; |  | ||||||
|     grid-template-areas: |  | ||||||
|     "name teacher credits";  |  | ||||||
|     column-gap:10px;  } |  | ||||||
|    |  | ||||||
|   .name { |  | ||||||
|     grid-area:name; |  | ||||||
|     align-self:center; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   .teacher{ |  | ||||||
|     grid-area:teacher; |  | ||||||
|     align-self:center; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   .credits{ |  | ||||||
|     grid-area:credits; |  | ||||||
|     align-self:center; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
| .listElement{ | .listElement{ | ||||||
|  min-width:625px; |  min-width:625px; | ||||||
|   border:2px solid black; |   border:2px solid black; | ||||||
|  | |||||||
| @ -3,8 +3,8 @@ import {restGet,restPatch,restPost,restDelete} from "@/rest/restConsumer.js"; | |||||||
| /** | /** | ||||||
|  * Create a new lesson |  * Create a new lesson | ||||||
|  */ |  */ | ||||||
| export async function createLesson(course, lessonStart, lessonEnd, lessonType, color, local){ | export async function createLesson(datas){ | ||||||
|     return restPost("/lesson", {course: course , lessonStart: lessonStart, lessonEnd: lessonEnd,lessonType:lessonType ,color : color , local : local} ) |     return restPost("/lesson", datas ) | ||||||
| } | } | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  | |||||||
| @ -20,6 +20,10 @@ export async function restDelete(endPoint) { | |||||||
| 	return await _rest(endPoint, {method: "DELETE"}); | 	return await _rest(endPoint, {method: "DELETE"}); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | export async function restDeleteItem(endPoint, data){ | ||||||
|  | 	return await _rest(endPoint, {method: "DELETE", credentials: 'include', body: JSON.stringify(data)}); | ||||||
|  | } | ||||||
|  |  | ||||||
| export async function restPatch(endPoint, data) { | export async function restPatch(endPoint, data) { | ||||||
| 	return await _rest(endPoint, {method: "PATCH", credentials: 'include', body: JSON.stringify(data)}); | 	return await _rest(endPoint, {method: "PATCH", credentials: 'include', body: JSON.stringify(data)}); | ||||||
| } | } | ||||||
| @ -41,6 +45,7 @@ async function _rest(endPoint, config){ | |||||||
| 		'Content-Type': 'application/json', | 		'Content-Type': 'application/json', | ||||||
| 	}); | 	}); | ||||||
| 	config['headers'] = config['headers'] == null ? headers : config['headers']; | 	config['headers'] = config['headers'] == null ? headers : config['headers']; | ||||||
|  |   console.log(config) | ||||||
| 	return toast.promise(fetch(restURL + endPoint, config), | 	return toast.promise(fetch(restURL + endPoint, config), | ||||||
| 		{  | 		{  | ||||||
| 			pending: config['pending'] != null ? config['pending'] : 'pending', | 			pending: config['pending'] != null ? config['pending'] : 'pending', | ||||||
|  | |||||||
| @ -1,4 +1,4 @@ | |||||||
| import {restGet,restPost,restPatch} from "@/rest/restConsumer.js"; | import {restGet, restPost, restPatch, restDelete, restDeleteItem} from "@/rest/restConsumer.js"; | ||||||
|  |  | ||||||
| export async function getAllSchedule(){ | export async function getAllSchedule(){ | ||||||
|     return restGet('/schedules'); |     return restGet('/schedules'); | ||||||
| @ -19,3 +19,12 @@ export async function getCurriculumSchedule(id){ | |||||||
| export async function addLessonToSchedule(id,lessonId){ | export async function addLessonToSchedule(id,lessonId){ | ||||||
|   return restPost('/schedule/' + id, lessonId) |   return restPost('/schedule/' + id, lessonId) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | export async function getSchedule(id){ | ||||||
|  |   return restGet('/schedule/' + id); | ||||||
|  |  | ||||||
|  | } | ||||||
|  |  | ||||||
|  | export async function deleteLessonFromSchedule(id,lessonId){ | ||||||
|  |     return restDeleteItem('/schedule/lesson/'+ id, lessonId) | ||||||
|  | } | ||||||
|  | |||||||
| @ -1,4 +1,5 @@ | |||||||
|   import {ref} from 'vue' |   import {ref} from 'vue' | ||||||
|  |  | ||||||
|   export function formatDate(date) { |   export function formatDate(date) { | ||||||
|     var d = new Date(date), |     var d = new Date(date), | ||||||
|         month = '' + (d.getMonth() + 1), |         month = '' + (d.getMonth() + 1), | ||||||
| @ -108,6 +109,7 @@ | |||||||
|    |    | ||||||
|   export function getHoursMinutes(date){ |   export function getHoursMinutes(date){ | ||||||
|     const d = new Date(date); |     const d = new Date(date); | ||||||
|     return d.getHours()+ ":" + d.getMinutes();   |     let hours = [d.getHours().toString().length == 1 ? "0" + d.getHours().toString() : d.getHours()]; | ||||||
|  |     return hours+ ":" + d.getMinutes();   | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user