-
-
Notifications
You must be signed in to change notification settings - Fork 83
feat(buttons): Add date format placeholders for templaterCreateNote and createNote actions #643
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ import type { | |
| } from 'packages/core/src/config/ButtonConfig'; | ||
| import { ButtonActionType } from 'packages/core/src/config/ButtonConfig'; | ||
| import { AbstractButtonActionConfig } from 'packages/core/src/fields/button/AbstractButtonActionConfig'; | ||
| import { ensureFileExtension, joinPath } from 'packages/core/src/utils/Utils'; | ||
| import { ensureFileExtension, joinPath, processDateFormatPlaceholders } from 'packages/core/src/utils/Utils'; | ||
|
|
||
| export class CreateNoteButtonActionConfig extends AbstractButtonActionConfig<CreateNoteButtonAction> { | ||
| constructor(mb: MetaBind) { | ||
|
|
@@ -21,8 +21,11 @@ export class CreateNoteButtonActionConfig extends AbstractButtonActionConfig<Cre | |
| _context: ButtonContext, | ||
| click: ButtonClickContext, | ||
| ): Promise<void> { | ||
| if (action.openIfAlreadyExists) { | ||
| const filePath = ensureFileExtension(joinPath(action.folderPath ?? '', action.fileName), 'md'); | ||
| const processedFileName = processDateFormatPlaceholders(action.fileName) ?? action.fileName; | ||
| const processedFolderPath = processDateFormatPlaceholders(action.folderPath); | ||
|
|
||
| if (action.openIfAlreadyExists && action.fileName) { | ||
|
||
| const filePath = ensureFileExtension(joinPath(processedFolderPath ?? '', processedFileName ?? ''), 'md'); | ||
| // if the file already exists, open it in the same tab | ||
| if (await this.mb.file.exists(filePath)) { | ||
| await this.mb.file.open(filePath, '', false); | ||
|
|
@@ -31,8 +34,8 @@ export class CreateNoteButtonActionConfig extends AbstractButtonActionConfig<Cre | |
| } | ||
|
|
||
| await this.mb.file.create( | ||
| action.folderPath ?? '', | ||
| action.fileName, | ||
| processedFolderPath ?? '', | ||
| processedFileName ?? 'Untitled', | ||
|
||
| 'md', | ||
| action.openNote ?? false, | ||
| click.openInNewTab(), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ import type { | |
| } from 'packages/core/src/config/ButtonConfig'; | ||
| import { ButtonActionType } from 'packages/core/src/config/ButtonConfig'; | ||
| import { AbstractButtonActionConfig } from 'packages/core/src/fields/button/AbstractButtonActionConfig'; | ||
| import { ensureFileExtension, joinPath } from 'packages/core/src/utils/Utils'; | ||
| import { ensureFileExtension, joinPath, processDateFormatPlaceholders } from 'packages/core/src/utils/Utils'; | ||
|
|
||
| export class TemplaterCreateNoteButtonActionConfig extends AbstractButtonActionConfig<TemplaterCreateNoteButtonAction> { | ||
| constructor(mb: MetaBind) { | ||
|
|
@@ -21,8 +21,11 @@ export class TemplaterCreateNoteButtonActionConfig extends AbstractButtonActionC | |
| _context: ButtonContext, | ||
| click: ButtonClickContext, | ||
| ): Promise<void> { | ||
| const processedFileName = processDateFormatPlaceholders(action.fileName); | ||
| const processedFolderPath = processDateFormatPlaceholders(action.folderPath); | ||
|
|
||
| if (action.openIfAlreadyExists && action.fileName) { | ||
|
||
| const filePath = ensureFileExtension(joinPath(action.folderPath ?? '', action.fileName), 'md'); | ||
| const filePath = ensureFileExtension(joinPath(processedFolderPath ?? '', processedFileName ?? ''), 'md'); | ||
| // if the file already exists, open it in the same tab | ||
| if (await this.mb.file.exists(filePath)) { | ||
| await this.mb.file.open(filePath, '', false); | ||
|
|
@@ -32,8 +35,8 @@ export class TemplaterCreateNoteButtonActionConfig extends AbstractButtonActionC | |
|
|
||
| await this.mb.internal.createNoteWithTemplater( | ||
| action.templateFile, | ||
| action.folderPath, | ||
| action.fileName, | ||
| processedFolderPath, | ||
| processedFileName, | ||
| action.openNote, | ||
| click.openInNewTab(), | ||
| ); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.