| | | 1 | | namespace Pomodoro.Web.Models; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Represents a completed pomodoro or break session for activity history |
| | | 5 | | /// </summary> |
| | | 6 | | public class ActivityRecord |
| | | 7 | | { |
| | 13167 | 8 | | public Guid Id { get; set; } = Guid.NewGuid(); |
| | 4098 | 9 | | public SessionType Type { get; set; } |
| | 7351 | 10 | | public string? TaskName { get; set; } |
| | 6083 | 11 | | public Guid? TaskId { get; set; } |
| | 8957 | 12 | | public DateTime CompletedAt { get; set; } |
| | 7769 | 13 | | public int DurationMinutes { get; set; } |
| | 198 | 14 | | public bool WasCompleted { get; set; } |
| | | 15 | | |
| | | 16 | | // For display purposes |
| | 492 | 17 | | public string DisplayText => Type switch |
| | 492 | 18 | | { |
| | 464 | 19 | | SessionType.Pomodoro => TaskName ?? Constants.SessionTypes.FocusTimeActivity, |
| | 18 | 20 | | SessionType.ShortBreak => Constants.SessionTypes.ShortBreakActivity, |
| | 9 | 21 | | SessionType.LongBreak => Constants.SessionTypes.LongBreakActivity, |
| | 1 | 22 | | _ => Constants.SessionTypes.UnknownActivity |
| | 492 | 23 | | }; |
| | | 24 | | |
| | 491 | 25 | | public string Icon => Type switch |
| | 491 | 26 | | { |
| | 463 | 27 | | SessionType.Pomodoro => Constants.SessionTypes.PomodoroEmoji, |
| | 18 | 28 | | SessionType.ShortBreak => Constants.SessionTypes.ShortBreakEmoji, |
| | 9 | 29 | | SessionType.LongBreak => Constants.SessionTypes.LongBreakEmoji, |
| | 1 | 30 | | _ => Constants.SessionTypes.TimerEmoji |
| | 491 | 31 | | }; |
| | | 32 | | |
| | 23 | 33 | | public string TimeAgo => GetTimeAgo(CompletedAt); |
| | | 34 | | |
| | | 35 | | private static string GetTimeAgo(DateTime completedAt) |
| | 23 | 36 | | { |
| | 23 | 37 | | var diff = DateTime.UtcNow - completedAt; |
| | | 38 | | |
| | 23 | 39 | | if (diff.TotalMinutes < Constants.TimeThresholds.OneMinute) |
| | 19 | 40 | | return Constants.TimeFormats.JustNowText; |
| | 4 | 41 | | if (diff.TotalMinutes < Constants.TimeThresholds.OneHourInMinutes) |
| | 1 | 42 | | return string.Format(Constants.TimeFormats.MinutesAgoFormat, (int)diff.TotalMinutes); |
| | 3 | 43 | | if (diff.TotalHours < Constants.TimeThresholds.OneDayInHours) |
| | 1 | 44 | | return string.Format(Constants.TimeFormats.HoursAgoFormat, (int)diff.TotalHours); |
| | 2 | 45 | | if (diff.TotalDays < Constants.TimeThresholds.OneWeekInDays) |
| | 1 | 46 | | return string.Format(Constants.TimeFormats.DaysAgoFormat, (int)diff.TotalDays); |
| | | 47 | | |
| | 1 | 48 | | return completedAt.ToString(Constants.TimeFormats.ShortDateFormat); |
| | 23 | 49 | | } |
| | | 50 | | } |