Skip to content

Commit af6ef4e

Browse files
committed
Add insertWeeksEvents and listWeeksEvents functions and fix regression, as part of 0.23.0
1 parent 3139816 commit af6ef4e

File tree

8 files changed

+166
-64
lines changed

8 files changed

+166
-64
lines changed

helpers/NPCalendar.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,14 @@ export async function writeTimeBlocksToCalendar(config: EventsConfig, note: TNot
226226
// Note: now also remove the NP DataStore.preference("timeblockTextMustContainString") if specified.
227227
const mustContainString = String(DataStore.preference('timeblockTextMustContainString')) ?? ''
228228
logDebug('NPCalendar / writeTimeBlocksToCalendar', `- Removing mustContainString '${mustContainString}' from time block string`)
229-
230229
const restOfTaskWithoutTimeBlock = thisPara.content
231230
.replace(`${mustContainString} ${origTimeBlockString}`, '')
232231
.replace(/\s{2,}/g, ' ')
233-
.trimEnd() // take off timeblock
232+
.trimEnd()
234233
const restOfTaskWithoutDateTime = removeDateTagsAndToday(restOfTaskWithoutTimeBlock)
235234
.replace(timeBlockString, '')
236235
.replace(/\s{2,}/g, ' ')
237-
logDebug('NPCalendar / writeTimeBlocksToCalendar', `- Will process time block '${timeBlockString}' for '${restOfTaskWithoutDateTime}'`)
236+
logDebug('NPCalendar / writeTimeBlocksToCalendar', `- Will process time block '${timeBlockString}' with restOfTaskWithoutDateTime:'${restOfTaskWithoutDateTime}' / restOfTaskWithoutTimeBlock:'${restOfTaskWithoutTimeBlock}'`)
238237

239238
// Do we want to add this particular event?
240239
if (config.confirmEventCreation && keepAsking) {
@@ -266,12 +265,12 @@ export async function writeTimeBlocksToCalendar(config: EventsConfig, note: TNot
266265
}
267266
// Add event ID (if wanted)
268267
if (config.addEventID) {
269-
const createdEvent = await Calendar.eventByID(eventID) ?? null
268+
const createdEvent = await Calendar.eventByID(eventID)
270269
thisParaContent += ` ${createdEvent?.calendarItemLink ?? ''}`
271270
}
272-
thisPara.content = thisParaContent
273271
logDebug('NPCalendar / writeTimeBlocksToCalendar', `- setting thisPara.content -> '${thisParaContent}'`)
274-
// FIXME(@EduardMe): there's something odd going on here. Often 3 characters are left or repeated at the end of the line as a result of this
272+
// FIXME(@EduardMe): there's something odd going on here. Often 1 or 3 characters are left or repeated at the end of the line as a result of this. Perhaps to do with emojis?
273+
thisPara.content = thisParaContent
275274
if (showLoadingProgress && !config.confirmEventCreation) {
276275
CommandBar.showLoading(true, `Inserting Calendar Events\n(${i + 1}/${timeblockParas.length})`, (i + 1) / timeblockParas.length)
277276
await CommandBar.onMainThread()

jgclark.EventHelpers/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
See [website README for more details](https://github.com/NotePlan/plugins/tree/main/jgclark.EventHelpers), and how to configure.
44

5+
## [0.23.0] - 2025-08-22 @jgclark
6+
### New
7+
- new command **/insert week's events as list**, which inserts this week's calendar events in the current note
8+
- new equivalent `insertWeeksEvents` and `listWeeksEvents` functions for use in automation (templating or x-callbacks)
9+
### Changed
10+
- changed setting 'Processed tag name' to 'Processed indicator string' to clarify that you can use any string, not just hashtags. And added a note that if this string contains an emoji then it sometimes triggers a bug in NotePlan where you get some repeated characters at the end of the line.
11+
### Fixed
12+
- regression on "/time blocks to calendar"
13+
514
## [0.22.2] - 2025-08-19 @jgclark
615
- add 'add computed final date' setting for '/process date offsets' command. (Previously it always added a final computed date to the relevant section heading. Now this can be turned off.)
716

jgclark.EventHelpers/README.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# 🕓 Event Helpers plugin
22
This plugin provides commands to help you do useful things with Events and Calendars that can't (yet) be done by NotePlan itself:
33

4-
- **insert day's events as list**: insert a list of this day's calendar events into the current note -- including doing so automatically in **day/week note templates**
5-
- **insert matching events**: insert a list of this day's calendar events that match certain patterns into the current note
6-
- **time blocks to calendar**: takes [NotePlan-defined time blocks](https://help.noteplan.co/article/52-part-2-tasks-events-and-reminders#timeblocking) and converts to them to full Calendar events in your current default calendar, as set by iCal. (See also [Display of Time Blocks](#display-of-time-blocks) below.)
7-
- **process date offsets**: finds date offset patterns and turns them into due dates, based on date at start of section. (See [Date Offsets](#process-date-offsets) below for full details.)
4+
- **insert day's events as list**: insert a list of this day's calendar events into the current note. Can be used automatically in a Daily note Template. Alias: **ide**.
5+
- **insert week's events as list**: insert a list of all the day's calendar events for this week into the current note. Can be used automatically in a Weekly note Template. Alias: **ide**.
6+
- **insert matching events**: insert a list of this day's calendar events that match certain patterns into the current note. Alias: **ime**.
7+
- **time blocks to calendar**: takes [NotePlan-defined time blocks](https://help.noteplan.co/article/52-part-2-tasks-events-and-reminders#timeblocking) and converts to them to full Calendar events in your current default calendar, as set by iCal. (See also [Display of Time Blocks](#display-of-time-blocks) below.) Aliases: **tbtc** or **tbcal**.
8+
- **process date offsets**: finds date offset patterns and turns them into due dates, based on date at start of section. (See [Date Offsets](#process-date-offsets) below for full details.) Alias: **offset**.
89
- **shift dates**: takes dates _in the selected lines_ and shifts them forwards or backwards by a given date interval. It works on both `>YYYY-MM-DD` and `>YYYY-Wnn` style dates. (User George Crump (@george65) has created a [video showing how this command works](https://storone.zoom.us/rec/play/tzI6AreYeKvoyHRw11HX93IGVf2OI-U7WgKXYn2rmGJvbFHXZp8PSr6ajmOrtWymOU5jFIItScSJnL9U.tboBQEXjdw1uRTqu).)
910

1011
Most of these commands require configuration, described in the sections below. On macOS, click the gear button on the 'Event Helpers' line in the Plugin Preferences panel to access the settings. Or on on iOS/iPadOS devices, use the **Events: update plugin settings** command instead.
@@ -51,7 +52,7 @@ Settings:
5152
- **Confirm Event Creation?**: optional boolean tag to indicate whether to ask user to confirm each event to be created
5253
- **Remove time blocks when processed?**: in `time blocks...` whether to remove time block after making an event from it
5354
- **Add event link?**: whether to add a nicely-formatted event link when creating an event from a time block. (This can return rather long strings (e.g. `⏰event:287B39C1-4D0A-46DC-BD72-84D79167EFDF`) and so you might want to use a theme option to shorten them until needed (details [below](#theme-customisation)).)
54-
- **Processed tag name**: if this is set, then this tag will get added on the end of the line with the time block, to show that it has been processed. Otherwise, next time this command is run, it will create another event. This can be used with or without addEventID.
55+
- **Processed indicator string**: if this is set, then this string will get added on the end of the line with the time block, to show that it has been processed. Otherwise, next time this command is run, it will create another event. This can be used with or without 'Add event link'.
5556
- **Locale**: optional Locale to use for times in events. If not given, will default to what the OS reports, or failing that, 'en-US'.
5657
- **Time options**: Optional Time format settings.
5758

@@ -77,7 +78,7 @@ The following **Parameters** are available:
7778
| `includeAllDayEvents` | boolean | include/exclude all day events | `includeAllDayEvents: false` |
7879
| `calendarSet` | string | limit which calendars are included | `calendarSet:"list,of,calendar,names"` |
7980
| `calendarNameMappings` | string | customize the name of the calendars |`calendarNameMappings:"Jonathan (iCloud);Me, Us (iCloud);Us"` |
80-
| `daysToCover` | number | include more than the current day | `daysToCover: 3` includes today + 2 days |
81+
| `daysToCover` | number | include more than the current day | `daysToCover: 3` includes today + the 2 following days |
8182
| `format` | string | customize the format | `'format:"..."'` |
8283
| `allday_format` | string | customize format for all day events | `'allday_format:"..."` |
8384

@@ -86,6 +87,18 @@ You can include other text (including line breaks indicated by `\n`) within the
8687

8788
NB: the `Sort order` setting above also controls how the output of this list is sorted.
8889

90+
### Using Event Lists from Callbacks
91+
As well as following x-callback calls are available:
92+
93+
| equivalent command | callback | parameters | result |
94+
| ---- | ------ | ---- | --- |
95+
| Insert day's events | noteplan://x-callback-url/runPlugin?pluginID=jgclark.EventHelpers&command=insertDaysEvents | JSON string (as above for Templates) | inserted to current note |
96+
| Insert matching events | noteplan://x-callback-url/runPlugin?pluginID=jgclark.EventHelpers&command=insertMatchingDaysEvents | JSON string (as above for Templates) | inserted to current note |
97+
| Insert week's events | noteplan://x-callback-url/runPlugin?pluginID=jgclark.EventHelpers&command=insertWeeksEvents | JSON string (as above for Templates) | inserted to current note |
98+
| List day's events as list | noteplan://x-callback-url/runPlugin?pluginID=jgclark.EventHelpers&command=listDaysEvents | JSON string (as above for Templates) | returns list of events as a markdown string |
99+
| List matching day's events as list | noteplan://x-callback-url/runPlugin?pluginID=jgclark.EventHelpers&command=listMatchingDaysEvents | JSON string (as above for Templates) | returns list of events as a markdown string |
100+
| List week's events as list | noteplan://x-callback-url/runPlugin?pluginID=jgclark.EventHelpers&command=listWeeksEvents | JSON string (as above for Templates) | returns list of events as a markdown string |
101+
89102
## /shift dates
90103
This command takes plain or scheduled day or week dates (i.e. `YYYY-MM-DD`, `>YYYY-MM-DD`, `YYYY-Wnn` or ``>YYYY-Wnn`) in the selected lines and shifts them forwards or backwards by a given date interval. This allows you to copy a set of tasks to use again, and have the dates moved forward by a month or year etc.
91104

jgclark.EventHelpers/__tests__/eventsToNotes.test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe('eventsToNotes.js tests', () => {
6464
})
6565
})
6666

67-
describe('smartStringReplace()', () => {
67+
describe('replaceFormatPlaceholderStringWithActualValues()', () => {
6868
// This function's tests use Partial<...> to use a subset of large objects without causing errors
6969
const config: Partial<EventsConfig> = {
7070
calendarNameMappings: [],
@@ -108,44 +108,44 @@ describe('eventsToNotes.js tests', () => {
108108
const replacements2 = e.getReplacements(event2, config)
109109

110110
test('event 1 format 1 easy', () => {
111-
const result = e.smartStringReplace(format1, replacements1)
111+
const result = e.replaceFormatPlaceholderStringWithActualValues(format1, replacements1)
112112
expect(result).toEqual('- (Jonathan) title of event1 https://example.com/easy\n> a few notes\n✓ Jonathan Clark, ? James Bond, x Martha, ? [email protected]')
113113
})
114114
test('event 1 format 2 more complex', () => {
115-
const result = e.smartStringReplace(format2, replacements1)
115+
const result = e.replaceFormatPlaceholderStringWithActualValues(format2, replacements1)
116116
const expected = '### (Jonathan, 20:00:00-22:00:00) title of event1 https://example.com/easy with Jonathan Clark, Martha Clark, [email protected]\n> a few notes\n---\n'
117117
expect(result).toEqual(expected)
118118
})
119119
test('event 2 format 1 easy', () => {
120-
const result = e.smartStringReplace(format1, replacements2)
120+
const result = e.replaceFormatPlaceholderStringWithActualValues(format1, replacements2)
121121
const expected =
122122
'- (Us) title of event2 with <brackets> & more https://example.com/bothersomeURL/example\n> a few notes with TITLE and URL\n✓ Jonathan Clark, ? James Bond, x Martha, ? [email protected]'
123123
expect(result).toEqual(expected)
124124
})
125125
test('event 2 format 2 more complex', () => {
126-
const result = e.smartStringReplace(format2, replacements2)
126+
const result = e.replaceFormatPlaceholderStringWithActualValues(format2, replacements2)
127127
const expected =
128128
'### (Us, 20:00:00-22:00:00) title of event2 with <brackets> & more https://example.com/bothersomeURL/example with Jonathan Clark, Martha Clark, [email protected]\n> a few notes with TITLE and URL\n---\n'
129129
expect(result).toEqual(expected)
130130
})
131131
test('event 2 format 3 for @EasyTarget with newlines and asterisks', () => {
132-
const result = e.smartStringReplace(format3, replacements2)
132+
const result = e.replaceFormatPlaceholderStringWithActualValues(format3, replacements2)
133133
const expected = '### [20:00:00] title of event2 with <brackets> & more\n- \n \n*****\n'
134134
// console.log(result)
135135
// console.log(result.length)
136136
// console.log(expected.length)
137137
expect(result).toEqual(expected)
138138
})
139139
test('event 2 format 4 for @EasyTarget with multiple new lines', () => {
140-
const result = e.smartStringReplace(format4, replacements2)
140+
const result = e.replaceFormatPlaceholderStringWithActualValues(format4, replacements2)
141141
const expected = '### [20:00:00] title of event2 with <brackets> & more\n- \n\n\n\n\n'
142142
// console.log(result)
143143
// console.log(result.length)
144144
// console.log(expected.length)
145145
expect(result).toEqual(expected)
146146
})
147147
test('event 1 format 5 date test', () => {
148-
const result = e.smartStringReplace(format5, replacements1)
148+
const result = e.replaceFormatPlaceholderStringWithActualValues(format5, replacements1)
149149
expect(result).toEqual('- 2021-01-23')
150150
})
151151
})

jgclark.EventHelpers/plugin.json

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,44 @@
88
"plugin.author": "jgclark",
99
"plugin.url": "https://github.com/NotePlan/plugins/tree/main/jgclark.EventHelpers",
1010
"plugin.changelog": "https://github.com/NotePlan/plugins/tree/main/jgclark.EventHelpers/CHANGELOG.md",
11-
"plugin.version": "0.22.2",
12-
"plugin.lastUpdateInfo": "0.22.2: add 'add computed final date' setting to '/process date offsets' command.\n0.22.1: improve setting defaults and documentation.\n0.22.0: can now use events() template calls in Weekly notes.\n0.21.3: bug fix adding time blocks to calendar.\n0.21.2: /shiftDates now covers more cases.\n0.21.1: add 'Yes to all' to option to create time blocks. Extend '/shift dates' to work on week dates.\n0.21.0: improvements to '/shift dates' and '/process date offsets'.",
11+
"plugin.version": "0.23.0",
12+
"plugin.lastUpdateInfo": "0.23.0: new command '/insert week's events as list'. Fix regression.\n0.22.2: add 'add computed final date' setting to '/process date offsets' command.\n0.22.1: improve setting defaults and documentation.\n0.22.0: can now use events() template calls in Weekly notes.\n0.21.3: bug fix adding time blocks to calendar.\n0.21.2: /shiftDates now covers more cases.\n0.21.1: add 'Yes to all' to option to create time blocks. Extend '/shift dates' to work on week dates.\n0.21.0: improvements to '/shift dates' and '/process date offsets'.",
1313
"plugin.dependencies": [],
1414
"plugin.script": "script.js",
1515
"plugin.isRemote": "false",
1616
"plugin.commands": [
1717
{
1818
"name": "time blocks to calendar",
19+
"alias": [
20+
"tbtc",
21+
"tbcal"
22+
],
1923
"description": "promote time blocks to be full calendar events",
2024
"jsFunction": "timeBlocksToCalendar"
2125
},
2226
{
2327
"name": "insert day's events as list",
28+
"alias": [
29+
"events",
30+
"ide"
31+
],
2432
"description": "insert list of this day's calendar events at cursor",
2533
"jsFunction": "insertDaysEvents"
2634
},
35+
{
36+
"name": "insert week's events as list",
37+
"alias": [
38+
"events",
39+
"iwe"
40+
],
41+
"description": "insert list of this week's calendar events at cursor",
42+
"jsFunction": "insertWeeksEvents"
43+
},
2744
{
2845
"name": "insert matching events",
46+
"alias": [
47+
"ime"
48+
],
2949
"description": "inserts this day's calendar events matching certain patterns at cursor",
3050
"jsFunction": "insertMatchingDaysEvents"
3151
},
@@ -39,9 +59,6 @@
3959
},
4060
{
4161
"name": "shift dates",
42-
"alias": [
43-
"offset"
44-
],
4562
"description": "takes dates in the selection and shifts them forwards or backwards by a given date interval",
4663
"jsFunction": "shiftDates"
4764
},
@@ -60,13 +77,28 @@
6077
"name": "listDaysEvents",
6178
"description": "function to list events for the current open Calendar note (for use in Templating)",
6279
"hidden": true,
63-
"jsFunction": "listDaysEvents"
80+
"jsFunction": "listDaysEvents",
81+
"parameters": [
82+
"paras as JSON string"
83+
]
6484
},
6585
{
6686
"name": "listMatchingDaysEvents",
6787
"description": "function to list events for the current open Calendar note that match string defined in the settings (for use in Templating)",
6888
"hidden": true,
69-
"jsFunction": "listMatchingDaysEvents"
89+
"jsFunction": "listMatchingDaysEvents",
90+
"parameters": [
91+
"paras as JSON string"
92+
]
93+
},
94+
{
95+
"name": "listWeeksEvents",
96+
"description": "function to list events for the current open Calendar note (for use in Templating or Callbacks)",
97+
"hidden": true,
98+
"jsFunction": "listWeeksEvents",
99+
"parameters": [
100+
"paras as JSON string"
101+
]
70102
},
71103
{
72104
"name": "Events: update plugin settings",
@@ -276,15 +308,15 @@
276308
"title": "Add event link?",
277309
"description": "Whether to add an event link in place of the time block, when creating an event from it",
278310
"type": "bool",
279-
"default": false,
311+
"default": true,
280312
"required": true
281313
},
282314
{
283315
"key": "processedTagName",
284-
"title": "Processed tag name",
285-
"description": "(Optional) Tag to add on a line after making its time block an event",
316+
"title": "Processed indicator string",
317+
"description": "(Optional) String to add on a line after making its time block an event, for example '#event_created'. Note: if this contains an emoji then it sometimes triggers a bug in NotePlan where you get some repeated characters at the end of the line.",
286318
"type": "string",
287-
"default": "#event_created",
319+
"default": "",
288320
"required": false
289321
},
290322
{

0 commit comments

Comments
 (0)