mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
delete note fixes
This commit is contained in:
parent
84246fd197
commit
9afea492db
@ -113,13 +113,13 @@ function getSomeNotePathSegments(note, hoistedNotePath = 'root') {
|
||||
|
||||
const notePaths = note.getSortedNotePaths(hoistedNotePath);
|
||||
|
||||
return notePaths[0].notePath;
|
||||
return notePaths.length > 0 ? notePaths[0].notePath : null;
|
||||
}
|
||||
|
||||
function getSomeNotePath(note, hoistedNotePath = 'root') {
|
||||
const notePath = getSomeNotePathSegments(note, hoistedNotePath);
|
||||
|
||||
return notePath.join('/');
|
||||
return notePath === null ? null : notePath.join('/');
|
||||
}
|
||||
|
||||
async function sortAlphabetically(noteId) {
|
||||
|
@ -1166,7 +1166,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
|
||||
const newActiveNode = this.getActiveNode();
|
||||
|
||||
// return focus if the previously active node was also focused
|
||||
if (newActiveNode && activeNodeFocused) {console.log("FOCUSING!!!");
|
||||
if (newActiveNode && activeNodeFocused) {
|
||||
newActiveNode.setFocus(true);
|
||||
}
|
||||
});
|
||||
|
@ -81,10 +81,10 @@ function getRecentChanges(req) {
|
||||
if (change.current_isDeleted) {
|
||||
const deleteId = change.current_deleteId;
|
||||
|
||||
const undeletedParentBranches = noteService.getUndeletedParentBranches(change.noteId, deleteId);
|
||||
const undeletedParentBranchIds = noteService.getUndeletedParentBranchIds(change.noteId, deleteId);
|
||||
|
||||
// note (and the subtree) can be undeleted if there's at least one undeleted parent (whose branch would be undeleted by this op)
|
||||
change.canBeUndeleted = undeletedParentBranches.length > 0;
|
||||
change.canBeUndeleted = undeletedParentBranchIds.length > 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
const scriptService = require('../../services/script');
|
||||
const attributeService = require('../../services/attributes');
|
||||
const repository = require('../../services/repository');
|
||||
const becca = require('../../services/becca/becca');
|
||||
const syncService = require('../../services/sync');
|
||||
|
||||
async function exec(req) {
|
||||
|
@ -59,32 +59,26 @@ eventService.subscribe([eventService.ENTITY_CHANGED, eventService.ENTITY_CHANGE_
|
||||
}
|
||||
});
|
||||
|
||||
eventService.subscribe([eventService.ENTITY_DELETED, eventService.ENTITY_DELETE_SYNCED], ({entityName, entityId}) => {
|
||||
eventService.subscribe([eventService.ENTITY_DELETED, eventService.ENTITY_DELETE_SYNCED], ({entityName, entity}) => {
|
||||
if (!becca.loaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (entityName === 'notes') {
|
||||
noteDeleted(entityId);
|
||||
noteDeleted(entity);
|
||||
} else if (entityName === 'branches') {
|
||||
branchDeleted(entityId);
|
||||
branchDeleted(entity);
|
||||
} else if (entityName === 'attributes') {
|
||||
attributeDeleted(entityId);
|
||||
attributeDeleted(entity);
|
||||
}
|
||||
});
|
||||
|
||||
function noteDeleted(noteId) {
|
||||
delete becca.notes[noteId];
|
||||
function noteDeleted(note) {
|
||||
delete becca.notes[note.noteId];
|
||||
}
|
||||
|
||||
function branchDeleted(branchId) {
|
||||
const branch = becca.branches[branchId];
|
||||
|
||||
if (!branch) {
|
||||
return;
|
||||
}
|
||||
|
||||
const childNote = becca.notes[noteId];
|
||||
function branchDeleted(branch) {
|
||||
const childNote = becca.notes[branch.noteId];
|
||||
|
||||
if (childNote) {
|
||||
childNote.parents = childNote.parents.filter(parent => parent.noteId !== branch.parentNoteId);
|
||||
@ -115,13 +109,7 @@ function branchUpdated(branch) {
|
||||
}
|
||||
}
|
||||
|
||||
function attributeDeleted(attributeId) {
|
||||
const attribute = becca.attributes[attributeId];
|
||||
|
||||
if (!attribute) {
|
||||
return;
|
||||
}
|
||||
|
||||
function attributeDeleted(attribute) {
|
||||
const note = becca.notes[attribute.noteId];
|
||||
|
||||
if (note) {
|
||||
@ -132,21 +120,21 @@ function attributeDeleted(attributeId) {
|
||||
note.invalidateThisCache();
|
||||
}
|
||||
|
||||
note.ownedAttributes = note.ownedAttributes.filter(attr => attr.attributeId !== attributeId);
|
||||
note.ownedAttributes = note.ownedAttributes.filter(attr => attr.attributeId !== attribute.attributeId);
|
||||
|
||||
const targetNote = attribute.targetNote;
|
||||
|
||||
if (targetNote) {
|
||||
targetNote.targetRelations = targetNote.targetRelations.filter(rel => rel.attributeId !== attributeId);
|
||||
targetNote.targetRelations = targetNote.targetRelations.filter(rel => rel.attributeId !== attribute.attributeId);
|
||||
}
|
||||
}
|
||||
|
||||
delete becca.attributes[attributeId];
|
||||
delete becca.attributes[attribute.attributeId];
|
||||
|
||||
const key = `${attribute.type}-${attribute.name.toLowerCase()}`;
|
||||
|
||||
if (key in becca.attributeIndex) {
|
||||
becca.attributeIndex[key] = becca.attributeIndex[key].filter(attr => attr.attributeId !== attributeId);
|
||||
becca.attributeIndex[key] = becca.attributeIndex[key].filter(attr => attr.attributeId !== attribute.attributeId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,17 +96,15 @@ class AbstractEntity {
|
||||
}
|
||||
|
||||
markAsDeleted(deleteId = null) {
|
||||
sql.execute(`UPDATE ${this.constructor.entityName} SET isDeleted = 1, deleteId = ? WHERE ${this.constructor.primaryKeyName} = ?`,
|
||||
[deleteId, this[this.constructor.primaryKeyName]]);
|
||||
const entityId = this[this.constructor.primaryKeyName];
|
||||
const entityName = this.constructor.entityName;
|
||||
|
||||
sql.execute(`UPDATE ${entityName} SET isDeleted = 1, deleteId = ? WHERE ${this.constructor.primaryKeyName} = ?`,
|
||||
[deleteId, entityId]);
|
||||
|
||||
this.addEntityChange(true);
|
||||
|
||||
const eventPayload = {
|
||||
entityName: this.constructor.entityName,
|
||||
entity: this
|
||||
};
|
||||
|
||||
eventService.emit(eventService.ENTITY_DELETED, eventPayload);
|
||||
eventService.emit(eventService.ENTITY_DELETED, { entityName, entity: this });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -551,6 +551,17 @@ class Note extends AbstractEntity {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Attribute} attribute belonging to this specific note (excludes inherited attributes)
|
||||
*
|
||||
* This method can be significantly faster than the getAttribute()
|
||||
*/
|
||||
getOwnedAttribute(type, name) {
|
||||
const attrs = this.getOwnedAttributes(type, name);
|
||||
|
||||
return attrs.length > 0 ? attrs[0] : null;
|
||||
}
|
||||
|
||||
get isArchived() {
|
||||
return this.hasAttribute('label', 'archived');
|
||||
}
|
||||
@ -773,6 +784,10 @@ class Note extends AbstractEntity {
|
||||
return this.ancestorCache;
|
||||
}
|
||||
|
||||
getTargetRelations() {
|
||||
return this.targetRelations;
|
||||
}
|
||||
|
||||
/** @return {Note[]} - returns only notes which are templated, does not include their subtrees
|
||||
* in effect returns notes which are influenced by note's non-inheritable attributes */
|
||||
get templatedNotes() {
|
||||
|
@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
const repository = require('./repository');
|
||||
const becca = require('./becca/becca');
|
||||
const log = require('./log');
|
||||
const protectedSessionService = require('./protected_session');
|
||||
const noteService = require('./notes');
|
||||
|
@ -523,7 +523,7 @@ function updateNote(noteId, noteUpdates) {
|
||||
function deleteBranch(branch, deleteId, taskContext) {
|
||||
taskContext.increaseProgressCount();
|
||||
|
||||
if (!branch || branch.isDeleted) {
|
||||
if (!branch) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -531,7 +531,7 @@ function deleteBranch(branch, deleteId, taskContext) {
|
||||
|| branch.noteId === 'root'
|
||||
|| branch.noteId === cls.getHoistedNoteId()) {
|
||||
|
||||
throw new Error("Can't delete root branch/note");
|
||||
throw new Error("Can't delete root or hoisted branch/note");
|
||||
}
|
||||
|
||||
branch.markAsDeleted(deleteId);
|
||||
@ -546,8 +546,6 @@ function deleteBranch(branch, deleteId, taskContext) {
|
||||
|
||||
// first delete children and then parent - this will show up better in recent changes
|
||||
|
||||
note.markAsDeleted(deleteId);
|
||||
|
||||
log.info("Deleting note " + note.noteId);
|
||||
|
||||
for (const attribute of note.getOwnedAttributes()) {
|
||||
@ -558,6 +556,8 @@ function deleteBranch(branch, deleteId, taskContext) {
|
||||
relation.markAsDeleted(deleteId);
|
||||
}
|
||||
|
||||
note.markAsDeleted(deleteId);
|
||||
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
@ -874,7 +874,7 @@ module.exports = {
|
||||
scanForLinks,
|
||||
duplicateSubtree,
|
||||
duplicateSubtreeWithoutRoot,
|
||||
getUndeletedParentBranches: getUndeletedParentBranchIds,
|
||||
getUndeletedParentBranchIds,
|
||||
triggerNoteTitleChanged,
|
||||
eraseDeletedNotesNow
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user