@golstats/gsc-timeline-reports 1.0.6 → 1.0.8

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.
@@ -45,6 +45,22 @@ const props = defineProps({
45
45
  type: Number,
46
46
  required: true,
47
47
  },
48
+ goals: {
49
+ type: Boolean,
50
+ default: true,
51
+ },
52
+ yellowCards: {
53
+ type: Boolean,
54
+ default: true,
55
+ },
56
+ redCards: {
57
+ type: Boolean,
58
+ default: true,
59
+ },
60
+ substitutions: {
61
+ type: Boolean,
62
+ default: true,
63
+ },
48
64
  token: {
49
65
  type: String,
50
66
  required: true,
@@ -85,19 +101,46 @@ const scrollContainer = ref(null)
85
101
 
86
102
  // --- NUEVO: Datos dummy para modo default ---
87
103
  const dummyEvents = [
104
+ // Primer tiempo (0-45)
105
+ {
106
+ minute: 5,
107
+ match_lapse: 1,
108
+ event: [
109
+ {
110
+ minute: 5,
111
+ minuteLabel: '5',
112
+ icon: 'icon-yellow-card',
113
+ team: 'visitante',
114
+ match_lapse: 1,
115
+ },
116
+ ],
117
+ },
88
118
  {
89
- minute: 16,
119
+ minute: 12,
90
120
  match_lapse: 1,
91
121
  event: [
92
122
  {
93
- minute: 16,
94
- minuteLabel: '16',
123
+ minute: 12,
124
+ minuteLabel: '12',
95
125
  icon: 'icon-goal',
96
126
  team: 'local',
97
127
  match_lapse: 1,
98
128
  },
99
129
  ],
100
130
  },
131
+ {
132
+ minute: 18,
133
+ match_lapse: 1,
134
+ event: [
135
+ {
136
+ minute: 18,
137
+ minuteLabel: '18',
138
+ icon: 'icon-yellow-card',
139
+ team: 'local',
140
+ match_lapse: 1,
141
+ },
142
+ ],
143
+ },
101
144
  {
102
145
  minute: 25,
103
146
  match_lapse: 1,
@@ -111,19 +154,73 @@ const dummyEvents = [
111
154
  },
112
155
  ],
113
156
  },
157
+ {
158
+ minute: 32,
159
+ match_lapse: 1,
160
+ event: [
161
+ {
162
+ minute: 32,
163
+ minuteLabel: '32',
164
+ icon: 'icon-goal',
165
+ team: 'visitante',
166
+ match_lapse: 1,
167
+ },
168
+ ],
169
+ },
170
+ {
171
+ minute: 38,
172
+ match_lapse: 1,
173
+ event: [
174
+ {
175
+ minute: 38,
176
+ minuteLabel: '38',
177
+ icon: 'icon-change',
178
+ team: 'local',
179
+ match_lapse: 1,
180
+ },
181
+ ],
182
+ },
183
+ {
184
+ minute: 42,
185
+ match_lapse: 1,
186
+ event: [
187
+ {
188
+ minute: 42,
189
+ minuteLabel: '42',
190
+ icon: 'icon-yellow-card',
191
+ team: 'visitante',
192
+ match_lapse: 1,
193
+ },
194
+ ],
195
+ },
196
+ // Medio tiempo (45)
114
197
  {
115
198
  minute: 45,
116
199
  match_lapse: 1,
117
200
  event: [
118
201
  {
119
202
  minute: 45,
120
- minuteLabel: '45',
203
+ minuteLabel: 'MT',
121
204
  icon: 'icon-change',
122
205
  team: 'local',
123
206
  match_lapse: 1,
124
207
  },
125
208
  ],
126
209
  },
210
+ // Segundo tiempo (45-90)
211
+ {
212
+ minute: 48,
213
+ match_lapse: 2,
214
+ event: [
215
+ {
216
+ minute: 48,
217
+ minuteLabel: '48',
218
+ icon: 'icon-yellow-card',
219
+ team: 'local',
220
+ match_lapse: 2,
221
+ },
222
+ ],
223
+ },
127
224
  {
128
225
  minute: 55,
129
226
  match_lapse: 2,
@@ -137,13 +234,78 @@ const dummyEvents = [
137
234
  },
138
235
  ],
139
236
  },
237
+ {
238
+ minute: 62,
239
+ match_lapse: 2,
240
+ event: [
241
+ {
242
+ minute: 62,
243
+ minuteLabel: '62',
244
+ icon: 'icon-change',
245
+ team: 'visitante',
246
+ match_lapse: 2,
247
+ },
248
+ ],
249
+ },
250
+ {
251
+ minute: 68,
252
+ match_lapse: 2,
253
+ event: [
254
+ {
255
+ minute: 68,
256
+ minuteLabel: '68',
257
+ icon: 'icon-yellow-card',
258
+ team: 'visitante',
259
+ match_lapse: 2,
260
+ },
261
+ ],
262
+ },
263
+ {
264
+ minute: 75,
265
+ match_lapse: 2,
266
+ event: [
267
+ {
268
+ minute: 75,
269
+ minuteLabel: '75',
270
+ icon: 'icon-goal',
271
+ team: 'local',
272
+ match_lapse: 2,
273
+ },
274
+ ],
275
+ },
276
+ {
277
+ minute: 82,
278
+ match_lapse: 2,
279
+ event: [
280
+ {
281
+ minute: 82,
282
+ minuteLabel: '82',
283
+ icon: 'icon-red-card',
284
+ team: 'local',
285
+ match_lapse: 2,
286
+ },
287
+ ],
288
+ },
289
+ {
290
+ minute: 87,
291
+ match_lapse: 2,
292
+ event: [
293
+ {
294
+ minute: 87,
295
+ minuteLabel: '87',
296
+ icon: 'icon-yellow-card',
297
+ team: 'visitante',
298
+ match_lapse: 2,
299
+ },
300
+ ],
301
+ },
140
302
  {
141
303
  minute: 90,
142
304
  match_lapse: 2,
143
305
  event: [
144
306
  {
145
307
  minute: 90,
146
- minuteLabel: '80',
308
+ minuteLabel: '90',
147
309
  icon: 'icon-goal',
148
310
  team: 'local',
149
311
  match_lapse: 2,
@@ -197,18 +359,47 @@ function calculateMaxMinute() {
197
359
  // Función para obtener los datos del partido
198
360
  async function fetchGameData() {
199
361
  if (props.isDefault) {
200
- // Si es default, usar los eventos dummy
201
- timelineMinutes.value = dummyEvents
202
- events.value = dummyEvents.map((minute) => minute.event)
362
+ // Si es default, usar los eventos dummy pero filtrarlos según las props
363
+ const filteredDummyEvents = dummyEvents
364
+ .map((minute) => {
365
+ if (!minute.event) return minute
366
+
367
+ // Filtrar eventos según las props
368
+ const filteredEvents = minute.event.filter((event) => {
369
+ // Crear un objeto temporal con la estructura que espera shouldShowEvent
370
+ const tempEvent = {
371
+ event_type_id: getEventTypeFromIcon(event.icon),
372
+ category_id: getCategoryFromIcon(event.icon),
373
+ minute: event.minute,
374
+ match_lapse: event.match_lapse,
375
+ team_id: event.team === 'local' ? props.homeTeam : props.awayTeam,
376
+ comments: '',
377
+ }
378
+
379
+ return shouldShowEvent(tempEvent)
380
+ })
381
+
382
+ return {
383
+ ...minute,
384
+ event: filteredEvents.length > 0 ? filteredEvents : null,
385
+ }
386
+ })
387
+ .filter((minute) => minute.event !== null) // Solo incluir minutos que tengan eventos
388
+
389
+ timelineMinutes.value = filteredDummyEvents
390
+ events.value = filteredDummyEvents.map((minute) => minute.event)
391
+
203
392
  // Ajustar valores para los handlers y el rango
204
- minStart.value = dummyEvents[0].minute
205
- minEnd.value = dummyEvents[dummyEvents.length - 1].minute
206
- startTime.value = dummyEvents[0].match_lapse.toString()
207
- endTime.value = dummyEvents[dummyEvents.length - 1].match_lapse.toString()
208
- leftHandlePosition.value = 0
209
- rightHandlePosition.value = dummyEvents.length - 1
210
- secondHalfEndMinute.value = dummyEvents[dummyEvents.length - 1].minute
211
- minTotal.value = dummyEvents[dummyEvents.length - 1].minute
393
+ if (filteredDummyEvents.length > 0) {
394
+ minStart.value = filteredDummyEvents[0].minute
395
+ minEnd.value = filteredDummyEvents[filteredDummyEvents.length - 1].minute
396
+ startTime.value = filteredDummyEvents[0].match_lapse.toString()
397
+ endTime.value = filteredDummyEvents[filteredDummyEvents.length - 1].match_lapse.toString()
398
+ leftHandlePosition.value = 0
399
+ rightHandlePosition.value = filteredDummyEvents.length - 1
400
+ secondHalfEndMinute.value = filteredDummyEvents[filteredDummyEvents.length - 1].minute
401
+ minTotal.value = filteredDummyEvents[filteredDummyEvents.length - 1].minute
402
+ }
212
403
  updateRangeWidth()
213
404
  return
214
405
  }
@@ -250,9 +441,11 @@ async function fetchGameData() {
250
441
  (e) =>
251
442
  e.minute === i &&
252
443
  e.match_lapse === 1 &&
444
+ shouldShowEvent(e) &&
253
445
  (e.category_id === 9 ||
254
446
  e.category_id === 3 ||
255
447
  e.event_type_id === 1 ||
448
+ e.event_type_id === 2 ||
256
449
  e.category_id === 10 ||
257
450
  e.category_id === 13 ||
258
451
  (e.event_type_id === 6 &&
@@ -263,7 +456,12 @@ async function fetchGameData() {
263
456
  events.push({
264
457
  minute: event.minute,
265
458
  minuteLabel: event.event_type_id === 6 ? 'MT' : event.minute.toString(),
266
- icon: getEventIcon(event.event_type_id === 1 ? event.event_type_id : event.category_id),
459
+ icon: getEventIcon(
460
+ event.event_type_id === 1 || event.event_type_id === 2
461
+ ? event.event_type_id
462
+ : event.category_id,
463
+ event,
464
+ ),
267
465
  team:
268
466
  event.team_id === props.homeTeam
269
467
  ? event.category_id === 13
@@ -289,9 +487,11 @@ async function fetchGameData() {
289
487
  (e) =>
290
488
  e.minute === i &&
291
489
  e.match_lapse === 2 &&
490
+ shouldShowEvent(e) &&
292
491
  (e.category_id === 9 ||
293
492
  e.category_id === 3 ||
294
493
  e.event_type_id === 1 ||
494
+ e.event_type_id === 2 ||
295
495
  e.category_id === 10 ||
296
496
  e.category_id === 13),
297
497
  )
@@ -300,7 +500,12 @@ async function fetchGameData() {
300
500
  events.push({
301
501
  minute: event.minute,
302
502
  minuteLabel: event.event_type_id === 6 ? 'MT' : event.minute.toString(),
303
- icon: getEventIcon(event.event_type_id === 1 ? event.event_type_id : event.category_id),
503
+ icon: getEventIcon(
504
+ event.event_type_id === 1 || event.event_type_id === 2
505
+ ? event.event_type_id
506
+ : event.category_id,
507
+ event,
508
+ ),
304
509
  team:
305
510
  event.team_id === props.homeTeam
306
511
  ? event.category_id === 13
@@ -370,21 +575,116 @@ async function fetchGameData() {
370
575
  }
371
576
  }
372
577
 
578
+ // Función para obtener el tipo de evento desde el ícono (para datos dummy)
579
+ function getEventTypeFromIcon(icon) {
580
+ const iconToEventType = {
581
+ 'icon-goal': 1,
582
+ 'icon-yellow-card': 2,
583
+ 'icon-red-card': 9,
584
+ 'icon-change': 10,
585
+ }
586
+ return iconToEventType[icon] || 1
587
+ }
588
+
589
+ // Función para obtener la categoría desde el ícono (para datos dummy)
590
+ function getCategoryFromIcon(icon) {
591
+ const iconToCategory = {
592
+ 'icon-goal': 3,
593
+ 'icon-yellow-card': 9,
594
+ 'icon-red-card': 9,
595
+ 'icon-change': 10,
596
+ }
597
+ return iconToCategory[icon] || 3
598
+ }
599
+
373
600
  // Función para determinar el icono según el tipo de evento
374
- function getEventIcon(eventTypeId) {
601
+ function getEventIcon(eventTypeId, event) {
375
602
  const iconMap = {
376
603
  3: 'icon-goal',
377
604
  1: 'icon-goal',
378
605
  13: 'icon-goal',
606
+ 2: 'icon-yellow-card',
379
607
  10: 'icon-change',
380
- 9: 'icon-red-card',
381
608
  // Agregar más mapeos según sea necesario
382
609
  }
610
+
611
+ // Para event_type_id === 2, siempre es tarjeta amarilla
612
+ if (eventTypeId === 2) {
613
+ return 'icon-yellow-card'
614
+ }
615
+
616
+ // Para category_id 9, diferenciar entre amarilla y roja basado en comentarios
617
+ if (eventTypeId === 9) {
618
+ if (event && event.comments && event.comments.includes('roja')) {
619
+ return 'icon-red-card'
620
+ } else {
621
+ return 'icon-yellow-card'
622
+ }
623
+ }
624
+
383
625
  return iconMap[eventTypeId] || '' // Por defecto retorna icon-goal
384
626
  }
385
627
 
628
+ // Función para filtrar eventos según las props de visibilidad
629
+ function shouldShowEvent(event) {
630
+ // Debug: mostrar las props actuales
631
+ console.log('Props actuales:', {
632
+ goals: props.goals,
633
+ yellowCards: props.yellowCards,
634
+ redCards: props.redCards,
635
+ substitutions: props.substitutions,
636
+ })
637
+
638
+ // Goles: event_type_id === 1 o category_id === 3 o category_id === 13
639
+ if (event.event_type_id === 1 || event.category_id === 3 || event.category_id === 13) {
640
+ if (!props.goals) {
641
+ console.log('Filtrando gol:', event)
642
+ return false
643
+ }
644
+ return true
645
+ }
646
+
647
+ // Tarjetas amarillas: event_type_id === 2 o category_id === 9 (pero no rojas)
648
+ if (event.event_type_id === 2 || (event.category_id === 9 && !event.comments?.includes('roja'))) {
649
+ if (!props.yellowCards) {
650
+ console.log('Filtrando tarjeta amarilla:', event)
651
+ return false
652
+ }
653
+ return true
654
+ }
655
+
656
+ // Tarjetas rojas: category_id === 9 con comentario que incluya "roja"
657
+ if (event.category_id === 9 && event.comments?.includes('roja')) {
658
+ if (!props.redCards) {
659
+ console.log('Filtrando tarjeta roja:', event)
660
+ return false
661
+ }
662
+ return true
663
+ }
664
+
665
+ // Cambios: category_id === 10
666
+ if (event.category_id === 10) {
667
+ if (!props.substitutions) {
668
+ console.log('Filtrando cambio:', event)
669
+ return false
670
+ }
671
+ return true
672
+ }
673
+
674
+ // Si no es ninguno de los tipos que filtramos, mostrarlo
675
+ return true
676
+ }
677
+
386
678
  // Observar cambios en el tamaño de la ventana
387
679
  onMounted(() => {
680
+ // Debug: verificar que las props estén llegando
681
+ console.log('gsc-timeline.vue - Props recibidas:', {
682
+ goals: props.goals,
683
+ yellowCards: props.yellowCards,
684
+ redCards: props.redCards,
685
+ substitutions: props.substitutions,
686
+ })
687
+
388
688
  calculateMaxMinute()
389
689
  updateContainerWidth()
390
690
  fetchGameData()