Skip to content

Build your personal knowledge base with Trilium Notes

fix relations in attributes

azivner49989695ffa9
diff --git a/src/public/javascripts/dialogs/attributes.js b/src/public/javascripts/dialogs/attributes.js
index 8bc6d85834..694f0b2a89 100644
--- a/src/public/javascripts/dialogs/attributes.js
+++ b/src/public/javascripts/dialogs/attributes.js
@@ -1,6 +1,8 @@
import noteDetailService from '../services/note_detail.js';
import server from '../services/server.js';
import infoService from "../services/info.js";
+import treeUtils from "../services/tree_utils.js";
+import linkService from "../services/link.js";
const $dialog = $("#attributes-dialog");
const $saveAttributesButton = $("#save-attributes-button");
@@ -53,10 +55,10 @@ function AttributesModel() {
});
};
- function prepareAttributes(attributes) {
+ async function showAttributes(attributes) {
for (const attr of attributes) {
attr.labelValue = attr.type === 'label' ? attr.value : '';
- attr.relationValue = attr.type === 'relation' ? attr.value : '';
+ attr.relationValue = attr.type === 'relation' ? (await treeUtils.getNoteTitle(attr.value) + " (" + attr.value + ")") : '';
attr.labelDefinition = (attr.type === 'label-definition' && attr.value) ? attr.value : {
labelType: "text",
multiplicityType: "singlevalue",
@@ -80,7 +82,7 @@ function AttributesModel() {
const attributes = await server.get('notes/' + noteId + '/attributes');
- prepareAttributes(attributes);
+ await showAttributes(attributes);
// attribute might not be rendered immediatelly so could not focus
setTimeout(() => $(".attribute-name:last").focus(), 100);
@@ -139,7 +141,7 @@ function AttributesModel() {
attr.value = attr.labelValue;
}
else if (attr.type === 'relation') {
- attr.value = attr.relationValue;
+ attr.value = treeUtils.getNoteIdFromNotePath(linkService.getNotePathFromLabel(attr.relationValue));
}
else if (attr.type === 'label-definition') {
attr.value = attr.labelDefinition;
@@ -156,7 +158,7 @@ function AttributesModel() {
const attributes = await server.put('notes/' + noteId + '/attributes', attributesToSave);
- prepareAttributes(attributes);
+ await showAttributes(attributes);
infoService.showMessage("Attributes have been saved.");
diff --git a/src/public/javascripts/services/note_detail.js b/src/public/javascripts/services/note_detail.js
index 2cafb633a7..c99fcbe009 100644
--- a/src/public/javascripts/services/note_detail.js
+++ b/src/public/javascripts/services/note_detail.js
@@ -263,7 +263,7 @@ async function loadAttributes() {
$attributeListInner.append(utils.formatLabel(attribute) + " ");
}
else if (attribute.type === 'relation') {
- $attributeListInner.append(attribute.name + " = ");
+ $attributeListInner.append(attribute.name + "=");
$attributeListInner.append(await linkService.createNoteLink(attribute.value));
$attributeListInner.append(" ");
}
diff --git a/src/public/javascripts/services/tree_cache.js b/src/public/javascripts/services/tree_cache.js
index 1b23a5055e..3e7582ca66 100644
--- a/src/public/javascripts/services/tree_cache.js
+++ b/src/public/javascripts/services/tree_cache.js
@@ -2,6 +2,7 @@ import utils from "./utils.js";
import Branch from "../entities/branch.js";
import NoteShort from "../entities/note_short.js";
import infoService from "./info.js";
+import messagingService from "./messaging.js";
import server from "./server.js";
class TreeCache {
@@ -48,7 +49,9 @@ class TreeCache {
return noteIds.map(noteId => {
if (!this.notes[noteId]) {
- throw new Error(`Can't find note ${noteId}`);
+ messagingService.logError(`Can't find note ${noteId}`);
+
+ return `[unknown ${noteId}]`;
}
else {
return this.notes[noteId];