Skip to content

Commit

Permalink
feat(List/Matrix View): ✨ Option to enbale/disable alphabetical sorti…
Browse files Browse the repository at this point in the history
…ng entirely
  • Loading branch information
SkepticMystic committed Dec 4, 2021
1 parent 4690e9b commit f8bf507
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 32 deletions.
64 changes: 45 additions & 19 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20267,12 +20267,16 @@ const DEFAULT_SETTINGS = {
downViewWrap: false,
dotsColour: "#000000",
dvWaitTime: 5000,
enableAlphaSort: true,
fieldSuggestor: true,
filterImpliedSiblingsOfDifferentTypes: false,
limitWriteBCCheckboxStates: {},
indexNotes: [""],
gridDots: false,
gridHeatmap: false,
heatmapColour: getComputedStyle(document.body).getPropertyValue("--text-accent"),
hierarchyNotes: [""],
HNUpField: "",
indexNotes: [""],
refreshOnNoteChange: false,
useAllMetadata: true,
openMatrixOnLoad: true,
Expand All @@ -20291,12 +20295,10 @@ const DEFAULT_SETTINGS = {
showGrid: true,
showPrevNext: true,
limitTrailCheckboxStates: {},
gridDots: false,
gridHeatmap: false,
heatmapColour: getComputedStyle(document.body).getPropertyValue("--text-accent"),
showAll: false,
noPathMessage: `This note has no real or implied parents`,
trailSeperator: "→",
treatCurrNodeAsImpliedSibling: false,
respectReadableLineLength: true,
userHiers: [
{
Expand Down Expand Up @@ -24838,7 +24840,7 @@ class MatrixView extends require$$0.ItemView {
: [];
currParents.forEach((parent) => {
closedUp.forEachInEdge(parent, (k, a, s, t) => {
if (s === basename)
if (s === basename && !settings.treatCurrNodeAsImpliedSibling)
return;
iSamesII.push(this.toInternalLinkObj(s, false, parent));
});
Expand All @@ -24862,9 +24864,11 @@ class MatrixView extends require$$0.ItemView {
? hier[dir].join(", ")
: `${hier[getOppDir(dir)].join(",")}${ARROW_DIRECTIONS[dir]}`;
const { alphaSortAsc } = settings;
[ru, rs, rd, rn, rp, iu, is, id, iN, ip].forEach((a) => a
.sort((a, b) => a.to < b.to ? (alphaSortAsc ? -1 : 1) : alphaSortAsc ? 1 : -1)
.sort((a, b) => a.order - b.order));
const squares = [ru, rs, rd, rn, rp, iu, is, id, iN, ip];
if (settings.enableAlphaSort) {
squares.forEach((sq) => sq.sort((a, b) => a.to < b.to ? (alphaSortAsc ? -1 : 1) : alphaSortAsc ? 1 : -1));
}
squares.forEach((sq) => sq.sort((a, b) => a.order - b.order));
loglevel.debug({ ru }, { rs }, { rd }, { rn }, { rp }, { iu }, { is }, { id }, { iN }, { ip });
return [
{
Expand Down Expand Up @@ -25966,14 +25970,18 @@ class BCSettingTab extends require$$0.PluginSettingTab {
await plugin.saveSettings();
}));
// TODO I don't think this setting works anymore. I removed it's functionality when adding multiple hierarchies
new require$$0.Setting(MLViewDetails)
.setName("Show all field names or just relation types")
.setDesc("This changes the headers in matrix/list view. You can have the headers be the list of metadata fields for each relation type (e.g. `parent, broader, upper`). Or you can have them just be the name of the relation type, i.e. 'Parent', 'Sibling', 'Child'. On = show the full list of names.")
.addToggle((toggle) => toggle.setValue(settings.showNameOrType).onChange(async (value) => {
settings.showNameOrType = value;
await plugin.saveSettings();
await plugin.getActiveTYPEView(MATRIX_VIEW).draw();
}));
// new Setting(MLViewDetails)
// .setName("Show all field names or just relation types")
// .setDesc(
// "This changes the headers in matrix/list view. You can have the headers be the list of metadata fields for each relation type (e.g. `parent, broader, upper`). Or you can have them just be the name of the relation type, i.e. 'Parent', 'Sibling', 'Child'. On = show the full list of names."
// )
// .addToggle((toggle) =>
// toggle.setValue(settings.showNameOrType).onChange(async (value) => {
// settings.showNameOrType = value;
// await plugin.saveSettings();
// await plugin.getActiveTYPEView(MATRIX_VIEW).draw();
// })
// );
new require$$0.Setting(MLViewDetails)
.setName("Show Relationship Type")
.setDesc("Show whether a link is real or implied. A real link is one you explicitly put in a note. E.g. parent:: [[Note]]. An implied link is the reverse of a real link. For example, if A is the real parent of B, then B must be the implied child of A.")
Expand All @@ -25982,6 +25990,15 @@ class BCSettingTab extends require$$0.PluginSettingTab {
await plugin.saveSettings();
await plugin.getActiveTYPEView(MATRIX_VIEW).draw();
}));
new require$$0.Setting(MLViewDetails)
.setName("Enable Alpahebtical Sorting")
.setDesc("By default, items in the Matrix view are sorted by the order they appear in your notes. Toggle this on to enable Alphabetical sorting. You can choose ascending/descending order in the setting below.")
.addToggle((toggle) => toggle.setValue(settings.enableAlphaSort).onChange(async (value) => {
settings.enableAlphaSort = value;
await plugin.saveSettings();
await plugin.getActiveTYPEView(MATRIX_VIEW).draw();
}));
// TODO hide this setting if !enableAlphaSort
new require$$0.Setting(MLViewDetails)
.setName("Sort Alphabetically Ascending/Descending")
.setDesc("Sort square items alphabetically in Ascending (on) or Descending (off) order.")
Expand All @@ -25990,6 +26007,16 @@ class BCSettingTab extends require$$0.PluginSettingTab {
await plugin.saveSettings();
await plugin.getActiveTYPEView(MATRIX_VIEW).draw();
}));
new require$$0.Setting(MLViewDetails)
.setName("Make Current Note an Implied Sibling")
.setDesc("Techincally, the current note is always it's own implied sibling. By default, it is not show as such. Toggle this on to make it show.")
.addToggle((toggle) => toggle
.setValue(settings.treatCurrNodeAsImpliedSibling)
.onChange(async (value) => {
settings.treatCurrNodeAsImpliedSibling = value;
await plugin.saveSettings();
await plugin.getActiveTYPEView(MATRIX_VIEW).draw();
}));
new require$$0.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 C --parent-> A create an implied sibling between B and C (they have the same parent, A). The two real relations B --parent-> A, and C --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 Down Expand Up @@ -49802,10 +49829,9 @@ class BCPlugin extends require$$0.Plugin {
const { constructor } = this.VIEWS.find((view) => view.type === type);
const leaves = this.app.workspace.getLeavesOfType(type);
if (leaves && leaves.length >= 1) {
const view = leaves[0].view;
if (view instanceof constructor) {
const { view } = leaves[0];
if (view instanceof constructor)
return view;
}
}
return null;
}
Expand Down
9 changes: 5 additions & 4 deletions src/BreadcrumbsSettingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,18 +343,19 @@ export class BCSettingTab extends PluginSettingTab {
);

new Setting(MLViewDetails)
.setName("Show Relationship Type")
.setName("Enable Alpahebtical Sorting")
.setDesc(
"Show whether a link is real or implied. A real link is one you explicitly put in a note. E.g. parent:: [[Note]]. An implied link is the reverse of a real link. For example, if A is the real parent of B, then B must be the implied child of A."
"By default, items in the Matrix view are sorted by the order they appear in your notes. Toggle this on to enable Alphabetical sorting. You can choose ascending/descending order in the setting below."
)
.addToggle((toggle) =>
toggle.setValue(settings.showRelationType).onChange(async (value) => {
settings.showRelationType = value;
toggle.setValue(settings.enableAlphaSort).onChange(async (value) => {
settings.enableAlphaSort = value;
await plugin.saveSettings();
await plugin.getActiveTYPEView(MATRIX_VIEW).draw();
})
);

// TODO hide this setting if !enableAlphaSort
new Setting(MLViewDetails)
.setName("Sort Alphabetically Ascending/Descending")
.setDesc(
Expand Down
13 changes: 8 additions & 5 deletions src/MatrixView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,16 @@ export default class MatrixView extends ItemView {
: `${hier[getOppDir(dir)].join(",")}${ARROW_DIRECTIONS[dir]}`;

const { alphaSortAsc } = settings;
[ru, rs, rd, rn, rp, iu, is, id, iN, ip].forEach((a) =>
a
.sort((a, b) =>
const squares = [ru, rs, rd, rn, rp, iu, is, id, iN, ip];

if (settings.enableAlphaSort) {
squares.forEach((sq) =>
sq.sort((a, b) =>
a.to < b.to ? (alphaSortAsc ? -1 : 1) : alphaSortAsc ? 1 : -1
)
.sort((a, b) => a.order - b.order)
);
);
}
squares.forEach((sq) => sq.sort((a, b) => a.order - b.order));

debug(
{ ru },
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export const DEFAULT_SETTINGS: BCSettings = {
downViewWrap: false,
dotsColour: "#000000",
dvWaitTime: 5000,
enableAlphaSort: true,
fieldSuggestor: true,
filterImpliedSiblingsOfDifferentTypes: false,
limitWriteBCCheckboxStates: {},
Expand Down
1 change: 1 addition & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface BCSettings {
defaultView: boolean;
downViewWrap: boolean;
dotsColour: string;
enableAlphaSort: boolean;
fieldSuggestor: boolean;
filterImpliedSiblingsOfDifferentTypes: boolean;
gridDots: boolean;
Expand Down
6 changes: 2 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,8 @@ export default class BCPlugin extends Plugin {
const { constructor } = this.VIEWS.find((view) => view.type === type);
const leaves = this.app.workspace.getLeavesOfType(type);
if (leaves && leaves.length >= 1) {
const view = leaves[0].view;
if (view instanceof constructor) {
return view;
}
const { view } = leaves[0];
if (view instanceof constructor) return view;
}
return null;
}
Expand Down

0 comments on commit f8bf507

Please sign in to comment.