Fügt eine neue Skriptfunktion zum Bereinigen von Benutzertoken hinzu und aktualisiert die Logik zum Synchronisieren des UserToken-Modells. Implementiert eine neue Controller-Methode zum Löschen von Datumsangaben für Clubs und passt die Routen entsprechend an. Ergänzt die Benutzeroberfläche in DiaryView.vue um die Möglichkeit, ein Datum zu löschen, und aktualisiert die Logik zur Überprüfung der Datumsaktualität.
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
<option v-for="entry in dates" :key="entry.id" :value="entry">{{ getFormattedDate(entry.date) }}
|
||||
</option>
|
||||
</select>
|
||||
<button v-if="date && date !== 'new' && trainingPlan.length === 0" class="btn-secondary" @click="deleteCurrentDate">Datum löschen</button>
|
||||
</label>
|
||||
</div>
|
||||
<div v-if="showForm && date === 'new'">
|
||||
@@ -464,6 +465,17 @@ export default {
|
||||
}
|
||||
},
|
||||
|
||||
async refreshDates(selectId) {
|
||||
const response = await apiClient.get(`/diary/${this.currentClub}`);
|
||||
this.dates = response.data.map(entry => ({ id: entry.id, date: entry.date }));
|
||||
// neueste zuerst
|
||||
this.dates.sort((a, b) => new Date(b.date) - new Date(a.date));
|
||||
if (selectId) {
|
||||
const match = this.dates.find(d => String(d.id) === String(selectId));
|
||||
if (match) this.date = { id: match.id, date: match.date };
|
||||
}
|
||||
},
|
||||
|
||||
setCurrentDate() {
|
||||
const today = new Date().toISOString().split('T')[0];
|
||||
this.newDate = today;
|
||||
@@ -517,11 +529,14 @@ export default {
|
||||
trainingEnd: this.trainingEnd || null,
|
||||
});
|
||||
this.dates.push({ id: response.data.id, date: response.data.date });
|
||||
this.date = { id: response.data.id, date: response.data.date };
|
||||
// Liste nach Datum sortieren (neueste zuerst)
|
||||
await this.refreshDates(response.data.id);
|
||||
this.showForm = false;
|
||||
this.newDate = '';
|
||||
this.trainingStart = response.data.trainingStart;
|
||||
this.trainingEnd = response.data.trainingEnd;
|
||||
// Direkt auf das leere Tagebuch des neuen Datums wechseln
|
||||
await this.handleDateChange();
|
||||
} catch (error) {
|
||||
alert('Ein Fehler ist aufgetreten. Bitte versuchen Sie es erneut.');
|
||||
}
|
||||
@@ -827,6 +842,13 @@ export default {
|
||||
async addPlanItem() {
|
||||
try {
|
||||
if (this.addNewItem || this.addNewTimeblock) {
|
||||
// Sicherstellen, dass das ausgewählte Datum existiert
|
||||
const list = await apiClient.get(`/diary/${this.currentClub}`).then(r => r.data);
|
||||
if (!list.some(e => String(e.id) === String(this.date?.id))) {
|
||||
await this.refreshDates();
|
||||
alert('Ausgewähltes Datum war nicht mehr aktuell. Bitte erneut versuchen.');
|
||||
return;
|
||||
}
|
||||
await apiClient.post(`/diary-date-activities/${this.currentClub}`, {
|
||||
diaryDateId: this.date.id,
|
||||
activity: this.addNewTimeblock ? '' : this.newPlanItem.activity,
|
||||
@@ -850,7 +872,34 @@ export default {
|
||||
this.trainingPlan = await apiClient.get(`/diary-date-activities/${this.currentClub}/${this.date.id}`).then(response => response.data);
|
||||
this.calculateIntermediateTimes();
|
||||
} catch (error) {
|
||||
alert('Ein Fehler ist aufgetreten. Bitte versuchen Sie es erneut.');
|
||||
const msg = (error && error.response && error.response.data && error.response.data.error) || 'Ein Fehler ist aufgetreten.';
|
||||
if (msg.toLowerCase().includes('foreign key') || msg.toLowerCase().includes('constraint')) {
|
||||
await this.refreshDates();
|
||||
alert('Datum war nicht (mehr) vorhanden. Die Datums-Auswahl wurde aktualisiert. Bitte erneut versuchen.');
|
||||
} else {
|
||||
alert(msg);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
async deleteCurrentDate() {
|
||||
if (!this.date || this.date === 'new') return;
|
||||
if (this.trainingPlan.length > 0) {
|
||||
alert('Datum kann nicht gelöscht werden: Es sind bereits Aktivitäten vorhanden.');
|
||||
return;
|
||||
}
|
||||
if (!confirm('Dieses Datum wirklich löschen?')) return;
|
||||
try {
|
||||
await apiClient.delete(`/diary/${this.currentClub}/${this.date.id}`);
|
||||
await this.refreshDates();
|
||||
this.date = null;
|
||||
this.trainingStart = '';
|
||||
this.trainingEnd = '';
|
||||
this.participants = [];
|
||||
this.trainingPlan = [];
|
||||
} catch (e) {
|
||||
const msg = (e && e.response && e.response.data && e.response.data.error) || 'Fehler beim Löschen.';
|
||||
alert(msg);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user