Skip to content

Commit d1b9d8e

Browse files
Merged 'develop-G5' into 'auto-develop'.
2 parents 909fbd0 + f110450 commit d1b9d8e

7 files changed

Lines changed: 187 additions & 14 deletions

File tree

back-end/src/base/ideasEquipments/ideasEquipments.repository.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Inject, Injectable } from '@nestjs/common';
2-
import { Filter, UpdateFilter, FindOneAndUpdateOptions, Db } from 'mongodb';
2+
import { Filter, UpdateFilter, FindOneAndUpdateOptions, Db, ObjectId } from 'mongodb';
33

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

@@ -12,11 +12,26 @@ export class IdeasEquipmentsRepository {
1212
}
1313

1414
async getAllIdeasEquipments() {
15-
return this.ideasEquipments.find().toArray();
15+
return await this.ideasEquipments
16+
.aggregate([
17+
{
18+
$lookup: {
19+
from: 'users',
20+
localField: 'user',
21+
foreignField: '_id',
22+
as: 'user',
23+
},
24+
},
25+
])
26+
.toArray();
1627
}
1728

1829
async createIdeaEquipment(query: IdeaEquipment) {
19-
return this.ideasEquipments.insertOne(query);
30+
const { user } = query;
31+
return this.ideasEquipments.insertOne({
32+
...query,
33+
user: new ObjectId(user),
34+
});
2035
}
2136

2237
async updateOneIdeaEquipment(
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { ObjectId } from 'mongodb';
2-
import { User } from '../../users/interfaces/users.interface';
3-
42
export interface IdeaEquipment {
53
_id?: ObjectId;
64
name: string;
75
description: string;
86
motivation: string;
97
link: string;
108
price: string;
11-
user: User;
9+
user: ObjectId;
1210
}

front-end/src/views/material-ideas/AddIdeas.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
Ajouter
2626
</button>
2727
</div>
28+
<IdeasPdf :items="items" />
2829

2930
<!-- Show added items in list view-->
3031
<ul class="rounded-sm block">
@@ -67,6 +68,7 @@
6768
import { http } from '@/api/network/axios';
6869
import PopUp from './PopUp.vue';
6970
import InfoLayout from './InfoLayout.vue';
71+
import IdeasPdf from './IdeasPdf.vue';
7072
7173
export default {
7274
data() {
@@ -120,6 +122,7 @@ export default {
120122
components: {
121123
PopUp,
122124
InfoLayout,
125+
IdeasPdf,
123126
},
124127
};
125128
</script>

front-end/src/views/material-ideas/Comments.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,10 @@ export default {
7474
socket.on('comment-added', (data) => {
7575
console.log('comment-added');
7676
console.log(data);
77-
this.items = data
77+
this.items = data;
7878
});
7979
8080
this.getComments();
81-
8281
},
8382
8483
unmounted() {
@@ -93,8 +92,8 @@ export default {
9392
comment,
9493
equipmentId,
9594
});
96-
console.log(items)
97-
socket.emit('add-comment', items)
95+
console.log(items);
96+
socket.emit('add-comment', items);
9897
this.items = items || [];
9998
this.comment = '';
10099
},
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
<template>
2+
<div>
3+
<button
4+
class="text-sm !text-opacity-60 text-dark-primary dark:text-light-primary flex w-full items-center justify-center pt-2.5"
5+
@click="generatePdf"
6+
>
7+
<svg
8+
xmlns="http://www.w3.org/2000/svg"
9+
width="16"
10+
height="16"
11+
fill="currentColor"
12+
class="mr-2"
13+
viewBox="0 0 16 16"
14+
>
15+
<path
16+
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"
17+
/>
18+
<path
19+
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"
20+
/>
21+
</svg>
22+
<p class="ml-2">Télécharcher toutes les suggestions</p>
23+
</button>
24+
</div>
25+
</template>
26+
27+
<script>
28+
import pdfMake from 'pdfmake/build/pdfmake';
29+
import pdfFonts from 'pdfmake/build/vfs_fonts';
30+
import CodingToolsLogo from '@/assets/images/CodingToolsLogo.png';
31+
import { useUserStore } from '@/store/modules/user.store';
32+
import { computed } from 'vue';
33+
34+
import { useAuthStore } from '@/store/modules/auth.store';
35+
36+
const authStore = useAuthStore();
37+
const userStore = useUserStore();
38+
39+
const user = computed(() => authStore.user);
40+
const userId = computed(() => user.value._id);
41+
42+
pdfMake.vfs = pdfFonts.pdfMake.vfs;
43+
44+
const date = new Date().toLocaleDateString();
45+
let base64Image = null;
46+
fetch(CodingToolsLogo)
47+
.then((response) => response.blob())
48+
.then((blob) => {
49+
const reader = new FileReader();
50+
reader.onloadend = () => {
51+
base64Image = reader.result;
52+
};
53+
reader.readAsDataURL(blob);
54+
})
55+
.catch((error) => {
56+
console.error("Erreur lors du chargement de l'image :", error);
57+
});
58+
59+
export default {
60+
props: ['items'],
61+
62+
methods: {
63+
generatePdf() {
64+
const docDefinition = {
65+
content: [
66+
{
67+
image: base64Image,
68+
width: 100,
69+
height: 75,
70+
alignment: 'left',
71+
},
72+
{
73+
text: 'Devis',
74+
fontSize: 18,
75+
bold: true,
76+
margin: [0, 0, 100, 30],
77+
alignment: 'right',
78+
},
79+
{
80+
text: `Récapitulatif des propositions de matériel`,
81+
margin: [0, 0, 0, 20],
82+
},
83+
{
84+
text: `Date de création du récapitulatif : ${date}`,
85+
},
86+
{
87+
text: `Récapitulatif créer par : ${user.value.profile.firstName} ${user.value.profile.lastName}`,
88+
},
89+
{
90+
style: 'tableBody',
91+
widths: 'auto',
92+
margin: [0, 10, 0, 0],
93+
table: {
94+
widths: ['auto', 'auto', '*', 'auto', 'auto', 'auto'],
95+
body: [
96+
[
97+
{ style: 'tableHeader', text: 'Nom' },
98+
{ style: 'tableHeader', text: 'Proposé par' },
99+
{ style: 'tableHeader', text: 'Description' },
100+
{ style: 'tableHeader', text: 'Lien' },
101+
{ style: 'tableHeader', text: 'Motivations' },
102+
{ style: 'tableHeader', text: 'Prix' },
103+
],
104+
...this.items.map(({ desc, link, motiv, price, title, user }) => {
105+
const [data] = user;
106+
console.log([title, data.profile.firstName, desc, link, motiv, `${price}`]);
107+
return [title, data.profile.firstName, desc, link, motiv, `${price}`];
108+
}),
109+
],
110+
},
111+
},
112+
],
113+
images: {
114+
CodingTools: './images/CodingToolsLogo.png',
115+
},
116+
styles: {
117+
tableBody: {
118+
fontSize: 10,
119+
margin: 5,
120+
},
121+
tableHeader: {
122+
fillColor: '#e5e7eb',
123+
margin: 5,
124+
},
125+
},
126+
};
127+
console.log(docDefinition);
128+
pdfMake.createPdf(docDefinition).download(`Suggestions_equipement`);
129+
},
130+
},
131+
};
132+
</script>

front-end/src/views/material-ideas/InfoLayout.vue

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
</button>
2121
<span class="text-2xl text-dark-primary dark:text-dark-font">Détails</span>
2222
<ul class="infoLayout">
23-
<!-- <li class="text-l dark-primary dark:text-dark-font" v-for="data in selectedItem">{{ data }}</li> -->
24-
2523
<li class="mt-3">
2624
<span class="text-xs !text-opacity-50 text-dark-primary dark-primary dark:text-dark-font"
2725
>Suggestion : </span
@@ -30,6 +28,16 @@
3028
{{ selectedItem.title }}
3129
</span>
3230
</li>
31+
<li class="mt-3">
32+
<span class="text-xs !text-opacity-50 text-dark-primary dark-primary dark:text-dark-font"
33+
>Proposé par : </span
34+
><br />
35+
<span class="text-l text-dark-primary dark:text-dark-font">
36+
<!-- ICI -->
37+
{{ this.selectedItem.user[0].profile.firstName }}
38+
{{ this.selectedItem.user[0].profile.lastName }}
39+
</span>
40+
</li>
3341
<li class="mt-3">
3442
<span class="text-xs !text-opacity-50 text-dark-primary dark-primary dark:text-dark-font"
3543
>Prix : </span
@@ -74,9 +82,9 @@
7482
<script>
7583
import Comments from './Comments.vue';
7684
import Pdf from './DraftPdf.vue';
77-
7885
export default {
7986
props: ['selectedItem'],
87+
8088
created() {
8189
this.$emit('getId');
8290
},

front-end/src/views/material-ideas/PopUp.vue

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,26 @@
6969
</template>
7070
<script>
7171
import { http } from '@/api/network/axios';
72+
import { useUserStore } from '@/store/modules/user.store';
73+
import { computed } from 'vue';
74+
75+
import { useAuthStore } from '@/store/modules/auth.store';
76+
77+
const authStore = useAuthStore();
78+
const userStore = useUserStore();
79+
80+
const user = computed(() => authStore.user);
81+
const userId = computed(() => user.value._id);
82+
83+
console.log(userId);
84+
7285
export default {
7386
props: ['title'],
74-
87+
data() {
88+
return {
89+
userId,
90+
};
91+
},
7592
methods: {
7693
async postBdd() {
7794
await http.post('/ideasequipments/add', {
@@ -80,6 +97,7 @@ export default {
8097
desc: this.desc,
8198
link: this.link,
8299
motiv: this.motiv,
100+
user: this.userId,
83101
});
84102
this.$emit('close');
85103
this.$emit('validation');

0 commit comments

Comments
 (0)