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);
|
const notePaths = note.getSortedNotePaths(hoistedNotePath);
|
||||||
|
|
||||||
return notePaths[0].notePath;
|
return notePaths.length > 0 ? notePaths[0].notePath : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSomeNotePath(note, hoistedNotePath = 'root') {
|
function getSomeNotePath(note, hoistedNotePath = 'root') {
|
||||||
const notePath = getSomeNotePathSegments(note, hoistedNotePath);
|
const notePath = getSomeNotePathSegments(note, hoistedNotePath);
|
||||||
|
|
||||||
return notePath.join('/');
|
return notePath === null ? null : notePath.join('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sortAlphabetically(noteId) {
|
async function sortAlphabetically(noteId) {
|
||||||
|
@ -1166,7 +1166,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
|
|||||||
const newActiveNode = this.getActiveNode();
|
const newActiveNode = this.getActiveNode();
|
||||||
|
|
||||||
// return focus if the previously active node was also focused
|
// return focus if the previously active node was also focused
|
||||||
if (newActiveNode && activeNodeFocused) {console.log("FOCUSING!!!");
|
if (newActiveNode && activeNodeFocused) {
|
||||||
newActiveNode.setFocus(true);
|
newActiveNode.setFocus(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -81,10 +81,10 @@ function getRecentChanges(req) {
|
|||||||
if (change.current_isDeleted) {
|
if (change.current_isDeleted) {
|
||||||
const deleteId = change.current_deleteId;
|
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)
|
// 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 scriptService = require('../../services/script');
|
||||||
const attributeService = require('../../services/attributes');
|
const attributeService = require('../../services/attributes');
|
||||||
const repository = require('../../services/repository');
|
const becca = require('../../services/becca/becca');
|
||||||
const syncService = require('../../services/sync');
|
const syncService = require('../../services/sync');
|
||||||
|
|
||||||
async function exec(req) {
|
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) {
|
if (!becca.loaded) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entityName === 'notes') {
|
if (entityName === 'notes') {
|
||||||
noteDeleted(entityId);
|
noteDeleted(entity);
|
||||||
} else if (entityName === 'branches') {
|
} else if (entityName === 'branches') {
|
||||||
branchDeleted(entityId);
|
branchDeleted(entity);
|
||||||
} else if (entityName === 'attributes') {
|
} else if (entityName === 'attributes') {
|
||||||
attributeDeleted(entityId);
|
attributeDeleted(entity);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function noteDeleted(noteId) {
|
function noteDeleted(note) {
|
||||||
delete becca.notes[noteId];
|
delete becca.notes[note.noteId];
|
||||||
}
|
}
|
||||||
|
|
||||||
function branchDeleted(branchId) {
|
function branchDeleted(branch) {
|
||||||
const branch = becca.branches[branchId];
|
const childNote = becca.notes[branch.noteId];
|
||||||
|
|
||||||
if (!branch) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const childNote = becca.notes[noteId];
|
|
||||||
|
|
||||||
if (childNote) {
|
if (childNote) {
|
||||||
childNote.parents = childNote.parents.filter(parent => parent.noteId !== branch.parentNoteId);
|
childNote.parents = childNote.parents.filter(parent => parent.noteId !== branch.parentNoteId);
|
||||||
@ -115,13 +109,7 @@ function branchUpdated(branch) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function attributeDeleted(attributeId) {
|
function attributeDeleted(attribute) {
|
||||||
const attribute = becca.attributes[attributeId];
|
|
||||||
|
|
||||||
if (!attribute) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const note = becca.notes[attribute.noteId];
|
const note = becca.notes[attribute.noteId];
|
||||||
|
|
||||||
if (note) {
|
if (note) {
|
||||||
@ -132,21 +120,21 @@ function attributeDeleted(attributeId) {
|
|||||||
note.invalidateThisCache();
|
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;
|
const targetNote = attribute.targetNote;
|
||||||
|
|
||||||
if (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()}`;
|
const key = `${attribute.type}-${attribute.name.toLowerCase()}`;
|
||||||
|
|
||||||
if (key in becca.attributeIndex) {
|
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) {
|
markAsDeleted(deleteId = null) {
|
||||||
sql.execute(`UPDATE ${this.constructor.entityName} SET isDeleted = 1, deleteId = ? WHERE ${this.constructor.primaryKeyName} = ?`,
|
const entityId = this[this.constructor.primaryKeyName];
|
||||||
[deleteId, 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);
|
this.addEntityChange(true);
|
||||||
|
|
||||||
const eventPayload = {
|
eventService.emit(eventService.ENTITY_DELETED, { entityName, entity: this });
|
||||||
entityName: this.constructor.entityName,
|
|
||||||
entity: this
|
|
||||||
};
|
|
||||||
|
|
||||||
eventService.emit(eventService.ENTITY_DELETED, eventPayload);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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() {
|
get isArchived() {
|
||||||
return this.hasAttribute('label', 'archived');
|
return this.hasAttribute('label', 'archived');
|
||||||
}
|
}
|
||||||
@ -773,6 +784,10 @@ class Note extends AbstractEntity {
|
|||||||
return this.ancestorCache;
|
return this.ancestorCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getTargetRelations() {
|
||||||
|
return this.targetRelations;
|
||||||
|
}
|
||||||
|
|
||||||
/** @return {Note[]} - returns only notes which are templated, does not include their subtrees
|
/** @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 */
|
* in effect returns notes which are influenced by note's non-inheritable attributes */
|
||||||
get templatedNotes() {
|
get templatedNotes() {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const repository = require('./repository');
|
const becca = require('./becca/becca');
|
||||||
const log = require('./log');
|
const log = require('./log');
|
||||||
const protectedSessionService = require('./protected_session');
|
const protectedSessionService = require('./protected_session');
|
||||||
const noteService = require('./notes');
|
const noteService = require('./notes');
|
||||||
|
@ -523,7 +523,7 @@ function updateNote(noteId, noteUpdates) {
|
|||||||
function deleteBranch(branch, deleteId, taskContext) {
|
function deleteBranch(branch, deleteId, taskContext) {
|
||||||
taskContext.increaseProgressCount();
|
taskContext.increaseProgressCount();
|
||||||
|
|
||||||
if (!branch || branch.isDeleted) {
|
if (!branch) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -531,7 +531,7 @@ function deleteBranch(branch, deleteId, taskContext) {
|
|||||||
|| branch.noteId === 'root'
|
|| branch.noteId === 'root'
|
||||||
|| branch.noteId === cls.getHoistedNoteId()) {
|
|| 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);
|
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
|
// first delete children and then parent - this will show up better in recent changes
|
||||||
|
|
||||||
note.markAsDeleted(deleteId);
|
|
||||||
|
|
||||||
log.info("Deleting note " + note.noteId);
|
log.info("Deleting note " + note.noteId);
|
||||||
|
|
||||||
for (const attribute of note.getOwnedAttributes()) {
|
for (const attribute of note.getOwnedAttributes()) {
|
||||||
@ -558,6 +556,8 @@ function deleteBranch(branch, deleteId, taskContext) {
|
|||||||
relation.markAsDeleted(deleteId);
|
relation.markAsDeleted(deleteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
note.markAsDeleted(deleteId);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -874,7 +874,7 @@ module.exports = {
|
|||||||
scanForLinks,
|
scanForLinks,
|
||||||
duplicateSubtree,
|
duplicateSubtree,
|
||||||
duplicateSubtreeWithoutRoot,
|
duplicateSubtreeWithoutRoot,
|
||||||
getUndeletedParentBranches: getUndeletedParentBranchIds,
|
getUndeletedParentBranchIds,
|
||||||
triggerNoteTitleChanged,
|
triggerNoteTitleChanged,
|
||||||
eraseDeletedNotesNow
|
eraseDeletedNotesNow
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user