diff --git a/Client/Pages/Index.razor b/Client/Pages/Index.razor index 447fbc7..503a72e 100644 --- a/Client/Pages/Index.razor +++ b/Client/Pages/Index.razor @@ -7,20 +7,10 @@
- - - - + + + +
@@ -92,6 +82,15 @@ } +else if (_isSyncing) +{ +
+
+
⏳
+

Syncing with google calendar...

+
+
+} else { diff --git a/Services/ConfigurationService.cs b/Services/ConfigurationService.cs index e0d54aa..a4c7cac 100644 --- a/Services/ConfigurationService.cs +++ b/Services/ConfigurationService.cs @@ -5,6 +5,7 @@ namespace ShiftScheduler.Services { public interface IConfigurationService { + string GetTimeZone(); ApplicationConfiguration GetConfiguration(); void UpdateConfiguration(ApplicationConfiguration configuration); Task ExportConfigurationAsync(); @@ -29,7 +30,12 @@ namespace ShiftScheduler.Services private readonly string _shiftsFilePath; private readonly string _transportFilePath; - readonly TimeZoneInfo localTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Europe/Zurich"); + private readonly TimeZoneInfo localTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Europe/Zurich"); + + public string GetTimeZone() + { + return localTimeZone.Id; + } public ConfigurationService(ApplicationConfiguration initialConfiguration) { diff --git a/Services/GoogleCalendarService.cs b/Services/GoogleCalendarService.cs index 6cc12ab..5c7186c 100644 --- a/Services/GoogleCalendarService.cs +++ b/Services/GoogleCalendarService.cs @@ -5,7 +5,6 @@ using Google.Apis.Services; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Http; using ShiftScheduler.Shared; -using System.Net; namespace ShiftScheduler.Services; @@ -15,17 +14,9 @@ public interface IGoogleCalendarService Task SyncShiftsToCalendarAsync(string calendarId, List shifts); } -public class GoogleCalendarService : IGoogleCalendarService +public class GoogleCalendarService(IHttpContextAccessor httpContextAccessor, IConfigurationService configurationService) + : IGoogleCalendarService { - private readonly IHttpContextAccessor _httpContextAccessor; - private readonly IcsExportService _icsExportService; - - public GoogleCalendarService(IHttpContextAccessor httpContextAccessor, IcsExportService icsExportService) - { - _httpContextAccessor = httpContextAccessor; - _icsExportService = icsExportService; - } - public async Task> GetCalendarsAsync() { var service = await CreateCalendarServiceAsync(); @@ -110,25 +101,25 @@ public class GoogleCalendarService : IGoogleCalendarService // Create morning event if it exists if (!string.IsNullOrEmpty(shift.MorningTime)) { - var morningEvent = CreateEventFromShift(shift, date, shift.MorningTime, "Morning", shiftWithTransport.MorningTransport); + var morningEvent = CreateEventFromShift(shift, date, shift.MorningTime, shiftWithTransport.MorningTransport); await ExecuteWithRetryAsync(async () => await service.Events.Insert(morningEvent, calendarId).ExecuteAsync()); } // Create afternoon event if it exists if (!string.IsNullOrEmpty(shift.AfternoonTime)) { - var afternoonEvent = CreateEventFromShift(shift, date, shift.AfternoonTime, "Afternoon", shiftWithTransport.AfternoonTransport); + var afternoonEvent = CreateEventFromShift(shift, date, shift.AfternoonTime, shiftWithTransport.AfternoonTransport); await ExecuteWithRetryAsync(async () => await service.Events.Insert(afternoonEvent, calendarId).ExecuteAsync()); } } - private static Event CreateEventFromShift(Shift shift, DateTime date, string timeRange, string period, TransportConnection? transport) + private Event CreateEventFromShift(Shift shift, DateTime date, string timeRange, TransportConnection? transport) { var times = timeRange.Split('-'); var startTime = date.Add(TimeSpan.Parse(times[0])); var endTime = date.Add(TimeSpan.Parse(times[1])); - var summary = $"{shift.Name} ({period})"; + var summary = $"{shift.Name}"; var description = ""; if (transport != null) @@ -144,20 +135,19 @@ public class GoogleCalendarService : IGoogleCalendarService Start = new EventDateTime { DateTimeDateTimeOffset = startTime, - TimeZone = "Europe/Zurich" + TimeZone = configurationService.GetTimeZone() }, End = new EventDateTime { DateTimeDateTimeOffset = endTime, - TimeZone = "Europe/Zurich" + TimeZone = configurationService.GetTimeZone() }, ExtendedProperties = new Event.ExtendedPropertiesData { Private__ = new Dictionary { ["shiftSchedulerEvent"] = "true", - ["shiftName"] = shift.Name, - ["period"] = period.ToLower() + ["shiftName"] = shift.Name } } }; @@ -167,12 +157,12 @@ public class GoogleCalendarService : IGoogleCalendarService { var departure = transport.DepartureTime.ToString("HH:mm"); var arrival = transport.ArrivalTime.ToString("HH:mm"); - return $"{departure} → {arrival}"; + return $"{transport.Platform}: {departure} → {arrival} ({transport.Duration.TotalMinutes} Minutes)"; } private async Task CreateCalendarServiceAsync() { - var httpContext = _httpContextAccessor.HttpContext ?? throw new InvalidOperationException("No HTTP context available"); + var httpContext = httpContextAccessor.HttpContext ?? throw new InvalidOperationException("No HTTP context available"); var accessToken = await httpContext.GetTokenAsync("access_token"); if (string.IsNullOrEmpty(accessToken)) diff --git a/Services/IcsExportService.cs b/Services/IcsExportService.cs index 8ab3ab4..28d752e 100644 --- a/Services/IcsExportService.cs +++ b/Services/IcsExportService.cs @@ -23,7 +23,7 @@ namespace ShiftScheduler.Services if (!string.IsNullOrEmpty(shift.MorningTime)) { var times = shift.MorningTime.Split('-'); - var summary = $"{shift.Name} (Morning)"; + var summary = $"{shift.Name}"; var description = ""; if (shiftWithTransport.MorningTransport != null) @@ -44,7 +44,7 @@ namespace ShiftScheduler.Services if (!string.IsNullOrEmpty(shift.AfternoonTime)) { var times = shift.AfternoonTime.Split('-'); - var summary = $"{shift.Name} (Afternoon)"; + var summary = $"{shift.Name}"; var description = ""; if (shiftWithTransport.AfternoonTransport != null)