option to erase notes immediately

This commit is contained in:
zadam
2021-09-16 14:38:09 +02:00
parent 9b9be5d155
commit 0448883782
10 changed files with 74 additions and 16 deletions

View File

@@ -14,6 +14,7 @@ const $deleteNotesListWrapper = $("#delete-notes-list-wrapper");
const $brokenRelationsListWrapper = $("#broken-relations-wrapper");
const $brokenRelationsCount = $("#broke-relations-count");
const $deleteAllClones = $("#delete-all-clones");
const $eraseNotes = $("#erase-notes");
let branchIds = null;
let resolve = null;
@@ -63,6 +64,9 @@ export async function showDialog(branchIdsToDelete) {
utils.openDialog($dialog);
$deleteAllClones.prop("checked", false);
$eraseNotes.prop("checked", false);
return new Promise((res, rej) => resolve = res);
}
@@ -70,6 +74,10 @@ export function isDeleteAllClonesChecked() {
return $deleteAllClones.is(":checked");
}
export function isEraseNotesChecked() {
return $eraseNotes.is(":checked");
}
$dialog.on('shown.bs.modal', () => $okButton.trigger("focus"));
$cancelButton.on('click', () => {
@@ -83,7 +91,8 @@ $okButton.on('click', () => {
resolve({
proceed: true,
deleteAllClones: isDeleteAllClonesChecked()
deleteAllClones: isDeleteAllClonesChecked(),
eraseNotes: isEraseNotesChecked()
});
});

View File

@@ -74,7 +74,7 @@ async function deleteNotes(branchIdsToDelete) {
return false;
}
let proceed, deleteAllClones;
let proceed, deleteAllClones, eraseNotes;
if (utils.isMobile()) {
proceed = true;
@@ -82,7 +82,7 @@ async function deleteNotes(branchIdsToDelete) {
}
else {
const deleteNotesDialog = await import("../dialogs/delete_notes.js");
({proceed, deleteAllClones} = await deleteNotesDialog.showDialog(branchIdsToDelete));
({proceed, deleteAllClones, eraseNotes} = await deleteNotesDialog.showDialog(branchIdsToDelete));
}
if (!proceed) {
@@ -97,7 +97,7 @@ async function deleteNotes(branchIdsToDelete) {
counter++;
const last = counter === branchIdsToDelete.length;
const query = `?taskId=${taskId}&last=${last ? 'true' : 'false'}`;
const query = `?taskId=${taskId}&eraseNotes=${eraseNotes ? 'true' : 'false'}&last=${last ? 'true' : 'false'}`;
const branch = froca.getBranch(branchIdToDelete);

View File

@@ -205,12 +205,17 @@ function setExpandedForSubtree(req) {
function deleteBranch(req) {
const last = req.query.last === 'true';
const eraseNotes = req.query.eraseNotes === 'true';
const branch = becca.getBranch(req.params.branchId);
const taskContext = TaskContext.getInstance(req.query.taskId, 'delete-notes');
const deleteId = utils.randomString(10);
const noteDeleted = noteService.deleteBranch(branch, deleteId, taskContext);
if (eraseNotes) {
noteService.eraseNotesWithDeleteId(deleteId);
}
if (last) {
taskContext.taskSucceeded();
}

View File

@@ -121,6 +121,22 @@ function getSearchRoot() {
return searchRoot;
}
function getSpecialNoteRoot() {
let specialNoteRoot = becca.getNote('special');
if (!specialNoteRoot) {
specialNoteRoot = noteService.createNewNote({
noteId: 'special',
title: 'special',
type: 'text',
content: '',
parentNoteId: getHiddenRoot().noteId
}).note;
}
return specialNoteRoot;
}
function getSqlConsoleRoot() {
let sqlConsoleRoot = becca.getNote('sqlconsole');

View File

@@ -63,6 +63,7 @@ function updateNote(req) {
function deleteNote(req) {
const noteId = req.params.noteId;
const taskId = req.query.taskId;
const eraseNotes = req.query.eraseNotes === 'true';
const last = req.query.last === 'true';
// note how deleteId is separate from taskId - single taskId produces separate deleteId for each "top level" deleted note
@@ -76,6 +77,10 @@ function deleteNote(req) {
noteService.deleteBranch(branch, deleteId, taskContext);
}
if (eraseNotes) {
noteService.eraseNotesWithDeleteId(deleteId);
}
if (last) {
taskContext.taskSucceeded();
}

View File

@@ -743,6 +743,20 @@ function eraseDeletedEntities(eraseEntitiesAfterTimeInSeconds = null) {
eraseAttributes(attributeIdsToErase);
}
function eraseNotesWithDeleteId(deleteId) {
const noteIdsToErase = sql.getColumn("SELECT noteId FROM notes WHERE deleteId = ?", [deleteId]);
eraseNotes(noteIdsToErase);
const branchIdsToErase = sql.getColumn("SELECT branchId FROM branches WHERE deleteId = ?", [deleteId]);
eraseBranches(branchIdsToErase);
const attributeIdsToErase = sql.getColumn("SELECT attributeId FROM attributes WHERE deleteId = ?", [deleteId]);
eraseAttributes(attributeIdsToErase);
}
function eraseDeletedNotesNow() {
eraseDeletedEntities(0);
}
@@ -885,5 +899,6 @@ module.exports = {
duplicateSubtreeWithoutRoot,
getUndeletedParentBranchIds,
triggerNoteTitleChanged,
eraseDeletedNotesNow
eraseDeletedNotesNow,
eraseNotesWithDeleteId
};

View File

@@ -17,6 +17,14 @@
</label>
</div>
<div class="checkbox">
<label data-toggle="tooltip" title="Normal (soft) deletion only marks the notes as deleted and they can be undeleted (in recent changes dialog) within a period of time. Checking this option will erase the notes immediatelly and it won't be possible to undelete the notes.">
<input id="erase-notes" value="1" type="checkbox">
erase notes permanently (can't be undone)
</label>
</div>
<div id="delete-notes-list-wrapper">
<h4>Following notes will be deleted (<span id="deleted-notes-count"></span>)</h4>