Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added functionality to show ongoing multi-day events #117

Merged
merged 1 commit into from
Mar 20, 2024
Merged
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
4 changes: 2 additions & 2 deletions manifest-beta.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"id": "ics",
"name": "ICS",
"version": "1.6.3",
"minAppVersion": "1.5.3",
"version": "1.6.4",
"minAppVersion": "1.5.11",
"description": "Parse multiple ICS files to include in your notes. Designed for Daily Notes and the Day Planner format. Through templates you can customize it for other use cases.",
"author": "Cloud Atlas",
"authorUrl": "https://cloud-atlas.ai",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion src/icalUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function adjustDateToOriginalTimezone(originalDate: Date, currentDate: Date, tzi
return momentCurrent.add(hourOffset, 'hours').add(minuteOffset, 'minutes').toDate();
}

export function filterMatchingEvents(icsArray: any[], dayToMatch: string) {
export function filterMatchingEvents(icsArray: any[], dayToMatch: string, showOngoing: boolean) {

return icsArray.reduce((matchingEvents, event) => {
var hasRecurrenceOverride = false
Expand Down Expand Up @@ -103,6 +103,13 @@ export function filterMatchingEvents(icsArray: any[], dayToMatch: string) {
matchingEvents.push(event);
}
}

if (showOngoing) {
if (moment(dayToMatch).isBetween(moment(event.start), moment(event.end), "day")) {
matchingEvents.push(event);
}
}

return matchingEvents;
}, []);;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default class ICSPlugin extends Plugin {

// Exception handling for parsing and filtering
try {
dateEvents = filterMatchingEvents(icsArray, date);
dateEvents = filterMatchingEvents(icsArray, date, calendarSetting.format.showOngoing);

} catch (filterError) {
console.error(`Error filtering events for calendar ${calendarSetting.icsName}: ${filterError}`);
Expand Down
2 changes: 2 additions & 0 deletions src/settings/ICSSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface Calendar {
location: boolean;
description: boolean;
showAttendees: boolean;
showOngoing: boolean;
}
}

Expand All @@ -30,6 +31,7 @@ export const DEFAULT_CALENDAR_FORMAT = {
description: false,
calendarType: 'remote', // Set the default type to 'remote'
showAttendees: false,
showOngoing: false
};

export const DEFAULT_SETTINGS: ICSSettings = {
Expand Down
12 changes: 11 additions & 1 deletion src/settings/ICSSettingsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ class SettingsModal extends Modal {
summary: boolean,
location: boolean,
description: boolean,
showAttendees: boolean
showAttendees: boolean,
showOngoing: boolean
} = DEFAULT_CALENDAR_FORMAT;
calendarType: string;
constructor(app: App, plugin: ICSPlugin, setting?: Calendar) {
Expand Down Expand Up @@ -368,6 +369,15 @@ class SettingsModal extends Modal {
this.format.showAttendees = value; // Set the new property
}));

const showOngoingToggle = new Setting(settingDiv)
.setName('Show Ongoing')
.setDesc('Display multi-day events that include target date')
.addToggle(toggle => toggle
.setValue(this.format.showOngoing || true) // Use the new property
.onChange(value => {
this.format.showOngoing = value; // Set the new property
}));

let footerEl = contentEl.createDiv();
let footerButtons = new Setting(footerEl);
footerButtons.addButton((b) => {
Expand Down