Manage course + delete course END
All checks were successful
Build and test backend / Build-backend (pull_request) Successful in 2m3s
Build and test backend / Test-backend (pull_request) Successful in 1m57s
Build and test FrontEnd / Build-frontend (pull_request) Successful in 23s

This commit is contained in:
Wawilski 2024-03-18 15:47:04 +01:00
parent a9e5e45872
commit c35f675a11
2 changed files with 30 additions and 38 deletions

View File

@ -1,14 +1,13 @@
<script setup> <script setup>
import i18n from "@/i18n.js" import i18n from "@/i18n.js"
import {ref} from 'vue' import {reactive , ref} from 'vue'
import { getCourses,deleteCourse,alterCourse,createCourse } from "@/rest/courses.js" import { getCourses,deleteCourse,alterCourse,createCourse } from "@/rest/courses.js"
import {getUser, getSelf, getTeachers } from "@/rest/Users.js" import {getUser, getSelf, getTeachers } from "@/rest/Users.js"
const self = await getSelf(); const self = await getSelf();
let curriculum = await getCourses(self.role); const curriculum = ref(await getCourses(self.role));
const profList = await getTeachers(); const profList = await getTeachers();
console.log(curriculum) console.log(curriculum)
@ -34,7 +33,7 @@
let toModify = Object.assign({},pattern); let toModify = Object.assign({},pattern);
let toAdd = Object.assign({}, pattern); let toAdd = Object.assign({}, pattern);
function addToCourse(){ async function addToCourse(){
let isnull= false; let isnull= false;
for(const [key, value] of Object.entries(toAdd)){ for(const [key, value] of Object.entries(toAdd)){
@ -45,13 +44,13 @@
} }
if (!isnull){ if (!isnull){
createCourse(toAdd.title,toAdd.credits,toAdd.owner); await createCourse(toAdd.title,toAdd.credits,toAdd.owner);
toAdd= Object.assign({},pattern); toAdd= Object.assign({},pattern);
setTimeout(() => {
window.location.reload(); curriculum.value = await getCourses(self.role);
}, "250");
}
} }}
function setModify(item){ function setModify(item){
for(const el in profList){ for(const el in profList){
@ -65,35 +64,36 @@
} }
function patchCourse(course){ async function patchCourse(course){
for (let element in toModify){ for (let element in toModify){
console.log(toModify,1) console.log(toModify,1)
console.log(toModify[element],2) console.log(toModify[element],2)
if (element =="owner" && (toModify[element].regNo != course.owner.regNo)){ if (element =="owner" && (toModify[element].regNo != course.owner.regNo)){
alterCourse(course.courseId,{owner:toModify[element].regNo}); await alterCourse(course.courseId,{owner:toModify[element].regNo});
} }
else if(element == "title" && (toModify[element] != course.title)){ else if(element == "title" && (toModify[element] != course.title)){
alterCourse(course.courseId,{title:toModify[element]}); await alterCourse(course.courseId,{title:toModify[element]});
} }
else if(element == "credits" && (parseInt(toModify[element]) != course.credits)){ else if(element == "credits" && (parseInt(toModify[element]) != course.credits)){
alterCourse(course.courseId,{credits:parseInt(toModify[element])}); await alterCourse(course.courseId,{credits:parseInt(toModify[element])});
} }
}
toModify= Object.assign({},pattern);
curriculum.value = await getCourses(self.role);
}toModify = Object.assign({},pattern);
setTimeout(() => {
window.location.reload();
}, "500");
} }
//Juste pour montrer le Delete Mode //Juste pour montrer le Delete Mode
let toRemove; let toRemove = null;
function removeCourse(course) { async function removeCourse(course) {
deleteCourse(course.id)
} await deleteCourse(course.courseId)
curriculum.value = await getCourses(self.role);
toRemove = null;
}
</script> </script>
<template> <template>
@ -131,19 +131,11 @@
<div style="margin-bottom:20px;"> <div style="margin-bottom:20px;">
{{i18n("courses.toDelete")}} : {{i18n("courses.toDelete")}} :
<select style="max-width:200px;" class="teacher" v-model="toRemove"> <select style="max-width:200px;" class="teacher" v-model="toRemove">
<option v-for="item in curriculum">{{item.title}}</option> <option v-for="item in curriculum" :value='item'>{{item.title}}</option>
</select> </select>
</div> </div>
<div style="margin-bottom:20px;"> <button class="delete" @click="deleteMod=!deleteMod; removeCourse(toRemove);"> {{i18n("courses.deleteCourse")}} </button>
{{i18n("login.password")}}:
<input >
</div>
<div style="margin-bottom:20px;">
{{i18n("login.cPassword")}} :
<input>
</div>
<button class="delete" @click="deleteMod=!deleteMod;removeCourse(toRemove);"> {{i18n("courses.deleteCourse")}} </button>
<button style="float:right;" @click="deleteMod=!deleteMod"> {{i18n("courses.back")}}</button> <button style="float:right;" @click="deleteMod=!deleteMod"> {{i18n("courses.back")}}</button>
</form> </form>
</div> </div>

View File

@ -16,8 +16,8 @@ export async function restPostFile(endPoint, file){
return await _rest(endPoint, {method: "POST", credentials: 'include', body: file, headers: headers }); return await _rest(endPoint, {method: "POST", credentials: 'include', body: file, headers: headers });
} }
export async function restDelete(endPoint, data) { export async function restDelete(endPoint) {
return await _rest(endPoint, {method: "DELETE", credentials: 'include', body: JSON.stringify(data)}); return await _rest(endPoint, {method: "DELETE"});
} }
export async function restPatch(endPoint, data) { export async function restPatch(endPoint, data) {