Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion back-end/src/base/articles/articles.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class ArticlesService {
// add new object id to id
queryArticle._id = new ObjectId();

queryArticle.owner = new ObjectId(queryArticle.owner);
queryArticle.owner._id = new ObjectId(queryArticle.owner._id);
queryArticle.date = new Date(queryArticle.date);
queryArticle.updatedAt = new Date();

Expand Down
10 changes: 8 additions & 2 deletions front-end/src/components/blog/AddArticles.vue
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,16 @@ const addArticle = async () => {
return;
}

const owner = {
_id: authStore?.user?._id,
firstName: authStore?.user?.profile?.firstName,
lastName: authStore?.user?.profile?.lastName,
};

// Groups all data for sending to the API
if (type.value == 'Infos') {
let data = {
owner: authStore.user._id,
owner: owner,
title: title.value,
descriptions: description.value,
content: content.value,
Expand All @@ -286,7 +292,7 @@ const addArticle = async () => {
await articleStore.addArticle(data);
} else {
let data = {
owner: authStore.user._id,
owner: owner,
title: title.value,
descriptions: description.value,
content: content.value,
Expand Down
96 changes: 48 additions & 48 deletions front-end/src/components/blog/CardArticle.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<!-- eslint-disable vue/no-v-html -->
<template>
<div class="boxShadow w-full">
<div class="boxShadow w-96">
<img
class="object-cover h-48 w-96 rounded-t-lg"
class="object-cover h-48 w-full rounded-t-lg"
:src="
item.picture && item.picture != ''
? item.picture
: 'https://cdn.discordapp.com/attachments/894865078824890408/1073218625718198342/Fof04PpacAQePOW.png'
"
alt=""
/>
<div v-if="item.owner === user._id || user.role === 2" class="absolute top-2 left-2">
<div v-if="item.owner._id === user._id || user.role === 2" class="absolute top-2 left-2">
<button
type="button"
@click="deleteArticle(item._id)"
Expand All @@ -19,7 +19,7 @@
<DeleteLogo />
</button>
</div>
<div v-if="item.owner === user._id || user.role === 2" class="absolute top-2 right-2">
<div v-if="item.owner._id === user._id || user.role === 2" class="absolute top-2 right-2">
<button
type="button"
@click="editArticle(item._id)"
Expand All @@ -29,20 +29,46 @@
</button>
</div>
<div class="pt-3 pb-2" v-if="item.type == 'Tuto' && (user.role == 2 || user.role == 3)">
<span
v-if="item.status == 'Accepted'"
class="bg-green-100 text-green-800 text-xs font-medium mr-2 px-2.5 py-0.5 rounded dark:bg-green-900 dark:text-green-300"
>
Accepté
</span>
<span
v-else
class="bg-yellow-100 text-yellow-800 text-xs font-medium mr-2 px-2.5 py-0.5 rounded dark:bg-yellow-900 dark:text-yellow-300"
<div
v-if="item.status != 'Accepted'"
class="flex flex-row items-center justify-evenly space-x-2"
>
En attente
</span>
<button
@click="updateStatus(item._id, 'Accepted')"
class="text-green-700 border border-green-700 focus:ring-4 focus:outline-none font-small rounded-lg text-2xs p-1 text-center inline-flex items-center dark:text-green-500"
>
<Validate />
</button>

<span
class="bg-yellow-100 text-yellow-800 text-xs font-medium mr-2 px-2.5 py-0.5 rounded dark:bg-yellow-900 dark:text-yellow-300"
>
En attente
</span>

<button
@click="deleteArticle(item._id)"
class="text-red-700 border border-red-700 focus:ring-4 focus:outline-none font-small rounded-lg text-2xs p-1 text-center inline-flex items-center dark:text-red-500"
>
<Cross class="!fill-red-700" />
</button>
</div>
<div v-else class="flex flex-row items-center justify-evenly space-x-2">
<span
v-if="item.status == 'Accepted'"
class="bg-green-100 text-green-800 text-xs font-medium mr-2 px-2.5 py-0.5 rounded dark:bg-green-900 dark:text-green-300"
>
Accepté
</span>
<button
@click="updateStatus(item._id, 'Pending')"
class="text-yellow-400 border border-yellow-400 focus:ring-4 focus:outline-none font-small rounded-lg text-2xs p-1 text-center inline-flex items-center dark:text-yellow-500"
>
<Pause class="!fill-yellow-400" />
</button>
</div>
</div>
<div class="pt-3 pb-2" v-else>
<div class="pt-3.5 pb-3.5" v-else>
<span
class="bg-blue-100 text-blue-800 text-xs font-medium mr-2 px-2.5 py-0.5 rounded dark:bg-blue-900 dark:text-blue-300"
>
Expand All @@ -51,17 +77,21 @@
</div>
<div class="pt-2 pb-5">
<a href="#">
<h5 class="mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white">
<h5
:class="item.title.length > 40 && 'text-xl'"
class="mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white capitalize"
>
{{ item.title ? item.title : 'Pas de titre spécifié' }}
</h5>
</a>
<p
:class="item.descriptions.length > 60 && 'text-md'"
class="min-h-[5rem] flex flex-col justify-center items-center justify-center font-normal text-gray-700 dark:text-gray-400"
>
{{ item.descriptions ? item.descriptions : 'Pas de description spécifiée' }}
</p>
</div>
<div class="pt-2 pb-5 flex flex-row justify-around items-center">
<div class="pt-2 pb-5 flex flex-row justify-evenly items-center">
<button
type="button"
@click="addLike(item._id)"
Expand Down Expand Up @@ -117,36 +147,6 @@
</div>
</button>
</div>

<!-- Validation -->
<div
v-if="item.type == 'Tuto' && (user.role == 2 || user.role == 3)"
class="flex flex-row place-content-evenly mb-3 items-center text-dark-primary dark:text-light-primary"
>
<div class="flex flex-row space-x-2">
<button
v-if="item.status != 'Accepted'"
@click="updateStatus(item._id, 'Accepted')"
class="text-green-700 border border-green-700 focus:ring-4 focus:outline-none font-medium rounded-lg text-xs p-2 text-center inline-flex items-center dark:text-green-500"
>
<Validate />
</button>
<button
v-else
@click="updateStatus(item._id, 'Pending')"
class="text-yellow-400 border border-yellow-400 focus:ring-4 focus:outline-none font-medium rounded-lg text-xs p-2 text-center inline-flex items-center dark:text-yellow-500"
>
<Pause class="!fill-yellow-400" />
</button>
<button
v-if="item.status != 'Accepted'"
@click="deleteArticle(item._id)"
class="text-red-700 border border-red-700 focus:ring-4 focus:outline-none font-medium rounded-lg text-xs p-2 text-center inline-flex items-center dark:text-red-500"
>
<Cross class="!fill-red-700" />
</button>
</div>
</div>
</div>
</template>

Expand Down
8 changes: 7 additions & 1 deletion front-end/src/components/blog/EditArticle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,15 @@ const editArticle = async () => {
return;
}

const owner = {
_id: authStore.user._id,
firstName: authStore.user.profile.firstName,
lastName: authStore.user.profile.lastName,
};

// Groups all data for sending to the API
let data = {
owner: authStore.user._id,
owner: owner,
title: title.value,
descriptions: descriptions.value,
content: content.value,
Expand Down
20 changes: 11 additions & 9 deletions front-end/src/components/blog/MarkdownViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@
class="mt-12 block max-w-xl p-6 bg-white border border-gray-200 rounded-lg shadow dark:bg-gray-800 dark:border-gray-700"
>
<h2>{{ description }}</h2>
<p>Publié le : {{ formatDate(date)}}</p>
<p>Par : {{ user }}</p>
<p>Publié le : {{ formatDate(date) }}</p>
<p>Par : {{ user }}</p>
</div>
</div>

Expand Down Expand Up @@ -336,13 +336,15 @@ if (!props.markdown) {
date.value = oneItems.value.date;
title.value = oneItems.value.title;
description.value = oneItems.value.descriptions;
let tempUser = await materialStore.getUserById(oneItems.value.owner)
let tempUser = await materialStore.getUserById(oneItems.value.owner._id);

// format for captital letters
user.value =
tempUser.profile.firstName.charAt(0).toUpperCase() + tempUser.profile.firstName.slice(1)
+ ' '
+ tempUser.profile.lastName.charAt(0).toUpperCase() + tempUser.profile.lastName.slice(1)
// format for captital letters
user.value =
tempUser.profile.firstName.charAt(0).toUpperCase() +
tempUser.profile.firstName.slice(1) +
' ' +
tempUser.profile.lastName.charAt(0).toUpperCase() +
tempUser.profile.lastName.slice(1);

renderMarkdown();
});
Expand All @@ -363,7 +365,7 @@ const step = ref(0);
const title = ref('Your title here');
const date = ref('The date it was uploaded');
const description = ref('Your description here');
const user = ref('Vous')
const user = ref('Vous');

// visuals
const open = ref(false);
Expand Down
2 changes: 1 addition & 1 deletion front-end/src/components/blog/ShowArticle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@
{{ comment.descriptions }}
</p>

<div v-if="oneItems.owner === user._id || user.role === 2" class="absolute top-2 right-2">
<div v-if="oneItems.owner._id === user._id || user.role === 2" class="absolute top-2 right-2">
<button
type="button"
@click="removeComment(oneItems._id, comment)"
Expand Down
8 changes: 7 additions & 1 deletion front-end/src/store/interfaces/article.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface ArticleStore {

export interface Article {
_id?: string;
owner: string;
owner: Owner;
date: Date;
title: string;
descriptions: string;
Expand Down Expand Up @@ -36,6 +36,12 @@ export interface Participants {
email: string;
}

export interface Owner {
_id: string;
firstName: string;
lastName: string;
}

export interface Comments {
_id: string;
email: string;
Expand Down
20 changes: 15 additions & 5 deletions front-end/src/store/modules/article.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ export const useArticleStore = defineStore('article', {
items: [
{
_id: '',
owner: '',
owner: {
_id: '',
firstName: '',
lastName: '',
},
date: new Date(),
title: '',
descriptions: '',
Expand All @@ -31,7 +35,11 @@ export const useArticleStore = defineStore('article', {
],
oneItems: {
_id: '',
owner: '',
owner: {
_id: '',
firstName: '',
lastName: '',
},
title: '',
date: new Date(),
descriptions: '',
Expand Down Expand Up @@ -92,9 +100,11 @@ export const useArticleStore = defineStore('article', {

//update article in the database
updateArticle: withErrorHandler(async function (id: string, article: Article) {
const response = await http.put(`/articles/update/${id}`, article);
const oneItems = response.data;
this.oneItems = oneItems;
await http.put(`/articles/update/${id}`, article);

const index = this.items.findIndex((el) => el._id === id);
this.items[index] = article;

return true;
}),

Expand Down