feat(match-report): improve result initialization and data synchronization in MatchReportApiDialog
- Enhanced the initializeResults method to retain existing match results when available, improving data consistency. - Added logic to set start and end dates based on available meeting data, ensuring accurate match timing. - Implemented populateResultsFromMeetingDetails to transfer existing set results from meeting details, enhancing data accuracy. - Improved fallback mechanisms for match results to ensure defaults are only created when necessary.
This commit is contained in:
@@ -1832,19 +1832,19 @@ Wir wünschen den Spielen einen schönen, spannenden und fairen Verlauf und begr
|
||||
}
|
||||
},
|
||||
|
||||
// Verwende die Matches aus dem Match-Objekt oder erstelle defaults
|
||||
// Verwende die Matches aus dem Match-Objekt oder lasse vorhandene Ergebnisse bestehen
|
||||
initializeResults() {
|
||||
if (this.match.matches && Array.isArray(this.match.matches)) {
|
||||
// Verwende existierende Matches vom Server
|
||||
this.results = this.match.matches.map(match => ({
|
||||
homeName: match.homePlayer || `Spieler Heim ${match.matchNumber || ''}`,
|
||||
guestName: match.guestPlayer || `Spieler Gast ${match.matchNumber || ''}`,
|
||||
sets: match.sets || ['', '', '', '', ''], // 5 leere Sätze
|
||||
completed: match.completed || false,
|
||||
result: match.result || ''
|
||||
if (this.match.matches && Array.isArray(this.match.matches) && this.match.matches.length > 0) {
|
||||
// Verwende existierende Matches vom Server / aus nuscore-Synchronisation
|
||||
this.results = this.match.matches.map((match, index) => ({
|
||||
homeName: match.homePlayer || (this.results[index] && this.results[index].homeName) || `Spieler Heim ${match.matchNumber || ''}`,
|
||||
guestName: match.guestPlayer || (this.results[index] && this.results[index].guestName) || `Spieler Gast ${match.matchNumber || ''}`,
|
||||
sets: match.sets || (this.results[index] && this.results[index].sets) || ['', '', '', '', ''],
|
||||
completed: typeof match.completed === 'boolean' ? match.completed : ((this.results[index] && this.results[index].completed) || false),
|
||||
result: match.result || (this.results[index] && this.results[index].result) || ''
|
||||
}));
|
||||
} else {
|
||||
// Fallback: Erstelle Default-Matches basierend auf Spielsystem
|
||||
} else if (!this.results || this.results.length === 0) {
|
||||
// Fallback: Erstelle Default-Matches basierend auf Spielsystem, falls noch keine Ergebnisse existieren
|
||||
const playMode = (this.meetingDetails && this.meetingDetails.playMode) ||
|
||||
(this.meetingData && (this.meetingData.playMode || this.meetingData.matchSystem || this.meetingData.system));
|
||||
const matchCount = this.getMatchCountForPlayMode(playMode);
|
||||
@@ -1948,18 +1948,34 @@ Wir wünschen den Spielen einen schönen, spannenden und fairen Verlauf und begr
|
||||
// Vereins-Einstellungen für Begrüßung laden
|
||||
await this.loadClubSettings();
|
||||
|
||||
// Setze Standardwert für Spielbeginn aus scheduleDate, falls noch nicht gesetzt
|
||||
// Setze Standardwert für Spielbeginn aus vorhandenen Daten, falls noch nicht gesetzt
|
||||
if (!this.match.startDate) {
|
||||
const scheduleDate = this.meetingDetails?.scheduleDate || this.meetingData?.scheduleDate;
|
||||
if (scheduleDate) {
|
||||
this.match.startDate = new Date(scheduleDate);
|
||||
const startDate =
|
||||
this.meetingDetails?.startDate ||
|
||||
this.meetingData?.startDate ||
|
||||
this.meetingDetails?.scheduleDate ||
|
||||
this.meetingData?.scheduleDate;
|
||||
if (startDate) {
|
||||
this.match.startDate = new Date(startDate);
|
||||
console.log('✅ Spielbeginn auf Standardwert gesetzt:', this.match.startDate);
|
||||
}
|
||||
}
|
||||
|
||||
// Ergebnisse initial auf Basis der Matrix vorbereiten
|
||||
// Spielende aus Meeting-Daten übernehmen, falls vorhanden
|
||||
if (!this.match.endDate) {
|
||||
const endDate = this.meetingDetails?.endDate || this.meetingData?.endDate;
|
||||
if (endDate) {
|
||||
this.match.endDate = new Date(endDate);
|
||||
console.log('✅ Spielende auf vorhandenen Wert gesetzt:', this.match.endDate);
|
||||
}
|
||||
}
|
||||
|
||||
// Ergebnisse initial auf Basis der Matrix vorbereiten (Namen/Zuweisungen)
|
||||
this.prepareResults();
|
||||
|
||||
// Bereits vorhandene Satzergebnisse aus nuscore übernehmen (falls vorhanden)
|
||||
this.populateResultsFromMeetingDetails();
|
||||
|
||||
// Wenn teamNotAppeared gesetzt ist und die Daten noch nicht angepasst wurden, wende die Anpassung an
|
||||
if (this.teamNotAppeared !== null && !this.meetingData.wo) {
|
||||
this.applyTeamNotAppeared();
|
||||
@@ -1983,6 +1999,56 @@ Wir wünschen den Spielen einen schönen, spannenden und fairen Verlauf und begr
|
||||
result: '1:0'
|
||||
}));
|
||||
},
|
||||
populateResultsFromMeetingDetails() {
|
||||
if (!this.meetingDetails || !Array.isArray(this.meetingDetails.matches)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const sourceMatches = this.meetingDetails.matches;
|
||||
const count = Math.min((this.results && this.results.length) || 0, sourceMatches.length);
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
const src = sourceMatches[i] || {};
|
||||
const dst = this.results[i];
|
||||
|
||||
if (!dst.sets || !Array.isArray(dst.sets)) {
|
||||
this.$set(dst, 'sets', ['', '', '', '', '']);
|
||||
}
|
||||
|
||||
let anySet = false;
|
||||
|
||||
for (let s = 0; s < dst.sets.length; s++) {
|
||||
const homeKey = `set${s + 1}A`;
|
||||
const guestKey = `set${s + 1}B`;
|
||||
const rawHome = src[homeKey];
|
||||
const rawGuest = src[guestKey];
|
||||
|
||||
const home = typeof rawHome === 'number' ? rawHome : parseInt(rawHome || 0);
|
||||
const guest = typeof rawGuest === 'number' ? rawGuest : parseInt(rawGuest || 0);
|
||||
|
||||
if ((home || 0) > 0 || (guest || 0) > 0) {
|
||||
dst.sets[s] = `${home}:${guest}`;
|
||||
anySet = true;
|
||||
} else if (!dst.sets[s]) {
|
||||
dst.sets[s] = '';
|
||||
}
|
||||
}
|
||||
|
||||
// Versuche, den Abschlussstatus aus nuscore zu übernehmen
|
||||
if (typeof src.matchesA !== 'undefined' || typeof src.matchesB !== 'undefined') {
|
||||
dst.completed = src.matchesA === 1 || src.matchesB === 1;
|
||||
} else if (anySet) {
|
||||
const homeWins = this.getPlayerSetWins(dst, 'home');
|
||||
const guestWins = this.getPlayerSetWins(dst, 'guest');
|
||||
dst.completed = homeWins >= 3 || guestWins >= 3;
|
||||
}
|
||||
|
||||
this.calculateMatchResult(i);
|
||||
}
|
||||
|
||||
// Synchronisiere in das Match-Objekt, damit initializeResults() darauf zurückgreifen kann
|
||||
this.syncResultsToMatch();
|
||||
},
|
||||
applyTeamNotAppeared() {
|
||||
if (!this.meetingData || this.teamNotAppeared === null) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user