From b6475077e615757016ce8f2b8fe28c80955f6bd8 Mon Sep 17 00:00:00 2001 From: Ross Keenan Date: Mon, 3 Jan 2022 16:31:31 +0200 Subject: [PATCH] feat(TagNote): :sparkles: Choose a default tag-note-field --- main.js | 19 +++++++++++++++++-- src/BreadcrumbsSettingTab.ts | 22 ++++++++++++++++++++++ src/constants.ts | 1 + src/interfaces.ts | 1 + src/main.ts | 5 ++--- 5 files changed, 43 insertions(+), 5 deletions(-) diff --git a/main.js b/main.js index a523269b..f6a6d3ee 100644 --- a/main.js +++ b/main.js @@ -21125,6 +21125,7 @@ const DEFAULT_SETTINGS = { limitJumpToFirstFields: [], showAll: false, noPathMessage: `This note has no real or implied parents`, + tagNoteField: "", threadIntoNewPane: false, threadingTemplate: "{{field}} of {{current}}", threadingDirTemplates: { up: "", same: "", down: "", next: "", prev: "" }, @@ -25549,6 +25550,20 @@ class BCSettingTab extends require$$0.PluginSettingTab { settings.fieldSuggestor = value; await plugin.saveSettings(); })); + const tagNoteDetails = subDetails("Tag Notes", alternativeHierarchyDetails); + new require$$0.Setting(tagNoteDetails) + .setName("Default Tag Note Field") + .setDesc(fragWithHTML("By default, tag notes use the first field in your hierarchies (usually an field). Choose a different one to use by default, without having to specify BC-tag-note-field: {field}.")) + .addDropdown((dd) => { + const options = {}; + getFields(settings.userHiers).forEach((field) => (options[field] = field)); + dd.addOptions(options); + dd.onChange(async (field) => { + settings.tagNoteField = field; + await plugin.saveSettings(); + await plugin.refreshIndex(); + }); + }); const hierarchyNoteDetails = subDetails("Hierarchy Notes", alternativeHierarchyDetails); new require$$0.Setting(hierarchyNoteDetails) .setName("Hierarchy Note(s)") @@ -52449,7 +52464,7 @@ class BCPlugin extends require$$0.Plugin { }); } addTagNotesToGraph(eligableAlts, frontms, mainG) { - const { userHiers } = this.settings; + const { userHiers, tagNoteField } = this.settings; const fields = getFields(userHiers); eligableAlts.forEach((altFile) => { const tagNoteFile = altFile.file; @@ -52469,7 +52484,7 @@ class BCPlugin extends require$$0.Plugin { .map(getDVBasename); let field = altFile[BC_TAG_NOTE_FIELD]; if (typeof field !== "string" || !fields.includes(field)) - field = fields[0]; + field = tagNoteField || fields[0]; targets.forEach((target) => { const sourceOrder = this.getSourceOrder(altFile); const targetOrder = this.getTargetOrder(frontms, tagNoteBasename); diff --git a/src/BreadcrumbsSettingTab.ts b/src/BreadcrumbsSettingTab.ts index 9cdd9fc6..5178d329 100644 --- a/src/BreadcrumbsSettingTab.ts +++ b/src/BreadcrumbsSettingTab.ts @@ -710,6 +710,28 @@ export class BCSettingTab extends PluginSettingTab { }) ); + const tagNoteDetails = subDetails("Tag Notes", alternativeHierarchyDetails); + + new Setting(tagNoteDetails) + .setName("Default Tag Note Field") + .setDesc( + fragWithHTML( + "By default, tag notes use the first field in your hierarchies (usually an field). Choose a different one to use by default, without having to specify BC-tag-note-field: {field}." + ) + ) + .addDropdown((dd: DropdownComponent) => { + const options = {}; + getFields(settings.userHiers).forEach( + (field) => (options[field] = field) + ); + dd.addOptions(options); + dd.onChange(async (field) => { + settings.tagNoteField = field; + await plugin.saveSettings(); + await plugin.refreshIndex(); + }); + }); + const hierarchyNoteDetails = subDetails( "Hierarchy Notes", alternativeHierarchyDetails diff --git a/src/constants.ts b/src/constants.ts index 57d8a047..1b17fa19 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -191,6 +191,7 @@ export const DEFAULT_SETTINGS: BCSettings = { limitJumpToFirstFields: [], showAll: false, noPathMessage: `This note has no real or implied parents`, + tagNoteField: "", threadIntoNewPane: false, threadingTemplate: "{{field}} of {{current}}", threadingDirTemplates: { up: "", same: "", down: "", next: "", prev: "" }, diff --git a/src/interfaces.ts b/src/interfaces.ts index c0ec3624..9c63d4ee 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -58,6 +58,7 @@ export interface BCSettings { showRefreshNotice: boolean; showTrail: boolean; squareDirectionsOrder: (0 | 1 | 2 | 3 | 4)[]; + tagNoteField: string; threadIntoNewPane: boolean; threadingTemplate: string; threadingDirTemplates: { [dir in Directions]: string }; diff --git a/src/main.ts b/src/main.ts index 80e9d7ff..2c983345 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1076,7 +1076,7 @@ export default class BCPlugin extends Plugin { frontms: dvFrontmatterCache[], mainG: MultiGraph ) { - const { userHiers } = this.settings; + const { userHiers, tagNoteField } = this.settings; const fields = getFields(userHiers); eligableAlts.forEach((altFile) => { const tagNoteFile = altFile.file; @@ -1087,7 +1087,6 @@ export default class BCPlugin extends Plugin { const hasThisTag = (file: TFile): boolean => { const allTags = this.getAllTags(file); - return altFile[BC_TAG_NOTE_EXACT] ? allTags.includes(tag) : allTags.some((t) => t.includes(tag)); @@ -1100,7 +1099,7 @@ export default class BCPlugin extends Plugin { let field = altFile[BC_TAG_NOTE_FIELD] as string; if (typeof field !== "string" || !fields.includes(field)) - field = fields[0]; + field = tagNoteField || fields[0]; targets.forEach((target) => { const sourceOrder = this.getSourceOrder(altFile);