Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
wip
zadam8bf794f13b97
diff --git a/src/public/javascripts/dialogs/attributes.js b/src/public/javascripts/dialogs/attributes.jsindex 35f2eaf5ad..4c80537aee 100644--- a/src/public/javascripts/dialogs/attributes.js+++ b/src/public/javascripts/dialogs/attributes.js@@ -169,9 +169,6 @@ function AttributesModel() {await showAttributes(attributes);toastService.showMessage("Attributes have been saved.");-- // FIXME detail should be also reloaded- appContext.trigger('reloadTree');};function addLastEmptyRow() {diff --git a/src/public/javascripts/entities/note_short.js b/src/public/javascripts/entities/note_short.jsindex 1f4645faed..c6f295e6ab 100644--- a/src/public/javascripts/entities/note_short.js+++ b/src/public/javascripts/entities/note_short.js@@ -18,10 +18,27 @@ class NoteShort {constructor(treeCache, row, branches) {this.treeCache = treeCache;+ /** @type {string[]} */+ this.attributes = [];++ /** @type {string[]} */+ this.targetRelations = [];++ /** @type {string[]} */+ this.parents = [];+ /** @type {string[]} */+ this.children = [];++ /** @type {Object.<string, string>} */+ this.parentToBranch = {};++ /** @type {Object.<string, string>} */+ this.childToBranch = {};+this.update(row, branches);}- update(row, branches) {+ update(row, branches = []) {/** @param {string} */this.noteId = row.noteId;/** @param {string} */@@ -37,23 +54,6 @@ class NoteShort {/** @param {boolean} */this.isDeleted = row.isDeleted;- /** @type {string[]} */- this.attributes = [];-- /** @type {string[]} */- this.targetRelations = [];-- /** @type {string[]} */- this.parents = [];- /** @type {string[]} */- this.children = [];-- /** @type {Object.<string, string>} */- this.parentToBranch = {};-- /** @type {Object.<string, string>} */- this.childToBranch = {};-for (const branch of branches) {if (this.noteId === branch.noteId) {this.parents.push(branch.parentNoteId);diff --git a/src/public/javascripts/services/load_results.js b/src/public/javascripts/services/load_results.jsindex c134de985e..a04fae2f76 100644--- a/src/public/javascripts/services/load_results.js+++ b/src/public/javascripts/services/load_results.js@@ -5,7 +5,13 @@ export class LoadResults {this.noteIdToSourceId = {};this.sourceIdToNoteIds = {};- this.branchIdToSourceId = {};+ this.branches = [];++ this.attributes = [];++ this.noteReorderings = [];++ this.noteRevisions = [];}addNote(noteId, sourceId) {@@ -23,36 +29,39 @@ export class LoadResults {}addBranch(branchId, sourceId) {- this.branchIdToSourceId[branchId] = this.branchIdToSourceId[branchId] || [];- this.branchIdToSourceId[branchId].push(sourceId);+ this.branches.push({branchId, sourceId});}getBranches() {-+ return this.branches+ .map(row => this.treeCache.branches[row.branchId])+ .filter(branch => !!branch);}addNoteReordering(parentNoteId, sourceId) {-+ this.noteReorderings.push(parentNoteId);}getNoteReorderings() {-+ return this.noteReorderings;}addAttribute(attributeId, sourceId) {-+ this.attributes.push({attributeId, sourceId});}getAttributes() {-+ return this.attributes+ .map(row => this.treeCache.attributes[row.attributeId])+ .filter(attr => !!attr);}addNoteRevision(noteRevisionId, noteId, sourceId) {-+ this.noteRevisions.push({noteRevisionId, noteId, sourceId});}hasNoteRevisionForNote(noteId) {-+ return !!this.noteRevisions.find(nr => nr.noteId === noteId);}getNoteIds() {diff --git a/src/public/javascripts/services/tree_cache.js b/src/public/javascripts/services/tree_cache.jsindex ac1a267e6c..3c87764738 100644--- a/src/public/javascripts/services/tree_cache.js+++ b/src/public/javascripts/services/tree_cache.js@@ -235,29 +235,43 @@ class TreeCache {const loadResults = new LoadResults(this);syncRows.filter(sync => sync.entityName === 'notes').forEach(sync => {+ const note = this.notes[sync.entityId];-- loadResults.addNote(sync.entityId, sync.sourceId);+ if (note) {+ note.update(sync.entity);+ loadResults.addNote(sync.entityId, sync.sourceId);+ }});syncRows.filter(sync => sync.entityName === 'branches').forEach(sync => {- noteIdsToReload.push(sync.parentNoteId);- noteIdsToReload.push(sync.noteId);+ const branch = this.branches[sync.entityId];- loadResults.addBranch(sync.entityId, sync.sourceId);+ if (branch) {+ branch.update(sync.entity);+ loadResults.addBranch(sync.entityId, sync.sourceId);+ }});syncRows.filter(sync => sync.entityName === 'note_reordering').forEach(sync => {- noteIdsToReload.push(sync.entityId);+ for (const branchId in sync.positions) {+ const branch = this.branches[branchId];++ if (branch) {+ branch.notePosition = sync.positions[branchId];+ }+ }loadResults.addNoteReordering(sync.entityId, sync.sourceId);});// missing reloading the relation target notesyncRows.filter(sync => sync.entityName === 'attributes').forEach(sync => {- noteIdsToReload.push(sync.noteId);+ const attribute = this.attributes[sync.entityId];- loadResults.addAttribute(sync.entityId, sync.sourceId);+ if (attribute) {+ attribute.update(sync.entity);+ loadResults.addAttribute(sync.entityId, sync.sourceId);+ }});// missing reloading the relation target notediff --git a/src/public/javascripts/widgets/attributes.js b/src/public/javascripts/widgets/attributes.jsindex b18fb6c4dc..2cf8fdd8ee 100644--- a/src/public/javascripts/widgets/attributes.js+++ b/src/public/javascripts/widgets/attributes.js@@ -89,7 +89,11 @@ class AttributesWidget extends StandardWidget {}entitiesReloadedListener({loadResults}) {- if (loadResults.getAttributes().find(attr => attr.type === 'relation' && attr.noteId === this.noteId)) {+ console.log("CHECK ATTRS", loadResults.getAttributes());++ if (loadResults.getAttributes().find(attr => attr.noteId === this.noteId)) {+ console.log("JAAAJ");+this.refresh();}}diff --git a/src/services/ws.js b/src/services/ws.jsindex b84d7f5bda..a2964d2936 100644--- a/src/services/ws.js+++ b/src/services/ws.js@@ -83,6 +83,8 @@ async function fillInAdditionalProperties(sync) {sync.noteId = await sql.getValue(`SELECT noteIdFROM note_revisionsWHERE noteRevisionId = ?`, [sync.entityId]);+ } else if (sync.entityName === 'note_reordering') {+ sync.positions = await sql.getMap(`SELECT branchId, notePosition FROM branches WHERE isDeleted = 0 AND parentNoteId = ?`, [sync.entityId]);}}