Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions ImmichFrame.Core/Helpers/CalendarExtensionMethods.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,44 @@
using Ical.Net.CalendarComponents;
using Ical.Net.CalendarComponents;
using Ical.Net.DataTypes;
using ImmichFrame.Core.Interfaces;
using ImmichFrame.Core.Models;

namespace ImmichFrame.WebApi.Helpers
{
public static class CalendarExtensionMethods
{
public static IAppointment ToAppointment(this Occurrence occurrence)
{
if (occurrence.Source.GetType() == typeof(CalendarEvent)) {
return ((CalendarEvent)occurrence.Source).ToAppointment();
string summary = "";
string description = "";
string location = "";

if (occurrence.Source is CalendarEvent calEvent)
{
summary = calEvent.Summary;
description = calEvent.Description ?? "";
location = calEvent.Location ?? "";
}

return new Appointment
{
//Summary = occurrence.Period.Duration.Summary,
//Description = occurrence.Source.Description,
Summary = summary,
Description = description,
StartTime = occurrence.Period.StartTime.AsSystemLocal,
Duration = occurrence.Period.Duration,
EndTime = occurrence.Period.EndTime.AsSystemLocal,
Location = ""
Location = location
};
}
public static IAppointment ToAppointment(this CalendarEvent calEvent)
{
return new Appointment
{
Summary = calEvent.Summary,
Description = calEvent.Description,
Description = calEvent.Description ?? "",
StartTime = calEvent.Start.AsSystemLocal,
Duration = calEvent.Duration,
EndTime = calEvent.End.AsSystemLocal,
Location = calEvent.Location
Location = calEvent.Location ?? ""
};
}
}
Expand Down
1 change: 1 addition & 0 deletions ImmichFrame.Core/Interfaces/IServerBehaviorSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace ImmichFrame.Core.Interfaces
public interface IServerBehaviorSettings
{
public List<string> Webcalendars { get; }
public int CalendarDaysAhead { get; }
public int RefreshAlbumPeopleInterval { get; }
public string? WeatherApiKey { get; }
public string? WeatherLatLong { get; }
Expand Down
12 changes: 8 additions & 4 deletions ImmichFrame.Core/Services/IcalCalendarService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,18 @@ public async Task<List<IAppointment>> GetAppointments()

var icals = await GetCalendars(cals);

// Clamp to a sane range: never negative, and cap well below DateTime overflow.
var daysAhead = Math.Clamp(_serverSettings.CalendarDaysAhead, 0, 3650);
var endDate = DateTime.Today.AddDays(daysAhead + 1);

foreach (var ical in icals)
{
var calendar = Calendar.Load(ical);

appointments.AddRange(calendar.GetOccurrences(DateTime.Today, DateTime.Today.AddDays(1)).Select(x => x.ToAppointment()));
appointments.AddRange(calendar.GetOccurrences(DateTime.Today, endDate)
.Select(x => x.ToAppointment()));
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

return appointments;
return appointments.OrderBy(x => x.StartTime).ToList();
});
}

Expand Down Expand Up @@ -90,4 +94,4 @@ public async Task<List<string>> GetCalendars(IEnumerable<(string? auth, string u

return icals;
}
}
}
2 changes: 2 additions & 0 deletions ImmichFrame.WebApi/Helpers/Config/ServerSettingsV1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class ServerSettingsV1 : IConfigSettable
public List<string> Tags { get; set; } = new List<string>();
public int? Rating { get; set; }
public List<string> Webcalendars { get; set; } = new List<string>();
public int CalendarDaysAhead { get; set; } = 0;
public int RefreshAlbumPeopleInterval { get; set; } = 12;
public string? WeatherApiKey { get; set; } = string.Empty;
public string? UnitSystem { get; set; } = "imperial";
Expand Down Expand Up @@ -101,6 +102,7 @@ public void ValidateAndInitialize() { }
class GeneralSettingsV1Adapter(ServerSettingsV1 _delegate) : IGeneralSettings
{
public List<string> Webcalendars => _delegate.Webcalendars;
public int CalendarDaysAhead => _delegate.CalendarDaysAhead;
public int RefreshAlbumPeopleInterval => _delegate.RefreshAlbumPeopleInterval;
public string? WeatherApiKey => _delegate.WeatherApiKey;
public string? WeatherLatLong => _delegate.WeatherLatLong;
Expand Down
1 change: 1 addition & 0 deletions ImmichFrame.WebApi/Models/ServerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public class GeneralSettings : IGeneralSettings, IConfigSettable
public string Layout { get; set; } = "splitview";
public int RenewImagesDuration { get; set; } = 30;
public List<string> Webcalendars { get; set; } = new();
public int CalendarDaysAhead { get; set; } = 0;
public int RefreshAlbumPeopleInterval { get; set; } = 12;
public string? WeatherApiKey { get; set; } = string.Empty;
public string? UnitSystem { get; set; } = "imperial";
Expand Down
19 changes: 7 additions & 12 deletions immichFrame.Web/src/lib/components/elements/appointments.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,38 @@
import { format } from 'date-fns';
import { configStore } from '$lib/stores/config.store';
import { clientIdentifierStore } from '$lib/stores/persist.store';

api.init();

function formatDates(startTime: string, endTime: string) {
let startDate = new Date(startTime);
let endDate = new Date(endTime);
let sameDay = startDate.getDate() == endDate.getDate();

let sameDay = startDate.toDateString() == endDate.toDateString();
let today = new Date();
let isToday = startDate.toDateString() == today.toDateString();
let clockFormat = $configStore.clockFormat ?? 'HH:mm';
let clockDateFormat = $configStore.clockDateFormat ?? 'eee, MMM d';
let fullFormat = clockDateFormat + ' ' + clockFormat;

if (sameDay) {
return format(startDate, clockFormat) + ' - ' + format(endDate, clockFormat);
if (isToday) {
return format(startDate, clockFormat) + ' - ' + format(endDate, clockFormat);
}
return format(startDate, clockDateFormat) + ' ' + format(startDate, clockFormat) + ' - ' + format(endDate, clockFormat);
}

return format(startDate, fullFormat) + ' - ' + format(endDate, fullFormat);
}

let appointments: api.IAppointment[] = $state() as api.IAppointment[];

onMount(() => {
GetAppointments();
const appointmentInterval = setInterval(() => GetAppointments(), 10 * 60 * 1000); //every 10 minutes

return () => {
clearInterval(appointmentInterval);
};
});

async function GetAppointments() {
let appointmentRequest = await api.getAppointments({
clientIdentifier: $clientIdentifierStore
});
if (appointmentRequest.status == 200) {
appointments = appointmentRequest.data;

appointments = appointmentRequest.data.sort((a, b) => {
return new Date(a.startTime ?? '').getTime() - new Date(b.startTime ?? '').getTime();
});
Expand Down