Skip to content

Commit

Permalink
2.1.4 New: custom property display
Browse files Browse the repository at this point in the history
  • Loading branch information
TfTHacker committed Jun 5, 2024
1 parent 81ee74c commit e7ecfd5
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 2.1.4

- New: In Settings under Custom Display List, the display of references can be customized to show properties from referenced files. In Settings, provide a comma separated list of case-sensitive property names. If a file has any of these properties when displayed in the reference list, the properties will also be displayed.

# 2.1.3

- Fix: after sorting list of references, they would not respond to being clicked on.
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": "obsidian42-strange-new-worlds",
"name": "Strange New Worlds",
"version": "2.1.3",
"version": "2.1.4",
"minAppVersion": "1.5.11",
"description": "Help see how your vault is interconnected with visual indicators.",
"author": "TfTHacker",
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": "obsidian42-strange-new-worlds",
"version": "2.1.3",
"version": "2.1.4",
"description": "Revealing networked thought and the strange new worlds created by your vault",
"scripts": {
"dev": "node esbuild.config.mjs",
Expand Down
4 changes: 3 additions & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface Settings {
enableIgnoreObsExcludeFoldersLinksTo: boolean; //Use Obsidians Exclude Files from folder - links to those "excluded" files
requireModifierKeyToActivateSNWView: boolean; //require CTRL hover to activate SNW view
sortOptionDefault: SortOption;
displayCustomPropertyList: string; //list of custom properties to display when showing references
}

export const DEFAULT_SETTINGS: Settings = {
Expand All @@ -51,5 +52,6 @@ export const DEFAULT_SETTINGS: Settings = {
enableIgnoreObsExcludeFoldersLinksFrom: false,
enableIgnoreObsExcludeFoldersLinksTo: false,
requireModifierKeyToActivateSNWView: false,
sortOptionDefault: 'name-asc'
sortOptionDefault: 'name-asc',
displayCustomPropertyList: ''
};
16 changes: 16 additions & 0 deletions src/ui/SettingsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,5 +311,21 @@ export class SettingsTab extends PluginSettingTab {
await this.plugin.saveSettings();
});
});

new Setting(containerEl).setHeading().setName('Custom Display Settings');

new Setting(this.containerEl)
.setName('Custom Property List')
.setDesc(
'Displays properties from referenced files in the references list. The list is comma separated list of case-sensitive property names.'
)
.addText((cb) => {
cb.setPlaceholder('Ex: Project, Summary')
.setValue(this.plugin.settings.displayCustomPropertyList)
.onChange(async (list) => {
this.plugin.settings.displayCustomPropertyList = list;
await this.plugin.saveSettings();
});
});
}
}
33 changes: 21 additions & 12 deletions src/ui/components/uic-ref-area.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const sortLinks = (links: Link[], option: SortOption): Link[] => {
});
};

// Creates a DIV for a colection of reference blocks to be displayed
// Creates a DIV for a collection of reference blocks to be displayed
const getRefAreaItems = async (refType: string, key: string, filePath: string): Promise<{ response: HTMLElement; refCount: number }> => {
let countOfRefs = 0;
let linksToLoop: Link[] = null;
Expand Down Expand Up @@ -116,6 +116,10 @@ const getRefAreaItems = async (refType: string, key: string, filePath: string):

let itemsDisplayedCounter = 0;

let customProperties = null;
if (plugin.settings.displayCustomPropertyList.trim() != '')
customProperties = plugin.settings.displayCustomPropertyList.split(',').map((x) => x.trim());

for (let index = 0; index < sortedFileKeys.length; index++) {
if (itemsDisplayedCounter > maxItemsToShow) continue;
const file_path = sortedFileKeys[index];
Expand Down Expand Up @@ -152,17 +156,22 @@ const getRefAreaItems = async (refType: string, key: string, filePath: string):
responseItemContainerEl.appendChild(refItemFileEl);

// Add custom property field to display
const fileCache = plugin.app.metadataCache.getFileCache(file_path.sourceFile);
if (fileCache?.frontmatter?.['Summary']) {
const customPropertyJsx = (
<div class="snw-custom-property-container">
<span class="snw-custom-property-name">Summary</span>
<span class="snw-custom-property-text">: {fileCache?.frontmatter?.['Summary']}</span>
</div>
);
const fieldEl = createDiv();
render(customPropertyJsx, fieldEl);
refItemFileLabelEl.append(fieldEl);
if (customProperties != null) {
const fileCache = plugin.app.metadataCache.getFileCache(file_path.sourceFile);
customProperties.forEach((propName) => {
const propValue = fileCache?.frontmatter?.[propName];
if (propValue) {
const customPropertyElement = (
<div class="snw-custom-property-container">
<span class="snw-custom-property-name">{propName}</span>
<span class="snw-custom-property-text">: {propValue}</span>
</div>
);
const fieldEl = createDiv();
render(customPropertyElement, fieldEl);
refItemFileLabelEl.append(fieldEl);
}
});
}

const refItemsCollectionE = createDiv();
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"2.1.0": "1.5.11",
"2.1.1": "1.5.11",
"2.1.2": "1.5.11",
"2.1.3": "1.5.11"
"2.1.3": "1.5.11",
"2.1.4": "1.5.11"
}

0 comments on commit e7ecfd5

Please sign in to comment.