Enhance training participation loading in MembersView with improved ID handling and logging
Updated the loadTrainingParticipations method to store participation totals using both string and number keys in the participation map, addressing potential type issues. Enhanced logging to provide detailed insights into the loading process, including responses and member counts, improving debugging capabilities and user experience.
This commit is contained in:
@@ -432,40 +432,59 @@ export default {
|
||||
const trainingStats = response.data.members || [];
|
||||
|
||||
console.log('[loadTrainingParticipations] Training Stats geladen:', trainingStats.length, 'Mitglieder');
|
||||
console.log('[loadTrainingParticipations] Response data:', JSON.stringify(response.data, null, 2));
|
||||
|
||||
// Erstelle eine Map für schnellen Zugriff: memberId -> participationTotal
|
||||
// Verwende parseInt, um sicherzustellen, dass IDs als Zahlen verglichen werden
|
||||
// Speichere sowohl String- als auch Number-Keys, um Typ-Probleme zu vermeiden
|
||||
const participationMap = new Map();
|
||||
trainingStats.forEach(stat => {
|
||||
const memberId = parseInt(stat.id, 10);
|
||||
participationMap.set(memberId, stat.participationTotal || 0);
|
||||
console.log(`[loadTrainingParticipations] Map gesetzt: ID ${memberId} -> ${stat.participationTotal || 0}`);
|
||||
const participationTotal = stat.participationTotal || 0;
|
||||
// Speichere sowohl als String als auch als Number
|
||||
const idAsString = String(stat.id);
|
||||
const idAsNumber = typeof stat.id === 'string' ? parseInt(stat.id, 10) : stat.id;
|
||||
|
||||
participationMap.set(idAsString, participationTotal);
|
||||
participationMap.set(idAsNumber, participationTotal);
|
||||
console.log(`[loadTrainingParticipations] Map gesetzt: ID "${idAsString}" (String) und ${idAsNumber} (Number) -> ${participationTotal}`);
|
||||
});
|
||||
|
||||
console.log('[loadTrainingParticipations] Participation Map Keys:', Array.from(participationMap.keys()));
|
||||
|
||||
// Setze Trainingsteilnahmen für alle Testmitglieder
|
||||
const testMembers = this.members.filter(m => m.testMembership);
|
||||
console.log('[loadTrainingParticipations] Testmitglieder gefunden:', testMembers.length);
|
||||
console.log('[loadTrainingParticipations] Testmitglieder IDs:', testMembers.map(m => ({ id: m.id, type: typeof m.id, name: `${m.firstName} ${m.lastName}` })));
|
||||
|
||||
testMembers.forEach(member => {
|
||||
const memberId = parseInt(member.id, 10);
|
||||
const count = participationMap.get(memberId);
|
||||
console.log(`[loadTrainingParticipations] Mitglied ${memberId} (${member.firstName} ${member.lastName}): count=${count}`);
|
||||
// Nur setzen, wenn ein Wert gefunden wurde (nicht undefined)
|
||||
if (count !== undefined) {
|
||||
this.$set(member, 'trainingParticipations', count);
|
||||
console.log(`[loadTrainingParticipations] Trainingsteilnahmen gesetzt: ${count}`);
|
||||
} else {
|
||||
// Fallback: 0 setzen, wenn kein Wert gefunden wurde
|
||||
this.$set(member, 'trainingParticipations', 0);
|
||||
console.log(`[loadTrainingParticipations] Kein Wert gefunden, setze 0`);
|
||||
// Versuche sowohl String- als auch Number-ID
|
||||
const idAsString = String(member.id);
|
||||
const idAsNumber = typeof member.id === 'string' ? parseInt(member.id, 10) : member.id;
|
||||
|
||||
// Versuche zuerst mit der ursprünglichen ID (String oder Number)
|
||||
let count = participationMap.get(member.id);
|
||||
|
||||
// Falls nicht gefunden, versuche mit konvertierter ID
|
||||
if (count === undefined) {
|
||||
count = participationMap.get(idAsString);
|
||||
}
|
||||
if (count === undefined) {
|
||||
count = participationMap.get(idAsNumber);
|
||||
}
|
||||
|
||||
console.log(`[loadTrainingParticipations] Mitglied ${member.id} (type: ${typeof member.id}) (${member.firstName} ${member.lastName}): count=${count}, map has String: ${participationMap.has(idAsString)}, map has Number: ${participationMap.has(idAsNumber)}`);
|
||||
|
||||
// Setze den Wert, wenn gefunden, sonst 0
|
||||
const finalCount = count !== undefined ? count : 0;
|
||||
// In Vue 3 ist $set nicht mehr nötig, direkte Zuweisung funktioniert
|
||||
member.trainingParticipations = finalCount;
|
||||
console.log(`[loadTrainingParticipations] Trainingsteilnahmen gesetzt: ${finalCount}`);
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Laden der Trainingsteilnahmen:', error);
|
||||
// Bei Fehler setze 0 für alle Testmitglieder
|
||||
this.members.forEach(member => {
|
||||
if (member.testMembership) {
|
||||
this.$set(member, 'trainingParticipations', 0);
|
||||
member.trainingParticipations = 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user