codevdesign 0.0.10 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## À propos
4
4
 
5
- Composants Vuetify 3 pour les projets Codev
5
+ Composants Vuetify 3 pour les projets Codev
6
6
 
7
7
  ## Table des matières
8
8
 
@@ -20,11 +20,12 @@ Vue 3
20
20
  Vuetify 3
21
21
  Vue-i18n
22
22
  Typescript 5
23
-
23
+ "@e965/xlsx"
24
24
 
25
25
  ## Installation
26
26
 
27
27
  Installez le package via npm en exécutant la commande suivante dans votre projet :
28
+
28
29
  ```
29
30
  npm install codevdesign
30
31
  ```
@@ -92,7 +93,7 @@ export default createI18n({
92
93
  globalInjection: true,
93
94
  fallbackLocale: window.langue,
94
95
  silentTranslationWarn: true,
95
- })
96
+ })
96
97
  ```
97
98
 
98
99
  Vous pouvez importer les composants directement depuis le package Codev Design comme suit :
@@ -100,19 +101,17 @@ Vous pouvez importer les composants directement depuis le package Codev Design c
100
101
  ```
101
102
  import { pivFooter, pivEntete, csqcMenu, csqcAlerteErreur, csqcSnackbar } from 'codevdesign'
102
103
  ```
103
- Ces composants sont prêts à être utilisés dans vos pages ou vos composants Vue.js.
104
104
 
105
+ Ces composants sont prêts à être utilisés dans vos pages ou vos composants Vue.js.
105
106
 
106
107
  ## Documentation
107
108
 
108
109
  Un bac à sable interactif avec la documentation détaillée des props des composants est disponible pour les membres de la CDPVD. Vous pouvez y accéder ici : https://espacedev.csqc.ca/codevdesign
109
110
 
110
-
111
111
  ## Gestion des versions
112
112
 
113
113
  Toutes les versions disponibles ainsi que les journaux des changements apportés sont disponibles sur la page npm du package : https://www.npmjs.com/package/codevdesign?activeTab=versions.
114
114
 
115
-
116
115
  ## Licence
117
116
 
118
117
  Ce package Codev Design est fourni sans licence spécifique. Vous pouvez l'utiliser dans vos projets à votre discrétion, mais il n'y a aucune garantie légale.
@@ -41,11 +41,19 @@
41
41
  <v-btn
42
42
  v-if="btnAjouter"
43
43
  color="primary"
44
- class="float-right"
44
+ class="ml-1 float-right"
45
45
  @click.stop="ajouter"
46
46
  >
47
47
  {{ props.btnAjouterTexte ? props.btnAjouterTexte : $t('csqc.bouton.ajouter') }}
48
48
  </v-btn>
49
+
50
+ <exportExcelComponent
51
+ v-if="excel"
52
+ :liste="filteredItems"
53
+ :chargement-liste="chargementListe"
54
+ :nom-fichier="excelNomFichier"
55
+ class="mt-1 ml-1 float-right"
56
+ />
49
57
  </v-col>
50
58
  </v-row>
51
59
 
@@ -61,10 +69,11 @@
61
69
  class="d-flex ControlesDatatable flex-wrap"
62
70
  >
63
71
  <v-data-table
72
+ ref="datatable"
64
73
  color="green"
65
- :headers="colonnes as any"
74
+ :headers="colonnes"
66
75
  :item-key="itemKey"
67
- :items="liste as any"
76
+ :items="liste"
68
77
  :search="recherche"
69
78
  :loading="chargementListe"
70
79
  @click:row="cliqueLigne"
@@ -124,14 +133,23 @@
124
133
  </template>
125
134
 
126
135
  <script setup lang="ts">
127
- import { ref, computed, defineProps, type Slots } from 'vue'
136
+ /* eslint-disable @typescript-eslint/no-explicit-any */
137
+
138
+ import { ref, computed, defineProps, type Slots, type PropType } from 'vue'
128
139
  import Recherche from '../csqcRecherche.vue'
129
140
  import confirmation from '../csqcConfirmation.vue'
130
- //import ExportExcel from './csqc-table-export-excel.vue';
141
+ import exportExcelComponent from './csqcTableExportExcel.vue'
131
142
  //import ModaleChoix from './csqc-table-modale-choix-colonnes.vue';
132
143
  //import axios from 'axios'
133
144
  import { useI18n } from 'vue-i18n'
134
145
 
146
+ interface Colonne {
147
+ title: string
148
+ key: string // Correspond à la clé des objets dans `liste`
149
+ align?: 'start' | 'center' | 'end'
150
+ sortable?: boolean
151
+ }
152
+
135
153
  // Props
136
154
  const props = defineProps({
137
155
  btnAjouter: { type: Boolean, default: true },
@@ -142,16 +160,22 @@
142
160
  operationEnCours: { type: Boolean, default: false },
143
161
  //choixSwitchOptionDepart: { type: Boolean, default: false },
144
162
  // classeRangee: { type: String, default: '' },
145
- colonnes: { type: Array, default: () => [] },
146
- // excelAfficher: { type: Boolean, default: false },
147
- // excelNomFichier: { type: String, default: 'donnees' },
163
+ colonnes: {
164
+ type: Array as PropType<Colonne[]>,
165
+ default: () => [],
166
+ },
167
+ excel: { type: Boolean, default: false },
168
+ excelNomFichier: { type: String, default: 'csqc' },
148
169
  //filtresDepart: { type: Object, default: null },
149
170
  //flechesTri: { type: Boolean, default: false },
150
171
  // formulaireId: { type: Number, default: -1 },
151
172
  //identifiant: { type: String, default: '' },
152
173
  itemKey: { type: String, default: 'id' },
153
174
  // itemsParPage: { type: Number, default: 10 },
154
- liste: { type: Array, default: () => [] },
175
+ liste: {
176
+ type: Array as PropType<Record<string, any>[]>,
177
+ default: () => [],
178
+ },
155
179
  // modulerDense: { type: Boolean, default: false },
156
180
  // multifiltre: { type: Boolean, default: false },
157
181
  // multiTri: { type: Boolean, default: false },
@@ -190,7 +214,6 @@
190
214
  const supprimerTitreTexte = computed(() => props.modaleSupprimerTitre || t('csqc.message.supprimerTitre'))
191
215
 
192
216
  // Fonction pour ouvrir le dialogue pour un item spécifique
193
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
194
217
  const ouvrirModaleSupprimer = (item: any) => {
195
218
  itemSelectionne.value = item
196
219
 
@@ -206,19 +229,25 @@
206
229
  const chargerRecherche = (val: string) => {
207
230
  recherche.value = val
208
231
  }
232
+
209
233
  const ajouter = () => {
210
234
  emit('ajouter')
211
235
  }
212
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
213
236
  const cliqueLigne = (e: Event, { item }: { item: any }) => {
214
237
  emit('cliqueLigne', item)
215
238
  }
216
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
239
+
217
240
  const modifier = (item: any) => {
218
241
  emit('modifier', item)
219
242
  }
243
+ const filteredItems = computed(() => {
244
+ if (!recherche.value) return props.liste // Si rien écrit, affiche tout
220
245
 
221
- const emit = defineEmits(['ajouter', 'cliqueLigne', 'supprimer', 'modifier'])
246
+ return props.liste.filter(item =>
247
+ Object.values(item).some(val => String(val).toLowerCase().includes(recherche.value.toLowerCase())),
248
+ )
249
+ })
250
+ const emit = defineEmits(['ajouter', 'cliqueLigne', 'supprimer', 'modifier', 'donneesExportees'])
222
251
  </script>
223
252
 
224
253
  <style scoped lang="css">
@@ -311,4 +340,9 @@
311
340
  .iconeEditer:hover {
312
341
  color: #095797;
313
342
  }
343
+
344
+ /* hover icone à droite du ajouter*/
345
+ .text-grisMoyen:hover {
346
+ color: #095797 !important;
347
+ }
314
348
  </style>
@@ -1,67 +1,58 @@
1
- <template>
2
- <v-icon
3
- right
4
- color="green darken-2"
5
- @click="exportSheet"
6
- >
7
- mdi-microsoft-excel
8
- </v-icon>
9
- </template>
10
- <script>
11
- import { utils, writeFileXLSX } from 'xlsx';
12
-
13
- export default {
14
- props: {
15
- chargementListe: {
16
- type: Boolean,
17
- default: false,
18
- },
19
- nomFichier: {
20
- required: true,
21
- type: String,
22
- },
23
- colonnes: {
24
- required: true,
25
- type: Array,
26
- },
27
- },
28
- data() {
29
- return {
30
- };
31
- },
32
- methods: {
33
- exportSheet() {
34
- this.$emit('demande', this.exportSheetEffective);
35
- },
36
-
37
- exportSheetEffective(itemsAExporter) {
38
- // https://github.com/SheetJS/SheetJS/tree/master/demos/vue/
39
-
40
- const header = this.colonnes.map((element) => element.value);
41
- const headerText = this.colonnes.map((element) => element.text);
42
-
43
- const dataRows = [];
44
- const itemsExportes = itemsAExporter.map((row) => {
45
- const dataRow = [];
46
- const item = {};
47
- header.map((column) => {
48
- dataRow.push(row[column]);
49
- if (row[column] != null) item[column] = row[column];
50
- return true;
51
- });
52
- dataRows.push(dataRow);
53
- return item;
54
- });
55
- const ws = utils.aoa_to_sheet([headerText, ...dataRows]);
56
- const wb = utils.book_new();
57
- utils.book_append_sheet(wb, ws, '1');
58
- writeFileXLSX(wb, `${this.nomFichier}.xlsx`);
59
-
60
- return itemsExportes;
61
- // this.$emit('apres');
62
- },
63
- },
64
- created() {
65
- },
66
- };
67
- </script>
1
+ <template>
2
+ <v-icon
3
+ right
4
+ color="grisMoyen"
5
+ @click="exportToXLSX"
6
+ icon="mdi-microsoft-excel"
7
+ >
8
+ </v-icon>
9
+ </template>
10
+
11
+ <script setup lang="ts">
12
+ import { utils, writeFileXLSX } from '@e965/xlsx'
13
+ import { defineProps, computed } from 'vue'
14
+
15
+ const props = defineProps<{
16
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
+ liste: any[]
18
+ nomFichier: string
19
+ chargementListe: boolean
20
+ }>()
21
+
22
+ // Extraction des clés uniques de tous les objets
23
+ const cleDynamique = computed(() => {
24
+ const keys = new Set<string>()
25
+
26
+ // Parcours tous les objets de la liste et ajoute leurs clés
27
+ props.liste.forEach(item => {
28
+ if (typeof item === 'object' && item !== null) {
29
+ Object.keys(item).forEach(key => keys.add(key))
30
+ }
31
+ })
32
+ return Array.from(keys)
33
+ })
34
+
35
+ // Fonction pour exporter les données en Excel
36
+ const exportToXLSX = () => {
37
+ if (!props.liste.length) {
38
+ console.warn('La liste est vide, exportation annulée.')
39
+ return
40
+ }
41
+
42
+ // Récupération des en-têtes depuis la fonction cleDynamique
43
+ const headers = cleDynamique.value
44
+
45
+ // Construction des lignes en respectant l'ordre des en-têtes
46
+ const rows = props.liste.map(item => {
47
+ return headers.map(key => (key in item ? item[key] : '')) // Valeur ou vide si absente
48
+ })
49
+
50
+ // Création des données Excel (en-têtes + lignes)
51
+ const data = [headers, ...rows]
52
+ // Génération du fichier Excel
53
+ const ws = utils.aoa_to_sheet(data)
54
+ const wb = utils.book_new()
55
+ utils.book_append_sheet(wb, ws, '1')
56
+ writeFileXLSX(wb, `${props.nomFichier}.xlsx`)
57
+ }
58
+ </script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codevdesign",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
4
4
  "description": "Composants Vuetify 3 pour les projets Codev",
5
5
  "files": [
6
6
  "./**/*.vue",
@@ -14,7 +14,8 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "vuetify": "^3.7.0",
17
- "vue-i18n": "^11.0.0"
17
+ "vue-i18n": "^11.0.0",
18
+ "@e965/xlsx": "^0.20.3"
18
19
  },
19
20
  "devDependencies": {
20
21
  "@types/node": "^22.13.5",