link backend Post Patch Delete Lesson
This commit is contained in:
parent
9112004326
commit
a2be04bfb3
@ -76,7 +76,7 @@ public class CourseController {
|
||||
{
|
||||
if (authServ.isNotIn(new Role[]{Role.Secretary,Role.Admin},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
System.out.println(course.getOwner().getRegNo());
|
||||
Course createdCourse = courseServ.save(course);
|
||||
if (createdCourse == null)
|
||||
return new ResponseEntity<>(null,HttpStatus.BAD_REQUEST);
|
||||
|
@ -52,10 +52,13 @@ public class LessonController {
|
||||
|
||||
|
||||
@PostMapping("/lesson")
|
||||
public ResponseEntity<HashMap<String, Object>> postLesson(@RequestHeader("Authorization")String token,
|
||||
@RequestBody Lesson lesson){
|
||||
public ResponseEntity<HashMap<String, Object>> postLesson(@RequestHeader("Authorization") String token,
|
||||
@RequestBody Map<String, Object> lessonInfos){
|
||||
if(authServ.isNotIn(new Role[]{Role.Secretary,Role.Admin},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
|
||||
Lesson lesson = lessonServ.createLesson(lessonInfos);
|
||||
Lesson createdLesson = lessonServ.save(lesson);
|
||||
if(createdLesson==null)
|
||||
return new ResponseEntity<>(null,HttpStatus.BAD_REQUEST);
|
||||
@ -68,8 +71,22 @@ public class LessonController {
|
||||
@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()))
|
||||
if(!lessonServ.modifyData(id, updates)){
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
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
|
||||
|
||||
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_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");
|
||||
|
@ -1,5 +1,6 @@
|
||||
package ovh.herisson.Clyde.EndPoints;
|
||||
|
||||
import ch.qos.logback.core.net.SyslogOutputStream;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
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.UserCurriculumService;
|
||||
import ovh.herisson.Clyde.Services.CurriculumService;
|
||||
import ovh.herisson.Clyde.Tables.Curriculum;
|
||||
import ovh.herisson.Clyde.Tables.Role;
|
||||
import ovh.herisson.Clyde.Tables.Schedule;
|
||||
import ovh.herisson.Clyde.Tables.ScheduleLesson;
|
||||
import ovh.herisson.Clyde.Tables.*;
|
||||
import ovh.herisson.Clyde.Services.LessonService;
|
||||
|
||||
import java.util.Map;
|
||||
@ -94,4 +92,16 @@ public class ScheduleController {
|
||||
|
||||
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;
|
||||
|
||||
import jakarta.transaction.Transactional;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
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")
|
||||
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.User;
|
||||
|
||||
import java.lang.reflect.GenericSignatureFormatError;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
@ -38,15 +39,11 @@ public class LessonService {
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public boolean modifyData(long id, Map<String ,Object> updates, Role role){
|
||||
Lesson target = lessonRepo.findById(id);
|
||||
public Lesson createLesson(Map<String,Object> lessonInfos) {
|
||||
Lesson target = new Lesson();
|
||||
|
||||
if(target == null || role != Role.Secretary)
|
||||
return false;
|
||||
|
||||
|
||||
for (Map.Entry<String , Object> entry: updates.entrySet()){
|
||||
switch (entry.getKey()){
|
||||
for (Map.Entry<String, Object> entry : lessonInfos.entrySet()) {
|
||||
switch (entry.getKey()) {
|
||||
case "lessonStart":
|
||||
target.setLessonStart((String) entry.getValue());
|
||||
break;
|
||||
@ -61,6 +58,40 @@ public class LessonService {
|
||||
case "lessonType":
|
||||
target.setLessonType((String) entry.getValue());
|
||||
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);
|
||||
|
@ -30,6 +30,14 @@ public class ScheduleLessonService {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean delete(long lessonId){
|
||||
if(lessonId == 0)
|
||||
return false;
|
||||
scheduleLessonRepo.delete(lessonRepo.findById(lessonId));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public Schedule getScheduleByCurriculum(Curriculum curriculum){
|
||||
return scheduleLessonRepo.findScheduleByCurriculum(curriculum);
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import org.hibernate.annotations.OnDeleteAction;
|
||||
public class Course {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private int courseID;
|
||||
private int courseId;
|
||||
private int credits;
|
||||
private String title;
|
||||
|
||||
@ -26,7 +26,10 @@ public class Course {
|
||||
public Course() {}
|
||||
|
||||
public int getCourseID() {
|
||||
return courseID;
|
||||
return courseId;
|
||||
}
|
||||
public void setCourseID(int courseId){
|
||||
this.courseId = courseId;
|
||||
}
|
||||
|
||||
public int getCredits() {
|
||||
|
@ -1,6 +1,8 @@
|
||||
package ovh.herisson.Clyde.Tables;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import org.hibernate.annotations.OnDelete;
|
||||
import org.hibernate.annotations.OnDeleteAction;
|
||||
|
||||
|
||||
@Entity
|
||||
@ -10,7 +12,8 @@ public class Lesson {
|
||||
private int lessonID;
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name= "Course")
|
||||
@OnDelete(action = OnDeleteAction.SET_NULL)
|
||||
@JoinColumn(name = "Course")
|
||||
private Course course;
|
||||
|
||||
private String lessonStart;
|
||||
|
@ -13,6 +13,7 @@ public class Schedule {
|
||||
|
||||
@OneToOne
|
||||
@JoinColumn(name = "Curriculum")
|
||||
@OnDelete(action = OnDeleteAction.SET_NULL)
|
||||
private Curriculum curriculum;
|
||||
|
||||
public Schedule(Curriculum curriculum){
|
||||
|
@ -14,10 +14,12 @@ public class ScheduleLesson{
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "Schedule")
|
||||
@OnDelete(action = OnDeleteAction.SET_NULL)
|
||||
private Schedule schedule;
|
||||
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@OnDelete(action = OnDeleteAction.SET_NULL)
|
||||
@JoinColumn(name = "Lesson")
|
||||
private Lesson lesson;
|
||||
|
||||
|
@ -155,11 +155,11 @@
|
||||
</div>
|
||||
<div class="containerElement"v-else>
|
||||
<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>
|
||||
</select>
|
||||
<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>
|
||||
</div>
|
||||
|
@ -1,18 +1,17 @@
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import i18n from '@/i18n.js'
|
||||
import {getDifferenceTime,lastDateOfMonth,formatDate,getFirstDay,sortByDate,matrixFromList,sundayToTheEnd,getMarginTop,getHoursMinutes, monthFromList} from '../scheduleFunctions.js'
|
||||
import {getAllSchedule, getOwnSchedule, getCurriculumSchedule,addLessonToSchedule} from "@/rest/scheduleRest.js";
|
||||
import {getLessons, getOwnedLessons, createLesson } from "@/rest/lessonSchedule.js"
|
||||
import {isLogged, getSelf,getTeachers} from "@/rest/Users.js"
|
||||
import {getAllCurriculums, getcurriculum} from "@/rest/curriculum.js"
|
||||
import {getCourse} from "@/rest/courses.js"
|
||||
import {formatDate,getHoursMinutes} from '../scheduleFunctions.js'
|
||||
import {getAllSchedule, deleteLessonFromSchedule ,getSchedule, getCurriculumSchedule,addLessonToSchedule} from "@/rest/scheduleRest.js";
|
||||
import {getLessons , createLesson, alterLesson , deleteLesson} from "@/rest/lessonSchedule.js"
|
||||
import {getTeachers} from "@/rest/Users.js"
|
||||
import { getcurriculum} from "@/rest/curriculum.js"
|
||||
|
||||
const trueSchedule = ref()
|
||||
const schedule = ref();
|
||||
const lessonFinder = ref();
|
||||
const curriculum = ref();
|
||||
const allSchedules = await getAllSchedule();
|
||||
const allSchedules = ref(await getAllSchedule());
|
||||
const filter = ref("null");
|
||||
const subFilter = ref("null");
|
||||
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 currentDate = new Date();
|
||||
|
||||
const editElementID = ref()
|
||||
|
||||
function editItem(id){
|
||||
editElementID.value = id;
|
||||
}
|
||||
|
||||
function invertedFormatDate(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 minDate = ref(invertedFormatDate((new Date()).setDate(currentDate.getDate()+1)))
|
||||
console.log(minDate.value)
|
||||
|
||||
function createLessonEvent(date,hour){
|
||||
const str = date.concat(' ',hour);
|
||||
@ -66,7 +68,41 @@ function createLessonEvent(date,hour){
|
||||
"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 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(){
|
||||
courses.value = (await getcurriculum(curriculum.value.curriculumId)).courses
|
||||
@ -136,12 +172,7 @@ async function setCourses(){
|
||||
}
|
||||
|
||||
function findCreatedLesson(){
|
||||
console.log(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) ){
|
||||
return lessonFinder.value[element];
|
||||
}
|
||||
@ -160,35 +191,86 @@ async function setCourses(){
|
||||
}
|
||||
}
|
||||
if(!isnull){
|
||||
let course = await getCourse(lessonBuffer.value.course.courseId);
|
||||
console.log(course)
|
||||
|
||||
let start = createLessonEvent(lessonBuffer.value.day,lessonBuffer.value.lessonStart)
|
||||
let end = createLessonEvent(lessonBuffer.value.day,lessonBuffer.value.lessonEnd)
|
||||
await createLesson(course,
|
||||
start,
|
||||
end,
|
||||
lessonBuffer.value.lessonType,
|
||||
lessonBuffer.value.color,lessonBuffer.value.local)
|
||||
|
||||
lessonCreatorBuffer.value.lessonStart = start;
|
||||
lessonCreatorBuffer.value.lessonEnd = end;
|
||||
lessonCreatorBuffer.value.color = lessonBuffer.value.color;
|
||||
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();
|
||||
lesson.value = findCreatedLesson();
|
||||
|
||||
trueSchedule.value = await getCurriculumSchedule(curriculum.value.curriculumId)
|
||||
await addLessonToSchedule(trueSchedule.value.scheduleId,lesson.value.lessonID)
|
||||
|
||||
}
|
||||
}
|
||||
lessonBuffer.value = Object.assign({}, pattern);
|
||||
lessonFinder.value = null;
|
||||
lessonCreatorBuffer.value = Object.assign({},lessonCreator)
|
||||
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>
|
||||
<template>
|
||||
<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="delete" @click="deleteMod = true;">Delete</button>
|
||||
<button class="delete" @click="deleteMod = !deleteMod;">{{!deleteMod ? "Delete" : "Remove Delete"}}</button>
|
||||
|
||||
</div>
|
||||
<div v-if="createMod">
|
||||
<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">
|
||||
<option v-for="item in allSchedules" :value='item'>{{item.curriculum.option}}</option>
|
||||
</select>
|
||||
@ -263,14 +345,58 @@ async function setCourses(){
|
||||
</select>
|
||||
|
||||
</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="containerElement">
|
||||
<div v-if="editElementID != element.lessonID">
|
||||
<div>
|
||||
{{element.course.title}}
|
||||
</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>
|
||||
@ -286,6 +412,7 @@ async function setCourses(){
|
||||
|
||||
.infosContainer {
|
||||
min-width:350px;
|
||||
width:70%;
|
||||
padding-bottom:50px;
|
||||
border:2px solid black;
|
||||
font-size:25px;
|
||||
@ -295,29 +422,6 @@ async function setCourses(){
|
||||
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{
|
||||
min-width:625px;
|
||||
border:2px solid black;
|
||||
|
@ -3,8 +3,8 @@ import {restGet,restPatch,restPost,restDelete} from "@/rest/restConsumer.js";
|
||||
/**
|
||||
* Create a new lesson
|
||||
*/
|
||||
export async function createLesson(course, lessonStart, lessonEnd, lessonType, color, local){
|
||||
return restPost("/lesson", {course: course , lessonStart: lessonStart, lessonEnd: lessonEnd,lessonType:lessonType ,color : color , local : local} )
|
||||
export async function createLesson(datas){
|
||||
return restPost("/lesson", datas )
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -20,6 +20,10 @@ export async function restDelete(endPoint) {
|
||||
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) {
|
||||
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',
|
||||
});
|
||||
config['headers'] = config['headers'] == null ? headers : config['headers'];
|
||||
console.log(config)
|
||||
return toast.promise(fetch(restURL + endPoint, config),
|
||||
{
|
||||
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(){
|
||||
return restGet('/schedules');
|
||||
@ -19,3 +19,12 @@ export async function getCurriculumSchedule(id){
|
||||
export async function addLessonToSchedule(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'
|
||||
|
||||
export function formatDate(date) {
|
||||
var d = new Date(date),
|
||||
month = '' + (d.getMonth() + 1),
|
||||
@ -108,6 +109,7 @@
|
||||
|
||||
export function getHoursMinutes(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();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user