Skip to content

Commit

Permalink
feat(Hierarchy Note): ✨ Option to have hierarchy note fill in real pa…
Browse files Browse the repository at this point in the history
…rents, or real children, or both

Neither is required
  • Loading branch information
SkepticMystic committed Aug 21, 2021
1 parent d4b0797 commit ea31f64
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 23 deletions.
47 changes: 38 additions & 9 deletions src/BreadcrumbsSettingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
43 changes: 30 additions & 13 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ const DEFAULT_SETTINGS: BreadcrumbsSettings = {
userHierarchies: [],
indexNote: [""],
hierarchyNotes: [""],
hierarchyNoteFieldName: "",
hierarchyNoteDownFieldName: "",
hierarchyNoteUpFieldName: "",
refreshIndexOnActiveLeafChange: false,
useAllMetadata: true,
parseJugglLinksWithoutJuggl: false,
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit ea31f64

Please sign in to comment.