Refactor Spielplan-Filterlogik in separate Utility-Funktionen und verbessere die Filterung im PDF-Generierungsprozess
This commit is contained in:
@@ -360,6 +360,7 @@
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { filterSpielplanRows, toApiTeamParam } from '../../utils/spielplan-filter.js'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
@@ -525,183 +526,16 @@ const filterData = () => {
|
||||
return
|
||||
}
|
||||
|
||||
let saisonFiltered = spielplanData.value
|
||||
|
||||
// Dann nach Wettbewerb filtern
|
||||
let wettbewerbFiltered = saisonFiltered
|
||||
if (selectedWettbewerb.value === 'punktrunde') {
|
||||
wettbewerbFiltered = saisonFiltered.filter(row => {
|
||||
const runde = (row.Runde || '').toLowerCase()
|
||||
const staffel = (row.Staffel || '').toLowerCase()
|
||||
const liga = (row.Liga || '').toLowerCase()
|
||||
const isPokal = runde.includes('pokal') || staffel.includes('pokal') || liga.includes('pokal')
|
||||
|
||||
return !isPokal
|
||||
})
|
||||
} else if (selectedWettbewerb.value === 'pokal') {
|
||||
wettbewerbFiltered = saisonFiltered.filter(row => {
|
||||
const runde = (row.Runde || '').toLowerCase()
|
||||
const staffel = (row.Staffel || '').toLowerCase()
|
||||
const liga = (row.Liga || '').toLowerCase()
|
||||
return runde.includes('pokal') || staffel.includes('pokal') || liga.includes('pokal')
|
||||
})
|
||||
}
|
||||
// "alle" zeigt alle Spiele ohne weitere Filterung
|
||||
|
||||
// Dann nach Mannschaft filtern
|
||||
if (selectedFilter.value === 'all') {
|
||||
filteredData.value = wettbewerbFiltered
|
||||
} else if (selectedFilter.value === 'erwachsene') {
|
||||
filteredData.value = wettbewerbFiltered.filter(row => {
|
||||
const heimMannschaft = (row.HeimMannschaft || '').toLowerCase()
|
||||
const gastMannschaft = (row.GastMannschaft || '').toLowerCase()
|
||||
const heimAltersklasse = (row.HeimMannschaftAltersklasse || '').toLowerCase()
|
||||
const gastAltersklasse = (row.GastMannschaftAltersklasse || '').toLowerCase()
|
||||
|
||||
// Prüfe ob eine der Mannschaften Harheimer TC ist
|
||||
const isHarheimerHeim = heimMannschaft.includes('harheimer tc')
|
||||
const isHarheimerGast = gastMannschaft.includes('harheimer tc')
|
||||
|
||||
if (!isHarheimerHeim && !isHarheimerGast) {
|
||||
return false // Kein Harheimer TC Spiel
|
||||
}
|
||||
|
||||
// Filtere nach Erwachsenen-Mannschaften (NICHT Jugend)
|
||||
const isErwachsenenHeim = isHarheimerHeim &&
|
||||
heimAltersklasse.includes('erwachsene') &&
|
||||
!heimAltersklasse.includes('jugend')
|
||||
const isErwachsenenGast = isHarheimerGast &&
|
||||
gastAltersklasse.includes('erwachsene') &&
|
||||
!gastAltersklasse.includes('jugend')
|
||||
|
||||
return isErwachsenenHeim || isErwachsenenGast
|
||||
})
|
||||
} else if (selectedFilter.value === 'nachwuchs') {
|
||||
filteredData.value = wettbewerbFiltered.filter(row => {
|
||||
const heimMannschaft = (row.HeimMannschaft || '').toLowerCase()
|
||||
const gastMannschaft = (row.GastMannschaft || '').toLowerCase()
|
||||
const heimAltersklasse = (row.HeimMannschaftAltersklasse || '').toLowerCase()
|
||||
const gastAltersklasse = (row.GastMannschaftAltersklasse || '').toLowerCase()
|
||||
|
||||
// Prüfe ob eine der Mannschaften Harheimer TC ist
|
||||
const isHarheimerHeim = heimMannschaft.includes('harheimer tc')
|
||||
const isHarheimerGast = gastMannschaft.includes('harheimer tc')
|
||||
|
||||
if (!isHarheimerHeim && !isHarheimerGast) {
|
||||
return false // Kein Harheimer TC Spiel
|
||||
}
|
||||
|
||||
// Filtere nach Jugend-Mannschaften (NUR Jugend)
|
||||
const isJugendHeim = isHarheimerHeim &&
|
||||
(heimAltersklasse.includes('jugend') || heimMannschaft.includes('jugend'))
|
||||
const isJugendGast = isHarheimerGast &&
|
||||
(gastAltersklasse.includes('jugend') || gastMannschaft.includes('jugend'))
|
||||
|
||||
return isJugendHeim || isJugendGast
|
||||
})
|
||||
} else {
|
||||
// Spezifische Mannschaft - Mapping zwischen CMS-Mannschaften und CSV-Daten
|
||||
filteredData.value = wettbewerbFiltered.filter(row => {
|
||||
const heimMannschaft = (row.HeimMannschaft || '').toLowerCase()
|
||||
const gastMannschaft = (row.GastMannschaft || '').toLowerCase()
|
||||
const heimAltersklasse = (row.HeimMannschaftAltersklasse || '').toLowerCase()
|
||||
const gastAltersklasse = (row.GastMannschaftAltersklasse || '').toLowerCase()
|
||||
|
||||
// Prüfe ob eine der Mannschaften Harheimer TC ist
|
||||
const isHarheimerHeim = heimMannschaft.includes('harheimer tc')
|
||||
const isHarheimerGast = gastMannschaft.includes('harheimer tc')
|
||||
|
||||
if (!isHarheimerHeim && !isHarheimerGast) {
|
||||
return false // Kein Harheimer TC Spiel
|
||||
}
|
||||
|
||||
const cmsMannschaft = selectedFilter.value
|
||||
|
||||
// Mapping zwischen CMS-Mannschaften und CSV-Daten
|
||||
const mannschaftMapping = {
|
||||
'Erwachsene 1': ['harheimer tc'], // Nur ohne römische Zahl
|
||||
'Erwachsene 2': ['harheimer tc ii'],
|
||||
'Erwachsene 3': ['harheimer tc iii'],
|
||||
'Erwachsene 4': ['harheimer tc iv'],
|
||||
'Erwachsene 5': ['harheimer tc v'],
|
||||
'Jugendmannschaft': ['harheimer tc'] // Jugend hat keine römische Zahl
|
||||
}
|
||||
|
||||
const csvVariants = mannschaftMapping[cmsMannschaft] || []
|
||||
|
||||
// Prüfe Mannschafts-Zuordnung UND Altersklasse
|
||||
const mannschaftMatch = csvVariants.some(variant => {
|
||||
// Strikte Übereinstimmung: Prüfe exakte Mannschaftsnamen
|
||||
if (isHarheimerHeim) {
|
||||
// Für "harheimer tc" (Erwachsene 1): Nur wenn KEINE römische Zahl folgt
|
||||
if (variant === 'harheimer tc') {
|
||||
return heimMannschaft === 'harheimer tc' ||
|
||||
heimMannschaft.startsWith('harheimer tc ') &&
|
||||
!heimMannschaft.match(/harheimer tc\s+[ivx]+/i)
|
||||
}
|
||||
// Für andere Mannschaften: Exakte Übereinstimmung
|
||||
return heimMannschaft === variant || heimMannschaft.startsWith(variant + ' ')
|
||||
}
|
||||
if (isHarheimerGast) {
|
||||
// Für "harheimer tc" (Erwachsene 1): Nur wenn KEINE römische Zahl folgt
|
||||
if (variant === 'harheimer tc') {
|
||||
return gastMannschaft === 'harheimer tc' ||
|
||||
gastMannschaft.startsWith('harheimer tc ') &&
|
||||
!gastMannschaft.match(/harheimer tc\s+[ivx]+/i)
|
||||
}
|
||||
// Für andere Mannschaften: Exakte Übereinstimmung
|
||||
return gastMannschaft === variant || gastMannschaft.startsWith(variant + ' ')
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
||||
if (!mannschaftMatch) {
|
||||
return false
|
||||
}
|
||||
|
||||
// Zusätzliche Altersklassen-Prüfung für spezifische Mannschaften
|
||||
if (cmsMannschaft.startsWith('Erwachsene')) {
|
||||
// Erwachsenen-Mannschaften: MUSS Erwachsene sein, DARF NICHT Jugend sein
|
||||
const isErwachsenenHeim = isHarheimerHeim &&
|
||||
heimAltersklasse.includes('erwachsene') &&
|
||||
!heimAltersklasse.includes('jugend')
|
||||
const isErwachsenenGast = isHarheimerGast &&
|
||||
gastAltersklasse.includes('erwachsene') &&
|
||||
!gastAltersklasse.includes('jugend')
|
||||
|
||||
return isErwachsenenHeim || isErwachsenenGast
|
||||
} else if (cmsMannschaft === 'Jugendmannschaft') {
|
||||
// Jugend-Mannschaft: MUSS Jugend sein
|
||||
const isJugendHeim = isHarheimerHeim &&
|
||||
(heimAltersklasse.includes('jugend') || heimMannschaft.includes('jugend'))
|
||||
const isJugendGast = isHarheimerGast &&
|
||||
(gastAltersklasse.includes('jugend') || gastMannschaft.includes('jugend'))
|
||||
|
||||
return isJugendHeim || isJugendGast
|
||||
}
|
||||
|
||||
return true // Fallback für unbekannte Mannschaften
|
||||
})
|
||||
}
|
||||
|
||||
filteredData.value = filterSpielplanRows(spielplanData.value, {
|
||||
team: selectedFilter.value,
|
||||
wettbewerb: selectedWettbewerb.value
|
||||
})
|
||||
}
|
||||
|
||||
const downloadPDF = () => {
|
||||
if (!filteredData.value || filteredData.value.length === 0) return
|
||||
|
||||
// Bestimme den Team-Parameter basierend auf dem Filter
|
||||
let teamParam = ''
|
||||
|
||||
if (selectedFilter.value === 'all') {
|
||||
teamParam = 'all'
|
||||
} else if (selectedFilter.value === 'erwachsene') {
|
||||
teamParam = 'erwachsene'
|
||||
} else if (selectedFilter.value === 'nachwuchs') {
|
||||
teamParam = 'nachwuchs'
|
||||
} else {
|
||||
// Für einzelne Mannschaften: Konvertiere Namen
|
||||
teamParam = selectedFilter.value.replace(/\s+/g, '_').toLowerCase()
|
||||
}
|
||||
const teamParam = toApiTeamParam(selectedFilter.value)
|
||||
|
||||
// Erstelle Download-URL für dynamische PDF-Generierung
|
||||
const params = new URLSearchParams({
|
||||
|
||||
Reference in New Issue
Block a user