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

303 lines
7.6 KiB
Vue
Raw Normal View History

2024-03-09 22:48:33 +01:00
<script setup>
2024-03-15 15:12:01 +01:00
import {reactive, ref } from 'vue'
2024-03-18 17:28:14 +01:00
import {getSelf,alterSelf,disconnect,deleteUser} from '../rest/Users.js'
import {getSelfCurriculum, getAllCurriculums} from '../rest/curriculum.js'
import {getCourses} from "../rest/courses.js"
2024-03-14 21:27:03 +01:00
import i18n from "@/i18n.js"
2024-03-15 15:12:01 +01:00
import { uploadProfilePicture } from '@/rest/uploads.js'
2024-03-18 17:28:14 +01:00
2024-03-16 15:06:21 +01:00
const user = await getSelf();
2024-03-16 17:01:26 +01:00
console.log(user);
2024-03-18 17:28:14 +01:00
const UserCurriculum = ref("");
const curricula = ref (await getAllCurriculums());
console.log(curricula)
console.log(user.role === "Teacher")
if(user.role === "Student"){
UserCurriculum.value = await getSelfCurriculum();
}
2024-03-16 17:01:26 +01:00
2024-03-18 17:28:14 +01:00
if(user.role === "Teacher"){
UserCurriculum.value = await getCourses("Teacher");
console.log(UserCurriculum.value)
}
2024-03-16 17:01:26 +01:00
const modif = ref(false);
const curric = ref(false);
const reg = ref(false);
2024-03-09 22:48:33 +01:00
2024-03-16 19:54:42 +01:00
const pattern = {
2024-03-16 17:01:26 +01:00
profilPictureUrl:null,
email:null,
adress:null,
password:null,
};
2024-03-16 19:54:42 +01:00
const patternInfos ={
email: null,
password: null,
passwordConfirm:null,
id:null,
}
2024-03-09 22:48:33 +01:00
2024-03-16 19:54:42 +01:00
let toModify= Object.assign({}, pattern);
let personnalInfos = Object.assign({}, patternInfos);
function resetInputs(inputs,list){
inputs=Object.assign({},list);
}
2024-03-16 17:01:26 +01:00
function ChangeInfos(){
for (const [key, value] in Object.entries(toModify)){
if(value !== null){
2024-03-16 19:54:42 +01:00
alterSelf({key:value});
2024-03-16 17:01:26 +01:00
}
}
2024-03-16 19:54:42 +01:00
toModify= Object.assign({}, pattern);
2024-03-16 17:01:26 +01:00
}
2024-03-18 17:28:14 +01:00
async function unRegister(){
await deleteUser(user.regNo);
}
2024-03-16 17:01:26 +01:00
function getPP(){
2024-03-18 17:28:14 +01:00
if(user.profilePictureUrl === null){
return "/Clyde.png"
}
2024-03-16 17:01:26 +01:00
return user.profilePictureUrl
}
</script>
2024-03-09 22:48:33 +01:00
<template>
<div class="body">
<div class="container">
<div class="profilPic">
2024-03-15 15:12:01 +01:00
<img class="subContainter" :src=getPP()>
2024-03-09 22:48:33 +01:00
</div>
<div class="globalInfos">
2024-03-18 17:28:14 +01:00
<div v-if="modif==false && curric==false && reg==false " class="infosContainer" >
2024-03-10 12:34:44 +01:00
<div>
2024-03-16 14:31:44 +01:00
{{user.firstName}} {{user.lastName}}
2024-03-09 22:48:33 +01:00
</div>
<div>
2024-03-10 16:01:47 +01:00
E-mail: {{user.email}}
</div>
2024-03-16 15:06:21 +01:00
<div v-if="user.role==='Student'">
2024-03-18 17:28:14 +01:00
{{user.option}} {{i18n(user.role)}}
2024-03-10 16:01:47 +01:00
</div>
<div v-else>
2024-03-18 17:28:14 +01:00
Role: {{i18n((user.role))}}
2024-03-09 22:48:33 +01:00
</div>
<div>
2024-03-14 21:27:03 +01:00
<button @click="modif=!modif"> {{i18n("profile.modify.data")}} </button>
2024-03-10 16:01:47 +01:00
</div>
2024-03-16 15:06:21 +01:00
<div v-if="(user.role==='Student')">
2024-03-15 22:47:40 +01:00
<button @click="reg=!reg">{{i18n("profile.reRegister")}}</button>
2024-03-18 17:28:14 +01:00
<button @click="unRegister()" style="float:right;background-color:rgb(150,0,0);">{{i18n("profile.unRegister")}}</button>
2024-03-16 17:01:26 +01:00
</div>
<div v-if="(user.role==='Student')">
2024-03-15 22:47:40 +01:00
<button @click="curric=!curric">{{i18n("profile.change.curriculum")}}</button>
2024-03-15 20:23:33 +01:00
</div>
2024-03-09 22:48:33 +01:00
</div>
2024-03-16 17:01:26 +01:00
<div v-else-if="modif" class="infosContainer">
2024-03-11 21:24:40 +01:00
<div>
2024-03-14 21:27:03 +01:00
{{i18n("profile.picture")}}:
2024-03-15 15:12:01 +01:00
<input type="file" @change="user.profilPicture = uploadProfilePicture($event.target.files);" accept="image/*">
2024-03-11 21:24:40 +01:00
</div>
<div>
E-mail:
2024-03-16 19:54:42 +01:00
<input type="mail" v-model="personnalInfos.email" />
2024-03-11 21:24:40 +01:00
</div>
<div>
2024-03-14 21:27:03 +01:00
{{i18n("profile.address")}}:
2024-03-16 19:54:42 +01:00
<input type="text" v-model="personnalInfos.id">
2024-03-11 21:24:40 +01:00
</div>
<div>
2024-03-14 21:27:03 +01:00
{{i18n("login.password")}}:
2024-03-16 19:54:42 +01:00
<input type="password" v-model="personnalInfos.password">
2024-03-11 21:24:40 +01:00
</div>
<div>
2024-03-14 21:27:03 +01:00
{{i18n("login.cPassword")}}:
2024-03-16 19:54:42 +01:00
<input type="password" v-model="personnalInfos.passwordConfirm">
2024-03-11 21:24:40 +01:00
</div>
<div>
2024-03-16 17:01:26 +01:00
<button @click=" modif=!modif; ChangeInfos();">{{i18n("courses.confirm")}}</button>
2024-03-16 19:54:42 +01:00
<button @click="modif=!modif; resetInputs(toModify,pattern);console.log(pattern)" style="float:right;">{{i18n("courses.back")}}</button>
2024-03-16 17:01:26 +01:00
</div>
</div>
<div v-else-if="curric" class="infosContainer">
2024-03-18 17:28:14 +01:00
<div style="height:40px;">
{{i18n("Curriculum")}}:
<select v-model="curriculum" >
<option v-for="item in curricula" style="font-size:20px;" :value="item">{{item.option}}</option>
2024-03-16 17:01:26 +01:00
</select>
</div>
<div>
<button @click=" curric=!curric;">{{i18n("courses.confirm")}}</button>
2024-03-18 17:28:14 +01:00
<button @click="curric=!curric; resetInputs(personnalInfos,patternInfos);" style="float:right;">{{i18n("courses.back")}}</button>
2024-03-16 17:01:26 +01:00
</div>
</div>
<div v-else-if="reg" class="infosContainer">
<div>
E-mail:
<input type="mail" v-model="toModify.email" />
</div>
<div>
2024-03-16 19:54:42 +01:00
ID :
<input type="text" v-model="toModify.id">
2024-03-16 17:01:26 +01:00
</div>
<div>
{{i18n("login.password")}}:
<input type="password" v-model="toModify.password">
</div>
<div>
{{i18n("login.cPassword")}}:
<input type="password" id="confirm">
</div>
<div>
<button @click=" reg=!reg;">{{i18n("courses.confirm")}}</button>
2024-03-16 19:54:42 +01:00
<button @click=" reg=!reg; resetInputs(personnalInfos,patternInfos);console.log(pattern)" style="float:right;">{{i18n("courses.back")}}</button>
2024-03-16 17:01:26 +01:00
</div>
</div>
2024-03-09 22:48:33 +01:00
</div>
2024-03-16 17:01:26 +01:00
2024-03-18 17:28:14 +01:00
<div v-if="modif==false && curric==false && reg==false "class="moreInfos">
2024-03-10 16:01:47 +01:00
2024-03-18 17:28:14 +01:00
<div v-if="(user.role ==='Student')">
2024-03-10 16:01:47 +01:00
<div class="listTitle">
2024-03-14 21:27:03 +01:00
{{i18n("profile.course.list")}}
2024-03-10 12:34:44 +01:00
</div>
2024-03-18 17:28:14 +01:00
<div class="listElement" v-for="item in UserCurriculum.courses">
2024-03-10 16:01:47 +01:00
<div class=" containerElement">
2024-03-18 17:28:14 +01:00
<div class="name"> {{item.title}} </div>
<div class="teacher">{{item.owner.lastName}}</div>
2024-03-10 16:01:47 +01:00
<div class="credits">Credits:{{item.credits}}</div>
</div>
2024-03-10 12:34:44 +01:00
</div>
</div>
2024-03-10 16:01:47 +01:00
<div>
</div>
2024-03-09 22:48:33 +01:00
</div>
</div>
</div>
</template>
<style scoped>
.container{
display:grid;
grid-template-columns:200px 900px;
grid-template-rows:200px auto;
column-gap:30px;
2024-03-15 20:23:33 +01:00
row-gap:45px;
2024-03-09 22:48:33 +01:00
grid-template-areas:
"profilPic globalInfos"
"minfos minfos";
}
.profilPic{
grid-area:profilPic;
}
.globalInfos {
grid-area:globalInfos;
align-self :center;
}
.subContainter{
width:100%;
background-color:rgb(50,50,50);
border-radius:20px;
border:4px solid black;
}
.moreInfos {
grid-area:minfos;
}
.body {
width:100%;
margin-bottom:10px;
}
2024-03-10 16:01:47 +01:00
.containerElement{
justify-content:center;
display:grid;
grid-template-columns:350px 350px 200px;
grid-template-areas:
"name teacher credits";
column-gap:10px;
}
.name {
grid-area:name;
align-self:center;
}
.teacher{
grid-area:teacher;
align-self:center;
}
.credits{
grid-area:credits;
align-self:center;
}
.listTitle{
display: flex;
justify-content: center;
align-items: center;
width:200px;
margin-left:auto;
margin-right:auto;
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-09 22:48:33 +01:00
2024-03-10 16:01:47 +01:00
.listElement{
border:2px solid black;
font-size:25px;
color:white;
padding:20px;
background-color:rgb(50,50,50);
border-radius:20px;
margin-bottom:10px;
}
.infosContainer {
padding-bottom:50px;
border:2px solid black;
font-size:25px;
color:white;
padding:20px;
background-color:rgb(50,50,50);
border-radius:20px;
}
button{
border:none;
background-color:rgb(239, 60, 168);
border-radius:10px;
height:35px;
margin-top:10px;
}
button:hover{
opacity:0.8;
}
2024-03-09 22:48:33 +01:00
</style>