Single isntances and some updates shit.
This commit is contained in:
@@ -2,8 +2,10 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Itenso.TimePeriod;
|
||||
using Wino.Core.Domain;
|
||||
using Wino.Core.Domain.Entities.Calendar;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Domain.Models.Calendar;
|
||||
|
||||
namespace Wino.Calendar.ViewModels.Data;
|
||||
|
||||
@@ -89,6 +91,35 @@ public partial class CalendarItemViewModel : ObservableObject, ICalendarItem, IC
|
||||
[ObservableProperty]
|
||||
public partial bool IsSelected { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The period of the day where this item is currently being displayed.
|
||||
/// Used for multi-day event title formatting.
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
[NotifyPropertyChangedFor(nameof(DisplayTitle))]
|
||||
public partial ITimePeriod DisplayingPeriod { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Calendar settings for time formatting.
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
[NotifyPropertyChangedFor(nameof(DisplayTitle))]
|
||||
public partial CalendarSettings CalendarSettings { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the display title based on the current displaying period.
|
||||
/// </summary>
|
||||
public string DisplayTitle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (DisplayingPeriod == null || CalendarSettings == null)
|
||||
return Title;
|
||||
|
||||
return GetDisplayTitle(DisplayingPeriod, CalendarSettings);
|
||||
}
|
||||
}
|
||||
|
||||
public ObservableCollection<CalendarEventAttendee> Attendees { get; } = new ObservableCollection<CalendarEventAttendee>();
|
||||
|
||||
public CalendarItemViewModel(CalendarItem calendarItem)
|
||||
@@ -96,5 +127,82 @@ public partial class CalendarItemViewModel : ObservableObject, ICalendarItem, IC
|
||||
CalendarItem = calendarItem;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the underlying CalendarItem with new data and raises property change notifications.
|
||||
/// </summary>
|
||||
/// <param name="calendarItem">The updated calendar item data.</param>
|
||||
public void UpdateFrom(CalendarItem calendarItem)
|
||||
{
|
||||
if (calendarItem == null || calendarItem.Id != CalendarItem.Id)
|
||||
return;
|
||||
|
||||
// Update all mutable properties
|
||||
CalendarItem.Title = calendarItem.Title;
|
||||
CalendarItem.Description = calendarItem.Description;
|
||||
CalendarItem.Location = calendarItem.Location;
|
||||
CalendarItem.StartDate = calendarItem.StartDate;
|
||||
CalendarItem.StartTimeZone = calendarItem.StartTimeZone;
|
||||
CalendarItem.EndTimeZone = calendarItem.EndTimeZone;
|
||||
CalendarItem.DurationInSeconds = calendarItem.DurationInSeconds;
|
||||
CalendarItem.Recurrence = calendarItem.Recurrence;
|
||||
CalendarItem.RecurringCalendarItemId = calendarItem.RecurringCalendarItemId;
|
||||
CalendarItem.OrganizerDisplayName = calendarItem.OrganizerDisplayName;
|
||||
CalendarItem.OrganizerEmail = calendarItem.OrganizerEmail;
|
||||
CalendarItem.IsLocked = calendarItem.IsLocked;
|
||||
CalendarItem.IsHidden = calendarItem.IsHidden;
|
||||
CalendarItem.CustomEventColorHex = calendarItem.CustomEventColorHex;
|
||||
CalendarItem.HtmlLink = calendarItem.HtmlLink;
|
||||
CalendarItem.Status = calendarItem.Status;
|
||||
CalendarItem.Visibility = calendarItem.Visibility;
|
||||
CalendarItem.ShowAs = calendarItem.ShowAs;
|
||||
CalendarItem.UpdatedAt = calendarItem.UpdatedAt;
|
||||
CalendarItem.AssignedCalendar = calendarItem.AssignedCalendar;
|
||||
|
||||
// Raise property changed for all bindable properties
|
||||
OnPropertyChanged(nameof(Title));
|
||||
OnPropertyChanged(nameof(StartDate));
|
||||
OnPropertyChanged(nameof(EndDate));
|
||||
OnPropertyChanged(nameof(DurationInSeconds));
|
||||
OnPropertyChanged(nameof(Period));
|
||||
OnPropertyChanged(nameof(IsAllDayEvent));
|
||||
OnPropertyChanged(nameof(IsMultiDayEvent));
|
||||
OnPropertyChanged(nameof(IsRecurringEvent));
|
||||
OnPropertyChanged(nameof(IsRecurringChild));
|
||||
OnPropertyChanged(nameof(IsRecurringParent));
|
||||
OnPropertyChanged(nameof(AssignedCalendar));
|
||||
OnPropertyChanged(nameof(DisplayTitle));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the display title for this calendar item when rendered in a specific day.
|
||||
/// </summary>
|
||||
public string GetDisplayTitle(ITimePeriod displayingPeriod, CalendarSettings calendarSettings)
|
||||
{
|
||||
if (!IsMultiDayEvent)
|
||||
return Title;
|
||||
|
||||
var periodRelation = Period.GetRelation(displayingPeriod);
|
||||
|
||||
if (periodRelation == PeriodRelation.StartInside || periodRelation == PeriodRelation.EnclosingStartTouching)
|
||||
{
|
||||
// Event starts within this day: "HH:mm -> Title"
|
||||
return $"{calendarSettings.GetTimeString(StartDate.TimeOfDay)} -> {Title}";
|
||||
}
|
||||
else if (periodRelation == PeriodRelation.EndInside || periodRelation == PeriodRelation.EnclosingEndTouching)
|
||||
{
|
||||
// Event ends within this day: "Title <- HH:mm"
|
||||
return $"{Title} <- {calendarSettings.GetTimeString(EndDate.TimeOfDay)}";
|
||||
}
|
||||
else if (periodRelation == PeriodRelation.Enclosing)
|
||||
{
|
||||
// Event spans the entire day
|
||||
return $"{Translator.CalendarItemAllDay} {Title}";
|
||||
}
|
||||
else
|
||||
{
|
||||
return Title;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString() => CalendarItem.Title;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user