1
0
forked from PGL/Clyde

change schedule Curriculum and own schedule

This commit is contained in:
Wawilski 2024-04-10 20:22:07 +02:00
parent 142ea996d8
commit 95ef4023d6
8 changed files with 142 additions and 45 deletions

View File

@ -44,8 +44,10 @@ public class LessonController {
@GetMapping("/lessons/owned") @GetMapping("/lessons/owned")
public ResponseEntity<Iterable<HashMap<String,Object>>> getOwnedLessons(@RequestHeader("Authorization") String token){ public ResponseEntity<Iterable<HashMap<String,Object>>> getOwnedLessons(@RequestHeader("Authorization") String token){
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Teacher},token)) System.out.println(authServ);
return new UnauthorizedResponse<>(null); if (authServ.isNotIn(new Role[]{Role.Admin,Role.Teacher},token)){
System.out.println("problem ici");
return new UnauthorizedResponse<>(null);}
return new ResponseEntity<>(ProtectionService.lessonsWithoutPassword(lessonServ.findAllOwnedLesson(authServ.getUserFromToken(token))),HttpStatus.OK); return new ResponseEntity<>(ProtectionService.lessonsWithoutPassword(lessonServ.findAllOwnedLesson(authServ.getUserFromToken(token))),HttpStatus.OK);
} }

View File

@ -8,6 +8,8 @@ import ovh.herisson.Clyde.Services.AuthenticatorService;
import ovh.herisson.Clyde.Services.ScheduleLessonService; 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.Tables.Curriculum;
import ovh.herisson.Clyde.Tables.Role; import ovh.herisson.Clyde.Tables.Role;
import ovh.herisson.Clyde.Tables.Schedule; import ovh.herisson.Clyde.Tables.Schedule;
@ -20,15 +22,18 @@ public class ScheduleController {
private final ScheduleService scheduleServ; private final ScheduleService scheduleServ;
private final UserCurriculumService userCurriculumService; private final UserCurriculumService userCurriculumService;
private final CurriculumService curriculumServ;
private final AuthenticatorService authServ; private final AuthenticatorService authServ;
private final ScheduleLessonService scheduleLessonServ; private final ScheduleLessonService scheduleLessonServ;
public ScheduleController(ScheduleService scheduleServ, UserCurriculumService userCurriculumService, AuthenticatorService authServ, ScheduleLessonService scheduleLessonServ) { public ScheduleController(ScheduleService scheduleServ, UserCurriculumService userCurriculumService, AuthenticatorService authServ, ScheduleLessonService scheduleLessonServ, CurriculumService curriculumServ) {
this.scheduleServ = scheduleServ; this.scheduleServ = scheduleServ;
this.userCurriculumService = userCurriculumService; this.userCurriculumService = userCurriculumService;
this.authServ = authServ; this.authServ = authServ;
this.scheduleLessonServ = scheduleLessonServ; this.scheduleLessonServ = scheduleLessonServ;
this.curriculumServ = curriculumServ;
} }
@GetMapping("/schedule/{id}") @GetMapping("/schedule/{id}")
@ -51,6 +56,14 @@ public class ScheduleController {
return new ResponseEntity<>(scheduleLessonServ.getDepthScheduleBySchedule(schedule),HttpStatus.OK); return new ResponseEntity<>(scheduleLessonServ.getDepthScheduleBySchedule(schedule),HttpStatus.OK);
} }
@GetMapping("/schedule/curriculum/{id}")
public ResponseEntity<Map<String, Object>> findCurriculumSchedule(@PathVariable Long id){
Schedule schedule = scheduleLessonServ.getScheduleByCurriculum(curriculumServ.findById(id));
if(schedule == null)
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
return new ResponseEntity<>(scheduleLessonServ.getDepthScheduleBySchedule(schedule),HttpStatus.OK);
}
@GetMapping("/schedules") @GetMapping("/schedules")
public ResponseEntity<Iterable<Map<String , Object>>> findAllSchedule(){ public ResponseEntity<Iterable<Map<String , Object>>> findAllSchedule(){
return new ResponseEntity<>(scheduleLessonServ.getAllSchedule(),HttpStatus.OK); return new ResponseEntity<>(scheduleLessonServ.getAllSchedule(),HttpStatus.OK);

View File

@ -2,13 +2,13 @@ package ovh.herisson.Clyde.Repositories;
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.Course;
import ovh.herisson.Clyde.Tables.Lesson; import ovh.herisson.Clyde.Tables.Lesson;
import ovh.herisson.Clyde.Tables.User;
public interface LessonRepository extends CrudRepository<Lesson, Long> { public interface LessonRepository extends CrudRepository<Lesson, Long> {
Lesson findById(long id); Lesson findById(long id);
@Query("select l from Lesson l where l.course.owner = ?1") @Query("select l from Lesson l where l.course = ?1")
Iterable<Lesson> findAllOwnedLesson(User teacher); Iterable<Lesson> findLessonByCourse(Course course);
} }

View File

@ -1,17 +1,23 @@
package ovh.herisson.Clyde.Services; package ovh.herisson.Clyde.Services;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import ovh.herisson.Clyde.Repositories.CourseRepository;
import ovh.herisson.Clyde.Repositories.LessonRepository; import ovh.herisson.Clyde.Repositories.LessonRepository;
import ovh.herisson.Clyde.Tables.Course;
import ovh.herisson.Clyde.Tables.Lesson; 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.util.ArrayList;
import java.util.Map; import java.util.Map;
@Service @Service
public class LessonService { public class LessonService {
private final LessonRepository lessonRepo; private final LessonRepository lessonRepo;
public LessonService(LessonRepository lessonRepo){ private final CourseRepository courseRepo;
public LessonService(LessonRepository lessonRepo, CourseRepository courseRepo){
this.lessonRepo = lessonRepo; this.lessonRepo = lessonRepo;
this.courseRepo = courseRepo;
} }
public Lesson save(Lesson lesson){ public Lesson save(Lesson lesson){
@ -23,7 +29,13 @@ public class LessonService {
public Iterable<Lesson> findAll(){return lessonRepo.findAll();} public Iterable<Lesson> findAll(){return lessonRepo.findAll();}
public Iterable<Lesson> findAllOwnedLesson(User teacher){ public Iterable<Lesson> findAllOwnedLesson(User teacher){
return lessonRepo.findAllOwnedLesson(teacher); ArrayList<Lesson> toReturn = new ArrayList<>();
ArrayList<Course> coursesOwned = (ArrayList<Course>) courseRepo.findAllOwnedCoures(teacher);
for (Course element : coursesOwned) {
for(Lesson lesson : lessonRepo.findLessonByCourse(element))
toReturn.add(lesson);
}
return toReturn;
} }
public boolean modifyData(long id, Map<String ,Object> updates, Role role){ public boolean modifyData(long id, Map<String ,Object> updates, Role role){

View File

@ -1,12 +1,49 @@
<script setup> <script setup>
import { ref } from 'vue' import { ref } from 'vue'
import {getDifferenceTime,lastDateOfMonth,formatDate,getFirstDay,sortByDate,matrixFromList,sundayToTheEnd,getMarginTop,getHoursMinutes, monthFromList} from '../scheduleFunctions.js' import {getDifferenceTime,lastDateOfMonth,formatDate,getFirstDay,sortByDate,matrixFromList,sundayToTheEnd,getMarginTop,getHoursMinutes, monthFromList} from '../scheduleFunctions.js'
import {getAllSchedule} from "@/rest/scheduleRest.js"; import {getAllSchedule, getOwnSchedule, getCurriculumSchedule} from "@/rest/scheduleRest.js";
import {getLessons, getOwnedLessons } from "@/rest/lessonSchedule.js"
import {isLogged, getSelf} from "@/rest/Users.js"
import {getAllCurriculums} from "@/rest/curriculum.js"
const allSchedule = await getAllSchedule(); const log = await isLogged();
const schedule = ref();
const shift = ref(getFirstDay(new Date()).getDay());
let value = 1;
const len = ref(lastDateOfMonth(new Date()));
const scheduleByWeek = ref();
const month = ref();
const mondayOfWeek =ref(getMonday(new Date()))
const currentDate = ref(new Date())
const allSchedules = await getAllSchedule();
let counter = 0;
const ownSchedule = ref();
console.log(allSchedules)
let user;
if(log){
user = await getSelf();
if(user.role == "Admin" || user.role == "Secretary" || user.role == "InscriptionService"){
}
else{
if(user.role == "Teacher"){
ownSchedule.value = await getOwnedLessons();
}
if(user.role == "Student"){
const trueSchedule = await getOwnSchedule();
ownSchedule.value = trueSchedule.lessons;}
schedule.value = ownSchedule.value;
scheduleByWeek.value = sundayToTheEnd(matrixFromList(schedule.value,mondayOfWeek.value));
month.value = monthFromList(schedule.value,new Date().getMonth());
}
}
const schedule = ref(allSchedule[0].lessons)
const display =ref("Month") const display =ref("Month")
@ -14,7 +51,7 @@
const days = ["Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi","Dimanche"]; const days = ["Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi","Dimanche"];
const months = ["Janvier","Fevrier","Mars","Avril",'Mai',"Juin","Juillet","Aout","Septembre","Octobre","Novembre","Decembre"] const months = ["Janvier","Fevrier","Mars","Avril",'Mai',"Juin","Juillet","Aout","Septembre","Octobre","Novembre","Decembre"]
const firstDayOfMonth = ref(getFirstDay(new Date())) const firstDayOfMonth = ref(getFirstDay(new Date()))
const monthDone = ref(false);
function getMonday(d) { function getMonday(d) {
d = new Date(d); d = new Date(d);
d.setHours(0,0,0); d.setHours(0,0,0);
@ -28,10 +65,13 @@
day.setDate(day.getDate() + d ); day.setDate(day.getDate() + d );
return day; return day;
} }
const mondayOfWeek =ref(getMonday(new Date()))
const currentDate = ref(new Date())
function verifUser(){
if(log)
return (user.role == "Student" || user.role == "Teacher");
return false
}
function isNotCourse(element){ function isNotCourse(element){
return element==null; return element==null;
} }
@ -41,42 +81,67 @@
const hour = element.lessonEnd.substring(3,5) -element.lessonStart.substring(3,5); const hour = element.lessonEnd.substring(3,5) -element.lessonStart.substring(3,5);
return (element.lessonEnd - element.lessonStart)%2; return (element.lessonEnd - element.lessonStart)%2;
} }
const scheduleByWeek = ref(sundayToTheEnd(matrixFromList(schedule.value,mondayOfWeek.value)));
const month = ref(monthFromList(schedule.value,new Date().getMonth())); function displayOwnSchedule(){
const shift = ref(getFirstDay(new Date()).getDay()); schedule.value = ownSchedule.value;
let value = 1; scheduleByWeek.value = sundayToTheEnd(matrixFromList(schedule.value,mondayOfWeek.value));
const len = ref(lastDateOfMonth(new Date())); month.value = monthFromList(schedule.value,currentDate.value.getMonth());
value = 1;
counter=0;
}
async function changeSchedule(){
scheduleByWeek.value = sundayToTheEnd(matrixFromList(schedule.value,mondayOfWeek.value));
month.value = monthFromList(schedule.value,currentDate.value.getMonth());
value = 1;
counter=0;
}
function changeWeek(i){ function changeWeek(i){
const temp = getAnyDays(i); const temp = getAnyDays(i);
mondayOfWeek.value = temp; mondayOfWeek.value = temp;
if(scheduleByWeek.value != null)
scheduleByWeek.value = sundayToTheEnd(matrixFromList(schedule.value, mondayOfWeek.value)) scheduleByWeek.value = sundayToTheEnd(matrixFromList(schedule.value, mondayOfWeek.value))
} }
function changeMonth(i){ function changeMonth(i){
const temp = currentDate.value; const temp = currentDate.value;
currentDate.value = new Date( ( 0< temp.getMonth()+i < 13 ? temp.getFullYear() : temp.getFullYear()+i), (0< temp.getMonth()+i <13 ? temp.getMonth()+i : 12 ),1); currentDate.value = new Date( ( 0< temp.getMonth()+i < 13 ? temp.getFullYear() : temp.getFullYear()+i), (0< temp.getMonth()+i <13 ? temp.getMonth()+i : 12 ),1);
month.value = monthFromList(schedule.value,currentDate.value.getMonth())
shift.value= getFirstDay(currentDate.value).getDay(); shift.value= getFirstDay(currentDate.value).getDay();
len.value= lastDateOfMonth(currentDate.value); len.value= lastDateOfMonth(currentDate.value);
value = 1; value = 1;
counter = 0;
if(month.value != null){
month.value = monthFromList(schedule.value,currentDate.value.getMonth())}
} }
function isAValue(){ function isAValue(){
if(value-shift.value<0){ if(value-shift.value<0 ){
counter++;
value++; value++;
return false return false;
} }
if(value-shift.value<len.value){ if(value-shift.value<len.value){
value++; value++;
counter++;
return true;} return true;}
if(value-shift.value>=len.value){ if(value-shift.value==len.value){
return false counter++;
if(counter> 35){
counter=1;
value = 2;
return true; }
return false;
} }
} }
</script> </script>
<template> <template>
<div class="grid"> <div class="grid">
@ -87,7 +152,8 @@
<th> <th>
<button @click="changeWeek(-7)">Previous</button> <button @click="changeWeek(-7)">Previous</button>
<button @click="changeWeek(7)">Next</button> <button @click="changeWeek(7)">Next</button>
<button @click="mondayOfWeek = getMonday(new Date()); scheduleByWeek = sundayToTheEnd(matrixFromList(schedule.value, mondayOfWeek))">Current</button> <button @click="mondayOfWeek = getMonday(new Date());
scheduleByWeek != null ? scheduleByWeek = sundayToTheEnd(matrixFromList(schedule.value, mondayOfWeek)) : null;">Current</button>
</th> </th>
<th class="header" v-for='d,index in 7' > <th class="header" v-for='d,index in 7' >
@ -106,7 +172,7 @@
<td v-for="m in 7"></td> <td v-for="m in 7"></td>
</tr> </tr>
</table> </table>
<div class="courseGrid"> <div v-if="scheduleByWeek != null " class="courseGrid">
<div class="dayCourse" v-for="element in scheduleByWeek"> <div class="dayCourse" v-for="element in scheduleByWeek">
<template v-for="i,index in element.length"> <template v-for="i,index in element.length">
<div class="course" v-bind:style="{background:element[index].color, <div class="course" v-bind:style="{background:element[index].color,
@ -147,14 +213,8 @@
</tr> </tr>
<tr v-for="n in 5" style="height:16.67%;"> <tr v-for="n in 5" style="height:16.67%;">
<td v-for="m,i in 7" style="height:16.67%; position:relative;"> <td v-for="m,i in 7" style="height:16.67%; position:relative;">
<div v-if="isAValue()" style="top:0; right:2%; border-radius:20%;color:rgb(200,200,200) ; position:absolute;z-index:50;">{{value-shift}}</div> <div v-if="isAValue()" style="top:0; right:2%; border-radius:20%;color:rgb(200,200,200) ; position:absolute;z-index:50;">{{value-shift}}</div>
<div v-if="month != null" style="overflow-y:scroll; height:100%;" >
<div style="overflow-y:scroll; height:100%;" >
<template v-for="element in month[value-shift]"> <template v-for="element in month[value-shift]">
<div class="course" v-bind:style="{background:element.color, height:100+'%'}"> <div class="course" v-bind:style="{background:element.color, height:100+'%'}">
@ -175,7 +235,6 @@
</td> </td>
</tr> </tr>
</table> </table>
</template> </template>
@ -186,6 +245,11 @@
<div class="options"> <div class="options">
<button v-if="display=='Week'" @click="display='Month'">Month</button> <button v-if="display=='Week'" @click="display='Month'">Month</button>
<button v-if="display=='Month'" @click="display='Week'; value=1;">Week</button> <button v-if="display=='Month'" @click="display='Week'; value=1;">Week</button>
<button v-if="verifUser()" @click="displayOwnSchedule()">OwnSchedule</button>
<select @change="changeSchedule()" v-model="schedule">
<option v-for="item in allSchedules" :value='item.lessons'>{{item.curriculum.option}}</option>
</select>
</div> </div>
</div> </div>
</template> </template>

View File

@ -39,13 +39,14 @@ export async function getLesson(id){
* - teacher * - teacher
* - Assistants * - Assistants
*/ */
export async function getLessons(role){ export async function getLessons(){
if(role==="Teacher"){
return restGet("/lessons/owned")
}
return restGet("/lessons") return restGet("/lessons")
} }
export async function getOwnedLessons(){
return restGet("/lessons/owned")
}
/** /**
* Change the options of a course * Change the options of a course

View File

@ -11,3 +11,7 @@ export async function getOwnSchedule(){
export async function createSchedule(curriculum) { export async function createSchedule(curriculum) {
return restPost('/schedule',{curriculum : curriculum}) return restPost('/schedule',{curriculum : curriculum})
} }
export async function getCurriculumSchedule(id){
return restGet('/schedule/curriculum/' + id)
}

View File

@ -67,11 +67,12 @@
} }
export function monthFromList(list,month){ export function monthFromList(list,month){
console.log(month)
console.log(list)
const beginning = getFirstDay(month); const beginning = getFirstDay(month);
const matrix = new Array(lastDateOfMonth(month)) const matrix = new Array(lastDateOfMonth(month))
for (let i = 0; i < matrix.length; i++) { for (let i = 0; i < matrix.length; i++) {
matrix[i] = []; matrix[i] = [];
} }
for(let key in list){ for(let key in list){
const temp = list[key]; const temp = list[key];