Update member activity handling to support activity codes and improve display logic
This commit enhances the `getMemberActivities` and `getMemberLastParticipations` functions to utilize activity codes when available, improving the uniqueness of activity identification. The `MemberActivityStatsDialog` component is updated to handle both string and object representations of activities, ensuring a consistent display and tooltip functionality. These changes streamline the activity data structure and enhance the user experience when viewing participation statistics.
This commit is contained in:
@@ -204,17 +204,22 @@ export const getMemberActivities = async (req, res) => {
|
||||
|
||||
const activity = ma.activity.predefinedActivity;
|
||||
const activityName = activity.name;
|
||||
const activityCode = activity.code || activity.name; // Verwende Code falls vorhanden, sonst Name
|
||||
const date = ma.activity.diaryDate?.date;
|
||||
|
||||
if (!activityMap.has(activityName)) {
|
||||
activityMap.set(activityName, {
|
||||
name: activityName,
|
||||
// Verwende Code als Key, falls vorhanden, sonst Name
|
||||
const key = activityCode;
|
||||
|
||||
if (!activityMap.has(key)) {
|
||||
activityMap.set(key, {
|
||||
name: activityName, // Vollständiger Name für Tooltip
|
||||
code: activityCode, // Code/Kürzel für Anzeige
|
||||
count: 0,
|
||||
dates: []
|
||||
});
|
||||
}
|
||||
|
||||
const activityData = activityMap.get(activityName);
|
||||
const activityData = activityMap.get(key);
|
||||
activityData.count++;
|
||||
if (date) {
|
||||
activityData.dates.push(date);
|
||||
@@ -403,7 +408,9 @@ export const getMemberLastParticipations = async (req, res) => {
|
||||
.forEach(ma => {
|
||||
const date = ma.activity.diaryDate.date;
|
||||
const diaryDateId = ma.activity.diaryDate.id;
|
||||
const activityName = ma.activity.predefinedActivity.name;
|
||||
const activity = ma.activity.predefinedActivity;
|
||||
const activityName = activity.name;
|
||||
const activityCode = activity.code || activity.name;
|
||||
|
||||
if (!participationsByDate.has(date)) {
|
||||
participationsByDate.set(date, {
|
||||
@@ -415,8 +422,13 @@ export const getMemberLastParticipations = async (req, res) => {
|
||||
|
||||
const dateEntry = participationsByDate.get(date);
|
||||
// Füge Aktivität nur hinzu, wenn sie noch nicht vorhanden ist (vermeide Duplikate)
|
||||
if (!dateEntry.activities.find(a => a === activityName)) {
|
||||
dateEntry.activities.push(activityName);
|
||||
// Speichere sowohl code als auch name
|
||||
const activityEntry = {
|
||||
code: activityCode,
|
||||
name: activityName
|
||||
};
|
||||
if (!dateEntry.activities.find(a => (a.code || a.name) === activityCode)) {
|
||||
dateEntry.activities.push(activityEntry);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -432,10 +444,11 @@ export const getMemberLastParticipations = async (req, res) => {
|
||||
// Formatiere für das Frontend: Flache Liste mit Datum und Aktivität
|
||||
const participations = [];
|
||||
sortedDates.forEach(dateEntry => {
|
||||
dateEntry.activities.forEach(activityName => {
|
||||
dateEntry.activities.forEach(activity => {
|
||||
participations.push({
|
||||
id: null, // Virtuell
|
||||
activityName: activityName,
|
||||
activityName: activity.code || activity.name, // Code für Anzeige
|
||||
activityFullName: activity.name, // Vollständiger Name für Tooltip
|
||||
date: dateEntry.date,
|
||||
diaryDateId: dateEntry.diaryDateId
|
||||
});
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<div class="participation-date-header">{{ formatDate(dateGroup.date) }}</div>
|
||||
<div class="participation-activities">
|
||||
<div v-for="(activity, index) in dateGroup.activities" :key="index" class="participation-item">
|
||||
<div class="participation-name">{{ activity }}</div>
|
||||
<div class="participation-name" :title="getActivityTooltip(activity)">{{ getActivityDisplay(activity) }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -29,8 +29,8 @@
|
||||
<div class="section">
|
||||
<h3 class="section-title">Statistik der Übungen</h3>
|
||||
<div v-if="activityStats && activityStats.length" class="stats-list">
|
||||
<div v-for="stat in activityStats" :key="stat.name" class="stat-item">
|
||||
<div class="stat-name">{{ stat.name }}</div>
|
||||
<div v-for="stat in activityStats" :key="stat.code || stat.name" class="stat-item">
|
||||
<div class="stat-name" :title="stat.name">{{ stat.code || stat.name }}</div>
|
||||
<div class="stat-count">{{ stat.count }}x</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -87,8 +87,19 @@ export default {
|
||||
}
|
||||
const dateGroup = grouped.get(date);
|
||||
// Füge Aktivität nur hinzu, wenn sie noch nicht vorhanden ist
|
||||
if (!dateGroup.activities.includes(participation.activityName)) {
|
||||
dateGroup.activities.push(participation.activityName);
|
||||
// Unterstütze sowohl alte (String) als auch neue (Objekt) Datenstruktur
|
||||
const activityEntry = participation.activityFullName
|
||||
? { code: participation.activityName, name: participation.activityFullName }
|
||||
: participation.activityName;
|
||||
|
||||
const exists = typeof activityEntry === 'string'
|
||||
? dateGroup.activities.includes(activityEntry)
|
||||
: dateGroup.activities.some(a =>
|
||||
(typeof a === 'string' ? a === activityEntry.code : (a.code || a.name) === activityEntry.code)
|
||||
);
|
||||
|
||||
if (!exists) {
|
||||
dateGroup.activities.push(activityEntry);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -111,6 +122,22 @@ export default {
|
||||
if (!dateString) return '';
|
||||
const date = new Date(dateString);
|
||||
return date.toLocaleDateString('de-DE');
|
||||
},
|
||||
getActivityDisplay(activity) {
|
||||
// Wenn activity ein String ist (alte Datenstruktur), verwende es direkt
|
||||
if (typeof activity === 'string') {
|
||||
return activity;
|
||||
}
|
||||
// Wenn activity ein Objekt ist, verwende code oder name
|
||||
return activity.code || activity.name || activity;
|
||||
},
|
||||
getActivityTooltip(activity) {
|
||||
// Wenn activity ein String ist (alte Datenstruktur), kein Tooltip
|
||||
if (typeof activity === 'string') {
|
||||
return '';
|
||||
}
|
||||
// Wenn activity ein Objekt ist, verwende name als Tooltip
|
||||
return activity.name || '';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
6
package-lock.json
generated
6
package-lock.json
generated
@@ -4018,9 +4018,9 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/js-yaml": {
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz",
|
||||
"integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==",
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.1.tgz",
|
||||
"integrity": "sha512-qQKT4zQxXl8lLwBtHMWwaTcGfFOZviOJet3Oy/xmGk2gZH677CJM9EvtfdSkgWcATZhj/55JZ0rmy3myCT5lsA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"argparse": "^2.0.1"
|
||||
|
||||
Reference in New Issue
Block a user