Erweitert die updateActivity-Methode in DiaryDateActivityService, um benutzerdefinierte Aktivitäten zu verarbeiten und neue vordefinierte Aktivitäten zu erstellen. Fügt eine Methode loadTrainingPlan in DiaryView.vue hinzu, um die Anzeige nach Änderungen zu aktualisieren.
This commit is contained in:
@@ -39,7 +39,34 @@ class DiaryDateActivityService {
|
||||
console.log('[DiaryDateActivityService::updateActivity] - activity not found');
|
||||
throw new Error('Activity not found');
|
||||
}
|
||||
console.log('[DiaryDateActivityService::updateActivity] - update activity');
|
||||
|
||||
// Wenn customActivityName gesendet wird, müssen wir die PredefinedActivity behandeln
|
||||
if (data.customActivityName) {
|
||||
console.log('[DiaryDateActivityService::updateActivity] - handling customActivityName:', data.customActivityName);
|
||||
|
||||
// Suche nach einer existierenden PredefinedActivity mit diesem Namen
|
||||
let predefinedActivity = await PredefinedActivity.findOne({
|
||||
where: { name: data.customActivityName }
|
||||
});
|
||||
|
||||
if (!predefinedActivity) {
|
||||
// Erstelle eine neue PredefinedActivity
|
||||
console.log('[DiaryDateActivityService::updateActivity] - creating new PredefinedActivity');
|
||||
predefinedActivity = await PredefinedActivity.create({
|
||||
name: data.customActivityName,
|
||||
description: '',
|
||||
duration: data.duration || activity.duration
|
||||
});
|
||||
}
|
||||
|
||||
// Setze die predefinedActivityId
|
||||
data.predefinedActivityId = predefinedActivity.id;
|
||||
|
||||
// Entferne customActivityName aus den zu aktualisierenden Daten
|
||||
delete data.customActivityName;
|
||||
}
|
||||
|
||||
console.log('[DiaryDateActivityService::updateActivity] - update activity', clubId, id, data, JSON.stringify(data));
|
||||
return await activity.update(data);
|
||||
}
|
||||
|
||||
|
||||
@@ -1151,12 +1151,25 @@ export default {
|
||||
durationText: item.durationText,
|
||||
groupId: item.groupId,
|
||||
});
|
||||
|
||||
// Lade die Daten neu, um die Änderungen anzuzeigen
|
||||
await this.loadTrainingPlan();
|
||||
|
||||
this.editingActivityId = null;
|
||||
} catch (error) {
|
||||
alert('Ein Fehler ist aufgetreten. Bitte versuchen Sie es erneut.');
|
||||
}
|
||||
},
|
||||
|
||||
async loadTrainingPlan() {
|
||||
try {
|
||||
this.trainingPlan = await apiClient.get(`/diary-date-activities/${this.currentClub}/${this.date.id}`).then(response => response.data);
|
||||
this.calculateIntermediateTimes();
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Laden des Trainingsplans:', error);
|
||||
}
|
||||
},
|
||||
|
||||
cancelActivityEdit() {
|
||||
this.editingActivityId = null;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user