change schedule Curriculum and own schedule
This commit is contained in:
		@ -44,8 +44,10 @@ public class LessonController {
 | 
			
		||||
 | 
			
		||||
    @GetMapping("/lessons/owned")
 | 
			
		||||
    public ResponseEntity<Iterable<HashMap<String,Object>>> getOwnedLessons(@RequestHeader("Authorization") String token){
 | 
			
		||||
        if (authServ.isNotIn(new Role[]{Role.Admin,Role.Teacher},token))
 | 
			
		||||
            return new UnauthorizedResponse<>(null);
 | 
			
		||||
        System.out.println(authServ);
 | 
			
		||||
        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);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -8,6 +8,8 @@ import ovh.herisson.Clyde.Services.AuthenticatorService;
 | 
			
		||||
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;
 | 
			
		||||
 | 
			
		||||
@ -20,15 +22,18 @@ public class ScheduleController {
 | 
			
		||||
    private final ScheduleService scheduleServ;
 | 
			
		||||
 | 
			
		||||
    private final UserCurriculumService userCurriculumService;
 | 
			
		||||
    
 | 
			
		||||
    private final CurriculumService curriculumServ;
 | 
			
		||||
    private final AuthenticatorService authServ;
 | 
			
		||||
 | 
			
		||||
    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.userCurriculumService = userCurriculumService;
 | 
			
		||||
        this.authServ = authServ;
 | 
			
		||||
        this.scheduleLessonServ = scheduleLessonServ;
 | 
			
		||||
        this.curriculumServ = curriculumServ;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @GetMapping("/schedule/{id}")
 | 
			
		||||
@ -50,6 +55,14 @@ public class ScheduleController {
 | 
			
		||||
            return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
 | 
			
		||||
        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")
 | 
			
		||||
    public ResponseEntity<Iterable<Map<String , Object>>> findAllSchedule(){
 | 
			
		||||
 | 
			
		||||
@ -2,13 +2,13 @@ package ovh.herisson.Clyde.Repositories;
 | 
			
		||||
 | 
			
		||||
import org.springframework.data.jpa.repository.Query;
 | 
			
		||||
import org.springframework.data.repository.CrudRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Course;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Lesson;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.User;
 | 
			
		||||
 | 
			
		||||
public interface LessonRepository extends CrudRepository<Lesson, Long> {
 | 
			
		||||
 | 
			
		||||
    Lesson findById(long id);
 | 
			
		||||
 | 
			
		||||
    @Query("select l from Lesson l where l.course.owner = ?1")
 | 
			
		||||
    Iterable<Lesson> findAllOwnedLesson(User teacher);
 | 
			
		||||
    @Query("select l from Lesson l where l.course = ?1")
 | 
			
		||||
    Iterable<Lesson> findLessonByCourse(Course course);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,17 +1,23 @@
 | 
			
		||||
package ovh.herisson.Clyde.Services;
 | 
			
		||||
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
import ovh.herisson.Clyde.Repositories.CourseRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Repositories.LessonRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Course;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Lesson;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Role;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.User;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
@Service
 | 
			
		||||
public class LessonService {
 | 
			
		||||
    private final LessonRepository lessonRepo;
 | 
			
		||||
    public LessonService(LessonRepository lessonRepo){
 | 
			
		||||
    private final CourseRepository courseRepo;
 | 
			
		||||
    public LessonService(LessonRepository lessonRepo, CourseRepository courseRepo){
 | 
			
		||||
        this.lessonRepo = lessonRepo;
 | 
			
		||||
        this.courseRepo = courseRepo;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Lesson save(Lesson lesson){
 | 
			
		||||
@ -23,7 +29,13 @@ public class LessonService {
 | 
			
		||||
    public Iterable<Lesson> findAll(){return lessonRepo.findAll();}
 | 
			
		||||
 | 
			
		||||
    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){
 | 
			
		||||
 | 
			
		||||
@ -1,12 +1,49 @@
 | 
			
		||||
<script setup>
 | 
			
		||||
  import { ref } from 'vue'
 | 
			
		||||
  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 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)
 | 
			
		||||
 | 
			
		||||
  const allSchedule = await getAllSchedule();
 | 
			
		||||
  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")
 | 
			
		||||
@ -14,7 +51,7 @@
 | 
			
		||||
  const days = ["Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi","Dimanche"];
 | 
			
		||||
  const months = ["Janvier","Fevrier","Mars","Avril",'Mai',"Juin","Juillet","Aout","Septembre","Octobre","Novembre","Decembre"]
 | 
			
		||||
  const firstDayOfMonth = ref(getFirstDay(new Date()))
 | 
			
		||||
  
 | 
			
		||||
  const monthDone = ref(false);
 | 
			
		||||
  function getMonday(d) {
 | 
			
		||||
    d = new Date(d);
 | 
			
		||||
    d.setHours(0,0,0);
 | 
			
		||||
@ -28,10 +65,13 @@
 | 
			
		||||
    day.setDate(day.getDate() + d );
 | 
			
		||||
    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){
 | 
			
		||||
    return element==null;
 | 
			
		||||
  }
 | 
			
		||||
@ -41,42 +81,67 @@
 | 
			
		||||
    const hour = element.lessonEnd.substring(3,5) -element.lessonStart.substring(3,5);
 | 
			
		||||
    return (element.lessonEnd - element.lessonStart)%2;
 | 
			
		||||
  }
 | 
			
		||||
  const scheduleByWeek = ref(sundayToTheEnd(matrixFromList(schedule.value,mondayOfWeek.value)));
 | 
			
		||||
  const month = ref(monthFromList(schedule.value,new Date().getMonth()));
 | 
			
		||||
  const shift = ref(getFirstDay(new Date()).getDay());
 | 
			
		||||
  let value = 1;
 | 
			
		||||
  const len = ref(lastDateOfMonth(new Date()));
 | 
			
		||||
  
 | 
			
		||||
  function displayOwnSchedule(){
 | 
			
		||||
    schedule.value = ownSchedule.value;
 | 
			
		||||
    scheduleByWeek.value = sundayToTheEnd(matrixFromList(schedule.value,mondayOfWeek.value));
 | 
			
		||||
      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){
 | 
			
		||||
    const temp = getAnyDays(i);
 | 
			
		||||
    mondayOfWeek.value = temp;
 | 
			
		||||
    scheduleByWeek.value = sundayToTheEnd(matrixFromList(schedule.value, mondayOfWeek.value))
 | 
			
		||||
    if(scheduleByWeek.value != null)
 | 
			
		||||
      scheduleByWeek.value = sundayToTheEnd(matrixFromList(schedule.value, mondayOfWeek.value))
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  function changeMonth(i){
 | 
			
		||||
    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);
 | 
			
		||||
    month.value = monthFromList(schedule.value,currentDate.value.getMonth())
 | 
			
		||||
    shift.value= getFirstDay(currentDate.value).getDay();
 | 
			
		||||
    len.value= lastDateOfMonth(currentDate.value);
 | 
			
		||||
    value = 1;
 | 
			
		||||
    counter = 0;
 | 
			
		||||
    if(month.value != null){
 | 
			
		||||
      month.value = monthFromList(schedule.value,currentDate.value.getMonth())}
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  function isAValue(){
 | 
			
		||||
    if(value-shift.value<0){
 | 
			
		||||
    if(value-shift.value<0 ){
 | 
			
		||||
      counter++;
 | 
			
		||||
      value++;
 | 
			
		||||
      return false
 | 
			
		||||
      return false;
 | 
			
		||||
    }
 | 
			
		||||
    if(value-shift.value<len.value){
 | 
			
		||||
      value++;
 | 
			
		||||
      counter++;
 | 
			
		||||
      return true;}
 | 
			
		||||
    
 | 
			
		||||
    if(value-shift.value>=len.value){
 | 
			
		||||
      return false
 | 
			
		||||
    if(value-shift.value==len.value){
 | 
			
		||||
      counter++;
 | 
			
		||||
      
 | 
			
		||||
      if(counter> 35){
 | 
			
		||||
        counter=1;
 | 
			
		||||
        value = 2;
 | 
			
		||||
        return true; }
 | 
			
		||||
      return false;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
</script>
 | 
			
		||||
<template>
 | 
			
		||||
  <div class="grid">
 | 
			
		||||
@ -87,7 +152,8 @@
 | 
			
		||||
          <th>
 | 
			
		||||
            <button @click="changeWeek(-7)">Previous</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 class="header" v-for='d,index in 7' >
 | 
			
		||||
@ -105,8 +171,8 @@
 | 
			
		||||
          <th class="hour">{{8 + index}}:00-{{9+index}}:00</th>
 | 
			
		||||
            <td v-for="m in 7"></td>
 | 
			
		||||
        </tr>
 | 
			
		||||
      </table>
 | 
			
		||||
      <div class="courseGrid">
 | 
			
		||||
        </table>
 | 
			
		||||
      <div v-if="scheduleByWeek != null " class="courseGrid">
 | 
			
		||||
        <div class="dayCourse" v-for="element in scheduleByWeek">
 | 
			
		||||
          <template v-for="i,index in element.length">
 | 
			
		||||
            <div class="course" v-bind:style="{background:element[index].color,
 | 
			
		||||
@ -147,14 +213,8 @@
 | 
			
		||||
          </tr>
 | 
			
		||||
          <tr v-for="n in 5" style="height:16.67%;">
 | 
			
		||||
            <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 style="overflow-y:scroll; height:100%;" >
 | 
			
		||||
              <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%;" >
 | 
			
		||||
              <template v-for="element in month[value-shift]">
 | 
			
		||||
              <div class="course" v-bind:style="{background:element.color, height:100+'%'}">
 | 
			
		||||
                  
 | 
			
		||||
@ -173,8 +233,7 @@
 | 
			
		||||
              </template>
 | 
			
		||||
              </div>
 | 
			
		||||
            </td>
 | 
			
		||||
        </tr>
 | 
			
		||||
 | 
			
		||||
        </tr> 
 | 
			
		||||
 | 
			
		||||
        </table>
 | 
			
		||||
      </template>
 | 
			
		||||
@ -186,6 +245,11 @@
 | 
			
		||||
    <div class="options">
 | 
			
		||||
      <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="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>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
@ -39,13 +39,14 @@ export async function getLesson(id){
 | 
			
		||||
 * - teacher
 | 
			
		||||
 * - Assistants
 | 
			
		||||
 */
 | 
			
		||||
export async function getLessons(role){
 | 
			
		||||
    if(role==="Teacher"){
 | 
			
		||||
        return restGet("/lessons/owned")
 | 
			
		||||
    }
 | 
			
		||||
export async function getLessons(){
 | 
			
		||||
    return restGet("/lessons")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export async function getOwnedLessons(){
 | 
			
		||||
  return restGet("/lessons/owned")
 | 
			
		||||
  
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Change the options of a course
 | 
			
		||||
 | 
			
		||||
@ -11,3 +11,7 @@ export async function getOwnSchedule(){
 | 
			
		||||
export async function createSchedule(curriculum) {
 | 
			
		||||
    return restPost('/schedule',{curriculum : curriculum})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export async function getCurriculumSchedule(id){
 | 
			
		||||
  return restGet('/schedule/curriculum/' + id)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -67,11 +67,12 @@
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  export function monthFromList(list,month){
 | 
			
		||||
    console.log(month)
 | 
			
		||||
    console.log(list)
 | 
			
		||||
    const beginning = getFirstDay(month);
 | 
			
		||||
    const matrix = new Array(lastDateOfMonth(month))
 | 
			
		||||
    for (let i = 0; i < matrix.length; i++) {
 | 
			
		||||
      matrix[i] = [];
 | 
			
		||||
      
 | 
			
		||||
    }
 | 
			
		||||
    for(let key in list){
 | 
			
		||||
      const temp = list[key];
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user