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

215 lines
5.2 KiB
Vue
Raw Normal View History

2024-04-05 08:57:19 +02:00
<!----------------------------------------------------
File: Forums.vue
Author: Anthony Debucquoy
Scope: Extension messagerie
Description: Forum des étudiants
----------------------------------------------------->
<script setup>
import { ref, reactive } from 'vue'
2024-04-13 16:05:01 +02:00
import i18n from '@/i18n.js'
2024-04-05 08:57:19 +02:00
import { getCourses } from '@/rest/courses.js'
2024-04-09 17:27:26 +02:00
import { ForumsOfCurrentCourse, getForumsOfCourse, createForum } from '@/rest/forum.js'
2024-04-09 23:41:24 +02:00
import { PostsOfCurrentForum, getPostsOfForum, createPost } from '@/rest/forum.js'
import { fetchedPost, fetchPost, sendAnswer } from '@/rest/forum.js'
2024-04-09 17:27:26 +02:00
import { getSelf } from '@/rest/Users.js'
2024-04-05 08:57:19 +02:00
const courses = await reactive(getCourses());
const selectedCourse = ref();
const selectedForum = ref();
2024-04-09 17:27:26 +02:00
const Role = (await getSelf()).role;
const addForumName = ref("");
2024-04-09 23:41:24 +02:00
const addPost = ref(false);
const addPostSubject = ref("");
const addPostContent = ref("");
2024-04-05 08:57:19 +02:00
</script>
<template>
<div id="app">
<div id="ForumSelector">
<select id="cours" value="" v-model="selectedCourse" @change="getForumsOfCourse(selectedCourse)">
<option v-for="course in courses" :value="course.courseId">{{course.title}}</option>
</select>
2024-04-13 15:56:43 +02:00
<select id="forum" value="" v-model="selectedForum" @change="getPostsOfForum(selectedForum !== 'create' ? selectedForum : null)" v-if="ForumsOfCurrentCourse != null">
2024-04-05 08:57:19 +02:00
<option v-for="forum in ForumsOfCurrentCourse" :value=forum.id>{{forum.name}}</option>
2024-04-13 16:05:01 +02:00
<option v-if="(Role === 'Admin' || Role === 'Teacher') && ForumsOfCurrentCourse != null" value="create">{{ i18n("forum.create") }}</option>
2024-04-05 08:57:19 +02:00
</select>
</div>
<div id="PostSelector" v-if="PostsOfCurrentForum != null">
2024-04-09 23:41:24 +02:00
<div @click="fetchPost(post.id)" class="postItem" v-for="post in PostsOfCurrentForum" :key="post.id">{{ post.subject }}</div>
<button v-if="Role === 'Admin' || Role === 'Teacher' " id="createPost" @click="addPost = true">+</button>
2024-04-05 08:57:19 +02:00
</div>
<div id="PostViewer" v-if="fetchedPost != null">
<div id="Post">
<h1>{{ fetchedPost.subject }}</h1>
{{fetchedPost.content}}
</div>
<div id="Messages">
2024-04-09 23:41:24 +02:00
<p v-for="msg in fetchedPost.answers">{{msg.author.firtName}} {{msg.author.lastName}} - {{msg.content}}</p>
2024-04-13 15:56:43 +02:00
<input v-if=!fetchedPost.locked type="text" placeholder="response" @keyup.enter="sendAnswer(fetchedPost.id, $event.target.value); $event.target.value = ''"/>
2024-04-05 08:57:19 +02:00
</div>
</div>
</div>
2024-04-13 15:56:43 +02:00
<div class=popup v-if="selectedForum === 'create' || addPost" @click.self="selectedForum = ''; addPost = false" >
2024-04-09 23:41:24 +02:00
<!-- Popup to add forum -->
2024-04-13 15:56:43 +02:00
<div id="addForumForm" v-if="selectedForum === 'create'" @keyup.enter="createForum(selectedCourse, addForumName); selectedForum = '';">
2024-04-13 16:05:01 +02:00
<label>{{ i18n("forum.create.name") }}</label>
2024-04-09 23:41:24 +02:00
<input type="text" placeholder="Name" v-model=addForumName />
</div>
<!-- Popup to add Post -->
<div id="addPostForm" v-if=addPost>
2024-04-13 16:05:01 +02:00
<label>i18n("forum.post.create.name")</label>
2024-04-13 15:56:43 +02:00
<input type="text" placeholder="subject" v-model=addPostSubject @keyup.enter="createPost(selectedForum, addPostSubject, addPostContent); addPost = false;"/>
2024-04-09 23:41:24 +02:00
<textarea v-model="addPostContent" placeholder=content></textarea>
2024-04-13 15:56:43 +02:00
<input type="submit" value="send" @click="createPost(selectedForum, addPostSubject, addPostContent); addPost = false;">
2024-04-09 17:27:26 +02:00
</div>
2024-04-09 23:41:24 +02:00
2024-04-09 17:27:26 +02:00
</div>
2024-04-05 08:57:19 +02:00
</template>
<style scoped>
2024-04-09 23:41:24 +02:00
.popup{
2024-04-09 17:27:26 +02:00
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background-color: #00000022;
z-index: 9;
}
#addForumForm{
position: relative;
width: 30%;
left: calc(50% - 30% / 2);
top: calc(50% - 10% / 2);
border-radius: 10px;
height: 10%;
background-color: white;
display: flex;
justify-content: center;
align-items: center;
gap: 10px;
}
2024-04-09 23:41:24 +02:00
#addPostForm{
position: relative;
width: 30%;
left: calc(50% - 30% / 2);
top: calc(50% - 50% / 2);
border-radius: 10px;
height: 50%;
background-color: white;
display: flex;
justify-content: center;
align-items: center;
gap: 10px;
}
2024-04-05 08:57:19 +02:00
#app{
display: grid;
width: 100%;
height: 100%;
grid-template: 5em auto / 25% 75%;
}
#ForumSelector{
background-color: #FFFFFF0E;
grid-column: 1 / 3;
border-radius: 100px;
margin: 10px;
display: flex;
justify-content: space-around;
}
#ForumSelector select{
background-color: #ffa000;
border: none;
margin: 10px;
border-radius: 10px;
width: 200px;
text-align: center;
}
2024-04-13 15:56:43 +02:00
#PostSelector button{
2024-04-05 08:57:19 +02:00
background-color: green;
2024-04-13 15:56:43 +02:00
color: white;
2024-04-05 08:57:19 +02:00
border: none;
2024-04-13 15:56:43 +02:00
height: 4vh;
margin: 5px;
border-radius: 0 30px 30px 0;
align-items: center;
justify-content: center;
2024-04-05 08:57:19 +02:00
}
#PostSelector{
background-color: #FFFFFF0E;
border-radius: 0 25px 25px 0;
margin: 10px 0 10px 10px;
overflow: hidden;
padding: 10px;
display: flex;
flex-direction: column;
}
.postItem{
color: darkorange;
display: flex;
font-family: sans-serif;
font-weight: bold;
height: 4vh;
margin: 5px;
border-radius: 0 30px 30px 0;
align-items: center;
justify-content: center;
border: 1px solid darkorange;
}
.postItem:hover{
background-color: gray;
}
#PostViewer{
background-color: #FFFFFF0E;
border-radius: 25px;
margin: 10px;
max-height: 100%;
overflow: scroll;
}
#Post{
padding: 25px;
2024-04-13 15:56:43 +02:00
color: white;
}
2024-04-05 08:57:19 +02:00
2024-04-13 15:56:43 +02:00
#Post > h1{
text-align: center;
text-decoration: underline;
2024-04-05 08:57:19 +02:00
}
#Messages{
padding: 25px;
border-top: 3px dotted white;
}
#Messages > p {
background-color: orange;
}
</style>