codevdesign 1.0.10 → 1.0.11

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.
@@ -118,7 +118,7 @@
118
118
  import { useDisplay } from 'vuetify'
119
119
  import ChaisePreferenceItem from './chaiseItem.vue'
120
120
  import csqcDialogue from '../csqcDialogue.vue'
121
- import axios from '../../../outils/appAxios'
121
+ import axios from '@/outils/appAxios'
122
122
  import type { Unite } from '@/codev/modeles/unite'
123
123
  import { useI18n } from 'vue-i18n'
124
124
  const modale = ref<InstanceType<typeof csqcDialogue> | null>(null)
@@ -22,7 +22,7 @@
22
22
  <script setup lang="ts">
23
23
  import { ref, watch, computed } from 'vue'
24
24
  import { useI18n } from 'vue-i18n'
25
- import appAxios from '../../outils/appAxios'
25
+ import appAxios from '@/outils/appAxios'
26
26
  import type { EmployeMinsLsCodev } from '../modeles/employeMinsLsCodev'
27
27
 
28
28
  const props = defineProps<{
@@ -1,586 +1,586 @@
1
- <template>
2
- <csqc-modale
3
- ref="modale"
4
- :titre="$tc('csqc-table.choixColonnes.titre')"
5
- :afficher-ok="false"
6
- :afficher-annuler="!sauvegardeEnCours"
7
- width="90vw"
8
- max-width="4000px"
9
- @fermer="fermer"
10
- >
11
- <v-alert
12
- v-model="afficherErreur"
13
- type="error"
14
- closable
15
- >{{ erreur }}</v-alert
16
- >
17
- <v-row>
18
- <v-col
19
- cols="12"
20
- class="pa-0 relative"
21
- >
22
- <v-btn
23
- v-show="choixRetourEnHaut"
24
- class="BarreRechercheBackIcone retourHautChoix"
25
- location="bottom right"
26
- absolute
27
- color="primary"
28
- @click="retourEnHaut('#choixColonnes-choix > .v-data-table__wrapper')"
29
- >
30
- <v-icon>mdi-arrow-up</v-icon>
31
- </v-btn>
32
- <v-data-table
33
- id="choixColonnes-choix"
34
- v-model:expanded="choixEnCours"
35
- class="limiteHauteurChoix"
36
- :headers="colonnesChoix"
37
- item-key="nomVue"
38
- :items="choix"
39
- single-expand
40
- disable-pagination
41
- hide-default-footer
42
- fixed-header
43
- @click:row="cliquer"
44
- >
45
- <template #header.action>
46
- <v-btn
47
- color="primary"
48
- class="float-right"
49
- size="small"
50
- :disabled="desactiverAjout"
51
- @click.stop="ajouter"
52
- >
53
- {{ $tc('csqc-table.button.ajouter') }}
54
- </v-btn>
55
- </template>
56
-
57
- <template #expanded-item="{ headers }">
58
- <td
59
- :colspan="headers.length"
60
- class="pa-0 ma-0"
61
- >
62
- <v-row
63
- class="pa-0 ma-0"
64
- no-gutters
65
- >
66
- <v-col
67
- cols="12"
68
- class="pa-0 ma-0"
69
- >
70
- <v-btn
71
- v-show="colonnesRetourEnHaut"
72
- class="BarreRechercheBackIcone retourHautChoix colonnes"
73
- location="bottom right"
74
- absolute
75
- color="primary"
76
- @click="retourEnHaut('#choixColonnes-vue > .v-data-table__wrapper')"
77
- >
78
- <v-icon>mdi-arrow-up</v-icon>
79
- </v-btn>
80
- <v-data-table
81
- id="choixColonnes-vue"
82
- v-model:sort-by="triColonnesChoix"
83
- v-sortable-data-table
84
- class="limiteHauteurChoix colonnes mt-1 mb-4 ml-2 ordonable"
85
- :headers="colonnesChoixColonne"
86
- :items="colonnesEnCours"
87
- item-key="value"
88
- hide-default-footer
89
- disable-pagination
90
- fixed-header
91
- :style="`margin-right: ${90 - $vuetify.breakpoint.scrollBarWidth}px;`"
92
- @sorted="changeOrdre"
93
- >
94
- <template
95
- v-if="choixEnCours[0]?.colonnes.length <= 0"
96
- #header.action
97
- >
98
- <v-tooltip
99
- location="left"
100
- color="warning"
101
- >
102
- <template #activator="{ props }">
103
- <v-icon
104
- color="warning"
105
- v-bind="props"
106
- >mdi-alert</v-icon
107
- >
108
- </template>
109
- {{ $tc('csqc-table.choixColonnes.activezUneColonne') }}
110
- </v-tooltip>
111
- </template>
112
-
113
- <template #item.action="{ item }">
114
- <v-btn
115
- class="mr-1"
116
- icon
117
- @click.stop="basculeColonneClique(item)"
118
- >
119
- <v-icon :color="couleurColonneCliquee(item)">{{
120
- colonneEstClique(item) ? 'mdi-eye' : 'mdi-eye-off'
121
- }}</v-icon>
122
- </v-btn>
123
- </template>
124
- <template #item.text="{ item }">{{ item.text ? item.text : item.value }}</template>
125
- </v-data-table>
126
- </v-col>
127
- </v-row>
128
- </td>
129
- </template>
130
-
131
- <template #item.nomVue="{ item }">
132
- <v-text-field
133
- v-if="item.nomVue === vueEnEdition"
134
- v-model.trim="nomVueEnCours"
135
- :label="$tc('csqc-table.choixColonnes.nomVue')"
136
- single-line
137
- density="compact"
138
- autofocus
139
- class="py-0 my-0"
140
- :rules="regles.nomVue"
141
- hide-details
142
- @keydown.enter="accepterEdition"
143
- @keydown.esc.stop="annulerEdition"
144
- ></v-text-field>
145
- <span
146
- v-else
147
- :class="{ 'error--text': !item.nomVue }"
148
- >
149
- {{ item.nomVue || $tc('csqc-table.choixColonnes.nomVueRequis') }}
150
- </span>
151
- </template>
152
- <template #item.action="{ item }">
153
- <template v-if="item.nomVue === vueEnEdition">
154
- <v-btn
155
- icon
156
- @click.stop.prevent="annulerEdition"
157
- ><v-icon class="iconeSupprimer">mdi-window-close</v-icon></v-btn
158
- >
159
- <v-btn
160
- icon
161
- @click.stop.prevent="accepterEdition"
162
- ><v-icon class="couleurHover">mdi-check</v-icon></v-btn
163
- >
164
- </template>
165
- <template v-else>
166
- <v-btn
167
- icon
168
- @click.stop.prevent="selectionner(item)"
169
- ><v-icon class="couleurHover">mdi-eye</v-icon></v-btn
170
- >
171
- <v-btn
172
- icon
173
- @click.stop.prevent="mettreDefaut(item)"
174
- >
175
- <v-icon
176
- class="couleurHover"
177
- :color="couleurDefaut(item)"
178
- >mdi-star</v-icon
179
- >
180
- </v-btn>
181
- <v-btn
182
- icon
183
- @click.stop.prevent="editer(item)"
184
- ><v-icon class="couleurHover">mdi-pencil</v-icon></v-btn
185
- >
186
- <v-btn
187
- icon
188
- @click.stop.prevent="supprimer(item)"
189
- ><v-icon class="iconeSupprimer">mdi-delete</v-icon></v-btn
190
- >
191
- </template>
192
- </template>
193
- </v-data-table>
194
- </v-col>
195
- </v-row>
196
-
197
- <template #actions>
198
- <v-btn
199
- color="primary"
200
- class="elevation-0"
201
- :disabled="!formValide"
202
- :loading="sauvegardeEnCours"
203
- @click.stop="sauvegarder"
204
- >
205
- {{ $tc('csqc-table.choixColonnes.ok') }}
206
- </v-btn>
207
- </template>
208
- </csqc-modale>
209
- </template>
210
-
211
- <script>
212
- import Sortable from 'sortablejs'
213
- import axios from 'axios'
214
- import CsqcModale from '../CsqcDialogue/csqc-boite-dialogue.vue'
215
-
216
- export default {
217
- directives: {
218
- sortableDataTable: {
219
- bind(el, binding, vnode) {
220
- const options = {
221
- animation: 150,
222
- onUpdate(event) {
223
- vnode.child.$emit('sorted', event)
224
- },
225
- }
226
- Sortable.create(el.getElementsByTagName('tbody')[0], options)
227
- },
228
- },
229
- },
230
- components: {
231
- 'csqc-modale': CsqcModale,
232
- },
233
- props: {
234
- urlbase: {
235
- required: true,
236
- type: String,
237
- },
238
- formulaireId: {
239
- required: true,
240
- type: Number,
241
- },
242
- identifiant: {
243
- required: true,
244
- type: String,
245
- },
246
- colonnes: {
247
- required: true,
248
- type: Array,
249
- },
250
- choixOrigine: {
251
- required: true,
252
- type: Array,
253
- },
254
- },
255
- data() {
256
- return {
257
- erreur: '',
258
- afficherErreur: false,
259
- choixEnCours: [],
260
- choix: [],
261
- colonnesEnCours: [],
262
- triColonnesChoix: ['ordre'],
263
- sauvegardeEnCours: false,
264
- choixRetourEnHaut: false,
265
- colonnesRetourEnHaut: false,
266
- nomVueEnCours: '',
267
- vueEnEdition: '',
268
- desactiverAjout: false,
269
- regles: {
270
- nomVue: [
271
- v => (v && v.trim().length >= 1) || this.$tc('csqc-table.choixColonnes.nomVueRequis'),
272
- v =>
273
- !this.choix.some(({ nomVue }) => v.trim() === nomVue) ||
274
- this.$tc('csqc-table.choixColonnes.nomVueExiste'),
275
- ],
276
- },
277
- }
278
- },
279
-
280
- computed: {
281
- colonnesCliquees() {
282
- if (this.choixEnCours.length <= 0) return []
283
-
284
- const retour = this.colonnesEnCours
285
- .filter(c => this.choixEnCours[0].colonnes.some(x => x === c.value))
286
- .map(c => c.value)
287
- return retour
288
- },
289
- colonnesChoixColonne() {
290
- const cols = [
291
- {
292
- text: this.$tc('csqc-table.choixColonnes.ordre'),
293
- align: 'start',
294
- sortable: false,
295
- value: 'ordre',
296
- width: '5%',
297
- },
298
- {
299
- text: this.$tc('csqc-table.choixColonnes.nomColonne', this.colonnesEnCours.length),
300
- align: 'start',
301
- sortable: false,
302
- value: 'text',
303
- width: '85%',
304
- },
305
- {
306
- value: 'action',
307
- sortable: false,
308
- width: '10%',
309
- align: 'right',
310
- },
311
- ]
312
- return cols
313
- },
314
- colonnesChoix() {
315
- return [
316
- {
317
- text: this.$tc('csqc-table.choixColonnes.vues', this.choix.length),
318
- value: 'nomVue',
319
- width: '70%',
320
- align: 'start',
321
- },
322
- {
323
- value: 'action',
324
- width: '30%',
325
- align: 'right',
326
- sortable: false,
327
- },
328
- ]
329
- },
330
- formValide() {
331
- return !this.choix.some(vue => vue.nomVue === '' || vue.colonnes.length <= 0)
332
- },
333
- },
334
-
335
- watch: {
336
- erreur() {
337
- this.afficherErreur = this.erreur !== ''
338
- },
339
- afficherErreur() {
340
- if (this.afficherErreur === false) {
341
- this.erreur = ''
342
- }
343
- },
344
- },
345
- methods: {
346
- ouvrir() {
347
- this.choix = JSON.parse(JSON.stringify(this.choixOrigine))
348
- this.$refs.modale.ouvrir()
349
- this.ecouteDefilerChoix()
350
- },
351
-
352
- fermer() {
353
- this.sauvegardeEnCours = false
354
- this.desactiverAjout = false
355
- this.vueEnEdition = ''
356
- this.choixEnCours = []
357
- this.colonnesEnCours = []
358
- this.erreur = ''
359
- this.$refs.modale.fermer()
360
- },
361
-
362
- ajouter() {
363
- const ch = {
364
- nomVue: '',
365
- colonnes: [],
366
- defaut: this.choix.length === 0,
367
- }
368
- this.choix.push(ch)
369
-
370
- this.cliquer(ch)
371
- this.editer(ch)
372
- },
373
- editer(ch) {
374
- this.desactiverAjout = true
375
- if (ch.nomVue !== '') this.supprimer({ nomVue: '' })
376
-
377
- this.erreur = ''
378
- this.nomVueEnCours = ch.nomVue
379
- this.vueEnEdition = ch.nomVue
380
- },
381
- accepterEdition() {
382
- if (!this.nomVueEnCours) {
383
- this.erreur = this.$tc('csqc-table.choixColonnes.nomVueRequis')
384
- return
385
- }
386
-
387
- if (this.choix.some(({ nomVue }) => nomVue === this.nomVueEnCours)) {
388
- this.erreur = this.$tc('csqc-table.choixColonnes.nomVueExiste')
389
- return
390
- }
391
-
392
- const ch = this.choix.find(({ nomVue }) => nomVue === this.vueEnEdition)
393
- const choixClique = this.choixEstClique(ch)
394
-
395
- ch.nomVue = this.nomVueEnCours
396
- if (choixClique) this.choixEnCours = [ch]
397
- this.vueEnEdition = ''
398
- this.nomVueEnCours = ''
399
- this.desactiverAjout = false
400
- },
401
- annulerEdition() {
402
- const ch = this.choix.find(({ nomVue }) => nomVue === this.vueEnEdition)
403
- if (ch.nomVue === '') this.supprimer(ch)
404
- this.vueEnEdition = ''
405
- this.nomVueEnCours = ''
406
- this.desactiverAjout = false
407
- },
408
-
409
- selectionner(ch) {
410
- this.$emit('selection', ch)
411
- this.fermer()
412
- },
413
-
414
- cliquer(ch) {
415
- if (this.choixEnCours.length > 0) this.retourEnHaut('#choixColonnes-vue > .v-data-table__wrapper')
416
- if (this.choixEstClique(ch)) {
417
- this.choixEnCours = []
418
- this.colonnesEnCours = []
419
- return
420
- }
421
-
422
- this.colonnesEnCours = JSON.parse(JSON.stringify(this.colonnes)) // Toujours commencer avec les colonnes par défaut
423
- this.choixEnCours = [ch]
424
- const tempCols = []
425
- const colsPlusDispo = []
426
-
427
- this.choixEnCours[0].colonnes.forEach(colonne => {
428
- const tCol = this.colonnesEnCours.find(c => c.value === colonne)
429
- if (tCol == null)
430
- colsPlusDispo.push(colonne) // Ne supprime pas dans la collection lors son itération
431
- else tempCols.push(tCol)
432
- })
433
-
434
- // Nettoyer la vue au besoin (effectif seulement si l'utilisateur sauve les choix)
435
- if (colsPlusDispo.length > 0) {
436
- this.choixEnCours[0].colonnes = this.choixEnCours[0].colonnes.filter(
437
- c => !colsPlusDispo.some(cpd => c === cpd),
438
- )
439
- }
440
-
441
- this.colonnesEnCours = tempCols.concat(
442
- this.colonnesEnCours.filter(c => !this.choixEnCours[0].colonnes.some(cch => cch === c.value)),
443
- )
444
- this.calculOrdreColonnes()
445
- this.ecouteDefilerColonnes()
446
- },
447
-
448
- choixEstClique(ch) {
449
- return ch.nomVue === this.choixEnCours[0]?.nomVue
450
- },
451
-
452
- mettreDefaut(ch) {
453
- this.choix.find(({ defaut }) => defaut).defaut = false
454
- this.choix.find(({ nomVue }) => nomVue === ch.nomVue).defaut = true
455
- },
456
- couleurDefaut(ch) {
457
- if (ch.defaut === true) {
458
- return '#daa520'
459
- }
460
-
461
- return 'gray'
462
- },
463
-
464
- colonneEstClique(colonne) {
465
- if (this.choixEnCours.length <= 0) {
466
- return false
467
- }
468
-
469
- return this.choixEnCours[0].colonnes.some(x => x === colonne.value)
470
- },
471
- couleurColonneCliquee(colonne) {
472
- if (this.colonneEstClique(colonne)) return 'primary'
473
- return 'gray'
474
- },
475
- basculeColonneClique(colonne) {
476
- if (this.colonneEstClique(colonne)) {
477
- this.choixEnCours[0].colonnes = this.choixEnCours[0].colonnes.filter(x => x !== colonne.value)
478
- return
479
- }
480
-
481
- this.choixEnCours[0].colonnes.push(colonne.value)
482
- },
483
-
484
- changeOrdre(event) {
485
- const movedItem = this.colonnesEnCours.splice(event.oldIndex, 1)[0]
486
- this.colonnesEnCours.splice(event.newIndex, 0, movedItem)
487
- this.calculOrdreColonnes()
488
- this.choixEnCours[0].colonnes = this.colonnesCliquees
489
- },
490
- calculOrdreColonnes() {
491
- for (let i = 0; i < this.colonnesEnCours.length; i += 1) {
492
- this.colonnesEnCours[i].ordre = 1 + i
493
- }
494
- },
495
-
496
- supprimer(ch) {
497
- if (this.choixEstClique(ch)) this.choixEnCours = []
498
-
499
- const index = this.choix.findIndex(({ nomVue }) => nomVue === ch.nomVue)
500
- if (index === -1) {
501
- return
502
- }
503
-
504
- if (this.choix[index].defaut) {
505
- const nonDefaut = this.choix.find(({ nomVue }) => nomVue !== ch.nomVue)
506
- if (nonDefaut) {
507
- nonDefaut.defaut = true
508
- }
509
- }
510
-
511
- this.choix.splice(index, 1)
512
- },
513
-
514
- // ENREGISTREMENT
515
- sauvegarder() {
516
- axios
517
- .post(`${this.urlbase}/api/ComposantUI/Colonnes/${this.formulaireId}/Identifiant/${this.identifiant}`, {
518
- valeur: JSON.stringify(this.choix),
519
- })
520
- .then(({ data }) => {
521
- this.choix = JSON.parse(data.resultat)
522
- this.$emit('sauvegarde', this.choix)
523
- if (this.choixEnCours.length > 0) this.$emit('selection', this.choixEnCours[0])
524
- this.fermer()
525
- })
526
- .catch(e => {
527
- this.erreur = e
528
- })
529
- },
530
-
531
- retourEnHaut(cible) {
532
- this.$vuetify.goTo(0, { container: cible })
533
- },
534
- defilerChoix(e) {
535
- this.choixRetourEnHaut = e.target.scrollTop >= 200
536
- },
537
- ecouteDefilerChoix() {
538
- const vdtwChoix = document.querySelector('#choixColonnes-choix > .v-data-table__wrapper')
539
- if (vdtwChoix == null) {
540
- setTimeout(this.ecouteDefilerChoix.bind(this), 100)
541
- return
542
- }
543
- vdtwChoix.addEventListener('scroll', this.defilerChoix.bind(this))
544
- },
545
- defilerColonnes(e) {
546
- this.colonnesRetourEnHaut = e.target.scrollTop >= 200
547
- },
548
- ecouteDefilerColonnes() {
549
- const vdtwCols = document.querySelector('#choixColonnes-vue > .v-data-table__wrapper')
550
- if (vdtwCols == null) {
551
- setTimeout(this.ecouteDefilerColonnes.bind(this), 100)
552
- return
553
- }
554
- vdtwCols.addEventListener('scroll', this.defilerColonnes.bind(this))
555
- },
556
- },
557
- }
558
- </script>
559
- <style scoped>
560
- .relative {
561
- position: relative;
562
- }
563
- .retourHautChoix {
564
- bottom: 4px !important;
565
- right: 4px;
566
- }
567
- .retourHautChoix.colonnes {
568
- bottom: 8px !important;
569
- right: 48px;
570
- }
571
- </style>
572
- <style>
573
- .limiteHauteurChoix > .v-data-table__wrapper {
574
- max-height: min(80vh - 200px, 900px);
575
- overflow-y: auto;
576
- }
577
- #choixColonnes-choix > .v-data-table__wrapper > table > thead > tr > th {
578
- z-index: 3;
579
- }
580
- .limiteHauteurChoix.colonnes > .v-data-table__wrapper {
581
- max-height: min(80vh - 294px, 600px);
582
- }
583
- .v-data-table.ordonable > .v-data-table__wrapper > table > tbody > tr {
584
- cursor: move;
585
- }
586
- </style>
1
+ <template>
2
+ <csqc-modale
3
+ ref="modale"
4
+ :titre="$tc('csqc-table.choixColonnes.titre')"
5
+ :afficher-ok="false"
6
+ :afficher-annuler="!sauvegardeEnCours"
7
+ width="90vw"
8
+ max-width="4000px"
9
+ @fermer="fermer"
10
+ >
11
+ <v-alert
12
+ v-model="afficherErreur"
13
+ type="error"
14
+ closable
15
+ >{{ erreur }}</v-alert
16
+ >
17
+ <v-row>
18
+ <v-col
19
+ cols="12"
20
+ class="pa-0 relative"
21
+ >
22
+ <v-btn
23
+ v-show="choixRetourEnHaut"
24
+ class="BarreRechercheBackIcone retourHautChoix"
25
+ location="bottom right"
26
+ absolute
27
+ color="primary"
28
+ @click="retourEnHaut('#choixColonnes-choix > .v-data-table__wrapper')"
29
+ >
30
+ <v-icon>mdi-arrow-up</v-icon>
31
+ </v-btn>
32
+ <v-data-table
33
+ id="choixColonnes-choix"
34
+ v-model:expanded="choixEnCours"
35
+ class="limiteHauteurChoix"
36
+ :headers="colonnesChoix"
37
+ item-key="nomVue"
38
+ :items="choix"
39
+ single-expand
40
+ disable-pagination
41
+ hide-default-footer
42
+ fixed-header
43
+ @click:row="cliquer"
44
+ >
45
+ <template #header.action>
46
+ <v-btn
47
+ color="primary"
48
+ class="float-right"
49
+ size="small"
50
+ :disabled="desactiverAjout"
51
+ @click.stop="ajouter"
52
+ >
53
+ {{ $tc('csqc-table.button.ajouter') }}
54
+ </v-btn>
55
+ </template>
56
+
57
+ <template #expanded-item="{ headers }">
58
+ <td
59
+ :colspan="headers.length"
60
+ class="pa-0 ma-0"
61
+ >
62
+ <v-row
63
+ class="pa-0 ma-0"
64
+ no-gutters
65
+ >
66
+ <v-col
67
+ cols="12"
68
+ class="pa-0 ma-0"
69
+ >
70
+ <v-btn
71
+ v-show="colonnesRetourEnHaut"
72
+ class="BarreRechercheBackIcone retourHautChoix colonnes"
73
+ location="bottom right"
74
+ absolute
75
+ color="primary"
76
+ @click="retourEnHaut('#choixColonnes-vue > .v-data-table__wrapper')"
77
+ >
78
+ <v-icon>mdi-arrow-up</v-icon>
79
+ </v-btn>
80
+ <v-data-table
81
+ id="choixColonnes-vue"
82
+ v-model:sort-by="triColonnesChoix"
83
+ v-sortable-data-table
84
+ class="limiteHauteurChoix colonnes mt-1 mb-4 ml-2 ordonable"
85
+ :headers="colonnesChoixColonne"
86
+ :items="colonnesEnCours"
87
+ item-key="value"
88
+ hide-default-footer
89
+ disable-pagination
90
+ fixed-header
91
+ :style="`margin-right: ${90 - $vuetify.breakpoint.scrollBarWidth}px;`"
92
+ @sorted="changeOrdre"
93
+ >
94
+ <template
95
+ v-if="choixEnCours[0]?.colonnes.length <= 0"
96
+ #header.action
97
+ >
98
+ <v-tooltip
99
+ location="left"
100
+ color="warning"
101
+ >
102
+ <template #activator="{ props }">
103
+ <v-icon
104
+ color="warning"
105
+ v-bind="props"
106
+ >mdi-alert</v-icon
107
+ >
108
+ </template>
109
+ {{ $tc('csqc-table.choixColonnes.activezUneColonne') }}
110
+ </v-tooltip>
111
+ </template>
112
+
113
+ <template #item.action="{ item }">
114
+ <v-btn
115
+ class="mr-1"
116
+ icon
117
+ @click.stop="basculeColonneClique(item)"
118
+ >
119
+ <v-icon :color="couleurColonneCliquee(item)">{{
120
+ colonneEstClique(item) ? 'mdi-eye' : 'mdi-eye-off'
121
+ }}</v-icon>
122
+ </v-btn>
123
+ </template>
124
+ <template #item.text="{ item }">{{ item.text ? item.text : item.value }}</template>
125
+ </v-data-table>
126
+ </v-col>
127
+ </v-row>
128
+ </td>
129
+ </template>
130
+
131
+ <template #item.nomVue="{ item }">
132
+ <v-text-field
133
+ v-if="item.nomVue === vueEnEdition"
134
+ v-model.trim="nomVueEnCours"
135
+ :label="$tc('csqc-table.choixColonnes.nomVue')"
136
+ single-line
137
+ density="compact"
138
+ autofocus
139
+ class="py-0 my-0"
140
+ :rules="regles.nomVue"
141
+ hide-details
142
+ @keydown.enter="accepterEdition"
143
+ @keydown.esc.stop="annulerEdition"
144
+ ></v-text-field>
145
+ <span
146
+ v-else
147
+ :class="{ 'error--text': !item.nomVue }"
148
+ >
149
+ {{ item.nomVue || $tc('csqc-table.choixColonnes.nomVueRequis') }}
150
+ </span>
151
+ </template>
152
+ <template #item.action="{ item }">
153
+ <template v-if="item.nomVue === vueEnEdition">
154
+ <v-btn
155
+ icon
156
+ @click.stop.prevent="annulerEdition"
157
+ ><v-icon class="iconeSupprimer">mdi-window-close</v-icon></v-btn
158
+ >
159
+ <v-btn
160
+ icon
161
+ @click.stop.prevent="accepterEdition"
162
+ ><v-icon class="couleurHover">mdi-check</v-icon></v-btn
163
+ >
164
+ </template>
165
+ <template v-else>
166
+ <v-btn
167
+ icon
168
+ @click.stop.prevent="selectionner(item)"
169
+ ><v-icon class="couleurHover">mdi-eye</v-icon></v-btn
170
+ >
171
+ <v-btn
172
+ icon
173
+ @click.stop.prevent="mettreDefaut(item)"
174
+ >
175
+ <v-icon
176
+ class="couleurHover"
177
+ :color="couleurDefaut(item)"
178
+ >mdi-star</v-icon
179
+ >
180
+ </v-btn>
181
+ <v-btn
182
+ icon
183
+ @click.stop.prevent="editer(item)"
184
+ ><v-icon class="couleurHover">mdi-pencil</v-icon></v-btn
185
+ >
186
+ <v-btn
187
+ icon
188
+ @click.stop.prevent="supprimer(item)"
189
+ ><v-icon class="iconeSupprimer">mdi-delete</v-icon></v-btn
190
+ >
191
+ </template>
192
+ </template>
193
+ </v-data-table>
194
+ </v-col>
195
+ </v-row>
196
+
197
+ <template #actions>
198
+ <v-btn
199
+ color="primary"
200
+ class="elevation-0"
201
+ :disabled="!formValide"
202
+ :loading="sauvegardeEnCours"
203
+ @click.stop="sauvegarder"
204
+ >
205
+ {{ $tc('csqc-table.choixColonnes.ok') }}
206
+ </v-btn>
207
+ </template>
208
+ </csqc-modale>
209
+ </template>
210
+
211
+ <script>
212
+ import Sortable from 'sortablejs'
213
+ import axios from '@/outils/appAxios'
214
+ import CsqcModale from '../CsqcDialogue/csqc-boite-dialogue.vue'
215
+
216
+ export default {
217
+ directives: {
218
+ sortableDataTable: {
219
+ bind(el, binding, vnode) {
220
+ const options = {
221
+ animation: 150,
222
+ onUpdate(event) {
223
+ vnode.child.$emit('sorted', event)
224
+ },
225
+ }
226
+ Sortable.create(el.getElementsByTagName('tbody')[0], options)
227
+ },
228
+ },
229
+ },
230
+ components: {
231
+ 'csqc-modale': CsqcModale,
232
+ },
233
+ props: {
234
+ urlbase: {
235
+ required: true,
236
+ type: String,
237
+ },
238
+ formulaireId: {
239
+ required: true,
240
+ type: Number,
241
+ },
242
+ identifiant: {
243
+ required: true,
244
+ type: String,
245
+ },
246
+ colonnes: {
247
+ required: true,
248
+ type: Array,
249
+ },
250
+ choixOrigine: {
251
+ required: true,
252
+ type: Array,
253
+ },
254
+ },
255
+ data() {
256
+ return {
257
+ erreur: '',
258
+ afficherErreur: false,
259
+ choixEnCours: [],
260
+ choix: [],
261
+ colonnesEnCours: [],
262
+ triColonnesChoix: ['ordre'],
263
+ sauvegardeEnCours: false,
264
+ choixRetourEnHaut: false,
265
+ colonnesRetourEnHaut: false,
266
+ nomVueEnCours: '',
267
+ vueEnEdition: '',
268
+ desactiverAjout: false,
269
+ regles: {
270
+ nomVue: [
271
+ v => (v && v.trim().length >= 1) || this.$tc('csqc-table.choixColonnes.nomVueRequis'),
272
+ v =>
273
+ !this.choix.some(({ nomVue }) => v.trim() === nomVue) ||
274
+ this.$tc('csqc-table.choixColonnes.nomVueExiste'),
275
+ ],
276
+ },
277
+ }
278
+ },
279
+
280
+ computed: {
281
+ colonnesCliquees() {
282
+ if (this.choixEnCours.length <= 0) return []
283
+
284
+ const retour = this.colonnesEnCours
285
+ .filter(c => this.choixEnCours[0].colonnes.some(x => x === c.value))
286
+ .map(c => c.value)
287
+ return retour
288
+ },
289
+ colonnesChoixColonne() {
290
+ const cols = [
291
+ {
292
+ text: this.$tc('csqc-table.choixColonnes.ordre'),
293
+ align: 'start',
294
+ sortable: false,
295
+ value: 'ordre',
296
+ width: '5%',
297
+ },
298
+ {
299
+ text: this.$tc('csqc-table.choixColonnes.nomColonne', this.colonnesEnCours.length),
300
+ align: 'start',
301
+ sortable: false,
302
+ value: 'text',
303
+ width: '85%',
304
+ },
305
+ {
306
+ value: 'action',
307
+ sortable: false,
308
+ width: '10%',
309
+ align: 'right',
310
+ },
311
+ ]
312
+ return cols
313
+ },
314
+ colonnesChoix() {
315
+ return [
316
+ {
317
+ text: this.$tc('csqc-table.choixColonnes.vues', this.choix.length),
318
+ value: 'nomVue',
319
+ width: '70%',
320
+ align: 'start',
321
+ },
322
+ {
323
+ value: 'action',
324
+ width: '30%',
325
+ align: 'right',
326
+ sortable: false,
327
+ },
328
+ ]
329
+ },
330
+ formValide() {
331
+ return !this.choix.some(vue => vue.nomVue === '' || vue.colonnes.length <= 0)
332
+ },
333
+ },
334
+
335
+ watch: {
336
+ erreur() {
337
+ this.afficherErreur = this.erreur !== ''
338
+ },
339
+ afficherErreur() {
340
+ if (this.afficherErreur === false) {
341
+ this.erreur = ''
342
+ }
343
+ },
344
+ },
345
+ methods: {
346
+ ouvrir() {
347
+ this.choix = JSON.parse(JSON.stringify(this.choixOrigine))
348
+ this.$refs.modale.ouvrir()
349
+ this.ecouteDefilerChoix()
350
+ },
351
+
352
+ fermer() {
353
+ this.sauvegardeEnCours = false
354
+ this.desactiverAjout = false
355
+ this.vueEnEdition = ''
356
+ this.choixEnCours = []
357
+ this.colonnesEnCours = []
358
+ this.erreur = ''
359
+ this.$refs.modale.fermer()
360
+ },
361
+
362
+ ajouter() {
363
+ const ch = {
364
+ nomVue: '',
365
+ colonnes: [],
366
+ defaut: this.choix.length === 0,
367
+ }
368
+ this.choix.push(ch)
369
+
370
+ this.cliquer(ch)
371
+ this.editer(ch)
372
+ },
373
+ editer(ch) {
374
+ this.desactiverAjout = true
375
+ if (ch.nomVue !== '') this.supprimer({ nomVue: '' })
376
+
377
+ this.erreur = ''
378
+ this.nomVueEnCours = ch.nomVue
379
+ this.vueEnEdition = ch.nomVue
380
+ },
381
+ accepterEdition() {
382
+ if (!this.nomVueEnCours) {
383
+ this.erreur = this.$tc('csqc-table.choixColonnes.nomVueRequis')
384
+ return
385
+ }
386
+
387
+ if (this.choix.some(({ nomVue }) => nomVue === this.nomVueEnCours)) {
388
+ this.erreur = this.$tc('csqc-table.choixColonnes.nomVueExiste')
389
+ return
390
+ }
391
+
392
+ const ch = this.choix.find(({ nomVue }) => nomVue === this.vueEnEdition)
393
+ const choixClique = this.choixEstClique(ch)
394
+
395
+ ch.nomVue = this.nomVueEnCours
396
+ if (choixClique) this.choixEnCours = [ch]
397
+ this.vueEnEdition = ''
398
+ this.nomVueEnCours = ''
399
+ this.desactiverAjout = false
400
+ },
401
+ annulerEdition() {
402
+ const ch = this.choix.find(({ nomVue }) => nomVue === this.vueEnEdition)
403
+ if (ch.nomVue === '') this.supprimer(ch)
404
+ this.vueEnEdition = ''
405
+ this.nomVueEnCours = ''
406
+ this.desactiverAjout = false
407
+ },
408
+
409
+ selectionner(ch) {
410
+ this.$emit('selection', ch)
411
+ this.fermer()
412
+ },
413
+
414
+ cliquer(ch) {
415
+ if (this.choixEnCours.length > 0) this.retourEnHaut('#choixColonnes-vue > .v-data-table__wrapper')
416
+ if (this.choixEstClique(ch)) {
417
+ this.choixEnCours = []
418
+ this.colonnesEnCours = []
419
+ return
420
+ }
421
+
422
+ this.colonnesEnCours = JSON.parse(JSON.stringify(this.colonnes)) // Toujours commencer avec les colonnes par défaut
423
+ this.choixEnCours = [ch]
424
+ const tempCols = []
425
+ const colsPlusDispo = []
426
+
427
+ this.choixEnCours[0].colonnes.forEach(colonne => {
428
+ const tCol = this.colonnesEnCours.find(c => c.value === colonne)
429
+ if (tCol == null)
430
+ colsPlusDispo.push(colonne) // Ne supprime pas dans la collection lors son itération
431
+ else tempCols.push(tCol)
432
+ })
433
+
434
+ // Nettoyer la vue au besoin (effectif seulement si l'utilisateur sauve les choix)
435
+ if (colsPlusDispo.length > 0) {
436
+ this.choixEnCours[0].colonnes = this.choixEnCours[0].colonnes.filter(
437
+ c => !colsPlusDispo.some(cpd => c === cpd),
438
+ )
439
+ }
440
+
441
+ this.colonnesEnCours = tempCols.concat(
442
+ this.colonnesEnCours.filter(c => !this.choixEnCours[0].colonnes.some(cch => cch === c.value)),
443
+ )
444
+ this.calculOrdreColonnes()
445
+ this.ecouteDefilerColonnes()
446
+ },
447
+
448
+ choixEstClique(ch) {
449
+ return ch.nomVue === this.choixEnCours[0]?.nomVue
450
+ },
451
+
452
+ mettreDefaut(ch) {
453
+ this.choix.find(({ defaut }) => defaut).defaut = false
454
+ this.choix.find(({ nomVue }) => nomVue === ch.nomVue).defaut = true
455
+ },
456
+ couleurDefaut(ch) {
457
+ if (ch.defaut === true) {
458
+ return '#daa520'
459
+ }
460
+
461
+ return 'gray'
462
+ },
463
+
464
+ colonneEstClique(colonne) {
465
+ if (this.choixEnCours.length <= 0) {
466
+ return false
467
+ }
468
+
469
+ return this.choixEnCours[0].colonnes.some(x => x === colonne.value)
470
+ },
471
+ couleurColonneCliquee(colonne) {
472
+ if (this.colonneEstClique(colonne)) return 'primary'
473
+ return 'gray'
474
+ },
475
+ basculeColonneClique(colonne) {
476
+ if (this.colonneEstClique(colonne)) {
477
+ this.choixEnCours[0].colonnes = this.choixEnCours[0].colonnes.filter(x => x !== colonne.value)
478
+ return
479
+ }
480
+
481
+ this.choixEnCours[0].colonnes.push(colonne.value)
482
+ },
483
+
484
+ changeOrdre(event) {
485
+ const movedItem = this.colonnesEnCours.splice(event.oldIndex, 1)[0]
486
+ this.colonnesEnCours.splice(event.newIndex, 0, movedItem)
487
+ this.calculOrdreColonnes()
488
+ this.choixEnCours[0].colonnes = this.colonnesCliquees
489
+ },
490
+ calculOrdreColonnes() {
491
+ for (let i = 0; i < this.colonnesEnCours.length; i += 1) {
492
+ this.colonnesEnCours[i].ordre = 1 + i
493
+ }
494
+ },
495
+
496
+ supprimer(ch) {
497
+ if (this.choixEstClique(ch)) this.choixEnCours = []
498
+
499
+ const index = this.choix.findIndex(({ nomVue }) => nomVue === ch.nomVue)
500
+ if (index === -1) {
501
+ return
502
+ }
503
+
504
+ if (this.choix[index].defaut) {
505
+ const nonDefaut = this.choix.find(({ nomVue }) => nomVue !== ch.nomVue)
506
+ if (nonDefaut) {
507
+ nonDefaut.defaut = true
508
+ }
509
+ }
510
+
511
+ this.choix.splice(index, 1)
512
+ },
513
+
514
+ // ENREGISTREMENT
515
+ sauvegarder() {
516
+ axios
517
+ .post(`${this.urlbase}/api/ComposantUI/Colonnes/${this.formulaireId}/Identifiant/${this.identifiant}`, {
518
+ valeur: JSON.stringify(this.choix),
519
+ })
520
+ .then(({ data }) => {
521
+ this.choix = JSON.parse(data.resultat)
522
+ this.$emit('sauvegarde', this.choix)
523
+ if (this.choixEnCours.length > 0) this.$emit('selection', this.choixEnCours[0])
524
+ this.fermer()
525
+ })
526
+ .catch(e => {
527
+ this.erreur = e
528
+ })
529
+ },
530
+
531
+ retourEnHaut(cible) {
532
+ this.$vuetify.goTo(0, { container: cible })
533
+ },
534
+ defilerChoix(e) {
535
+ this.choixRetourEnHaut = e.target.scrollTop >= 200
536
+ },
537
+ ecouteDefilerChoix() {
538
+ const vdtwChoix = document.querySelector('#choixColonnes-choix > .v-data-table__wrapper')
539
+ if (vdtwChoix == null) {
540
+ setTimeout(this.ecouteDefilerChoix.bind(this), 100)
541
+ return
542
+ }
543
+ vdtwChoix.addEventListener('scroll', this.defilerChoix.bind(this))
544
+ },
545
+ defilerColonnes(e) {
546
+ this.colonnesRetourEnHaut = e.target.scrollTop >= 200
547
+ },
548
+ ecouteDefilerColonnes() {
549
+ const vdtwCols = document.querySelector('#choixColonnes-vue > .v-data-table__wrapper')
550
+ if (vdtwCols == null) {
551
+ setTimeout(this.ecouteDefilerColonnes.bind(this), 100)
552
+ return
553
+ }
554
+ vdtwCols.addEventListener('scroll', this.defilerColonnes.bind(this))
555
+ },
556
+ },
557
+ }
558
+ </script>
559
+ <style scoped>
560
+ .relative {
561
+ position: relative;
562
+ }
563
+ .retourHautChoix {
564
+ bottom: 4px !important;
565
+ right: 4px;
566
+ }
567
+ .retourHautChoix.colonnes {
568
+ bottom: 8px !important;
569
+ right: 48px;
570
+ }
571
+ </style>
572
+ <style>
573
+ .limiteHauteurChoix > .v-data-table__wrapper {
574
+ max-height: min(80vh - 200px, 900px);
575
+ overflow-y: auto;
576
+ }
577
+ #choixColonnes-choix > .v-data-table__wrapper > table > thead > tr > th {
578
+ z-index: 3;
579
+ }
580
+ .limiteHauteurChoix.colonnes > .v-data-table__wrapper {
581
+ max-height: min(80vh - 294px, 600px);
582
+ }
583
+ .v-data-table.ordonable > .v-data-table__wrapper > table > tbody > tr {
584
+ cursor: move;
585
+ }
586
+ </style>
@@ -0,0 +1,116 @@
1
+ import axios, { type AxiosInstance, type AxiosError, type AxiosResponse } from 'axios'
2
+ import { useAppStore } from '@/store/appStore'
3
+ import router from '@/router'
4
+
5
+ type ApiReponse<T = unknown> =
6
+ // Succès
7
+ | {
8
+ succes: true
9
+ resultat: T
10
+ status?: number
11
+ message?: string
12
+ location?: string
13
+ parametres?: unknown
14
+ [k: string]: unknown
15
+ }
16
+ // Échec (le backend peut quand même renvoyer resultat null/absent)
17
+ | {
18
+ succes: false
19
+ resultat?: unknown
20
+ status?: number
21
+ message?: string
22
+ location?: string
23
+ parametres?: unknown
24
+ [k: string]: unknown
25
+ }
26
+
27
+ let client: AxiosInstance | null = null
28
+ let cachedBaseUrl = '' // pour éviter de régénérer une instance axios si rien n’a changé
29
+
30
+ export default {
31
+ clearCache: false,
32
+
33
+ getAxios(): AxiosInstance {
34
+ // Singleton + clearCache
35
+ if (client && !this.clearCache) return client
36
+
37
+ const appStore = useAppStore()
38
+
39
+ const rawUrl = appStore.modeleCharger
40
+ ? appStore.appModele!.urlBase
41
+ : window.location.origin + import.meta.env.BASE_URL
42
+
43
+ const urlBase = rawUrl.endsWith('/') ? rawUrl.slice(0, -1) : rawUrl
44
+
45
+ // Si la base URL n'a pas changé et qu'on a déjà un client, on le renvoie
46
+ if (client && cachedBaseUrl === urlBase && !this.clearCache) return client
47
+ cachedBaseUrl = urlBase
48
+
49
+ client = axios.create({
50
+ baseURL: `${urlBase}/api`,
51
+ withCredentials: true,
52
+ timeout: 30_000,
53
+ headers: {
54
+ Accept: 'application/json',
55
+ 'Content-Type': 'application/json',
56
+ 'X-Requested-With': 'XMLHttpRequest',
57
+ },
58
+ // validateStatus: (s) => s >= 200 && s < 300, // défaut axios
59
+ })
60
+
61
+ client.interceptors.response.use(
62
+ (response: AxiosResponse<any>) => {
63
+ const data = response.data
64
+
65
+ // Détection de la réponse { succes, resultat }
66
+ if (data && typeof data === 'object' && 'succes' in data) {
67
+ const env = data as ApiReponse
68
+ return env.succes === true ? env.resultat : Promise.reject(env)
69
+ }
70
+
71
+ // Sinon, renvoyer data si présent, sinon la réponse complète
72
+ return data ?? response
73
+ },
74
+
75
+ (error: AxiosError<any>) => {
76
+ const status = error.response?.status
77
+ const payload = error.response?.data?.resultat ?? { message: error.message }
78
+
79
+ // 403 / 404
80
+ if (status === 403 || status === 404) {
81
+ try {
82
+ appStore.lancerErreur(payload)
83
+ if (router.currentRoute.value.name !== '403') {
84
+ router.push({ name: '403' })
85
+ }
86
+ } catch {
87
+ // no-op
88
+ }
89
+ return Promise.reject(payload)
90
+ }
91
+
92
+ // gérer les autres 4XX ici
93
+
94
+ // Log minimal
95
+ console.error('HTTP error', {
96
+ status,
97
+ url: error.config?.url,
98
+ payload,
99
+ })
100
+
101
+ // Remonter l’erreur normalisée dans appstore
102
+ try {
103
+ if (payload?.resultat) appStore.lancerErreur(payload)
104
+ else if (payload) appStore.lancerErreur(payload)
105
+ } catch {
106
+ // no-op
107
+ }
108
+ return Promise.reject(payload)
109
+ },
110
+ )
111
+
112
+ // reset le flag si on l’avait utilisé pour forcer la recréation de l'instance
113
+ this.clearCache = false
114
+ return client
115
+ },
116
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codevdesign",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "Composants Vuetify 3 pour les projets Codev",
5
5
  "files": [
6
6
  "./**/*.vue",