feat: add team name normalization for selected schedule in PDF generation
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 50s

This commit is contained in:
Torsten Schulz (local)
2026-07-17 16:01:39 +02:00
parent 91006bb0c5
commit ad778328e8

View File

@@ -2497,12 +2497,53 @@ export default {
const club = this.clubs.find(c => c.id === clubIdNum);
return club ? club.name : '';
},
getSelectedScheduleTeamName() {
if (!this.selectedTeam?.name) return '';
const normalizeClubName = (name) => String(name || '')
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, '')
.toLowerCase()
.replace(/\b\d+\b/g, ' ')
.replace(/\s*\([jm]\d+\)\s*/gi, ' ')
.replace(/[^a-z]+/g, ' ')
.replace(/\s+/g, ' ')
.trim();
const clubName = this.getCurrentClubName();
const normalizedClubName = normalizeClubName(clubName);
const ownTeamNames = [...new Set(this.matches
.flatMap((match) => [match.homeTeam?.name, match.guestTeam?.name])
.filter((name) => {
const normalizedName = normalizeClubName(name);
return normalizedClubName && (
normalizedName === normalizedClubName ||
normalizedName.startsWith(`${normalizedClubName} `)
);
}))];
const selectedName = String(this.selectedTeam.name).trim();
const selectedNamePattern = new RegExp(`\\(${selectedName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\)`, 'i');
const teamWithMatchingAgeGroup = ownTeamNames.find((name) => selectedNamePattern.test(name));
if (teamWithMatchingAgeGroup) return teamWithMatchingAgeGroup;
// Bei Erwachsenen steht die erste Mannschaft oft ohne römische "I" im Namen.
if (/^I$/i.test(selectedName)) {
const firstTeam = ownTeamNames.find((name) => normalizeClubName(name) === normalizedClubName);
if (firstTeam) return firstTeam;
}
const teamWithMatchingSuffix = ownTeamNames.find((name) =>
new RegExp(`\\s${selectedName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}$`, 'i').test(name)
);
return teamWithMatchingSuffix || (ownTeamNames.length === 1 ? ownTeamNames[0] : '');
},
async generatePDF() {
const element = this.$refs.scheduleShell?.$el || this.$refs.scheduleContainer;
const highlightName = this.getCurrentClubName();
const clubName = this.getCurrentClubName();
const highlightName = this.getSelectedScheduleTeamName();
if (element) {
const pdfGen = new PDFGenerator(20, 10, this.$t);
pdfGen.addTitle(`${this.$t('schedule.gamesFor')} ${highlightName} ${this.$t('common.in')} ${this.selectedLeague}`);
pdfGen.addTitle(`${this.$t('schedule.gamesFor')} ${clubName} ${this.$t('common.in')} ${this.selectedLeague}`);
// Die Ortsliste steht auf Seite 2. In der Spieltabelle bleiben Datum,
// Uhrzeit, Heim- und Gastmannschaft sowie ggf. die Altersklasse.
@@ -2530,7 +2571,7 @@ export default {
pdfGen.addNewPage();
const uniqueLocations = this.getUniqueLocations();
uniqueLocations.forEach((addressLines, clubName) => {
if (!clubName.includes(highlightName)) {
if (!clubName.includes(this.getCurrentClubName())) {
pdfGen.addAddress(clubName, addressLines);
}
});