Request and changes
This commit is contained in:
parent
a2be04bfb3
commit
bd1c236635
@ -61,6 +61,8 @@ public class ApplicationsController {
|
|||||||
authorizedApps.add(Applications.Rdv);
|
authorizedApps.add(Applications.Rdv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!authServ.isNotIn(new Role[]{Role.Teacher,Role.Admin},token))
|
||||||
|
authorizedApps.add(Applications.ManageOwnedLessons);
|
||||||
//if Teacher or Secretary or Admin add ManageCourses App
|
//if Teacher or Secretary or Admin add ManageCourses App
|
||||||
if (!authServ.isNotIn(new Role[]{Role.Teacher,Role.Secretary,Role.Admin},token))
|
if (!authServ.isNotIn(new Role[]{Role.Teacher,Role.Secretary,Role.Admin},token))
|
||||||
authorizedApps.add(Applications.ManageCourses);
|
authorizedApps.add(Applications.ManageCourses);
|
||||||
@ -71,7 +73,8 @@ public class ApplicationsController {
|
|||||||
|
|
||||||
if (!authServ.isNotIn(new Role[]{Role.Secretary,Role.Admin},token)){
|
if (!authServ.isNotIn(new Role[]{Role.Secretary,Role.Admin},token)){
|
||||||
authorizedApps.add(Applications.UsersList);
|
authorizedApps.add(Applications.UsersList);
|
||||||
authorizedApps.add(Applications.ManageSchedules);}
|
authorizedApps.add(Applications.ManageSchedules);
|
||||||
|
authorizedApps.add(Applications.LessonRequests);}
|
||||||
return authorizedApps;
|
return authorizedApps;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
|
|||||||
import ovh.herisson.Clyde.Services.AuthenticatorService;
|
import ovh.herisson.Clyde.Services.AuthenticatorService;
|
||||||
import ovh.herisson.Clyde.Services.LessonService;
|
import ovh.herisson.Clyde.Services.LessonService;
|
||||||
import ovh.herisson.Clyde.Services.ProtectionService;
|
import ovh.herisson.Clyde.Services.ProtectionService;
|
||||||
|
import ovh.herisson.Clyde.Services.ScheduleLessonService;
|
||||||
import ovh.herisson.Clyde.Tables.Lesson;
|
import ovh.herisson.Clyde.Tables.Lesson;
|
||||||
import ovh.herisson.Clyde.Tables.Role;
|
import ovh.herisson.Clyde.Tables.Role;
|
||||||
|
|
||||||
@ -18,10 +19,12 @@ import java.util.Map;
|
|||||||
public class LessonController {
|
public class LessonController {
|
||||||
private final LessonService lessonServ;
|
private final LessonService lessonServ;
|
||||||
|
|
||||||
|
private final ScheduleLessonService scheduleLessonServ;
|
||||||
private final AuthenticatorService authServ;
|
private final AuthenticatorService authServ;
|
||||||
|
|
||||||
public LessonController(LessonService lessonServ, AuthenticatorService authServ) {
|
public LessonController(LessonService lessonServ, ScheduleLessonService scheduleLessonService, AuthenticatorService authServ) {
|
||||||
this.lessonServ = lessonServ;
|
this.lessonServ = lessonServ;
|
||||||
|
this.scheduleLessonServ = scheduleLessonService;
|
||||||
this.authServ = authServ;
|
this.authServ = authServ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,6 +63,8 @@ public class LessonController {
|
|||||||
|
|
||||||
Lesson lesson = lessonServ.createLesson(lessonInfos);
|
Lesson lesson = lessonServ.createLesson(lessonInfos);
|
||||||
Lesson createdLesson = lessonServ.save(lesson);
|
Lesson createdLesson = lessonServ.save(lesson);
|
||||||
|
scheduleLessonServ.saveToAllSchedule(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);
|
||||||
|
@ -0,0 +1,125 @@
|
|||||||
|
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.LessonRequestService;
|
||||||
|
import ovh.herisson.Clyde.Services.LessonService;
|
||||||
|
import ovh.herisson.Clyde.Services.ProtectionService;
|
||||||
|
import ovh.herisson.Clyde.Tables.LessonChangesRequest;
|
||||||
|
import ovh.herisson.Clyde.Tables.RequestState;
|
||||||
|
import ovh.herisson.Clyde.Tables.Role;
|
||||||
|
import ovh.herisson.Clyde.Tables.User;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
|
||||||
|
public class LessonRequestsController {
|
||||||
|
private final LessonRequestService lessonRequestServ;
|
||||||
|
private final AuthenticatorService authServ;
|
||||||
|
|
||||||
|
private final LessonService lessonServ;
|
||||||
|
public LessonRequestsController(LessonRequestService lessonRequestServer, AuthenticatorService authServ, LessonService lessonServ) {
|
||||||
|
this.lessonRequestServ = lessonRequestServer;
|
||||||
|
this.authServ = authServ;
|
||||||
|
this.lessonServ = lessonServ;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/requests/lessonRequest/{id}")
|
||||||
|
public ResponseEntity<Map<String,Object>> getById(@RequestHeader("Authorization") String token, @PathVariable long id){
|
||||||
|
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary},token))
|
||||||
|
return new UnauthorizedResponse<>(null);
|
||||||
|
|
||||||
|
LessonChangesRequest lessonRequest= lessonRequestServ.findById(id);
|
||||||
|
|
||||||
|
return new ResponseEntity<>(ProtectionService.lessonRequestWithoutPassword(lessonRequest), HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/requests/lessonRequests/owned")
|
||||||
|
public ResponseEntity<Iterable<Map<String, Object>>> getOwnedRequests(@RequestHeader("Authorization") String token){
|
||||||
|
if(authServ.isNotIn(new Role[]{Role.Admin,Role.Teacher},token))
|
||||||
|
return new UnauthorizedResponse<>(null);
|
||||||
|
User user = authServ.getUserFromToken(token);
|
||||||
|
Iterable<LessonChangesRequest> lessonChangesRequests = lessonRequestServ.findOwnRequests(user);
|
||||||
|
return new ResponseEntity<>(ProtectionService.lessonRequestsWithoutPassword(lessonChangesRequests),HttpStatus.OK);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/requests/lessonRequests")
|
||||||
|
public ResponseEntity<Iterable<Map<String,Object>>> getAllRequests(@RequestHeader("Authorization") String token){
|
||||||
|
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary},token))
|
||||||
|
return new UnauthorizedResponse<>(null);
|
||||||
|
|
||||||
|
Iterable<LessonChangesRequest> lessonRequests= lessonRequestServ.getAll();
|
||||||
|
|
||||||
|
return new ResponseEntity<>(ProtectionService.lessonRequestsWithoutPassword(lessonRequests), HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/requests/lessonRequest")
|
||||||
|
public ResponseEntity<Map<String, Object>> makeRequest(@RequestBody LessonChangesRequest lessonRequest){
|
||||||
|
System.out.println(lessonRequest.getLesson());
|
||||||
|
System.out.println(lessonRequest.getLessonEnd());
|
||||||
|
LessonChangesRequest lessonChangesRequest = lessonRequestServ.save(lessonRequest);
|
||||||
|
return new ResponseEntity<>(ProtectionService.lessonRequestWithoutPassword(lessonChangesRequest),HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PatchMapping("/requests/lessonRequest/{id}")
|
||||||
|
public ResponseEntity<LessonChangesRequest> changeRequestState(@PathVariable long id,
|
||||||
|
@RequestHeader("Authorization") String token,
|
||||||
|
@RequestBody Map<String , Object> infos){
|
||||||
|
if(authServ.isNotIn(new Role[]{Role.Secretary,Role.Admin},token))
|
||||||
|
return new UnauthorizedResponse<>(null);
|
||||||
|
|
||||||
|
LessonChangesRequest lessonRequest = lessonRequestServ.findById(id);
|
||||||
|
String local = "";
|
||||||
|
RequestState state = null;
|
||||||
|
for (Map.Entry<String, Object> entry : infos.entrySet()) {
|
||||||
|
switch (entry.getKey()) {
|
||||||
|
case "local":
|
||||||
|
local = (String) entry.getValue();
|
||||||
|
break;
|
||||||
|
case "state":
|
||||||
|
state = RequestState.valueOf((String)entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state == null)
|
||||||
|
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||||
|
|
||||||
|
if(lessonRequest.getRequestType() == 0 ) {
|
||||||
|
if (!lessonRequestServ.modifyCreateRequestState(lessonRequest, state, local))
|
||||||
|
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(lessonRequest.getRequestType() == 1){
|
||||||
|
infos.put("lessonStart", lessonRequest.getLessonStart());
|
||||||
|
infos.put("lessonEnd", lessonRequest.getLessonEnd());
|
||||||
|
infos.put("lessonType",lessonRequest.getLessonType());
|
||||||
|
if(!lessonRequestServ.modifyChangeRequestState(infos,lessonRequest.getLesson(),state))
|
||||||
|
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||||
|
lessonRequest.setState(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
else{
|
||||||
|
lessonRequestServ.modifyDeleleRequest(lessonRequest, state);
|
||||||
|
}
|
||||||
|
lessonRequestServ.save(lessonRequest);
|
||||||
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@DeleteMapping("/requests/lessonRequest/{id}")
|
||||||
|
public ResponseEntity<String> deleteRequest(@RequestHeader("Authorization") String token, @PathVariable long id){
|
||||||
|
if(authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary,Role.Teacher},token))
|
||||||
|
return new UnauthorizedResponse<>(null);
|
||||||
|
LessonChangesRequest lessonChangesRequest = lessonRequestServ.findById(id);
|
||||||
|
if (lessonChangesRequest == null)
|
||||||
|
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||||
|
lessonRequestServ.delete(lessonChangesRequest);
|
||||||
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
|
}
|
||||||
|
}
|
@ -29,10 +29,11 @@ public class MockController {
|
|||||||
public final ScheduleService scheduleService;
|
public final ScheduleService scheduleService;
|
||||||
public final ScheduleLessonService scheduleLessonService;
|
public final ScheduleLessonService scheduleLessonService;
|
||||||
|
|
||||||
|
public final LessonRequestService lessonRequestService;
|
||||||
ArrayList<User> mockUsers;
|
ArrayList<User> mockUsers;
|
||||||
|
|
||||||
|
|
||||||
public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CurriculumCourseService CurriculumCourseService, CurriculumService curriculumService, CourseService courseService, InscriptionService inscriptionService, LessonService lessonService, ScheduleService scheduleService, ScheduleLessonService scheduleLessonService){
|
public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CurriculumCourseService CurriculumCourseService, CurriculumService curriculumService, CourseService courseService, InscriptionService inscriptionService, LessonService lessonService, ScheduleService scheduleService, ScheduleLessonService scheduleLessonService, LessonRequestService lessonRequestService){
|
||||||
this.tokenRepo = tokenRepo;
|
this.tokenRepo = tokenRepo;
|
||||||
this.userRepo = userRepo;
|
this.userRepo = userRepo;
|
||||||
this.tokenService = tokenService;
|
this.tokenService = tokenService;
|
||||||
@ -43,6 +44,7 @@ public class MockController {
|
|||||||
this.lessonService = lessonService;
|
this.lessonService = lessonService;
|
||||||
this.scheduleService = scheduleService;
|
this.scheduleService = scheduleService;
|
||||||
this.scheduleLessonService = scheduleLessonService;
|
this.scheduleLessonService = scheduleLessonService;
|
||||||
|
this.lessonRequestService = lessonRequestService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Saves an example of each user type by :
|
/** Saves an example of each user type by :
|
||||||
@ -113,10 +115,16 @@ public class MockController {
|
|||||||
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");
|
||||||
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");
|
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");
|
||||||
|
|
||||||
|
LessonChangesRequest request1 = new LessonChangesRequest(joke,RequestState.Pending,null,null,null,null,2,null,1);
|
||||||
|
LessonChangesRequest request2 = new LessonChangesRequest(joke,RequestState.Pending,"Fri Apr 19 2024 10:30 ","Fri Apr 19 2024 12:30 ",null,null,1,null,2);
|
||||||
|
LessonChangesRequest request3 = new LessonChangesRequest(joke,RequestState.Pending,"Fri Apr 19 2024 13:30 ","Fri Apr 19 2024 15:30 ","Course",progra1,0,"rgb(27,49,100)",4);
|
||||||
|
|
||||||
|
|
||||||
Schedule infoBab1Schedule = new Schedule(infoBab1);
|
Schedule infoBab1Schedule = new Schedule(infoBab1);
|
||||||
Schedule chemistryBab1Schedule = new Schedule(chemistryBab1);
|
Schedule chemistryBab1Schedule = new Schedule(chemistryBab1);
|
||||||
Schedule psychoBab1Schedule = new Schedule(psychologyBab1);
|
Schedule psychoBab1Schedule = new Schedule(psychologyBab1);
|
||||||
|
|
||||||
|
|
||||||
scheduleService.save(infoBab1Schedule);
|
scheduleService.save(infoBab1Schedule);
|
||||||
scheduleService.save(chemistryBab1Schedule);
|
scheduleService.save(chemistryBab1Schedule);
|
||||||
scheduleService.save(psychoBab1Schedule);
|
scheduleService.save(psychoBab1Schedule);
|
||||||
@ -137,6 +145,10 @@ public class MockController {
|
|||||||
scheduleLessonService.save(new ScheduleLesson(psychoBab1Schedule,lesson_0_psycho1));
|
scheduleLessonService.save(new ScheduleLesson(psychoBab1Schedule,lesson_0_psycho1));
|
||||||
scheduleLessonService.save(new ScheduleLesson(psychoBab1Schedule,lesson_0_commun));
|
scheduleLessonService.save(new ScheduleLesson(psychoBab1Schedule,lesson_0_commun));
|
||||||
|
|
||||||
|
|
||||||
|
lessonRequestService.save(request1);
|
||||||
|
lessonRequestService.save(request2);
|
||||||
|
lessonRequestService.save(request3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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.LessonChangesRequest;
|
||||||
|
import ovh.herisson.Clyde.Tables.User;
|
||||||
|
|
||||||
|
public interface LessonChangesRequestRepository extends CrudRepository<LessonChangesRequest, Long> {
|
||||||
|
LessonChangesRequest findById(long id);
|
||||||
|
|
||||||
|
|
||||||
|
@Query("select lr from LessonChangesRequest lr where lr.user = ?1")
|
||||||
|
Iterable<LessonChangesRequest> findOwnRequests(User user);
|
||||||
|
}
|
@ -21,7 +21,10 @@ public interface ScheduleLessonRepository extends CrudRepository<ScheduleLesson,
|
|||||||
Schedule findScheduleByCurriculum(Curriculum curriculum);
|
Schedule findScheduleByCurriculum(Curriculum curriculum);
|
||||||
|
|
||||||
@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> findLessonsBySchedule(Schedule schedule);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Modifying
|
@Modifying
|
||||||
@Transactional
|
@Transactional
|
||||||
|
@ -1,9 +1,16 @@
|
|||||||
package ovh.herisson.Clyde.Repositories;
|
package ovh.herisson.Clyde.Repositories;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.CrudRepository;
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
import ovh.herisson.Clyde.Tables.Course;
|
||||||
|
import ovh.herisson.Clyde.Tables.Lesson;
|
||||||
import ovh.herisson.Clyde.Tables.Schedule;
|
import ovh.herisson.Clyde.Tables.Schedule;
|
||||||
|
|
||||||
public interface ScheduleRepository extends CrudRepository<Schedule,Long> {
|
public interface ScheduleRepository extends CrudRepository<Schedule,Long> {
|
||||||
|
|
||||||
Schedule findById(long id);
|
Schedule getById(long id);
|
||||||
|
|
||||||
|
|
||||||
|
@Query("select distinct sl from Schedule sl where EXISTS (select c.curriculum from CurriculumCourse c where (sl.curriculum = c.curriculum) AND (c.course = ?1))")
|
||||||
|
Iterable<Schedule> findAllLessonSchedule(Course course);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,93 @@
|
|||||||
|
package ovh.herisson.Clyde.Services;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import ovh.herisson.Clyde.Repositories.*;
|
||||||
|
import ovh.herisson.Clyde.Tables.*;
|
||||||
|
|
||||||
|
import java.sql.SQLOutput;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class LessonRequestService {
|
||||||
|
private final LessonChangesRequestRepository lessonChangesRepo;
|
||||||
|
|
||||||
|
private final UserRepository userRepo;
|
||||||
|
|
||||||
|
private final LessonRepository lessonRepo;
|
||||||
|
|
||||||
|
private final LessonService lessonServ;
|
||||||
|
|
||||||
|
private final ScheduleLessonRepository scheduleLessonRepo;
|
||||||
|
|
||||||
|
private final ScheduleRepository scheduleRepository;
|
||||||
|
|
||||||
|
private final ScheduleLessonService scheduleLessonService;
|
||||||
|
|
||||||
|
private final CourseRepository courseRepository;
|
||||||
|
public LessonRequestService(LessonChangesRequestRepository lessonChangesRepo,
|
||||||
|
UserRepository userRepo, LessonRepository lessonRepo,
|
||||||
|
LessonService lessonServ, ScheduleLessonRepository scheduleLessonRepo, ScheduleRepository scheduleRepository, ScheduleLessonService scheduleLessonService, CourseRepository courseRepository) {
|
||||||
|
this.lessonChangesRepo = lessonChangesRepo;
|
||||||
|
this.userRepo = userRepo;
|
||||||
|
this.lessonRepo = lessonRepo;
|
||||||
|
this.lessonServ = lessonServ;
|
||||||
|
this.scheduleLessonRepo = scheduleLessonRepo;
|
||||||
|
this.scheduleRepository = scheduleRepository;
|
||||||
|
this.scheduleLessonService = scheduleLessonService;
|
||||||
|
this.courseRepository = courseRepository;
|
||||||
|
}
|
||||||
|
public Iterable<LessonChangesRequest> findOwnRequests(User user){
|
||||||
|
return lessonChangesRepo.findOwnRequests(user);
|
||||||
|
}
|
||||||
|
public LessonChangesRequest save(LessonChangesRequest lessonRequest){
|
||||||
|
return lessonChangesRepo.save(lessonRequest);
|
||||||
|
}
|
||||||
|
public LessonChangesRequest findById(long id){
|
||||||
|
return lessonChangesRepo.findById(id);
|
||||||
|
}
|
||||||
|
public Iterable<LessonChangesRequest> getAll(){return lessonChangesRepo.findAll();}
|
||||||
|
|
||||||
|
public boolean modifyCreateRequestState(LessonChangesRequest lessonRequest, RequestState state, String local ){
|
||||||
|
if(lessonRequest == null || state == lessonRequest.getState() || state == null){
|
||||||
|
return false;}
|
||||||
|
if (state == RequestState.Accepted){
|
||||||
|
Course course = courseRepository.findById(lessonRequest.getCourse().getCourseID());
|
||||||
|
if(courseRepository.findById(lessonRequest.getCourse().getCourseID())==null|| local == null){
|
||||||
|
return false;}
|
||||||
|
Lesson lesson = new Lesson(
|
||||||
|
course,
|
||||||
|
lessonRequest.getLessonStart(),
|
||||||
|
lessonRequest.getLessonEnd(),
|
||||||
|
lessonRequest.getColor(),
|
||||||
|
local,
|
||||||
|
lessonRequest.getLessonType());
|
||||||
|
lesson = lessonRepo.save(lesson);
|
||||||
|
scheduleLessonService.saveToAllSchedule(lesson);
|
||||||
|
}
|
||||||
|
lessonRequest.setState(state);
|
||||||
|
save(lessonRequest);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean modifyChangeRequestState(Map<String, Object> updates, long lessonId,RequestState state){
|
||||||
|
if(state == RequestState.Accepted){
|
||||||
|
System.out.println(updates.toString());
|
||||||
|
|
||||||
|
Lesson lesson = lessonServ.findById(lessonId);
|
||||||
|
return lessonServ.modifyData(lesson.getLessonID(),updates);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void modifyDeleleRequest(LessonChangesRequest lessonChangesRequest, RequestState state){
|
||||||
|
if(state == RequestState.Accepted){
|
||||||
|
lessonServ.delete(lessonServ.findById(lessonChangesRequest.getLesson()));
|
||||||
|
lessonChangesRequest.setState(state);}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void delete (LessonChangesRequest toDelete) {
|
||||||
|
lessonChangesRepo.delete(toDelete);
|
||||||
|
}
|
||||||
|
}
|
@ -68,17 +68,11 @@ public class LessonService {
|
|||||||
|
|
||||||
public boolean modifyData(long id, Map<String ,Object> updates){
|
public boolean modifyData(long id, Map<String ,Object> updates){
|
||||||
Lesson target = lessonRepo.findById(id);
|
Lesson target = lessonRepo.findById(id);
|
||||||
System.out.println(target);
|
|
||||||
|
|
||||||
if(target == null)
|
if(target == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
||||||
System.out.println("test");
|
|
||||||
System.out.println(updates.entrySet());
|
|
||||||
|
|
||||||
for (Map.Entry<String , Object> entry: updates.entrySet()){
|
for (Map.Entry<String , Object> entry: updates.entrySet()){
|
||||||
System.out.println(entry);
|
|
||||||
switch (entry.getKey()){
|
switch (entry.getKey()){
|
||||||
case "lessonStart":
|
case "lessonStart":
|
||||||
target.setLessonStart((String) entry.getValue());
|
target.setLessonStart((String) entry.getValue());
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
package ovh.herisson.Clyde.Services;
|
package ovh.herisson.Clyde.Services;
|
||||||
|
|
||||||
import ovh.herisson.Clyde.Tables.Course;
|
import ovh.herisson.Clyde.Tables.*;
|
||||||
import ovh.herisson.Clyde.Tables.InscriptionRequest;
|
|
||||||
import ovh.herisson.Clyde.Tables.Lesson;
|
|
||||||
import ovh.herisson.Clyde.Tables.User;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -119,6 +116,32 @@ public class ProtectionService {
|
|||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Map<String, Object> lessonRequestWithoutPassword(LessonChangesRequest lessonRequest){
|
||||||
|
if (lessonRequest == null)
|
||||||
|
return null;
|
||||||
|
Map<String, Object> toReturn = new HashMap<>();
|
||||||
|
toReturn.put("id", lessonRequest.getId());
|
||||||
|
toReturn.put("lessonStart", lessonRequest.getLessonStart());
|
||||||
|
toReturn.put("lessonEnd", lessonRequest.getLessonEnd());
|
||||||
|
toReturn.put("lessonType",lessonRequest.getLessonType());
|
||||||
|
toReturn.put("course", courseWithoutPassword(lessonRequest.getCourse()));
|
||||||
|
toReturn.put("user", userWithoutPassword(lessonRequest.getUser()));
|
||||||
|
toReturn.put("requestType", lessonRequest.getRequestType());
|
||||||
|
toReturn.put("state", lessonRequest.getState());
|
||||||
|
toReturn.put("lessonId",lessonRequest.getLesson());
|
||||||
|
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Iterable<Map<String, Object>> lessonRequestsWithoutPassword(Iterable<LessonChangesRequest> lessonChangesRequests){
|
||||||
|
ArrayList<Map<String,Object>> toReturn = new ArrayList<>();
|
||||||
|
|
||||||
|
for(LessonChangesRequest lessonChangeRequest: lessonChangesRequests){
|
||||||
|
toReturn.add(lessonRequestWithoutPassword(lessonChangeRequest));
|
||||||
|
}
|
||||||
|
return toReturn;
|
||||||
|
|
||||||
|
}
|
||||||
public static Iterable<Map<String ,Object>> requestsWithoutPasswords(Iterable<InscriptionRequest> inscriptionRequests){
|
public static Iterable<Map<String ,Object>> requestsWithoutPasswords(Iterable<InscriptionRequest> inscriptionRequests){
|
||||||
|
|
||||||
ArrayList<Map<String,Object>> toReturn = new ArrayList<>();
|
ArrayList<Map<String,Object>> toReturn = new ArrayList<>();
|
||||||
|
@ -9,6 +9,7 @@ import ovh.herisson.Clyde.Tables.*;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class ScheduleLessonService {
|
public class ScheduleLessonService {
|
||||||
@ -30,6 +31,16 @@ public class ScheduleLessonService {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean saveToAllSchedule(Lesson lesson){
|
||||||
|
Iterable<Schedule> schedules = scheduleRepo.findAllLessonSchedule(lesson.getCourse());
|
||||||
|
if(schedules == null)
|
||||||
|
return false;
|
||||||
|
for (Schedule schedule : schedules){
|
||||||
|
save(new ScheduleLesson(schedule, lesson));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean delete(long lessonId){
|
public boolean delete(long lessonId){
|
||||||
if(lessonId == 0)
|
if(lessonId == 0)
|
||||||
return false;
|
return false;
|
||||||
|
@ -14,7 +14,7 @@ public class ScheduleService {
|
|||||||
return scheduleRepo.save(schedule);
|
return scheduleRepo.save(schedule);
|
||||||
}
|
}
|
||||||
public Schedule findById(long id){
|
public Schedule findById(long id){
|
||||||
return scheduleRepo.findById(id);
|
return scheduleRepo.getById(id);
|
||||||
}
|
}
|
||||||
public void delete(Schedule schedule){
|
public void delete(Schedule schedule){
|
||||||
scheduleRepo.delete(schedule);
|
scheduleRepo.delete(schedule);
|
||||||
|
@ -13,6 +13,9 @@ public enum Applications {
|
|||||||
Msg,
|
Msg,
|
||||||
Forum,
|
Forum,
|
||||||
Rdv,
|
Rdv,
|
||||||
|
// teachers authorization
|
||||||
|
|
||||||
|
ManageOwnedLessons,
|
||||||
|
|
||||||
// teachers and Secretary authorization
|
// teachers and Secretary authorization
|
||||||
ManageCourses,
|
ManageCourses,
|
||||||
@ -20,6 +23,7 @@ public enum Applications {
|
|||||||
|
|
||||||
//Secretary authorization
|
//Secretary authorization
|
||||||
ManageSchedules,
|
ManageSchedules,
|
||||||
|
LessonRequests,
|
||||||
|
|
||||||
// InscriptionService authorization
|
// InscriptionService authorization
|
||||||
Inscription,
|
Inscription,
|
||||||
|
@ -0,0 +1,130 @@
|
|||||||
|
package ovh.herisson.Clyde.Tables;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import org.hibernate.annotations.OnDelete;
|
||||||
|
import org.hibernate.annotations.OnDeleteAction;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
public class LessonChangesRequest {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
|
private int id;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "Users")
|
||||||
|
@OnDelete(action = OnDeleteAction.CASCADE)
|
||||||
|
private User user;
|
||||||
|
|
||||||
|
private long lessonId;
|
||||||
|
|
||||||
|
private RequestState state;
|
||||||
|
|
||||||
|
private String lessonStart;
|
||||||
|
|
||||||
|
private String lessonEnd;
|
||||||
|
|
||||||
|
private String color;
|
||||||
|
@OneToOne
|
||||||
|
@JoinColumn(name ="Course")
|
||||||
|
private Course course;
|
||||||
|
|
||||||
|
private String lessonType;
|
||||||
|
|
||||||
|
private int requestType;
|
||||||
|
|
||||||
|
public LessonChangesRequest(User user, RequestState state, String lessonStart,
|
||||||
|
String lessonEnd, String lessonType, Course course,
|
||||||
|
int requestType, String color,long lessonId){
|
||||||
|
this.user = user;
|
||||||
|
this.state = state;
|
||||||
|
this.requestType = requestType;
|
||||||
|
this.lessonType = lessonType;
|
||||||
|
this.lessonStart = lessonStart;
|
||||||
|
this.lessonEnd= lessonEnd;
|
||||||
|
this.color = color;
|
||||||
|
this.course = course;
|
||||||
|
this.lessonId = lessonId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LessonChangesRequest() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public RequestState getState() {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public User getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getLesson(){
|
||||||
|
return lessonId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLessonStart() {
|
||||||
|
return lessonStart;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLessonEnd() {
|
||||||
|
return lessonEnd;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public int getRequestType() {
|
||||||
|
return requestType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLessonType() {
|
||||||
|
return lessonType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColor() {
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Course getCourse() {
|
||||||
|
return course;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setState(RequestState state) {
|
||||||
|
this.state = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUser(User user) {
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLessonStart(String lessonStart) {
|
||||||
|
this.lessonStart = lessonStart;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLessonType(String lessonType) {
|
||||||
|
this.lessonType = lessonType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLessonEnd(String lessonEnd) {
|
||||||
|
this.lessonEnd = lessonEnd;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColor(String color) {
|
||||||
|
this.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRequestType(int requestType) {
|
||||||
|
this.requestType = requestType;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void setCourse(Course course){
|
||||||
|
this.course = course;
|
||||||
|
}
|
||||||
|
}
|
@ -29,6 +29,8 @@ app.language=Language
|
|||||||
app.manage.profile=Manage profile
|
app.manage.profile=Manage profile
|
||||||
app.studentList=Students List
|
app.studentList=Students List
|
||||||
app.users=Users
|
app.users=Users
|
||||||
|
app.manageOwnLessons=Manage Owned Courses Schedule
|
||||||
|
app.lessonRequests=Schedule Requests
|
||||||
request.moreInfos=More Infos
|
request.moreInfos=More Infos
|
||||||
request.accept=Accept
|
request.accept=Accept
|
||||||
request.refuse=Refuse
|
request.refuse=Refuse
|
||||||
|
@ -29,6 +29,8 @@ app.language=Langue
|
|||||||
app.manage.profile=Gérer le profil
|
app.manage.profile=Gérer le profil
|
||||||
app.studentList=Liste des étudiants
|
app.studentList=Liste des étudiants
|
||||||
app.users=Utilisateurs
|
app.users=Utilisateurs
|
||||||
|
app.manageOwnLessons=Gérer ses horaires de cours
|
||||||
|
app.lessonRequests=Requêtes d'horaire
|
||||||
request.moreInfos=Plus d'Infos
|
request.moreInfos=Plus d'Infos
|
||||||
request.accept=Accepter
|
request.accept=Accepter
|
||||||
request.refuse=Refuser
|
request.refuse=Refuser
|
||||||
|
220
frontend/src/Apps/LessonRequests.vue
Normal file
220
frontend/src/Apps/LessonRequests.vue
Normal file
@ -0,0 +1,220 @@
|
|||||||
|
|
||||||
|
<script setup>
|
||||||
|
import i18n from "@/i18n.js"
|
||||||
|
import {ref} from 'vue'
|
||||||
|
import {changeRequestState, getAllRequests} from "@/rest/LessonRequests.js";
|
||||||
|
import {getLesson} from "@/rest/lessonSchedule.js";
|
||||||
|
import {formatDate, getHoursMinutes} from "@/scheduleFunctions.js";
|
||||||
|
|
||||||
|
const requests = ref(await getAllRequests());
|
||||||
|
|
||||||
|
const AcceptMod = ref(false);
|
||||||
|
const moreInfosMod = ref(false);
|
||||||
|
const requestTypes = ["Create", "Modify", "Delete"]
|
||||||
|
const editElementID = ref('');
|
||||||
|
const chosenLocal = ref("");
|
||||||
|
const locals = ["A0B1","A1B1","A2B1","A0B2"];
|
||||||
|
const moreInfos = ref({});
|
||||||
|
async function upPage(id,review){
|
||||||
|
await changeRequestState(id, review) ;
|
||||||
|
requests.value = await getAllRequests();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function AcceptSetup(id,type){
|
||||||
|
if(type !== 2 ){
|
||||||
|
AcceptMod.value = !AcceptMod.value;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
await upPage(id,{local: null,state:'Accepted'});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function editItem(item){
|
||||||
|
editElementID.value = item.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setMoreInfos(item){
|
||||||
|
moreInfos.value["requestType"] = requestTypes[item.requestType]
|
||||||
|
moreInfos.value["day"] = formatDate(new Date(item.lessonStart))
|
||||||
|
moreInfos.value["start"] = getHoursMinutes(new Date(item.lessonStart));
|
||||||
|
moreInfos.value["end"] = getHoursMinutes(new Date(item.lessonEnd));
|
||||||
|
moreInfos.value["lessonType"] = item.lessonType;
|
||||||
|
[item["course"] == null ? moreInfos.value["course"] = null: moreInfos.value["course"]=item.course.title]
|
||||||
|
if (item.requestType==1 || item.requestType == 2){
|
||||||
|
let temp = await getLesson(item.lessonId);
|
||||||
|
if(item.requestType == 1){
|
||||||
|
moreInfos.value["course"] = temp.course.title;
|
||||||
|
moreInfos.value["old_day"] = formatDate(new Date(temp.lessonStart));
|
||||||
|
moreInfos.value["old_start"] = getHoursMinutes(new Date(temp.lessonStart));
|
||||||
|
moreInfos.value["old_end"] = getHoursMinutes(new Date(temp.lessonEnd));
|
||||||
|
moreInfos.value["old_type"] = temp.lessonType;
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<template>
|
||||||
|
|
||||||
|
<div class="body">
|
||||||
|
<div v-for="item of requests" :key="item.id" :style="{width:[moreInfosMod ? 95:70] + '%'}" class="centerer">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div v-if ="item.state === 'Pending'" class="listElement">
|
||||||
|
<div class="containerElement" v-if="editElementID !== item.id">
|
||||||
|
<div class="id">{{requestTypes[item.requestType]}}</div>
|
||||||
|
<div class="surname">{{item.state}}</div>
|
||||||
|
<div class="firstname">{{item.user.lastName}}</div>
|
||||||
|
|
||||||
|
<div class="infos">
|
||||||
|
<button @click=" editItem(item);moreInfosMod=!moreInfosMod; setMoreInfos(item); console.log(item);" style="background-color:rgb(105,05,105);" >
|
||||||
|
{{i18n("request.moreInfos")}}
|
||||||
|
</button></div>
|
||||||
|
<div class="accept"><button @click="editItem(item); AcceptSetup(item.id,item.requestType);" style="background-color:rgb(0,105,50);">{{i18n("request.accept")}}</button></div>
|
||||||
|
<div class="refuse"><button @click="upPage(item.id,{local: null,state:'Refused'})" style="background-color:rgb(105,0,0);">{{i18n("request.refuse")}}</button></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else class="containerElement" style="width:auto; height:auto;">
|
||||||
|
<div v-if="AcceptMod">
|
||||||
|
Local:
|
||||||
|
<select v-model="chosenLocal">
|
||||||
|
<option v-for="item in locals">{{item}}</option>
|
||||||
|
</select>
|
||||||
|
<button @click="AcceptMod = !AcceptMod;upPage(item.id,{local: chosenLocal, state:'Accepted'})"></button>
|
||||||
|
</div>
|
||||||
|
<template v-if="moreInfosMod" v-for="key,value in moreInfos">
|
||||||
|
|
||||||
|
<div class="container" v-if="key != null" style="align-self:center;">
|
||||||
|
<div style="margin:0 auto 0 auto">
|
||||||
|
{{value}}:
|
||||||
|
{{key}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<button @click = "moreInfosMod = !moreInfosMod; editElementID = ''">back</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.centerer{
|
||||||
|
margin:0 auto 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.containerElement{
|
||||||
|
justify-content:center;
|
||||||
|
display:grid;
|
||||||
|
grid-template-columns:10% 14.2% 19% 14.2% 14.2% 14.2% 14.2%;
|
||||||
|
grid-template-areas:
|
||||||
|
"id type surname firstname infos accept refuse";
|
||||||
|
column-gap:10px; }
|
||||||
|
|
||||||
|
.container{
|
||||||
|
padding-left:50px;
|
||||||
|
font-size:.8em;
|
||||||
|
justify-content:center;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(6, 1fr);
|
||||||
|
grid-template-rows: repeat(auto-fill, 120px);
|
||||||
|
grid-row-gap: 1em;
|
||||||
|
|
||||||
|
grid-column-gap: 0.2em;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.listElement{
|
||||||
|
min-width:625px;
|
||||||
|
border:2px solid black;
|
||||||
|
font-size:25px;
|
||||||
|
color:white;
|
||||||
|
padding:20px;
|
||||||
|
background-color:rgb(50,50,50);
|
||||||
|
border-radius:20px;
|
||||||
|
margin-bottom:10px;
|
||||||
|
|
||||||
|
}
|
||||||
|
.infos {
|
||||||
|
grid-area:infos;
|
||||||
|
align-self:center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.accept{
|
||||||
|
grid-area:accept;
|
||||||
|
align-self:center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.refuse{
|
||||||
|
grid-area:refuse;
|
||||||
|
align-self:center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.id{
|
||||||
|
grid-area:id;
|
||||||
|
margin-left:40px;
|
||||||
|
align-self:center;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.surname{
|
||||||
|
grid-area:surname;
|
||||||
|
align-self:center;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow:ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
.firstname{
|
||||||
|
grid-area:firstname;
|
||||||
|
align-self:center;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow:ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
button{
|
||||||
|
font-size:15px;
|
||||||
|
height:50px;
|
||||||
|
width:100px;
|
||||||
|
border:none;
|
||||||
|
border-radius:20px;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.body {
|
||||||
|
width:100%;
|
||||||
|
margin-top:3.5%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.buttonGrid{
|
||||||
|
display:grid;
|
||||||
|
grid-template-columns: auto auto;
|
||||||
|
column-gap:50px;
|
||||||
|
grid-template-areas:
|
||||||
|
"create delete";
|
||||||
|
}.listTitle{
|
||||||
|
min-width:380px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
width:25%;
|
||||||
|
margin-left:auto;
|
||||||
|
margin-right:auto;
|
||||||
|
border:2px solid black;
|
||||||
|
font-size:25px;
|
||||||
|
color:white;
|
||||||
|
padding:20px;
|
||||||
|
background-color:rgb(50,50,50);
|
||||||
|
border-radius:20px;
|
||||||
|
margin-bottom:10px;
|
||||||
|
|
||||||
|
button:hover{
|
||||||
|
opacity:0.8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
|
|
@ -173,17 +173,6 @@
|
|||||||
margin-top:3.5%;
|
margin-top:3.5%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.infosContainer {
|
|
||||||
min-width:350px;
|
|
||||||
padding-bottom:50px;
|
|
||||||
border:2px solid black;
|
|
||||||
font-size:25px;
|
|
||||||
color:white;
|
|
||||||
padding:20px;
|
|
||||||
background-color:rgb(50,50,50);
|
|
||||||
border-radius:20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.containerElement{
|
.containerElement{
|
||||||
justify-content:center;
|
justify-content:center;
|
||||||
display:grid;
|
display:grid;
|
||||||
|
270
frontend/src/Apps/ManageOwnLessons.vue
Normal file
270
frontend/src/Apps/ManageOwnLessons.vue
Normal file
@ -0,0 +1,270 @@
|
|||||||
|
<script setup>
|
||||||
|
import { ref } from 'vue'
|
||||||
|
import i18n from '@/i18n.js'
|
||||||
|
import {formatDate,getHoursMinutes} from '../scheduleFunctions.js'
|
||||||
|
import {getOwnedLessons} from "@/rest/lessonSchedule.js";
|
||||||
|
import {getSelf} from "@/rest/Users.js";
|
||||||
|
import {createRequest} from "@/rest/LessonRequests.js"
|
||||||
|
import {getcurriculum} from "@/rest/curriculum.js";
|
||||||
|
import {getAllSchedule} from "@/rest/scheduleRest.js";
|
||||||
|
|
||||||
|
|
||||||
|
const curriculum = ref();
|
||||||
|
const allSchedules = ref(await getAllSchedule());
|
||||||
|
const schedule = ref(await getOwnedLessons());
|
||||||
|
const createMod = ref(false);
|
||||||
|
const user = await getSelf();
|
||||||
|
const editElementID = ref();
|
||||||
|
const requestType = ref(0);
|
||||||
|
const currentDate = new Date();
|
||||||
|
const types = ["TP","TD","Course","Exam"];
|
||||||
|
const colors = {"TP":"rgb(36,175,255)","TD":"rgb(255,36,175)","Exam":"rgb(175,255,36)","Course":"rgb(255,36,175)"}
|
||||||
|
const courses = ref();
|
||||||
|
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
|
||||||
|
}
|
||||||
|
function invertedFormatDate(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 [year, month, day].join('-');
|
||||||
|
}
|
||||||
|
function createLessonEvent(date,hour){
|
||||||
|
const str = date.concat(' ',hour);
|
||||||
|
return new Date(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 pattern = {
|
||||||
|
"lessonId":null,
|
||||||
|
"course": null,
|
||||||
|
"day":null,
|
||||||
|
"lessonStart": null,
|
||||||
|
"lessonEnd": null,
|
||||||
|
"lessonType": null,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const patternRequest ={
|
||||||
|
"user": user,
|
||||||
|
"state": "Pending",
|
||||||
|
"requestType": null,
|
||||||
|
"lessonId":null,
|
||||||
|
"lessonType":null,
|
||||||
|
"lessonStart":null,
|
||||||
|
"lessonEnd":null,
|
||||||
|
"color":null,
|
||||||
|
"course":null,}
|
||||||
|
|
||||||
|
const toModify = ref(Object.assign({}, pattern));
|
||||||
|
const requestBuffer = ref(Object.assign({},patternRequest));
|
||||||
|
|
||||||
|
function setModify(lesson){
|
||||||
|
toModify.value.lessonId = editElementID.value;
|
||||||
|
toModify.value.day = invertedFormatDate(new Date(lesson.lessonStart));
|
||||||
|
toModify.value.lessonStart = getHoursMinutes(lesson.lessonStart);
|
||||||
|
toModify.value.lessonEnd = getHoursMinutes(lesson.lessonEnd);
|
||||||
|
toModify.value.lessonType = lesson.lessonType
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createLessonRequest(){
|
||||||
|
if(requestType.value === 0 || requestType.value === 1){
|
||||||
|
//modify
|
||||||
|
requestBuffer.value.color = colors[toModify.value.lessonType] ;
|
||||||
|
requestBuffer.value.requestType = requestType.value;
|
||||||
|
let start = createLessonEvent(toModify.value.day,toModify.value.lessonStart)
|
||||||
|
let end = createLessonEvent(toModify.value.day,toModify.value.lessonEnd)
|
||||||
|
for (let element in toModify.value){
|
||||||
|
if(element !== "day" && element !== "lessonStart" && element !== "lessonEnd"){
|
||||||
|
requestBuffer.value[element] = toModify.value[element];
|
||||||
|
}
|
||||||
|
if(element === "lessonStart"){
|
||||||
|
requestBuffer.value.lessonStart = start;
|
||||||
|
}
|
||||||
|
if(element === "lessonEnd"){
|
||||||
|
requestBuffer.value.lessonEnd = end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(requestType.value === 2) {
|
||||||
|
//delete
|
||||||
|
requestBuffer.value.lessonId = editElementID;
|
||||||
|
requestBuffer.value.requestType = requestType.value;
|
||||||
|
}
|
||||||
|
await createRequest(requestBuffer.value);
|
||||||
|
editElementID.value = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async function askChanges(i){
|
||||||
|
requestType.value= i;
|
||||||
|
await createLessonRequest()
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
|
||||||
|
<div class="body">
|
||||||
|
<button @click="createMod = !createMod">Ask Create Request</button>
|
||||||
|
<div v-if="createMod">
|
||||||
|
<form class="listElement" style="width:40%; margin:0 auto 0 auto;">
|
||||||
|
<div style="margin-bottom:20px;">
|
||||||
|
Schedule :
|
||||||
|
<select @change="setCourses()"v-model="curriculum">
|
||||||
|
<option v-for="item in allSchedules" :value='item.curriculum'>{{item.curriculum.option}}</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div style="margin-bottom:20px;">
|
||||||
|
Lesson :
|
||||||
|
<select v-if="curriculum != null" v-model="toModify.course">
|
||||||
|
<option v-for="item in courses" :value='item'>{{item.title}}</option>
|
||||||
|
</select>
|
||||||
|
</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="08:00" max="18:00" required />
|
||||||
|
</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>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<button class="create" @click="createMod=!createMod; askChanges(1);"> {{i18n("courses.confirm")}} </button>
|
||||||
|
<button style="float:right;" @click="createMod=!createMod">{{i18n("courses.back")}}</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div v-if="!createMod"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);">
|
||||||
|
Ask Changes
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div v-else>
|
||||||
|
<button @click="askChanges(0);"> {{i18n("courses.confirm")}} </button>
|
||||||
|
<button @click="editElementID= '';"> {{i18n("courses.back")}} </button>
|
||||||
|
</div>
|
||||||
|
<div class="listElement">
|
||||||
|
<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>{{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:
|
||||||
|
{{element.local}}
|
||||||
|
<div style="float:right;">
|
||||||
|
<button @click="askChanges(2)" class="delete"> ask Deletion </button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.body {
|
||||||
|
width:100%;
|
||||||
|
margin-top:3.5%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.listElement{
|
||||||
|
min-width:625px;
|
||||||
|
border:2px solid black;
|
||||||
|
font-size:25px;
|
||||||
|
color:white;
|
||||||
|
padding:20px;
|
||||||
|
background-color:rgb(50,50,50);
|
||||||
|
border-radius:20px;
|
||||||
|
margin-bottom:10px;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
input, select{
|
||||||
|
padding:10px 10px 10px 10px;
|
||||||
|
font-size:25px;
|
||||||
|
cursor: pointer;
|
||||||
|
border:none;
|
||||||
|
border-radius:15px;
|
||||||
|
}
|
||||||
|
button{
|
||||||
|
font-size:15px;
|
||||||
|
height:50px;
|
||||||
|
width:100px;
|
||||||
|
border:none;
|
||||||
|
border-radius:20px;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.delete{
|
||||||
|
grid-area:delete;
|
||||||
|
background-color:rgb(200,0,0);
|
||||||
|
}
|
||||||
|
button:hover{
|
||||||
|
opacity:0.8;
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
@ -14,7 +14,6 @@ import i18n from '@/i18n.js'
|
|||||||
const allSchedules = ref(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 filters = ["Type","Teacher","Course"];
|
const filters = ["Type","Teacher","Course"];
|
||||||
const types = ["TP","TD","Course","Exam"];
|
const types = ["TP","TD","Course","Exam"];
|
||||||
const locals = ["A0B1","A1B1","A2B1","A0B2"]
|
const locals = ["A0B1","A1B1","A2B1","A0B2"]
|
||||||
@ -29,9 +28,6 @@ const currentDate = new Date();
|
|||||||
|
|
||||||
const editElementID = ref()
|
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),
|
||||||
@ -94,8 +90,8 @@ const toModify = ref(Object.assign({}, pattern));
|
|||||||
toModify.value.day = invertedFormatDate(new Date(lesson.lessonStart));
|
toModify.value.day = invertedFormatDate(new Date(lesson.lessonStart));
|
||||||
toModify.value.lessonStart = getHoursMinutes(lesson.lessonStart);
|
toModify.value.lessonStart = getHoursMinutes(lesson.lessonStart);
|
||||||
toModify.value.lessonEnd = getHoursMinutes(lesson.lessonEnd);
|
toModify.value.lessonEnd = getHoursMinutes(lesson.lessonEnd);
|
||||||
toModify.value.local = lesson.local
|
toModify.value.local = lesson.local;
|
||||||
toModify.value.lessonType = lesson.lessonType
|
toModify.value.lessonType = lesson.lessonType;
|
||||||
}
|
}
|
||||||
|
|
||||||
function inFuture(lesson){
|
function inFuture(lesson){
|
||||||
@ -171,14 +167,6 @@ async function setCourses(){
|
|||||||
subFilter.value = "null"
|
subFilter.value = "null"
|
||||||
}
|
}
|
||||||
|
|
||||||
function findCreatedLesson(){
|
|
||||||
for(let element in lessonFinder.value){
|
|
||||||
if((lessonFinder.value[element].course.courseId ==lessonBuffer.value.course.courseId) && (lessonFinder.value[element].local == lessonBuffer.value.local) ){
|
|
||||||
return lessonFinder.value[element];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function newLesson(){
|
async function newLesson(){
|
||||||
let isnull = false;
|
let isnull = false;
|
||||||
@ -205,12 +193,8 @@ async function setCourses(){
|
|||||||
await createLesson(lessonCreatorBuffer.value);
|
await createLesson(lessonCreatorBuffer.value);
|
||||||
|
|
||||||
lessonFinder.value = await getLessons();
|
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);
|
lessonBuffer.value = Object.assign({}, pattern);
|
||||||
lessonFinder.value = null;
|
lessonFinder.value = null;
|
||||||
@ -410,18 +394,6 @@ async function patchLesson(lesson){
|
|||||||
margin-top:3.5%;
|
margin-top:3.5%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.infosContainer {
|
|
||||||
min-width:350px;
|
|
||||||
width:70%;
|
|
||||||
padding-bottom:50px;
|
|
||||||
border:2px solid black;
|
|
||||||
font-size:25px;
|
|
||||||
color:white;
|
|
||||||
padding:20px;
|
|
||||||
background-color:rgb(50,50,50);
|
|
||||||
border-radius:20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.listElement{
|
.listElement{
|
||||||
min-width:625px;
|
min-width:625px;
|
||||||
border:2px solid black;
|
border:2px solid black;
|
||||||
@ -434,15 +406,6 @@ async function patchLesson(lesson){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.modify{
|
|
||||||
font-size:25px;
|
|
||||||
padding:10px 10px 10px 10px;
|
|
||||||
background-color: rgb(239,60,168);
|
|
||||||
cursor: pointer;
|
|
||||||
border:none;
|
|
||||||
border-radius:15px;
|
|
||||||
}
|
|
||||||
|
|
||||||
input, select{
|
input, select{
|
||||||
padding:10px 10px 10px 10px;
|
padding:10px 10px 10px 10px;
|
||||||
font-size:25px;
|
font-size:25px;
|
||||||
|
23
frontend/src/rest/LessonRequests.js
Normal file
23
frontend/src/rest/LessonRequests.js
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { restGet, restPost, restDelete, restPatch } from './restConsumer.js'
|
||||||
|
|
||||||
|
export async function getLessonRequest(id){
|
||||||
|
return restGet('/requests/lessonRequest/' + id);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getAllRequests(){
|
||||||
|
return restGet("/requests/lessonRequests");
|
||||||
|
}
|
||||||
|
export async function getOwnedRequests(){
|
||||||
|
return restGet("/requests/lessonRequests/owned");
|
||||||
|
}
|
||||||
|
export async function createRequest(request){
|
||||||
|
return restPost("/requests/lessonRequest", request);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function changeRequestState(id, infos){
|
||||||
|
return restPatch("/requests/lessonRequest/" + id, infos);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function deleteRequest(id){
|
||||||
|
return restDelete("/requests/lessonRequest/"+id);
|
||||||
|
}
|
@ -11,6 +11,8 @@ import Users from "@/Apps/UsersList.vue"
|
|||||||
import Students from "@/Apps/StudentsList.vue"
|
import Students from "@/Apps/StudentsList.vue"
|
||||||
import Schedule from "@/Apps/Schedule.vue"
|
import Schedule from "@/Apps/Schedule.vue"
|
||||||
import ManageSchedule from "@/Apps/ManageSchedule.vue"
|
import ManageSchedule from "@/Apps/ManageSchedule.vue"
|
||||||
|
import ManageOwnedLessons from "@/Apps/ManageOwnLessons.vue";
|
||||||
|
import LessonRequests from "@/Apps/LessonRequests.vue";
|
||||||
|
|
||||||
const apps = {
|
const apps = {
|
||||||
'/schedule': Schedule,
|
'/schedule': Schedule,
|
||||||
@ -21,6 +23,8 @@ const apps = {
|
|||||||
'/manage-courses' : Courses,
|
'/manage-courses' : Courses,
|
||||||
'/users-list' : Users,
|
'/users-list' : Users,
|
||||||
'/students-list' : Students,
|
'/students-list' : Students,
|
||||||
|
'/manage-owned-lessons': ManageOwnedLessons,
|
||||||
|
'/manage-schedule-requests' : LessonRequests,
|
||||||
}
|
}
|
||||||
|
|
||||||
const appsList = {
|
const appsList = {
|
||||||
@ -33,6 +37,8 @@ const appsList = {
|
|||||||
'ManageCourses': { path: '#/manage-courses', icon: 'fa-book', text: i18n("app.manage.courses") },
|
'ManageCourses': { path: '#/manage-courses', icon: 'fa-book', text: i18n("app.manage.courses") },
|
||||||
'StudentsList':{ path: '#/students-list',icon: 'fa-users',text: i18n("app.studentList")},
|
'StudentsList':{ path: '#/students-list',icon: 'fa-users',text: i18n("app.studentList")},
|
||||||
'UsersList':{ path: '#/users-list',icon: 'fa-users',text: i18n("app.users")},
|
'UsersList':{ path: '#/users-list',icon: 'fa-users',text: i18n("app.users")},
|
||||||
|
'ManageOwnedLessons':{path: '#/manage-owned-lessons',icon:'fa-calendar-days',text: i18n("app.manageOwnLessons")},
|
||||||
|
'LessonRequests':{path: '#/manage-schedule-requests', icon:'fa-book', text: i18n("app.lessonRequests")},
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user