Skip to content

Commit

Permalink
Moved ignore pattern to global #169
Browse files Browse the repository at this point in the history
  • Loading branch information
YukiGasai committed Oct 2, 2023
1 parent 62883fd commit 8929100
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 56 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "google-calendar",
"name": "Google Calendar",
"version": "1.10.9",
"version": "1.10.10",
"minAppVersion": "0.12.0",
"description": "Interact with your Google Calendar from Inside Obsidian",
"author": "YukiGasai",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "google-calendar",
"version": "1.10.9",
"version": "1.10.10",
"description": "Interact with your Google Calendar from Inside Obsidian",
"main": "main.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/GoogleCalendarPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const DEFAULT_SETTINGS: GoogleCalendarPluginSettings = {
showNotice: true,
autoCreateEventNotes: true,
autoCreateEventNotesMarker: "obsidian",
autoCreateEventNotesIgnoreList: [],
ignorePatternList: [],
autoCreateEventKeepOpen: false,
importStartOffset: 1,
importEndOffset: 1,
Expand Down
14 changes: 14 additions & 0 deletions src/googleApi/GoogleListEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,20 @@ async function googleListEventsByCalendar(
//Get the events because cache was no option
let totalEventList: GoogleEvent[] = await requestEventsFromApi(GoogleCalendar, startDate.toISOString(), endDate.toISOString());

//Filter out events with ignore pattern
// Ignore this if no ignore list is set
if(plugin.settings.ignorePatternList.length > 0) {
totalEventList = totalEventList.filter(event =>
!plugin.settings.ignorePatternList.some(ignoreText => {
// Check if the ignore text is a regex pattern
if(ignoreText.startsWith("/") && ignoreText.endsWith("/")) {
const regex = new RegExp(ignoreText.slice(1, -1));
return regex.test(event.summary) || regex.test(event.description);
}
return event.description?.includes(ignoreText) || event.summary?.includes(ignoreText)
}))
}

//Turn multi day events into multiple events
totalEventList = resolveMultiDayEventsHelper(totalEventList, startDate, endDate);

Expand Down
14 changes: 0 additions & 14 deletions src/helper/AutoEventNoteCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,6 @@ export const checkForEventNotes = async (plugin: GoogleCalendarPlugin): Promise<
// Don't allow multi day events to be created automatically
events = events.filter(event => event.eventType !== "multiDay")

// Remove events that contain the ignore marker
if(plugin.settings.autoCreateEventNotesIgnoreList.length) {
events = events.filter(event =>
!plugin.settings.autoCreateEventNotesIgnoreList.some(ignoreText => {
// Check if the ignore text is a regex pattern
if(ignoreText.startsWith("/") && ignoreText.endsWith("/")) {
const regex = new RegExp(ignoreText.slice(1, -1));
return regex.test(event.summary) || regex.test(event.description);
}
return event.description?.includes(ignoreText) || event.summary?.includes(ignoreText)
})
)
}

// check every event from the trigger text :obsidian:
for (let i = 0; i < events.length; i++) {
// Create a event note for all events if the trigger text is empty
Expand Down
2 changes: 1 addition & 1 deletion src/helper/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ export interface GoogleCalendarPluginSettings {
defaultFolder: string;
autoCreateEventNotes: boolean;
autoCreateEventNotesMarker: string;
autoCreateEventNotesIgnoreList: string[];
autoCreateEventKeepOpen: boolean;
importStartOffset: number;
importEndOffset: number;

// Calendar settings
defaultCalendar: string;
calendarBlackList: [string, string][];
ignorePatternList: string[];
insertTemplates: Template[];
useDefaultTemplate: boolean;

Expand Down
75 changes: 37 additions & 38 deletions src/view/GoogleCalendarSettingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,44 +275,6 @@ export class GoogleCalendarSettingTab extends PluginSettingTab {
});
})

new Setting(containerEl)
.setName("Auto create Ignore List")
.setDesc("A list of strings, if contained in the event summary or description, the event will not be auto imported")
.setClass("SubSettings")
.addText(text => {
text.setValue(this.ignoreListText);
text.onChange(value => {
this.ignoreListText = value;
});
})
.addButton(button => {
button.setButtonText("Add");
button.onClick(async () => {
this.plugin.settings.autoCreateEventNotesIgnoreList = [
...this.plugin.settings.autoCreateEventNotesIgnoreList,
this.ignoreListText
];
this.ignoreListText = "";
await this.plugin.saveSettings();
this.display();
})
})

for (const ignorePattern of this.plugin.settings.autoCreateEventNotesIgnoreList ) {
new Setting(containerEl)
.setName(ignorePattern)
.setClass("SubSettings")
.addButton(button => {
button.setButtonText("Remove");
button.onClick(async () => {
this.plugin.settings.autoCreateEventNotesIgnoreList.remove(ignorePattern);
await this.plugin.saveSettings();
this.display();
})
});
}


new Setting(containerEl)
.setName("Keep auto created Notes open")
.setDesc("When creating a new note should it stay open for direct editing")
Expand Down Expand Up @@ -463,6 +425,43 @@ export class GoogleCalendarSettingTab extends PluginSettingTab {
});
}

new Setting(containerEl)
.setName("Pattern ignore list")
.setDesc("A list of strings/regex pattern, if contained in the event summary or description, the event will not be used by the plugin")
.addText(text => {
text.setValue(this.ignoreListText);
text.onChange(value => {
this.ignoreListText = value;
});
})
.addButton(button => {
button.setButtonText("Add");
button.onClick(async () => {
this.plugin.settings.ignorePatternList = [
...this.plugin.settings.ignorePatternList,
this.ignoreListText
];
this.ignoreListText = "";
await this.plugin.saveSettings();
this.display();
})
})

for (const ignorePattern of this.plugin.settings.ignorePatternList ) {
new Setting(containerEl)
.setName(ignorePattern)
.setClass("SubSettings")
.addButton(button => {
button.setButtonText("Remove");
button.onClick(async () => {
this.plugin.settings.ignorePatternList.remove(ignorePattern);
await this.plugin.saveSettings();
this.display();
})
});
}


if (settingsAreCompleteAndLoggedIn()) {

new Setting(containerEl)
Expand Down

0 comments on commit 8929100

Please sign in to comment.