Manage course + delete course END
This commit is contained in:
parent
a9e5e45872
commit
c35f675a11
@ -1,14 +1,13 @@
|
||||
<script setup>
|
||||
import i18n from "@/i18n.js"
|
||||
import {ref} from 'vue'
|
||||
import {reactive , ref} from 'vue'
|
||||
import { getCourses,deleteCourse,alterCourse,createCourse } from "@/rest/courses.js"
|
||||
import {getUser, getSelf, getTeachers } from "@/rest/Users.js"
|
||||
|
||||
|
||||
const self = await getSelf();
|
||||
|
||||
let curriculum = await getCourses(self.role);
|
||||
|
||||
const curriculum = ref(await getCourses(self.role));
|
||||
const profList = await getTeachers();
|
||||
|
||||
console.log(curriculum)
|
||||
@ -34,7 +33,7 @@
|
||||
let toModify = Object.assign({},pattern);
|
||||
let toAdd = Object.assign({}, pattern);
|
||||
|
||||
function addToCourse(){
|
||||
async function addToCourse(){
|
||||
let isnull= false;
|
||||
|
||||
for(const [key, value] of Object.entries(toAdd)){
|
||||
@ -45,13 +44,13 @@
|
||||
|
||||
}
|
||||
if (!isnull){
|
||||
createCourse(toAdd.title,toAdd.credits,toAdd.owner);
|
||||
await createCourse(toAdd.title,toAdd.credits,toAdd.owner);
|
||||
toAdd= Object.assign({},pattern);
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, "250");
|
||||
}
|
||||
}
|
||||
|
||||
curriculum.value = await getCourses(self.role);
|
||||
|
||||
|
||||
}}
|
||||
|
||||
function setModify(item){
|
||||
for(const el in profList){
|
||||
@ -65,34 +64,35 @@
|
||||
}
|
||||
|
||||
|
||||
function patchCourse(course){
|
||||
async function patchCourse(course){
|
||||
for (let element in toModify){
|
||||
console.log(toModify,1)
|
||||
console.log(toModify[element],2)
|
||||
|
||||
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)){
|
||||
alterCourse(course.courseId,{title:toModify[element]});
|
||||
await alterCourse(course.courseId,{title:toModify[element]});
|
||||
}
|
||||
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
|
||||
let toRemove;
|
||||
let toRemove = null;
|
||||
|
||||
function removeCourse(course) {
|
||||
deleteCourse(course.id)
|
||||
async function removeCourse(course) {
|
||||
|
||||
await deleteCourse(course.courseId)
|
||||
curriculum.value = await getCourses(self.role);
|
||||
toRemove = null;
|
||||
}
|
||||
|
||||
</script>
|
||||
@ -131,18 +131,10 @@
|
||||
<div style="margin-bottom:20px;">
|
||||
{{i18n("courses.toDelete")}} :
|
||||
<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>
|
||||
</div>
|
||||
<div style="margin-bottom:20px;">
|
||||
{{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>
|
||||
</form>
|
||||
|
@ -16,8 +16,8 @@ export async function restPostFile(endPoint, file){
|
||||
return await _rest(endPoint, {method: "POST", credentials: 'include', body: file, headers: headers });
|
||||
}
|
||||
|
||||
export async function restDelete(endPoint, data) {
|
||||
return await _rest(endPoint, {method: "DELETE", credentials: 'include', body: JSON.stringify(data)});
|
||||
export async function restDelete(endPoint) {
|
||||
return await _rest(endPoint, {method: "DELETE"});
|
||||
}
|
||||
|
||||
export async function restPatch(endPoint, data) {
|
||||
|
Loading…
Reference in New Issue
Block a user