Skip to content

Commit

Permalink
Merge pull request #495 from CodingFactory-Repos/develop-G2
Browse files Browse the repository at this point in the history
Develop g2
  • Loading branch information
Loule95450 committed Jun 16, 2023
2 parents 31a4752 + 8d1b960 commit 0fc78ee
Show file tree
Hide file tree
Showing 17 changed files with 635 additions and 182 deletions.
14 changes: 14 additions & 0 deletions back-end/src/base/articles/articles.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,20 @@ export class ArticlesController {
return res.status(201).json(article);
}

// add document
@Put('/document/:id')
async addDocument(@Req() req: Request, @Res() res: Response) {
const article = await this.articlesService.addDocument(req.params.id, req.body);
return res.status(201).json(article);
}

// remove document
@Put('/removeDocument/:id')
async removeDocument(@Req() req: Request, @Res() res: Response) {
const article = await this.articlesService.removeDocument(req.params.id, req.body);
return res.status(201).json(article);
}

// delete article
@Delete('/delete/:id')
async deleteArticle(@Req() req: Request, @Res() res: Response) {
Expand Down
16 changes: 16 additions & 0 deletions back-end/src/base/articles/articles.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,22 @@ export class ArticlesService {
return await this.articlesRepository.updateOneArticle({ _id: new ObjectId(id) }, update);
}

// add document
async addDocument(id, queryDocument) {
queryDocument._id = new ObjectId();
const update = { $push: { documents: queryDocument } };

return await this.articlesRepository.updateOneArticle({ _id: new ObjectId(id) }, update);
}

// remove document
async removeDocument(id, queryDocument) {
queryDocument._id = new ObjectId(queryDocument._id);
const update = { $pull: { documents: queryDocument } };

return await this.articlesRepository.updateOneArticle({ _id: new ObjectId(id) }, update);
}

// delete article
async deleteArticle(id) {
return await this.articlesRepository.deleteOneArticle(id);
Expand Down
3 changes: 2 additions & 1 deletion back-end/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { config } from 'src/config/config';

import { AppModule } from 'src/app.module';
import { corsOptionsDelegate } from 'src/config/cors';
import * as bodyParser from 'body-parser';

//! Proxy settings, production only
// <NestExpressApplication>
Expand All @@ -27,7 +28,7 @@ async function bootstrap() {
);

app.use(cookieParser());

app.use(bodyParser.json({ limit: '50mb' }));
app.enableCors(corsOptionsDelegate);
//! versioning, production only
// app.enableVersioning({
Expand Down
123 changes: 115 additions & 8 deletions front-end/src/components/RessourcesComponents/AddCourse.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,34 @@
</h3>
<div class="modal-body">
<form class="w-full max-w-sm">
<input type="text" name="title" v-model="this.tag" placeholder="Title :" /><br />
<input type="datetime-local" class="text-field" v-model="this.periodStart" /><br />
<input type="datetime-local" class="text-field" v-model="this.periodEnd" /><br />
<input type="url" placeholder="picture link" v-model="this.picture" /><br />
<input type="text" name="title" v-model="tag" placeholder="Title :" /><br />
<VueDatePicker
placeholder="debut"
v-model="periodStart"
:format="dateFormat"
:language="datePickerLanguage"
/>
<VueDatePicker
placeholder="fin"
v-model="periodEnd"
:format="dateFormat"
:language="datePickerLanguage"
/>
<input type="url" placeholder="picture link" v-model="picture" /><br />
<input
type="text"
name="language"
v-model="this.language"
v-model="language"
placeholder="Language :"
/><br />
@input="searchLanguage"
autocomplete="off"
/>
<ul v-if="showSuggest">
<li v-for="suggest in languageSuggest" :key="suggest" @click="selectSuggest(suggest)">
{{ suggest }}
</li>
</ul>
<input type="file" id="file" ref="fileInput" @change="onFileSelected" />
<div class="flex justify-center mt-6">
<button
class="px-4 py-2 text-white bg-blue-500 rounded-lg hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-opacity-50"
Expand All @@ -41,6 +59,8 @@

<script lang="ts">
import { useCoursStore } from '@/store/modules/course.store';
import VueDatePicker from '@vuepic/vue-datepicker';
import Swal from 'sweetalert2';
export default {
name: 'AddCourses',
Expand All @@ -57,11 +77,33 @@ export default {
project: [],
site: '',
teacherId: '',
languages: [],
languageSuggest: [],
showSuggest: false,
dateFormat: 'yyyy-MM-dd HH:mm',
datePickerLanguage: 'fr', // Langue du date picker
selectedFile: null,
base64String: '',
};
},
methods: {
AddCourses() {
AddCourses(event) {
event.preventDefault();
// Vérifier si tous les champs sont remplis
if (!this.tag || !this.periodStart || !this.periodEnd || !this.picture || !this.language) {
Swal.fire({
title: 'Vous devez remplir tous les champs',
text: 'Veuillez remplir tous les champs pour ajouter un nouveau cours',
icon: 'error',
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'OK',
});
return;
}
const course = useCoursStore();
this.newCourse = {
tag: this.tag,
classTag: '',
Expand All @@ -74,8 +116,73 @@ export default {
project: [],
site: '',
teacherId: '',
files: this.base64String,
};
course.addCourse(this.newCourse);
Swal.fire({
title: 'Votre cours a été ajouté',
icon: 'success',
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'OK',
}).then(async (result) => {
if (result.isConfirmed) {
// Ajouter le cours
course.addCourse(this.newCourse);
}
});
// Rediriger vers la page des cours
this.$emit('close');
},
onFileSelected(event) {
this.selectedFile = event.target.files[0];
this.convertToBase64();
},
convertToBase64() {
if (this.selectedFile) {
const reader = new FileReader();
reader.onload = (event) => {
let result = event.target.result;
this.base64String = result.toString();
};
reader.readAsDataURL(this.selectedFile);
}
},
searchLanguage() {
//recherche de toutes les matieres
this.showSuggest = true;
this.getAllTagCourse();
this.languageSuggest = [];
this.languages.forEach((element) => {
let alreadyInList = false;
if (element.toUpperCase().includes(this.language.toUpperCase()) && this.language != '') {
this.languageSuggest.forEach((languageInList) => {
if (languageInList == element.toUpperCase()) {
alreadyInList = true;
}
});
if (!alreadyInList) {
this.languageSuggest.push(element.toUpperCase());
}
}
});
},
getAllTagCourse() {
this.languages = []; //reset la list
const courseStore = useCoursStore();
const course = courseStore.items;
course.forEach((element) => {
if (!this.languages.includes(element.language)) {
this.languages.push(element.language);
}
});
},
selectSuggest(suggest) {
this.language = suggest;
},
},
};
Expand Down
15 changes: 7 additions & 8 deletions front-end/src/components/RessourcesComponents/Cours.vue
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
<template>
<div>
<div v-if="userRole === Roles.USER">
<h1>ELEVE</h1>
</div>
<div class="flex items-center justify-center">
<button
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-full mr-4"
class="bg-blue-500 hover:bg-blue-700 font-bold py-2 px-4 rounded-full mr-4"
@click="
startYears-- && endYears--;
getCurrentYearsCours();
"
>
</button>
<span class="text-2xl font-bold">{{ startYears }} - {{ endYears }}</span>
<span class="text-2xl font-bold text-gray-900 dark:text-white"
>{{ startYears }} - {{ endYears }}</span
>
<button
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-full ml-4"
class="bg-blue-500 hover:bg-blue-700 font-bold py-2 px-4 rounded-full ml-4"
@click="
startYears++ && endYears++;
getCurrentYearsCours();
Expand All @@ -28,7 +27,7 @@
<div class="flex items-center justify-center">
<div class="flex items-center justify-center">
<button
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-full"
class="bg-blue-500 hover:bg-blue-700 font-bold py-2 px-4 rounded-full"
@click="showModal = true"
>
+
Expand All @@ -46,7 +45,7 @@
<div class="grid grid-cols-2 md:grid-cols-3 gap-4">
<div
v-for="item in coursesFiltered"
class="max-w-sm bg-white border border-gray-200 rounded-lg shadow dark:bg-gray-800 dark:border-gray-700"
class="max-w-sm bg-white border border-gray-200 rounded-lg shadow dark:bg-gray-800 dark:border-gray-700 text-gray-900 dark:text-white"
@click="openCourse(item._id)"
>
<img
Expand Down
Loading

0 comments on commit 0fc78ee

Please sign in to comment.