Skip to content

Commit

Permalink
Merge pull request #117 from The1029/master
Browse files Browse the repository at this point in the history
added functionality to show ongoing multi-day events
  • Loading branch information
muness authored Mar 20, 2024
2 parents 1deb7b2 + 590238a commit 70116b3
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 7 deletions.
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

0 comments on commit 70116b3

Please sign in to comment.