1
0
forked from PGL/Clyde
Clyde/frontend/src/Apps/ManageCourses.vue

292 lines
7.6 KiB
Vue
Raw Normal View History

2024-03-12 11:10:14 +01:00
<script setup>
2024-03-14 21:27:03 +01:00
import i18n from "@/i18n.js"
2024-03-18 15:47:04 +01:00
import {reactive , ref} from 'vue'
2024-03-16 14:31:44 +01:00
import { getCourses,deleteCourse,alterCourse,createCourse } from "@/rest/courses.js"
import {getUser, getSelf, getTeachers } from "@/rest/Users.js"
2024-03-17 21:38:10 +01:00
const self = await getSelf();
2024-03-18 15:47:04 +01:00
const curriculum = ref(await getCourses(self.role));
2024-03-17 21:38:10 +01:00
const profList = await getTeachers();
2024-03-13 15:07:17 +01:00
2024-03-13 17:48:48 +01:00
const createMod = ref(false)
const deleteMod = ref(false)
const editElementID = ref("")
2024-03-13 17:48:48 +01:00
function editItem(id){
editElementID = id;
}
//Juste pour montrer le Create Mode
2024-03-17 21:38:10 +01:00
2024-03-13 15:07:17 +01:00
const pattern = {
2024-03-17 21:38:10 +01:00
"title":null,
"credits":null,
"owner":null,
}
2024-03-13 15:07:17 +01:00
2024-03-17 21:38:10 +01:00
let toModify = Object.assign({},pattern);
2024-03-13 15:07:17 +01:00
let toAdd = Object.assign({}, pattern);
2024-03-18 15:47:04 +01:00
async function addToCourse(){
2024-03-13 15:07:17 +01:00
let isnull= false;
2024-03-17 21:38:10 +01:00
2024-03-13 15:07:17 +01:00
for(const [key, value] of Object.entries(toAdd)){
2024-03-17 21:38:10 +01:00
console.log(toAdd.owner);
2024-03-13 15:07:17 +01:00
if(value === null){
isnull=true;
}
2024-03-17 21:38:10 +01:00
}
if (!isnull){
2024-03-18 15:47:04 +01:00
await createCourse(toAdd.title,toAdd.credits,toAdd.owner);
2024-03-17 21:38:10 +01:00
toAdd= Object.assign({},pattern);
2024-03-18 15:47:04 +01:00
curriculum.value = await getCourses(self.role);
}}
2024-03-13 17:48:48 +01:00
2024-03-17 21:38:10 +01:00
function setModify(item){
for(const el in profList){
2024-03-13 15:07:17 +01:00
2024-03-17 21:38:10 +01:00
if(profList[el].regNo === item.owner.regNo){
toModify.owner= profList[el];
}
}
toModify.credits= item.credits;
toModify.title= item.title;
}
2024-03-18 15:47:04 +01:00
async function patchCourse(course){
2024-03-17 21:38:10 +01:00
for (let element in toModify){
2024-03-18 14:51:27 +01:00
console.log(toModify,1)
console.log(toModify[element],2)
2024-03-17 21:38:10 +01:00
2024-03-18 14:51:27 +01:00
if (element =="owner" && (toModify[element].regNo != course.owner.regNo)){
2024-03-18 15:47:04 +01:00
await alterCourse(course.courseId,{owner:toModify[element].regNo});
2024-03-17 21:38:10 +01:00
}
else if(element == "title" && (toModify[element] != course.title)){
2024-03-18 15:47:04 +01:00
await alterCourse(course.courseId,{title:toModify[element]});
2024-03-17 21:38:10 +01:00
}
2024-03-18 14:51:27 +01:00
else if(element == "credits" && (parseInt(toModify[element]) != course.credits)){
2024-03-18 15:47:04 +01:00
await alterCourse(course.courseId,{credits:parseInt(toModify[element])});
2024-03-17 21:38:10 +01:00
}
2024-03-18 15:47:04 +01:00
}
toModify= Object.assign({},pattern);
curriculum.value = await getCourses(self.role);
2024-03-18 14:51:27 +01:00
2024-03-18 15:47:04 +01:00
2024-03-17 21:38:10 +01:00
}
2024-03-13 17:48:48 +01:00
//Juste pour montrer le Delete Mode
2024-03-18 15:47:04 +01:00
let toRemove = null;
async function removeCourse(course) {
await deleteCourse(course.courseId)
curriculum.value = await getCourses(self.role);
toRemove = null;
}
2024-03-13 15:07:17 +01:00
2024-03-12 11:10:14 +01:00
</script>
<template>
<div class="body">
2024-03-17 21:38:10 +01:00
<div v-if="!deleteMod && !createMod && (self.role !== 'Teacher')" class="listTitle buttonGrid">
2024-03-18 14:51:27 +01:00
<button class="create" @click="editElementID= '';createMod = true;">
2024-03-14 22:33:16 +01:00
{{i18n("courses.createCourse")}}
2024-03-13 15:07:17 +01:00
</button>
2024-03-13 17:48:48 +01:00
<button class="delete" @click="deleteMod=true" >
2024-03-14 22:33:16 +01:00
{{i18n("courses.deleteCourse")}}
2024-03-13 15:07:17 +01:00
</button>
</div>
<div v-if="createMod">
2024-03-23 23:56:24 +01:00
<form class="listElement" style="width:40%;margin-right:auto;margin-left:auto;">
2024-03-13 17:48:48 +01:00
<div style="margin-bottom:20px;">
2024-03-14 21:27:03 +01:00
{{i18n("name")}} :
2024-03-17 21:38:10 +01:00
<input v-model="toAdd.title">
2024-03-13 15:07:17 +01:00
</div>
2024-03-13 17:48:48 +01:00
<div style="margin-bottom:20px;">
2024-03-17 21:38:10 +01:00
{{i18n("Teacher")}} :
<select style="max-width:200px;" class="teacher" v-model="toAdd.owner">
2024-03-18 14:51:27 +01:00
<option v-for="item in profList" :value="item">{{item.lastName}}</option>
2024-03-13 15:07:17 +01:00
</select>
</div>
2024-03-13 17:48:48 +01:00
<div style="margin-bottom:20px;">
2024-03-17 21:38:10 +01:00
{{i18n("Credits")}} :
2024-03-13 15:07:17 +01:00
<input v-model="toAdd.credits">
</div>
2024-03-14 21:27:03 +01:00
<button class="create" @click="createMod=!createMod; addToCourse();"> {{i18n("courses.confirm")}} </button>
<button style="float:right;" @click="createMod=!createMod">{{i18n("courses.back")}}</button>
2024-03-13 17:48:48 +01:00
</form>
</div>
<div v-if="deleteMod">
2024-03-23 23:56:24 +01:00
<form class="listElement" style="width:40%;margin-right:auto;margin-left:auto;">
2024-03-13 17:48:48 +01:00
<div style="margin-bottom:20px;">
2024-03-14 21:27:03 +01:00
{{i18n("courses.toDelete")}} :
2024-03-13 17:48:48 +01:00
<select style="max-width:200px;" class="teacher" v-model="toRemove">
2024-03-18 15:47:04 +01:00
<option v-for="item in curriculum" :value='item'>{{item.title}}</option>
2024-03-13 17:48:48 +01:00
</select>
</div>
2024-03-18 15:47:04 +01:00
<button class="delete" @click="deleteMod=!deleteMod; removeCourse(toRemove);"> {{i18n("courses.deleteCourse")}} </button>
2024-03-14 21:27:03 +01:00
<button style="float:right;" @click="deleteMod=!deleteMod"> {{i18n("courses.back")}}</button>
2024-03-13 15:07:17 +01:00
</form>
</div>
2024-03-13 17:48:48 +01:00
2024-03-23 23:56:24 +01:00
<div v-if="!createMod && !deleteMod" v-for="item in curriculum" :key="item.title" style="width:50%;margin-left:auto; margin-right:auto;">
2024-03-17 21:38:10 +01:00
<div v-if="editElementID !== item.title" style ="padding:15px 15px 15px 15px;">
<button @click="editElementID = item.title; setModify(item); ">
2024-03-14 21:27:03 +01:00
{{i18n("courses.modify")}}
2024-03-17 21:38:10 +01:00
</button>
</div>
<div v-else>
<button @click="editElementID= '';patchCourse(item)"> {{i18n("courses.confirm")}} </button>
<button @click="editElementID= '';"> {{i18n("courses.back")}} </button>
2024-03-13 15:07:17 +01:00
</div>
2024-03-23 23:56:24 +01:00
<div class="listElement" >
2024-03-17 21:38:10 +01:00
<div class="containerElement" v-if="editElementID !== item.title" >
2024-03-13 15:07:17 +01:00
2024-03-17 21:38:10 +01:00
<div class="name"> {{item.title}} </div>
<div class="teacher">{{item.owner.lastName}}</div>
<div class="credits">{{i18n("Credits")}}:{{item.credits}}</div>
2024-03-12 11:10:14 +01:00
</div>
2024-03-13 15:07:17 +01:00
<div class="containerElement"v-else>
2024-03-17 21:38:10 +01:00
<input style="max-width:200px;" class="name" v-model="toModify.title">
<select v-if="self.role === 'Secretary'" style="max-width:200px;" class="teacher" v-model="toModify.owner">
2024-03-18 14:51:27 +01:00
<option v-for="(item,index) in profList" :value='item'>{{item.lastName}}</option>
2024-03-13 15:07:17 +01:00
</select>
2024-03-17 21:38:10 +01:00
<div v-else class="teacher">{{item.owner.lastName}}</div>
<input v-if="self.role==='Secretary'"style="max-width:100px;"class="credits" v-model="toModify.credits">
<div v-else class="credits">{{i18n("Credits")}}:{{item.credits}}</div>
2024-03-13 15:07:17 +01:00
</div>
</div>
2024-03-12 11:10:14 +01:00
</div>
</div>
</template>
<style scoped>
.body {
width:100%;
2024-03-23 23:56:24 +01:00
margin-top:3.5%;
2024-03-12 11:10:14 +01:00
}
2024-03-23 23:56:24 +01:00
.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;
}
2024-03-12 11:10:14 +01:00
.containerElement{
2024-03-23 23:56:24 +01:00
justify-content:center;
2024-03-12 11:10:14 +01:00
display:grid;
2024-03-23 23:56:24 +01:00
grid-template-columns:38.8% 38.8% 22.4%;
2024-03-12 11:10:14 +01:00
grid-template-areas:
"name teacher credits";
2024-03-23 23:56:24 +01:00
column-gap:10px; }
2024-03-12 11:10:14 +01:00
.name {
grid-area:name;
align-self:center;
}
.teacher{
grid-area:teacher;
align-self:center;
}
.credits{
grid-area:credits;
align-self:center;
}
.listElement{
2024-03-23 23:56:24 +01:00
min-width:625px;
2024-03-12 11:10:14 +01:00
border:2px solid black;
font-size:25px;
color:white;
padding:20px;
background-color:rgb(50,50,50);
border-radius:20px;
margin-bottom:10px;
2024-03-23 23:56:24 +01:00
2024-03-12 11:10:14 +01:00
}
2024-03-13 15:07:17 +01:00
.modify{
font-size:25px;
padding:10px 10px 10px 10px;
background-color: rgb(239,60,168);
cursor: pointer;
border:none;
border-radius:15px;
}
input, select{
2024-03-13 17:48:48 +01:00
padding:10px 10px 10px 10px;
2024-03-13 15:07:17 +01:00
font-size:25px;
cursor: pointer;
border:none;
border-radius:15px;
}
button{
font-size:15px;
height:50px;
width:100px;
border:none;
border-radius:20px;
}
.buttonGrid{
display:grid;
grid-template-columns: auto auto;
column-gap:50px;
grid-template-areas:
"create delete";
}
.create{
grid-area:create;
background-color:rgb(0,200,0);
}
.delete{
grid-area:delete;
background-color:rgb(200,0,0);
}
.listTitle{
2024-03-23 23:56:24 +01:00
min-width:380px;
2024-03-13 15:07:17 +01:00
display: flex;
justify-content: center;
align-items: center;
2024-03-23 23:56:24 +01:00
width:25%;
2024-03-13 15:07:17 +01:00
margin-left:auto;
margin-right:auto;
border:2px solid black;
font-size:25px;
color:white;
padding:20px;
background-color:rgb(50,50,50);
2024-03-23 23:56:24 +01:00
border-radius:20px;
margin-bottom:10px;
2024-03-13 15:07:17 +01:00
button:hover{
opacity:0.8;
}
}
2024-03-12 11:10:14 +01:00
</style>