Skip to content

Commit

Permalink
Merge pull request #480 from CodingFactory-Repos/develop-G5
Browse files Browse the repository at this point in the history
Adding the name of the user that created the suggestion
  • Loading branch information
Loule95450 committed Jun 15, 2023
2 parents 56d4f41 + 8065cdc commit 07ad8c7
Show file tree
Hide file tree
Showing 9 changed files with 197 additions and 18 deletions.
21 changes: 18 additions & 3 deletions back-end/src/base/ideasEquipments/ideasEquipments.repository.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Inject, Injectable } from '@nestjs/common';
import { Filter, UpdateFilter, FindOneAndUpdateOptions, Db } from 'mongodb';
import { Filter, UpdateFilter, FindOneAndUpdateOptions, Db, ObjectId } from 'mongodb';

import { IdeaEquipment } from 'src/base/ideasEquipments/interfaces/ideasEquipments.interface';

Expand All @@ -12,11 +12,26 @@ export class IdeasEquipmentsRepository {
}

async getAllIdeasEquipments() {
return this.ideasEquipments.find().toArray();
return await this.ideasEquipments
.aggregate([
{
$lookup: {
from: 'users',
localField: 'user',
foreignField: '_id',
as: 'user',
},
},
])
.toArray();
}

async createIdeaEquipment(query: IdeaEquipment) {
return this.ideasEquipments.insertOne(query);
const { user } = query;
return this.ideasEquipments.insertOne({
...query,
user: new ObjectId(user),
});
}

async updateOneIdeaEquipment(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { ObjectId } from 'mongodb';
import { User } from '../../users/interfaces/users.interface';

export interface IdeaEquipment {
_id?: ObjectId;
name: string;
description: string;
motivation: string;
link: string;
price: string;
user: User;
user: ObjectId;
}
1 change: 1 addition & 0 deletions front-end/src/views/MaterialsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import Bell from '@/components/common/svg/Bell.vue';
import ApprouvalCenter from '@/components/materials/ApprouvalCenter.vue';
import { useMaterialStore } from '@/store/modules/material.store';
import { useRouter } from 'vue-router';
import pdfMakeFonts from '@/utils/pdfMakeFonts';
// This file will register globalThis.pdfMake.vfs, the documentation does not explicity define the behavior
// Unless you want to change the font, you don't need to assign pdfmake.vfs = globalThis.pdfMake.vfs.
Expand Down
3 changes: 3 additions & 0 deletions front-end/src/views/material-ideas/AddIdeas.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
Ajouter
</button>
</div>
<IdeasPdf :items="items" />

<!-- Show added items in list view-->
<ul class="rounded-sm block">
Expand Down Expand Up @@ -67,6 +68,7 @@
import { http } from '@/api/network/axios';
import PopUp from './PopUp.vue';
import InfoLayout from './InfoLayout.vue';
import IdeasPdf from './IdeasPdf.vue';
export default {
data() {
Expand Down Expand Up @@ -120,6 +122,7 @@ export default {
components: {
PopUp,
InfoLayout,
IdeasPdf,
},
};
</script>
Expand Down
7 changes: 3 additions & 4 deletions front-end/src/views/material-ideas/Comments.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,10 @@ export default {
socket.on('comment-added', (data) => {
console.log('comment-added');
console.log(data);
this.items = data
this.items = data;
});
this.getComments();
},
unmounted() {
Expand All @@ -93,8 +92,8 @@ export default {
comment,
equipmentId,
});
console.log(items)
socket.emit('add-comment', items)
console.log(items);
socket.emit('add-comment', items);
this.items = items || [];
this.comment = '';
},
Expand Down
10 changes: 6 additions & 4 deletions front-end/src/views/material-ideas/DraftPdf.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
</template>

<script>
import pdfMake from 'pdfmake/build/pdfmake';
import pdfFonts from 'pdfmake/build/vfs_fonts';
// import pdfMake from 'pdfmake/build/pdfmake';
// import pdfFonts from 'pdfmake/build/vfs_fonts';
import CodingToolsLogo from '@/assets/images/CodingToolsLogo.png';
import { useUserStore } from '@/store/modules/user.store';
import { computed } from 'vue';
Expand All @@ -37,7 +37,9 @@ const userStore = useUserStore();
const user = computed(() => authStore.user);
const userId = computed(() => user.value._id);
pdfMake.vfs = pdfFonts.pdfMake.vfs;
import { createPdf } from 'pdfmake/build/pdfmake';
import * as _ from 'pdfmake/build/vfs_fonts.js';
const fonts = globalThis.pdfMake.vfs ?? _.pdfMake.vfs;
const date = new Date().toLocaleDateString();
let base64Image = null;
Expand Down Expand Up @@ -118,7 +120,7 @@ export default {
},
},
};
pdfMake.createPdf(docDefinition).download(`devis_${this.item.title}`);
createPdf(docDefinition, null, null, fonts).download(`devis_${this.item.title}`);
},
},
};
Expand Down
135 changes: 135 additions & 0 deletions front-end/src/views/material-ideas/IdeasPdf.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<template>
<div>
<button
class="text-sm !text-opacity-60 text-dark-primary dark:text-light-primary flex w-full items-center justify-center pt-2.5"
@click="generatePdf"
>
<svg
xmlns="http://www.w3.org/2000/svg"
width="16"
height="16"
fill="currentColor"
class="mr-2"
viewBox="0 0 16 16"
>
<path
d="M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5z"
/>
<path
d="M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708l3 3z"
/>
</svg>
<p class="ml-2">Télécharcher toutes les suggestions</p>
</button>
</div>
</template>

<script>
// import pdfMake from 'pdfmake/build/pdfmake';
// import pdfFonts from 'pdfmake/build/vfs_fonts';
import CodingToolsLogo from '@/assets/images/CodingToolsLogo.png';
import { useUserStore } from '@/store/modules/user.store';
import { computed } from 'vue';
import { useAuthStore } from '@/store/modules/auth.store';
const authStore = useAuthStore();
const userStore = useUserStore();
const user = computed(() => authStore.user);
const userId = computed(() => user.value._id);
import { createPdf } from 'pdfmake/build/pdfmake';
import * as _ from 'pdfmake/build/vfs_fonts.js';
const fonts = globalThis.pdfMake.vfs ?? _.pdfMake.vfs;
const date = new Date().toLocaleDateString();
let base64Image = null;
fetch(CodingToolsLogo)
.then((response) => response.blob())
.then((blob) => {
const reader = new FileReader();
reader.onloadend = () => {
base64Image = reader.result;
};
reader.readAsDataURL(blob);
})
.catch((error) => {
console.error("Erreur lors du chargement de l'image :", error);
});
export default {
props: ['items'],
methods: {
generatePdf() {
const docDefinition = {
content: [
{
image: base64Image,
width: 100,
height: 75,
alignment: 'left',
},
{
text: 'Devis',
fontSize: 18,
bold: true,
margin: [0, 0, 100, 30],
alignment: 'right',
},
{
text: `Récapitulatif des propositions de matériel`,
margin: [0, 0, 0, 20],
},
{
text: `Date de création du récapitulatif : ${date}`,
},
{
text: `Récapitulatif créer par : ${user.value.profile.firstName} ${user.value.profile.lastName}`,
},
{
style: 'tableBody',
widths: 'auto',
margin: [0, 10, 0, 0],
table: {
widths: ['auto', 'auto', '*', 'auto', 'auto', 'auto'],
body: [
[
{ style: 'tableHeader', text: 'Nom' },
{ style: 'tableHeader', text: 'Proposé par' },
{ style: 'tableHeader', text: 'Description' },
{ style: 'tableHeader', text: 'Lien' },
{ style: 'tableHeader', text: 'Motivations' },
{ style: 'tableHeader', text: 'Prix' },
],
...this.items.map(({ desc, link, motiv, price, title, user }) => {
const [data] = user;
console.log([title, data.profile.firstName, desc, link, motiv, `${price}`]);
return [title, data.profile.firstName, desc, link, motiv, `${price}`];
}),
],
},
},
],
images: {
CodingTools: './images/CodingToolsLogo.png',
},
styles: {
tableBody: {
fontSize: 10,
margin: 5,
},
tableHeader: {
fillColor: '#e5e7eb',
margin: 5,
},
},
};
console.log(docDefinition);
createPdf(docDefinition, null, null, fonts).download(`Suggestions_equipement`);
},
},
};
</script>
14 changes: 11 additions & 3 deletions front-end/src/views/material-ideas/InfoLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
</button>
<span class="text-2xl text-dark-primary dark:text-dark-font">Détails</span>
<ul class="infoLayout">
<!-- <li class="text-l dark-primary dark:text-dark-font" v-for="data in selectedItem">{{ data }}</li> -->

<li class="mt-3">
<span class="text-xs !text-opacity-50 text-dark-primary dark-primary dark:text-dark-font"
>Suggestion : </span
Expand All @@ -30,6 +28,16 @@
{{ selectedItem.title }}
</span>
</li>
<li class="mt-3">
<span class="text-xs !text-opacity-50 text-dark-primary dark-primary dark:text-dark-font"
>Proposé par : </span
><br />
<span class="text-l text-dark-primary dark:text-dark-font">
<!-- ICI -->
{{ this.selectedItem.user[0].profile.firstName }}
{{ this.selectedItem.user[0].profile.lastName }}
</span>
</li>
<li class="mt-3">
<span class="text-xs !text-opacity-50 text-dark-primary dark-primary dark:text-dark-font"
>Prix : </span
Expand Down Expand Up @@ -74,9 +82,9 @@
<script>
import Comments from './Comments.vue';
import Pdf from './DraftPdf.vue';
export default {
props: ['selectedItem'],
created() {
this.$emit('getId');
},
Expand Down
20 changes: 19 additions & 1 deletion front-end/src/views/material-ideas/PopUp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,26 @@
</template>
<script>
import { http } from '@/api/network/axios';
import { useUserStore } from '@/store/modules/user.store';
import { computed } from 'vue';
import { useAuthStore } from '@/store/modules/auth.store';
const authStore = useAuthStore();
const userStore = useUserStore();
const user = computed(() => authStore.user);
const userId = computed(() => user.value._id);
console.log(userId);
export default {
props: ['title'],
data() {
return {
userId,
};
},
methods: {
async postBdd() {
await http.post('/ideasequipments/add', {
Expand All @@ -80,6 +97,7 @@ export default {
desc: this.desc,
link: this.link,
motiv: this.motiv,
user: this.userId,
});
this.$emit('close');
this.$emit('validation');
Expand Down

0 comments on commit 07ad8c7

Please sign in to comment.