From ea31f643915a89a47492fbe9b8f5658c2f108fc7 Mon Sep 17 00:00:00 2001 From: Ross Keenan Date: Sat, 21 Aug 2021 16:09:55 +0200 Subject: [PATCH] feat(Hierarchy Note): :sparkles: Option to have hierarchy note fill in real parents, or real children, or both Neither is required --- src/BreadcrumbsSettingTab.ts | 47 +++++++++++++++++++++++++++++------- src/interfaces.ts | 3 ++- src/main.ts | 43 +++++++++++++++++++++++---------- 3 files changed, 70 insertions(+), 23 deletions(-) diff --git a/src/BreadcrumbsSettingTab.ts b/src/BreadcrumbsSettingTab.ts index baff171b..9e5c53de 100644 --- a/src/BreadcrumbsSettingTab.ts +++ b/src/BreadcrumbsSettingTab.ts @@ -241,20 +241,49 @@ export class BreadcrumbsSettingTab extends PluginSettingTab { }); new Setting(hierarchyNoteDetails) - .setName("Hierarchy Note Field Name") + .setName("Hierarchy Note Up Field Name") .setDesc( - "Using the breadcrumbs generated by the hierarchy note, which ↓ type should they count as? This has to be a of the ↓ types of one of your exisiting hierarchies. If you want it to be something else, you can make a new hierarchy just for it." + "Using the breadcrumbs generated by the hierarchy note, which ↑ type should they count as? This has to be one of the ↓ types of one of your existing hierarchies. If you want it to be something else, you can make a new hierarchy just for it." ) .addText((text) => { - let finalValue: string; - text - .setPlaceholder("Hierarchy Note(s)") - .setValue(plugin.settings.hierarchyNoteFieldName) - .onChange(async (value) => { - finalValue = value; - }); + let finalValue: string = settings.hierarchyNoteUpFieldName; + text.setPlaceholder("").setValue(settings.hierarchyNoteUpFieldName); + + text.inputEl.onblur = async () => { + finalValue = text.getValue(); + if (finalValue === "") { + settings.hierarchyNoteUpFieldName = finalValue; + await plugin.saveSettings(); + } else { + const downFieldNames = settings.userHierarchies + .map((hier) => hier.up) + .flat(3); + + debug(settings, { downFieldNames, finalValue }); + + if (downFieldNames.includes(finalValue)) { + settings.hierarchyNoteUpFieldName = finalValue; + await plugin.saveSettings(); + } else { + new Notice( + "The field name must be one of the exisitng ↓ fields in your hierarchies." + ); + } + } + }; + }); + + new Setting(hierarchyNoteDetails) + .setName("Hierarchy Note Down Field Name") + .setDesc( + "Using the breadcrumbs generated by the hierarchy note, which ↓ type should they count as? This has to be one of the ↓ types of one of your existing hierarchies. If you want it to be something else, you can make a new hierarchy just for it." + ) + .addText((text) => { + let finalValue: string = settings.hierarchyNoteDownFieldName; + text.setPlaceholder("").setValue(settings.hierarchyNoteDownFieldName); text.inputEl.onblur = async () => { + finalValue = text.getValue(); if (finalValue === "") { plugin.settings.hierarchyNoteFieldName = finalValue; await plugin.saveSettings(); diff --git a/src/interfaces.ts b/src/interfaces.ts index 5c649c90..66d5a3a7 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -5,7 +5,8 @@ export interface BreadcrumbsSettings { userHierarchies: userHierarchy[]; indexNote: string[]; hierarchyNotes: string[]; - hierarchyNoteFieldName: string; + hierarchyNoteDownFieldName: string; + hierarchyNoteUpFieldName: string; refreshIndexOnActiveLeafChange: boolean; useAllMetadata: boolean; parseJugglLinksWithoutJuggl: boolean; diff --git a/src/main.ts b/src/main.ts index 5589513a..afba6f11 100644 --- a/src/main.ts +++ b/src/main.ts @@ -45,7 +45,8 @@ const DEFAULT_SETTINGS: BreadcrumbsSettings = { userHierarchies: [], indexNote: [""], hierarchyNotes: [""], - hierarchyNoteFieldName: "", + hierarchyNoteDownFieldName: "", + hierarchyNoteUpFieldName: "", refreshIndexOnActiveLeafChange: false, useAllMetadata: true, parseJugglLinksWithoutJuggl: false, @@ -498,20 +499,36 @@ export default class BreadcrumbsPlugin extends Plugin { }); if (hierarchyNotesArr.length) { - const { hierarchyNoteFieldName } = settings; - - const g = graphs.hierGs.find( - (hierG) => hierG.down[hierarchyNoteFieldName] - ).down[hierarchyNoteFieldName]; - - hierarchyNotesArr.forEach((adjListItem) => { - adjListItem.children.forEach((child) => { - g.setEdge(adjListItem.note, child, { - dir: "down", - fieldName: hierarchyNoteFieldName, + const { hierarchyNoteUpFieldName, hierarchyNoteDownFieldName } = settings; + + if (hierarchyNoteUpFieldName !== "") { + const gUp = graphs.hierGs.find( + (hierG) => hierG.up[hierarchyNoteUpFieldName] + ).up[hierarchyNoteUpFieldName]; + + hierarchyNotesArr.forEach((adjListItem) => { + adjListItem.children.forEach((child) => { + gUp.setEdge(child, adjListItem.note, { + dir: "up", + fieldName: hierarchyNoteUpFieldName, + }); }); }); - }); + } + if (hierarchyNoteDownFieldName !== "") { + const gDown = graphs.hierGs.find( + (hierG) => hierG.down[hierarchyNoteDownFieldName] + ).down[hierarchyNoteDownFieldName]; + + hierarchyNotesArr.forEach((adjListItem) => { + adjListItem.children.forEach((child) => { + gDown.setEdge(adjListItem.note, child, { + dir: "down", + fieldName: hierarchyNoteDownFieldName, + }); + }); + }); + } } DIRECTIONS.forEach((dir) => {