Skip to content

Commit

Permalink
feat(List/Matrix View): ✨ Metadata field to sort items in L/M view! (#92
Browse files Browse the repository at this point in the history
)
  • Loading branch information
SkepticMystic committed Nov 19, 2021
1 parent efc6a8c commit d6452c3
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 95 deletions.
72 changes: 52 additions & 20 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2606,6 +2606,7 @@ const DEFAULT_SETTINGS = {
dvWaitTime: 5000,
refreshIntervalTime: 0,
defaultView: true,
orderField: "order",
showNameOrType: true,
showRelationType: true,
filterImpliedSiblingsOfDifferentTypes: false,
Expand Down Expand Up @@ -20072,15 +20073,13 @@ function getFieldValues(frontmatterCache, field, settings) {
const strs = splits.map((link) => link.match(dropHeaderOrAlias)[1].split("/").last());
values.push(...strs);
}
else {
else
values.push(rawItemAsString.split("/").last());
}
}
else if (value.path !== undefined) {
const lastSplit = value.path.split("/").last();
if (lastSplit !== undefined) {
if (lastSplit !== undefined)
values.push(lastSplit);
}
}
});
});
Expand All @@ -20107,23 +20106,21 @@ async function getNeighbourObjArr(plugin, fileFrontmatterArr) {
}
let jugglLinks = [];
if (plugin.app.plugins.plugins.juggl !== undefined ||
plugin.settings.parseJugglLinksWithoutJuggl) {
jugglLinks = await getJugglLinks(plugin.app, plugin.settings);
settings.parseJugglLinksWithoutJuggl) {
jugglLinks = await getJugglLinks(plugin.app, settings);
}
const neighbourObjArr = fileFrontmatterArr.map((fileFrontmatter) => {
var _a;
const { file } = fileFrontmatter;
const order = (_a = fileFrontmatter[settings.orderField]) !== null && _a !== void 0 ? _a : 9999;
const currNode = fileFrontmatter.file.basename || fileFrontmatter.file.name;
const hierFields = {
current: fileFrontmatter.file,
current: file,
order,
hierarchies: [],
};
userHierarchies.forEach((hier) => {
const newHier = {
up: {},
same: {},
down: {},
next: {},
prev: {},
};
const newHier = blankDirObjs();
// Add regular metadata links
if (settings.useAllMetadata) {
for (const dir of DIRECTIONS) {
Expand Down Expand Up @@ -20406,8 +20403,8 @@ function addNodeIfNot(g, node, attr) {
g.addNode(node, attr);
}
function addEdgeIfNot(g, source, target, attr) {
addNodeIfNot(g, source);
addNodeIfNot(g, target);
// addNodeIfNot(g, source, attr);
// addNodeIfNot(g, target, attr);
if (!g.hasEdge(source, target))
g.addEdge(source, target, attr);
}
Expand Down Expand Up @@ -22110,6 +22107,7 @@ class MatrixView extends obsidian.ItemView {
constructor(leaf, plugin) {
super(leaf);
this.icon = TRAIL_ICON;
this.getOrder = (node) => Number.parseInt(this.plugin.currGraphs.main.getNodeAttribute(node, "order"));
this.plugin = plugin;
}
async onload() {
Expand Down Expand Up @@ -22202,6 +22200,7 @@ class MatrixView extends obsidian.ItemView {
to,
cls: linkClass(this.app, to, realQ),
alt: this.getAlt(to, settings),
order: this.getOrder(to),
});
});
return internalLinkObjArr;
Expand Down Expand Up @@ -22305,6 +22304,7 @@ class MatrixView extends obsidian.ItemView {
to: impliedSibling,
cls: linkClass(this.app, impliedSibling, false),
alt: this.getAlt(impliedSibling, settings),
order: this.getOrder(impliedSibling),
});
});
});
Expand All @@ -22326,6 +22326,7 @@ class MatrixView extends obsidian.ItemView {
to,
cls: linkClass(this.app, to, item.real),
alt: this.getAlt(to, settings),
order: this.getOrder(to),
};
});
});
Expand All @@ -22348,6 +22349,18 @@ class MatrixView extends obsidian.ItemView {
? `${hier[getOppDir(dir)].join(",")}<${dir}]>`
: hier[dir].join(", ");
};
[
rUp,
rSame,
rDown,
rNext,
rPrev,
iUp,
iSameArr,
iDown,
iNext,
iPrev,
].forEach((a) => a.sort((a, b) => a.order - b.order));
return [
{
realItems: rUp,
Expand Down Expand Up @@ -23573,6 +23586,14 @@ class BCSettingTab extends obsidian.PluginSettingTab {
await plugin.saveSettings();
await plugin.getActiveMatrixView().draw();
}));
new obsidian.Setting(MLViewDetails)
.setName("Sorting Field Name")
.setDesc("The metadata field name used to indicate the order in which items should be sorted in the L/M view.")
.addText((text) => text.setValue(settings.orderField).onChange(async (value) => {
settings.orderField = value;
await plugin.saveSettings();
await plugin.getActiveMatrixView().draw();
}));
new obsidian.Setting(MLViewDetails)
.setName("Filter Implied Siblings")
.setDesc("Implied siblings are: 1) notes with the same parent, or 2) notes that are real siblings. This setting only applies to type 1 implied siblings. If enabled, Breadcrumbs will filter type 1 implied siblings so that they not only share the same parent, but the parent relation has the exact same type. For example, the two real relations B --parent-> A, and A --parent-> A create an implied sibling between B and C (they have the same parent, A). The two real relations B --parent-> A, and A --up-> A create an implied sibling between B and C (they also have the same parent, A). But if this setting is turned on, the second implied sibling would not show, because the parent types are differnet (parent versus up).")
Expand All @@ -23591,7 +23612,7 @@ class BCSettingTab extends obsidian.PluginSettingTab {
settings.rlLeaf = value;
await plugin.saveSettings();
await ((_a = plugin.getActiveMatrixView()) === null || _a === void 0 ? void 0 : _a.onClose());
await openView(this.app, MATRIX_VIEW, MatrixView);
await openView(this.app, MATRIX_VIEW, MatrixView, value ? "right" : "left");
}));
const trailDetails = containerEl.createEl("details");
trailDetails.createEl("summary", { text: "Trail/Grid" });
Expand Down Expand Up @@ -34937,6 +34958,7 @@ class BCPlugin extends obsidian.Plugin {
super(...arguments);
this.visited = [];
this.activeLeafChange = undefined;
this.statusBatItemEl = undefined;
this.initEverything = async () => {
const { settings } = this;
this.currGraphs = await this.initGraphs();
Expand Down Expand Up @@ -35147,6 +35169,7 @@ class BCPlugin extends obsidian.Plugin {
});
// TODO get a better icon for this
this.addRibbonIcon("dice", "Breadcrumbs Visualisation", () => new VisModal(this.app, this).open());
this.statusBatItemEl = this.addStatusBarItem();
this.addSettingTab(new BCSettingTab(this.app, this));
}
getActiveMatrixView() {
Expand Down Expand Up @@ -35258,16 +35281,25 @@ class BCPlugin extends obsidian.Plugin {
const CSVRows = useCSV ? await this.getCSVRows() : [];
neighbourObjArr.forEach((neighbours) => {
const currFileName = neighbours.current.basename || neighbours.current.name;
addNodeIfNot(graphs.main, currFileName);
neighbours.hierarchies.forEach((hier, i) => {
DIRECTIONS.forEach((dir) => {
for (const fieldName in hier[dir]) {
const g = graphs.hierGs[i][dir][fieldName];
const targets = hier[dir][fieldName];
this.populateGraph(g, currFileName, targets, dir, fieldName);
targets.forEach((target) => {
// addEdgeIfNot also addsNodeIfNot
// addNodeIfNot(graphs.main, target);
var _a, _b;
addNodeIfNot(graphs.main, currFileName, {
dir,
fieldName,
order: neighbours.order,
});
addNodeIfNot(graphs.main, target, {
dir,
fieldName,
order: (_b = (_a = neighbourObjArr.find((neighbour) => (neighbour.current.basename || neighbour.current.name) ===
target)) === null || _a === void 0 ? void 0 : _a.order) !== null && _b !== void 0 ? _b : 9999,
});
addEdgeIfNot(graphs.main, currFileName, target, {
dir,
fieldName,
Expand Down
20 changes: 19 additions & 1 deletion src/BreadcrumbsSettingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,19 @@ export class BCSettingTab extends PluginSettingTab {
})
);

new Setting(MLViewDetails)
.setName("Sorting Field Name")
.setDesc(
"The metadata field name used to indicate the order in which items should be sorted in the L/M view."
)
.addText((text) =>
text.setValue(settings.orderField).onChange(async (value) => {
settings.orderField = value;
await plugin.saveSettings();
await plugin.getActiveMatrixView().draw();
})
);

new Setting(MLViewDetails)
.setName("Filter Implied Siblings")
.setDesc(
Expand All @@ -348,7 +361,12 @@ export class BCSettingTab extends PluginSettingTab {
settings.rlLeaf = value;
await plugin.saveSettings();
await plugin.getActiveMatrixView()?.onClose();
await openView(this.app, MATRIX_VIEW, MatrixView);
await openView(
this.app,
MATRIX_VIEW,
MatrixView,
value ? "right" : "left"
);
})
);

Expand Down
21 changes: 21 additions & 0 deletions src/MatrixView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ export default class MatrixView extends ItemView {
to,
cls: linkClass(this.app, to, realQ),
alt: this.getAlt(to, settings),
order: this.getOrder(to),
});
});

Expand Down Expand Up @@ -272,6 +273,11 @@ export default class MatrixView extends ItemView {
return index;
}

getOrder = (node: string) =>
Number.parseInt(
this.plugin.currGraphs.main.getNodeAttribute(node, "order")
);

getHierSquares(
userHierarchies: userHierarchy[],
data: { [dir in Directions]: Graph }[],
Expand Down Expand Up @@ -329,6 +335,7 @@ export default class MatrixView extends ItemView {
to: impliedSibling,
cls: linkClass(this.app, impliedSibling, false),
alt: this.getAlt(impliedSibling, settings),
order: this.getOrder(impliedSibling),
});
});
});
Expand Down Expand Up @@ -356,6 +363,7 @@ export default class MatrixView extends ItemView {
to,
cls: linkClass(this.app, to, item.real),
alt: this.getAlt(to, settings),
order: this.getOrder(to),
};
});
});
Expand All @@ -381,6 +389,19 @@ export default class MatrixView extends ItemView {
: hier[dir].join(", ");
};

[
rUp,
rSame,
rDown,
rNext,
rPrev,
iUp,
iSameArr,
iDown,
iNext,
iPrev,
].forEach((a) => a.sort((a, b) => a.order - b.order));

return [
{
realItems: rUp,
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const DEFAULT_SETTINGS: BCSettings = {
dvWaitTime: 5000,
refreshIntervalTime: 0,
defaultView: true,
orderField: "order",
showNameOrType: true,
showRelationType: true,
filterImpliedSiblingsOfDifferentTypes: false,
Expand Down
8 changes: 5 additions & 3 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface BCSettings {
dvWaitTime: number;
refreshIntervalTime: number;
defaultView: boolean;
orderField: string;
showNameOrType: boolean;
showRelationType: boolean;
filterImpliedSiblingsOfDifferentTypes: boolean;
Expand Down Expand Up @@ -81,9 +82,9 @@ export interface JugglLink {

export interface neighbourObj {
current: TFile;
parents: string[];
siblings: string[];
children: string[];
/** DV only recognises it if it's a string? */
order: string;
hierarchies: HierarchyFields[];
}

export type relObj = { [key: string]: string[] } | { current: TFile };
Expand All @@ -102,6 +103,7 @@ export interface internalLinkObj {
to: string;
cls: string;
alt: string | null;
order: number;
}

export interface SquareProps {
Expand Down
22 changes: 19 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export default class BCPlugin extends Plugin {
refreshIntervalID: number;
currGraphs: BCIndex;
activeLeafChange: EventRef = undefined;
statusBatItemEl: HTMLElement = undefined;

async refreshIndex() {
if (!this.activeLeafChange) this.registerActiveLeafEvent();
Expand Down Expand Up @@ -230,6 +231,8 @@ export default class BCPlugin extends Plugin {
new VisModal(this.app, this).open()
);

this.statusBatItemEl = this.addStatusBarItem();

this.addSettingTab(new BCSettingTab(this.app, this));
}

Expand Down Expand Up @@ -476,16 +479,29 @@ export default class BCPlugin extends Plugin {
neighbourObjArr.forEach((neighbours) => {
const currFileName =
neighbours.current.basename || neighbours.current.name;
addNodeIfNot(graphs.main, currFileName);
neighbours.hierarchies.forEach((hier, i) => {
DIRECTIONS.forEach((dir) => {
for (const fieldName in hier[dir]) {
const g = graphs.hierGs[i][dir][fieldName];
const targets = hier[dir][fieldName];

this.populateGraph(g, currFileName, targets, dir, fieldName);
targets.forEach((target) => {
// addEdgeIfNot also addsNodeIfNot
// addNodeIfNot(graphs.main, target);
addNodeIfNot(graphs.main, currFileName, {
dir,
fieldName,
order: neighbours.order,
});
addNodeIfNot(graphs.main, target, {
dir,
fieldName,
order:
neighbourObjArr.find(
(neighbour) =>
(neighbour.current.basename || neighbour.current.name) ===
target
)?.order ?? 9999,
});
addEdgeIfNot(graphs.main, currFileName, target, {
dir,
fieldName,
Expand Down
Loading

0 comments on commit d6452c3

Please sign in to comment.