codevdesign 0.0.53 → 0.0.54

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