mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 09:58:32 +02:00
wip
This commit is contained in:
parent
48b401164a
commit
8bf794f13b
@ -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() {
|
||||
|
@ -18,25 +18,6 @@ class NoteShort {
|
||||
constructor(treeCache, row, branches) {
|
||||
this.treeCache = treeCache;
|
||||
|
||||
this.update(row, branches);
|
||||
}
|
||||
|
||||
update(row, branches) {
|
||||
/** @param {string} */
|
||||
this.noteId = row.noteId;
|
||||
/** @param {string} */
|
||||
this.title = row.title;
|
||||
/** @param {int} */
|
||||
this.contentLength = row.contentLength;
|
||||
/** @param {boolean} */
|
||||
this.isProtected = row.isProtected;
|
||||
/** @param {string} one of 'text', 'code', 'file' or 'render' */
|
||||
this.type = row.type;
|
||||
/** @param {string} content-type, e.g. "application/json" */
|
||||
this.mime = row.mime;
|
||||
/** @param {boolean} */
|
||||
this.isDeleted = row.isDeleted;
|
||||
|
||||
/** @type {string[]} */
|
||||
this.attributes = [];
|
||||
|
||||
@ -54,6 +35,25 @@ class NoteShort {
|
||||
/** @type {Object.<string, string>} */
|
||||
this.childToBranch = {};
|
||||
|
||||
this.update(row, branches);
|
||||
}
|
||||
|
||||
update(row, branches = []) {
|
||||
/** @param {string} */
|
||||
this.noteId = row.noteId;
|
||||
/** @param {string} */
|
||||
this.title = row.title;
|
||||
/** @param {int} */
|
||||
this.contentLength = row.contentLength;
|
||||
/** @param {boolean} */
|
||||
this.isProtected = row.isProtected;
|
||||
/** @param {string} one of 'text', 'code', 'file' or 'render' */
|
||||
this.type = row.type;
|
||||
/** @param {string} content-type, e.g. "application/json" */
|
||||
this.mime = row.mime;
|
||||
/** @param {boolean} */
|
||||
this.isDeleted = row.isDeleted;
|
||||
|
||||
for (const branch of branches) {
|
||||
if (this.noteId === branch.noteId) {
|
||||
this.parents.push(branch.parentNoteId);
|
||||
|
@ -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() {
|
||||
|
@ -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];
|
||||
|
||||
|
||||
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];
|
||||
|
||||
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 note
|
||||
syncRows.filter(sync => sync.entityName === 'attributes').forEach(sync => {
|
||||
noteIdsToReload.push(sync.noteId);
|
||||
const attribute = this.attributes[sync.entityId];
|
||||
|
||||
if (attribute) {
|
||||
attribute.update(sync.entity);
|
||||
loadResults.addAttribute(sync.entityId, sync.sourceId);
|
||||
}
|
||||
});
|
||||
|
||||
// missing reloading the relation target note
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -83,6 +83,8 @@ async function fillInAdditionalProperties(sync) {
|
||||
sync.noteId = await sql.getValue(`SELECT noteId
|
||||
FROM note_revisions
|
||||
WHERE 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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user