Skip to content

Commit

Permalink
Merge branch 'multipleHierarchies'
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Aug 13, 2021
2 parents 29de0b0 + b220758 commit 815fc64
Show file tree
Hide file tree
Showing 18 changed files with 1,034 additions and 502 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [0.10.14](https://github.com/SkepticMystic/breadcrumbs/compare/0.10.13...0.10.14) (2021-08-12)


### Features

* :sparkles: Get multiple hierarchies working with l/m view! ([558ae67](https://github.com/SkepticMystic/breadcrumbs/commit/558ae670eb050e945ef053199d31838fdf099861))
* :sparkles: Multiple field names for each direction in a hierarchy ([0f3babb](https://github.com/SkepticMystic/breadcrumbs/commit/0f3babbb3f507f5e48c06ade14de2435f8976f36))
* :sparkles: Multiple hierarchies setting! ([2eda709](https://github.com/SkepticMystic/breadcrumbs/commit/2eda7095c4b28d3fc28c847412646cbd1eebbf38))
* **Stats View:** :sparkles: Progress on new stats view ([5389720](https://github.com/SkepticMystic/breadcrumbs/commit/53897209aec532376c15e0e6bc1e8e9dee5896ba))
* **Stats View:** :sparkles: Update stats view for multiple hierarchies ([24f5dae](https://github.com/SkepticMystic/breadcrumbs/commit/24f5dae5aa3d2b454f46069dba0719142224759e))


### Bug Fixes

* :bug: Everything on the front-end works as it used to ([ea0e8ff](https://github.com/SkepticMystic/breadcrumbs/commit/ea0e8ff3beac9befeba75932b8c5fac51ec562be))

### [0.10.13](https://github.com/SkepticMystic/breadcrumbs/compare/0.10.12...0.10.13) (2021-08-10)


Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "breadcrumbs",
"name": "Breadcrumbs",
"version": "0.10.13",
"version": "0.10.14",
"minAppVersion": "0.12.12",
"description": "Visualise & navigate your vault's structure",
"author": "SkepticMystic",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "breadcrumbs-plugin",
"version": "0.10.13",
"version": "0.10.14",
"description": "Visualise & navigate your vault's structure",
"main": "main.js",
"scripts": {
Expand Down
234 changes: 196 additions & 38 deletions src/BreadcrumbsSettingTab.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
App,
ButtonComponent,
DropdownComponent,
Notice,
PluginSettingTab,
Expand All @@ -12,9 +13,10 @@ import {
VIEW_TYPE_BREADCRUMBS_MATRIX,
VISTYPES,
} from "src/constants";
import type { Relations, visTypes } from "src/interfaces";
import type { Relations, userHierarchy, visTypes } from "src/interfaces";
import type BreadcrumbsPlugin from "src/main";
import { isInVault, splitAndTrim } from "src/sharedFunctions";
import { hierToStr, isInVault, splitAndTrim } from "src/sharedFunctions";
import { isEqual } from "lodash";

export class BreadcrumbsSettingTab extends PluginSettingTab {
plugin: BreadcrumbsPlugin;
Expand All @@ -30,7 +32,119 @@ export class BreadcrumbsSettingTab extends PluginSettingTab {
containerEl.empty();
containerEl.createEl("h2", { text: "Settings for Breadcrumbs plugin" });

const fieldDetails: HTMLDetailsElement = containerEl.createEl("details");
function hierIndex(
currHiers: userHierarchy[],
values: [string[], string[], string[]]
) {
return currHiers.findIndex(
(hier) =>
isEqual(hier.up, values[0]) &&
isEqual(hier.same, values[1]) &&
isEqual(hier.down, values[2])
);
}

const addHierarchyRow = (
values: userHierarchy = { up: ["↑"], same: ["→"], down: ["↓"] },
existing = false
) => {
const row = createDiv({ cls: "hierarchy-row" });

const hierarchyNames = row.createSpan({});

const upInput = hierarchyNames.createEl("input", {
value: values.up.join(", "),
});
const sameInput = hierarchyNames.createEl("input", {
value: values.same.join(", "),
});
const downInput = hierarchyNames.createEl("input", {
value: values.down.join(", "),
});
let cleanInputs = [upInput.value, sameInput.value, downInput.value].map(
splitAndTrim
) as [string[], string[], string[]];

[upInput, sameInput, downInput].forEach((input) =>
input.addEventListener("change", () => {
saveButton.toggleClass("hierarchy-unsaved", true);
saveButton.textContent = "Unsaved";
})
);

const deleteButton = row.createEl("button", { text: "X" }, (el) => {
el.addEventListener("click", async () => {
row.remove();
const removeIndex = hierIndex(
plugin.settings.userHierarchies,
[upInput.value, sameInput.value, downInput.value].map(
splitAndTrim
) as [string[], string[], string[]]
);

if (removeIndex > -1) {
plugin.settings.userHierarchies.splice(removeIndex, 1);
await plugin.saveSettings();
}
new Notice("Hierarchy Removed.");
});
});

const saveButton = row.createEl(
"button",
{
text: existing ? "Saved" : "Unsaved",
cls: (existing ? "" : "hierarchy-unsaved ") + "save-hierarchy-button",
},
function (el) {
el.addEventListener("click", async () => {
if (saveButton.hasClass("hierarchy-unsaved")) {
const removeIndex = hierIndex(
plugin.settings.userHierarchies,
cleanInputs
);
console.log({ removeIndex });

if (removeIndex > -1) {
plugin.settings.userHierarchies.splice(removeIndex, 1);
await plugin.saveSettings();
}
}
cleanInputs = [upInput.value, sameInput.value, downInput.value].map(
splitAndTrim
) as [string[], string[], string[]];
saveButton.toggleClass("hierarchy-unsaved", false);
saveButton.textContent = "Saved";
if (
hierIndex(
plugin.settings.userHierarchies,
[upInput.value, sameInput.value, downInput.value].map(
splitAndTrim
) as [string[], string[], string[]]
) > -1
) {
new Notice(
"A hierarchy with these Up, Same, and Down values already exists."
);
} else {
plugin.settings.userHierarchies.push({
up: splitAndTrim(upInput.value),
same: splitAndTrim(sameInput.value),
down: splitAndTrim(downInput.value),
});
await plugin.saveSettings();
new Notice("Hierarchy saved.");
}
});
}
);

return row;
};

const fieldDetails: HTMLDetailsElement = containerEl.createEl("details", {
cls: "field-details",
});
fieldDetails.createEl("summary", { text: "Metadata Field Names" });

fieldDetails.createEl("p", {
Expand All @@ -41,43 +155,87 @@ export class BreadcrumbsSettingTab extends PluginSettingTab {
});

new Setting(fieldDetails)
.setName("Parent Metadata Field")
.setDesc("The key name you use as the parent field.")
.addText((text) =>
text
.setPlaceholder("Field name")
.setValue(plugin.settings.parentFieldName)
.onChange(async (value) => {
plugin.settings.parentFieldName = value;
await plugin.saveSettings();
})
);
.setName("Add Hierarchy")
.setDesc("Add a new hierarchy.")
.addButton((button: ButtonComponent) => {
let b = button
.setTooltip("Add Additional")
.setButtonText("+")
.onClick(async () => {
fieldDetails.append(addHierarchyRow());
});
});
console.log(splitAndTrim(""));

fieldDetails.createEl(
"button",
{ text: "Reset Hierarchies" },
async (el) => {
el.addEventListener("click", async () => {
const rows = fieldDetails.querySelectorAll(".hierarchy-row");
rows.forEach((row) => row.remove());
plugin.settings.userHierarchies = [];
await plugin.saveSettings();
new Notice("Hierarchies reset.");
});
}
);

fieldDetails.createEl("button", { text: "Show Hierarchies" }, (el) => {
el.addEventListener("click", () => {
if (plugin.settings.userHierarchies.length) {
new Notice(
plugin.settings.userHierarchies.map(hierToStr).join("\n\n")
);
} else {
new Notice("No hierarchies currently exist.");
}
console.log({ hierarchies: plugin.settings.userHierarchies });
});
});

new Setting(fieldDetails)
.setName("Sibling Metadata Field")
.setDesc("The key name you use as the sibling field.")
.addText((text) =>
text
.setPlaceholder("Field name")
.setValue(plugin.settings.siblingFieldName)
.onChange(async (value) => {
plugin.settings.siblingFieldName = value;
await plugin.saveSettings();
})
);
plugin.settings.userHierarchies.forEach((userHier) => {
fieldDetails.append(addHierarchyRow(userHier, true));
});

new Setting(fieldDetails)
.setName("Child Metadata Field")
.setDesc("The key name you use as the child field.")
.addText((text) =>
text
.setPlaceholder("Field name")
.setValue(plugin.settings.childFieldName)
.onChange(async (value) => {
plugin.settings.childFieldName = value;
await plugin.saveSettings();
})
);
// new Setting(fieldDetails)
// .setName("Parent Metadata Field")
// .setDesc("The key name you use as the parent field.")
// .addText((text) =>
// text
// .setPlaceholder("Field name")
// .setValue(plugin.settings.parentFieldName)
// .onChange(async (value) => {
// plugin.settings.parentFieldName = value;
// await plugin.saveSettings();
// })
// );

// new Setting(fieldDetails)
// .setName("Sibling Metadata Field")
// .setDesc("The key name you use as the sibling field.")
// .addText((text) =>
// text
// .setPlaceholder("Field name")
// .setValue(plugin.settings.siblingFieldName)
// .onChange(async (value) => {
// plugin.settings.siblingFieldName = value;
// await plugin.saveSettings();
// })
// );

// new Setting(fieldDetails)
// .setName("Child Metadata Field")
// .setDesc("The key name you use as the child field.")
// .addText((text) =>
// text
// .setPlaceholder("Field name")
// .setValue(plugin.settings.childFieldName)
// .onChange(async (value) => {
// plugin.settings.childFieldName = value;
// await plugin.saveSettings();
// })
// );

const generalDetails: HTMLDetailsElement = containerEl.createEl("details");
generalDetails.createEl("summary", { text: "General Options" });
Expand Down
76 changes: 0 additions & 76 deletions src/Components/List.svelte

This file was deleted.

Loading

0 comments on commit 815fc64

Please sign in to comment.