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
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user