Skip to content

Commit

Permalink
Merge branch 'impliedRelations' of https://github.com/SkepticMystic/b…
Browse files Browse the repository at this point in the history
…readcrumbs into impliedRelations
  • Loading branch information
HEmile committed Jan 15, 2022
2 parents d6179b7 + 5137253 commit 57130d1
Show file tree
Hide file tree
Showing 19 changed files with 24,665 additions and 24,643 deletions.
47,943 changes: 23,978 additions & 23,965 deletions main.js

Large diffs are not rendered by default.

104 changes: 104 additions & 0 deletions src/AlternativeHierarchies/JugglLinks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import type { MultiGraph } from "graphology";
import { parseTypedLink } from "juggl-api";
import type { TFile } from "obsidian";
import { splitLinksRegex } from "../constants";
import { getFieldInfo, getTargetOrder, populateMain } from "../graphUtils";
import type { BCSettings, dvFrontmatterCache, JugglLink } from "../interfaces";
import type BCPlugin from "../main";
import { getFields } from "../sharedFunctions";

// TODO I think it'd be better to do this whole thing as an obj instead of JugglLink[]
// => {[note: string]: {type: string, linksInLine: string[]}[]}
export async function getJugglLinks(
plugin: BCPlugin,
files: TFile[]
): Promise<JugglLink[]> {
const { settings, app, db } = plugin;
db.start2G("getJugglLinks");

const { userHiers } = settings;

// Add Juggl links
const typedLinksArr: JugglLink[] = await Promise.all(
files.map(async (file) => {
const jugglLink: JugglLink = { file, links: [] };

// Use Obs metadatacache to get the links in the current file
const links = app.metadataCache.getFileCache(file)?.links ?? [];

const content = links.length ? await app.vault.cachedRead(file) : "";
const lines = content.split("\n");

links.forEach((link) => {
const lineNo = link.position.start.line;
const line = lines[lineNo];

// Check the line for wikilinks, and return an array of link.innerText
const linksInLine =
line
.match(splitLinksRegex)
?.map((link) => link.slice(2, link.length - 2))
?.map((innerText) => innerText.split("|")[0]) ?? [];

const typedLinkPrefix =
app.plugins.plugins.juggl?.settings.typedLinkPrefix ?? "-";

const parsedLinks = parseTypedLink(link, line, typedLinkPrefix);

const field = parsedLinks?.properties?.type ?? "";
if (field === "") return;
const { fieldDir } = getFieldInfo(userHiers, field) || {};
if (!fieldDir) return;

jugglLink.links.push({
dir: fieldDir,
field,
linksInLine,
});
});
return jugglLink;
})
);

const allFields = getFields(userHiers);

const filteredLinks = typedLinksArr.map((jugglLink) => {
// Filter out links whose type is not in allFields
jugglLink.links = jugglLink.links.filter((link) =>
allFields.includes(link.field)
);
return jugglLink;
});
db.end2G({ filteredLinks });
return filteredLinks;
}

export function addJugglLinksToGraph(
settings: BCSettings,
jugglLinks: JugglLink[],
frontms: dvFrontmatterCache[],
mainG: MultiGraph
) {
jugglLinks.forEach((jugglLink) => {
const { basename } = jugglLink.file;
jugglLink.links.forEach((link) => {
const { dir, field, linksInLine } = link;
if (dir === "") return;
const sourceOrder = getTargetOrder(frontms, basename);
linksInLine.forEach((linkInLine) => {
// Is this a bug? Why not `getSourceOrder`?
const targetsOrder = getTargetOrder(frontms, linkInLine);

populateMain(
settings,
mainG,
basename,
field,
linkInLine,
sourceOrder,
targetsOrder
);
});
});
});
}
64 changes: 33 additions & 31 deletions src/BreadcrumbsSettingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Setting,
} from "obsidian";
import { isInVault, openView } from "obsidian-community-lib";
import { refreshIndex } from "./refreshIndex";
import Checkboxes from "./Components/Checkboxes.svelte";
import KoFi from "./Components/KoFi.svelte";
import UserHierarchies from "./Components/UserHierarchies.svelte";
Expand All @@ -22,8 +23,9 @@ import {
} from "./constants";
import type { DebugLevel, Relations, visTypes } from "./interfaces";
import type BCPlugin from "./main";
import MatrixView from "./MatrixView";
import MatrixView from "./Views/MatrixView";
import { getFields, splitAndTrim, strToRegex } from "./sharedFunctions";
import { drawTrail } from "./Views/TrailView";

const fragWithHTML = (html: string) =>
createFragment((frag) => (frag.createDiv().innerHTML = html));
Expand Down Expand Up @@ -163,7 +165,7 @@ export class BCSettingTab extends PluginSettingTab {
toggle.setValue(!settings.showAllAliases).onChange(async (value) => {
settings.showAllAliases = !value;
await plugin.saveSettings();
await plugin.refreshIndex();
await refreshIndex(plugin);
})
);

Expand All @@ -176,7 +178,7 @@ export class BCSettingTab extends PluginSettingTab {
toggle.setValue(settings.useAllMetadata).onChange(async (value) => {
settings.useAllMetadata = value;
await plugin.saveSettings();
await plugin.refreshIndex();
await refreshIndex(plugin);
})
);

Expand Down Expand Up @@ -305,7 +307,7 @@ export class BCSettingTab extends PluginSettingTab {
) {
settings.squareDirectionsOrder = value
.split("")
.map((order) => Number.parseInt(order));
.map((order) => Number.parseInt(order)) as (0 | 1 | 2 | 3 | 4)[];
await plugin.saveSettings();
await plugin.getActiveTYPEView(MATRIX_VIEW).draw();
} else {
Expand Down Expand Up @@ -436,7 +438,7 @@ export class BCSettingTab extends PluginSettingTab {
toggle.setValue(settings.showBCs).onChange(async (value) => {
settings.showBCs = value;
await plugin.saveSettings();
await plugin.drawTrail();
await drawTrail(plugin);
})
);

Expand All @@ -451,7 +453,7 @@ export class BCSettingTab extends PluginSettingTab {
.onChange(async (value) => {
settings.showBCsInEditLPMode = value;
await plugin.saveSettings();
await plugin.drawTrail();
await drawTrail(plugin);
})
);

Expand Down Expand Up @@ -484,7 +486,7 @@ export class BCSettingTab extends PluginSettingTab {
.onChange(async (value) => {
settings.showTrail = value;
await plugin.saveSettings();
await plugin.drawTrail();
await drawTrail(plugin);
});
})
.addToggle((toggle) => {
Expand All @@ -494,27 +496,27 @@ export class BCSettingTab extends PluginSettingTab {
.onChange(async (value) => {
settings.showGrid = value;
await plugin.saveSettings();
await plugin.drawTrail();
await drawTrail(plugin);
});
})
.addToggle((toggle) => {
.addToggle((toggle) => {
toggle
.setTooltip("Show Juggl view")
.setValue(settings.showJuggl)
.onChange(async (value) => {
settings.showJuggl = value;
await plugin.saveSettings();
await plugin.drawTrail();
});
})
.setTooltip("Show Juggl view")
.setValue(settings.showJuggl)
.onChange(async (value) => {
settings.showJuggl = value;
await plugin.saveSettings();
await drawTrail(plugin);
});
})
.addToggle((toggle) => {
toggle
.setTooltip("Show Next/Previous view")
.setValue(settings.showPrevNext)
.onChange(async (value) => {
settings.showPrevNext = value;
await plugin.saveSettings();
await plugin.drawTrail();
await drawTrail(plugin);
});
});

Expand All @@ -527,7 +529,7 @@ export class BCSettingTab extends PluginSettingTab {
toggle.setValue(settings.gridDots).onChange(async (value) => {
settings.gridDots = value;
await plugin.saveSettings();
await plugin.drawTrail();
await drawTrail(plugin);
})
);

Expand All @@ -554,7 +556,7 @@ export class BCSettingTab extends PluginSettingTab {
toggle.setValue(settings.gridHeatmap).onChange(async (value) => {
settings.gridHeatmap = value;
await plugin.saveSettings();
await plugin.drawTrail();
await drawTrail(plugin);
})
);

Expand Down Expand Up @@ -610,7 +612,7 @@ export class BCSettingTab extends PluginSettingTab {
settings.showAllPathsIfNoneToIndexNote = value;

await plugin.saveSettings();
await plugin.drawTrail();
await drawTrail(plugin);
})
);

Expand All @@ -624,7 +626,7 @@ export class BCSettingTab extends PluginSettingTab {
settings.showAll = value;

await plugin.saveSettings();
await plugin.drawTrail();
await drawTrail(plugin);
})
);

Expand All @@ -640,7 +642,7 @@ export class BCSettingTab extends PluginSettingTab {
.onChange(async (value) => {
settings.trailSeperator = value;
await plugin.saveSettings();
await plugin.drawTrail();
await drawTrail(plugin);
})
);

Expand All @@ -656,7 +658,7 @@ export class BCSettingTab extends PluginSettingTab {
.onChange(async (value) => {
settings.noPathMessage = value;
await plugin.saveSettings();
await plugin.drawTrail();
await drawTrail(plugin);
})
);

Expand All @@ -671,7 +673,7 @@ export class BCSettingTab extends PluginSettingTab {
.onChange(async (value) => {
settings.respectReadableLineLength = value;
await plugin.saveSettings();
await plugin.drawTrail();
await drawTrail(plugin);
})
);

Expand Down Expand Up @@ -782,7 +784,7 @@ export class BCSettingTab extends PluginSettingTab {
dd.onChange(async (field) => {
settings.tagNoteField = field;
await plugin.saveSettings();
await plugin.refreshIndex();
await refreshIndex(plugin);
});
});

Expand All @@ -807,7 +809,7 @@ export class BCSettingTab extends PluginSettingTab {
dd.onChange(async (field) => {
settings.regexNoteField = field;
await plugin.saveSettings();
await plugin.refreshIndex();
await refreshIndex(plugin);
});
});

Expand All @@ -830,7 +832,7 @@ export class BCSettingTab extends PluginSettingTab {
if (value === "" || strToRegex(value)) {
settings.namingSystemRegex = value;
await plugin.saveSettings();
await plugin.refreshIndex();
await refreshIndex(plugin);
} else {
new Notice("Invalid Regex");
}
Expand All @@ -849,7 +851,7 @@ export class BCSettingTab extends PluginSettingTab {
const value = text.getValue();
settings.namingSystemSplit = value;
await plugin.saveSettings();
await plugin.refreshIndex();
await refreshIndex(plugin);
};
});

Expand All @@ -864,7 +866,7 @@ export class BCSettingTab extends PluginSettingTab {
dd.onChange(async (value) => {
settings.namingSystemField = value;
await plugin.saveSettings();
await plugin.refreshIndex();
await refreshIndex(plugin);
});
});
new Setting(noSystemDetails)
Expand All @@ -880,7 +882,7 @@ export class BCSettingTab extends PluginSettingTab {
.onChange(async (value) => {
settings.namingSystemEndsWithDelimiter = value;
await plugin.saveSettings();
await plugin.refreshIndex();
await refreshIndex(plugin);
})
);

Expand Down
3 changes: 2 additions & 1 deletion src/Components/Checkboxes.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import type BCPlugin from "../main";
import { refreshIndex } from "../refreshIndex";
export let plugin: BCPlugin;
export let settingName: string;
Expand All @@ -17,7 +18,7 @@
plugin.settings[settingName] = selected;
await plugin.saveSettings();
await plugin.refreshIndex();
await refreshIndex(plugin);
}
</script>

Expand Down
2 changes: 1 addition & 1 deletion src/Components/Ducks.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import type { App } from "obsidian";
import { hoverPreview, openOrSwitch } from "obsidian-community-lib";
import type DucksView from "../DucksView";
import type DucksView from "../Views/DucksView";
import type BCPlugin from "../main";
import FaInfo from "svelte-icons/fa/FaInfo.svelte";
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Lists.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { hoverPreview, openOrSwitch } from "obsidian-community-lib";
import { dropPathNDendron } from "../sharedFunctions";
import type { BCSettings, SquareProps } from "../interfaces";
import type MatrixView from "../MatrixView";
import type MatrixView from "../Views/MatrixView";
export let filteredSquaresArr: SquareProps[][];
export let currFile: TFile;
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Matrix.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type { App, TFile } from "obsidian";
import { hoverPreview, openOrSwitch } from "obsidian-community-lib";
import type { BCSettings, SquareProps } from "../interfaces";
import type MatrixView from "../MatrixView";
import type MatrixView from "../Views/MatrixView";
import { dropPathNDendron } from "../sharedFunctions";
export let filteredSquaresArr: SquareProps[][];
Expand Down
5 changes: 3 additions & 2 deletions src/Components/SideTree.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
import { dfsAllPaths, getOppDir, getSubCloseSub } from "../graphUtils";
import type { Directions } from "../interfaces";
import type BCPlugin from "../main";
import { refreshIndex } from "../refreshIndex";
import { dropDendron } from "../sharedFunctions";
import type TreeView from "../TreeView";
import type TreeView from "../Views/TreeView";
export let plugin: BCPlugin;
export let view: TreeView;
Expand Down Expand Up @@ -70,7 +71,7 @@
<button
aria-label="Refresh Stats View (also refreshes Breadcrumbs Index)"
on:click={async () => {
await plugin.refreshIndex();
await refreshIndex(plugin);
await view.draw();
}}
>
Expand Down
Loading

0 comments on commit 57130d1

Please sign in to comment.