Skip to content

Commit

Permalink
feat(WriteBCToFile): ✨ Setting to limit which fields are written to f…
Browse files Browse the repository at this point in the history
…iles
  • Loading branch information
SkepticMystic committed Sep 10, 2021
1 parent ea552d0 commit 258343f
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 15 deletions.
69 changes: 62 additions & 7 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6676,6 +6676,8 @@ const writeBCToFile = (app, plugin, currGraphs, file) => {
const succs = fieldG.predecessors(file.basename);
succs.forEach(async (succ) => {
const { fieldName } = fieldG.node(succ);
if (!plugin.settings.limitWriteBCCheckboxStates[fieldName])
return;
const currHier = plugin.settings.userHierarchies.filter(hier => hier[dir].includes(fieldName))[0];
let oppField = currHier[oppDir][0];
if (!oppField)
Expand Down Expand Up @@ -24285,14 +24287,30 @@ class BreadcrumbsSettingTab extends obsidian.PluginSettingTab {
settings.limitTrailCheckboxStates = {};
settings.userHierarchies.forEach(userHier => {
userHier.up.forEach(async (field) => {
// First sort out limitTrailCheckboxStates
settings.limitTrailCheckboxStates[field] = true;
await plugin.saveSettings();
if (field !== "") {
settings.limitTrailCheckboxStates[field] = true;
await plugin.saveSettings();
}
});
});
await plugin.saveSettings();
drawLimitTrailCheckboxes(checkboxDiv);
}
async function resetLimitWriteBCCheckboxes() {
settings.limitWriteBCCheckboxStates = {};
settings.userHierarchies.forEach(userHier => {
DIRECTIONS.forEach(dir => {
userHier.up.forEach(async (field) => {
if (field !== "") {
settings.limitWriteBCCheckboxStates[field] = true;
await plugin.saveSettings();
}
});
});
});
await plugin.saveSettings();
drawLimitWriteBCCheckboxes(checkboxDiv);
}
row.createEl("button", { text: "X" }, (el) => {
el.addEventListener("click", async () => {
row.remove();
Expand All @@ -24302,7 +24320,8 @@ class BreadcrumbsSettingTab extends obsidian.PluginSettingTab {
await plugin.saveSettings();
}
// Refresh limitTrailFields
resetLimitTrailCheckboxes();
await resetLimitTrailCheckboxes();
await resetLimitWriteBCCheckboxes();
new obsidian.Notice("Hierarchy Removed.");
});
});
Expand All @@ -24320,7 +24339,8 @@ class BreadcrumbsSettingTab extends obsidian.PluginSettingTab {
if (removeIndex > -1) {
settings.userHierarchies.splice(removeIndex, 1);
await plugin.saveSettings();
resetLimitTrailCheckboxes();
await resetLimitTrailCheckboxes();
await resetLimitWriteBCCheckboxes();
}
}
cleanInputs = [upInput.value, sameInput.value, downInput.value].map(splitAndTrim);
Expand All @@ -24337,7 +24357,8 @@ class BreadcrumbsSettingTab extends obsidian.PluginSettingTab {
});
await plugin.saveSettings();
new obsidian.Notice("Hierarchy saved.");
resetLimitTrailCheckboxes();
await resetLimitTrailCheckboxes();
await resetLimitWriteBCCheckboxes();
}
});
});
Expand Down Expand Up @@ -24610,6 +24631,8 @@ class BreadcrumbsSettingTab extends obsidian.PluginSettingTab {
const checkboxStates = settings.limitTrailCheckboxStates;
settings.userHierarchies.forEach(userHier => {
userHier.up.forEach(async (field) => {
if (field === '')
return;
// First sort out limitTrailCheckboxStates
if (checkboxStates[field] === undefined) {
checkboxStates[field] = true;
Expand Down Expand Up @@ -24766,9 +24789,40 @@ class BreadcrumbsSettingTab extends obsidian.PluginSettingTab {
}));
const writeBCsToFileDetails = containerEl.createEl("details");
writeBCsToFileDetails.createEl("summary", { text: "Write Breadcrumbs to File" });
const limitWriteBCDiv = writeBCsToFileDetails.createDiv({ cls: 'limit-ML-fields' });
limitWriteBCDiv.createEl('strong', { 'text': 'Limit to only write certain fields to files' });
const limitWriteBCCheckboxDiv = limitWriteBCDiv.createDiv({ cls: 'checkboxes' });
function drawLimitWriteBCCheckboxes(div) {
limitWriteBCCheckboxDiv.empty();
const checkboxStates = settings.limitWriteBCCheckboxStates;
settings.userHierarchies.forEach(userHier => {
DIRECTIONS.forEach(dir => {
userHier[dir].forEach(async (field) => {
if (field === '')
return;
// First sort out limitWriteBCCheckboxStates
if (checkboxStates[field] === undefined) {
checkboxStates[field] = true;
await plugin.saveSettings();
}
const cbDiv = div.createDiv();
const checkedQ = checkboxStates[field];
const cb = cbDiv.createEl('input', { type: 'checkbox', attr: { id: field } });
cb.checked = checkedQ;
cbDiv.createEl('label', { text: field, attr: { for: field } });
cb.addEventListener('change', async (event) => {
checkboxStates[field] = cb.checked;
await plugin.saveSettings();
console.log(settings.limitWriteBCCheckboxStates);
});
});
});
});
}
drawLimitWriteBCCheckboxes(limitWriteBCCheckboxDiv);
new obsidian.Setting(writeBCsToFileDetails)
.setName("Show the `Write Breadcrumbs to ALL Files` command")
.setDesc("This command attempts to update ALL files with implied breadcrumbs pointing to them. So, it is not even shown by default (even though it has 3 confirmation boxes to ensure you want to run it")
.setDesc("This command attempts to update ALL files with implied breadcrumbs pointing to them. So, it is not shown by default (even though it has 3 confirmation boxes to ensure you want to run it")
.addToggle((toggle) => toggle
.setValue(settings.showWriteAllBCsCmd)
.onChange(async (value) => {
Expand Down Expand Up @@ -37113,6 +37167,7 @@ const DEFAULT_SETTINGS = {
noPathMessage: `This note has no real or implied parents`,
trailSeperator: "→",
respectReadableLineLength: true,
limitWriteBCCheckboxStates: {},
showWriteAllBCsCmd: false,
visGraph: "Force Directed Graph",
visRelation: "Parent",
Expand Down
73 changes: 65 additions & 8 deletions src/BreadcrumbsSettingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,32 @@ export class BreadcrumbsSettingTab extends PluginSettingTab {
settings.limitTrailCheckboxStates = {}
settings.userHierarchies.forEach(userHier => {
userHier.up.forEach(async field => {
// First sort out limitTrailCheckboxStates
settings.limitTrailCheckboxStates[field] = true;
await plugin.saveSettings()

if (field !== "") {
settings.limitTrailCheckboxStates[field] = true;
await plugin.saveSettings()
}
})
})
await plugin.saveSettings()
drawLimitTrailCheckboxes(checkboxDiv)
}

async function resetLimitWriteBCCheckboxes() {
settings.limitWriteBCCheckboxStates = {}
settings.userHierarchies.forEach(userHier => {
DIRECTIONS.forEach(dir => {
userHier.up.forEach(async field => {
if (field !== "") {
settings.limitWriteBCCheckboxStates[field] = true;
await plugin.saveSettings()
}
})
})
})
await plugin.saveSettings()
drawLimitWriteBCCheckboxes(checkboxDiv)
}

const deleteButton = row.createEl("button", { text: "X" }, (el) => {
el.addEventListener("click", async () => {
row.remove();
Expand All @@ -111,7 +127,8 @@ export class BreadcrumbsSettingTab extends PluginSettingTab {
}

// Refresh limitTrailFields
resetLimitTrailCheckboxes()
await resetLimitTrailCheckboxes()
await resetLimitWriteBCCheckboxes()

new Notice("Hierarchy Removed.");
});
Expand Down Expand Up @@ -147,7 +164,8 @@ export class BreadcrumbsSettingTab extends PluginSettingTab {
if (removeIndex > -1) {
settings.userHierarchies.splice(removeIndex, 1);
await plugin.saveSettings();
resetLimitTrailCheckboxes()
await resetLimitTrailCheckboxes()
await resetLimitWriteBCCheckboxes()
}
}
cleanInputs = [upInput.value, sameInput.value, downInput.value].map(
Expand All @@ -170,7 +188,8 @@ export class BreadcrumbsSettingTab extends PluginSettingTab {
await plugin.saveSettings();
new Notice("Hierarchy saved.");

resetLimitTrailCheckboxes()
await resetLimitTrailCheckboxes()
await resetLimitWriteBCCheckboxes()
}
});
}
Expand Down Expand Up @@ -530,6 +549,7 @@ export class BreadcrumbsSettingTab extends PluginSettingTab {

settings.userHierarchies.forEach(userHier => {
userHier.up.forEach(async field => {
if (field === '') return
// First sort out limitTrailCheckboxStates
if (checkboxStates[field] === undefined) {
checkboxStates[field] = true;
Expand Down Expand Up @@ -734,10 +754,47 @@ export class BreadcrumbsSettingTab extends PluginSettingTab {
const writeBCsToFileDetails: HTMLDetailsElement = containerEl.createEl("details");
writeBCsToFileDetails.createEl("summary", { text: "Write Breadcrumbs to File" });

const limitWriteBCDiv = writeBCsToFileDetails.createDiv({ cls: 'limit-ML-fields' })
limitWriteBCDiv.createEl('strong', { 'text': 'Limit to only write certain fields to files' })

const limitWriteBCCheckboxDiv = limitWriteBCDiv.createDiv({ cls: 'checkboxes' })

function drawLimitWriteBCCheckboxes(div: HTMLDivElement) {
limitWriteBCCheckboxDiv.empty()
const checkboxStates = settings.limitWriteBCCheckboxStates

settings.userHierarchies.forEach(userHier => {
DIRECTIONS.forEach(dir => {
userHier[dir].forEach(async field => {
if (field === '') return
// First sort out limitWriteBCCheckboxStates
if (checkboxStates[field] === undefined) {
checkboxStates[field] = true;
await plugin.saveSettings()
}
const cbDiv = div.createDiv()
const checkedQ = checkboxStates[field]
const cb = cbDiv.createEl('input', { type: 'checkbox', attr: { id: field } })
cb.checked = checkedQ
const label = cbDiv.createEl('label', { text: field, attr: { for: field } })

cb.addEventListener('change', async (event) => {
checkboxStates[field] = cb.checked;
await plugin.saveSettings()
console.log(settings.limitWriteBCCheckboxStates)
})
})

})
})
}

drawLimitWriteBCCheckboxes(limitWriteBCCheckboxDiv)

new Setting(writeBCsToFileDetails)
.setName("Show the `Write Breadcrumbs to ALL Files` command")
.setDesc(
"This command attempts to update ALL files with implied breadcrumbs pointing to them. So, it is not even shown by default (even though it has 3 confirmation boxes to ensure you want to run it"
"This command attempts to update ALL files with implied breadcrumbs pointing to them. So, it is not shown by default (even though it has 3 confirmation boxes to ensure you want to run it"
)
.addToggle((toggle) =>
toggle
Expand Down
1 change: 1 addition & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface BreadcrumbsSettings {
noPathMessage: string;
trailSeperator: string;
respectReadableLineLength: boolean;
limitWriteBCCheckboxStates: { [field: string]: boolean };
showWriteAllBCsCmd: boolean;
visGraph: visTypes;
visRelation: Relations;
Expand Down
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const DEFAULT_SETTINGS: BreadcrumbsSettings = {
noPathMessage: `This note has no real or implied parents`,
trailSeperator: "→",
respectReadableLineLength: true,
limitWriteBCCheckboxStates: {},
showWriteAllBCsCmd: false,
visGraph: "Force Directed Graph",
visRelation: "Parent",
Expand Down
2 changes: 2 additions & 0 deletions src/sharedFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,8 @@ export const writeBCToFile = (app: App, plugin: BreadcrumbsPlugin, currGraphs: B

succs.forEach(async succ => {
const { fieldName } = fieldG.node(succ);
if (!plugin.settings.limitWriteBCCheckboxStates[fieldName]) return

const currHier = plugin.settings.userHierarchies.filter(hier => hier[dir].includes(fieldName))[0]
let oppField: string = currHier[oppDir][0];
if (!oppField) oppField = `<Reverse>${fieldName}`
Expand Down

0 comments on commit 258343f

Please sign in to comment.