mirror of
https://github.com/zadam/trilium.git
synced 2025-11-12 00:05:50 +01:00
undelete note WIP
This commit is contained in:
@@ -101,7 +101,8 @@ async function deleteBranch(req) {
|
||||
const branch = await repository.getBranch(req.params.branchId);
|
||||
const taskContext = TaskContext.getInstance(req.query.taskId, 'delete-notes');
|
||||
|
||||
const noteDeleted = await notes.deleteBranch(branch, taskContext);
|
||||
const deleteId = utils.randomString(10);
|
||||
const noteDeleted = await notes.deleteBranch(branch, deleteId, taskContext);
|
||||
|
||||
if (last) {
|
||||
taskContext.taskSucceeded();
|
||||
|
||||
@@ -55,12 +55,15 @@ async function deleteNote(req) {
|
||||
const taskId = req.query.taskId;
|
||||
const last = req.query.last === 'true';
|
||||
|
||||
// note how deleteId is separate from taskId - single taskId produces separate deleteId for each "top level" deleted note
|
||||
const deleteId = utils.randomString(10);
|
||||
|
||||
const note = await repository.getNote(noteId);
|
||||
|
||||
const taskContext = TaskContext.getInstance(taskId, 'delete-notes');
|
||||
|
||||
for (const branch of await note.getBranches()) {
|
||||
await noteService.deleteBranch(branch, taskContext);
|
||||
await noteService.deleteBranch(branch, deleteId, taskContext);
|
||||
}
|
||||
|
||||
if (last) {
|
||||
|
||||
@@ -10,6 +10,8 @@ async function getRecentChanges() {
|
||||
SELECT
|
||||
notes.noteId,
|
||||
notes.isDeleted AS current_isDeleted,
|
||||
notes.deleteId AS current_deleteId,
|
||||
notes.isErased AS current_isErased,
|
||||
notes.title AS current_title,
|
||||
notes.isProtected AS current_isProtected,
|
||||
note_revisions.title,
|
||||
@@ -19,21 +21,23 @@ async function getRecentChanges() {
|
||||
JOIN notes USING(noteId)
|
||||
ORDER BY
|
||||
note_revisions.utcDateCreated DESC
|
||||
LIMIT 1000
|
||||
LIMIT 200
|
||||
)
|
||||
UNION ALL SELECT * FROM (
|
||||
SELECT
|
||||
notes.noteId,
|
||||
notes.isDeleted AS current_isDeleted,
|
||||
notes.deleteId AS current_deleteId,
|
||||
notes.isErased AS current_isErased,
|
||||
notes.title AS current_title,
|
||||
notes.isProtected AS current_isProtected,
|
||||
notes.title,
|
||||
notes.utcDateCreated AS date
|
||||
notes.utcDateModified AS date
|
||||
FROM
|
||||
notes
|
||||
ORDER BY
|
||||
utcDateCreated DESC
|
||||
LIMIT 1000
|
||||
utcDateModified DESC
|
||||
LIMIT 200
|
||||
)
|
||||
ORDER BY date DESC
|
||||
LIMIT 200`);
|
||||
@@ -48,6 +52,27 @@ async function getRecentChanges() {
|
||||
change.title = change.current_title = "[Protected]";
|
||||
}
|
||||
}
|
||||
|
||||
if (change.current_isDeleted) {
|
||||
if (change.current_isErased) {
|
||||
change.canBeUndeleted = false;
|
||||
}
|
||||
else {
|
||||
const deleteId = change.current_deleteId;
|
||||
|
||||
const undeletedParentCount = await sql.getValue(`
|
||||
SELECT COUNT(parentNote.noteId)
|
||||
FROM branches
|
||||
JOIN notes AS parentNote ON parentNote.noteId = branches.parentNoteId
|
||||
WHERE branches.noteId = ?
|
||||
AND branches.isDeleted = 1
|
||||
AND branches.deleteId = ?
|
||||
AND parentNote.isDeleted = 0`, [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 = undeletedParentCount > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return recentChanges;
|
||||
|
||||
Reference in New Issue
Block a user