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

File diff suppressed because one or more lines are too long

12
package-lock.json generated
View File

@ -2890,9 +2890,9 @@
}
},
"electron": {
"version": "13.3.0",
"resolved": "https://registry.npmjs.org/electron/-/electron-13.3.0.tgz",
"integrity": "sha512-d/BvOLDjI4i7yf9tqCuLL2fFGA2TrM/D9PyRpua+rJolG0qrwp/FohP02L0m+44kmPpofIo4l3NPwLmzyKKimA==",
"version": "13.4.0",
"resolved": "https://registry.npmjs.org/electron/-/electron-13.4.0.tgz",
"integrity": "sha512-KJGWS2qa0xZXIMPMDUNkRVO8/JxRd4+M0ejYYOzu2LIQ5ijecPzNuNR9nvDkml9XyyRBzu975FkhJcwD17ietQ==",
"dev": true,
"requires": {
"@electron/get": "^1.0.1",
@ -6873,9 +6873,9 @@
}
},
"sanitize-html": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/sanitize-html/-/sanitize-html-2.5.0.tgz",
"integrity": "sha512-smU67ODza8E0rJF7oY37qQqMF5srxwEkqsgV17PFfdYAtIxnicH8LIyDEGINJIso8bPaxRZS7zGhCjg6BeDoqQ==",
"version": "2.5.1",
"resolved": "https://registry.npmjs.org/sanitize-html/-/sanitize-html-2.5.1.tgz",
"integrity": "sha512-hUITPitQk+eFNLtr4dEkaaiAJndG2YE87IOpcfBSL1XdklWgwcNDJdr9Ppe8QKL/C3jFt1xH/Mbj20e0GZQOfg==",
"requires": {
"deepmerge": "^4.2.2",
"escape-string-regexp": "^4.0.0",

View File

@ -66,7 +66,7 @@
"request": "^2.88.2",
"rimraf": "3.0.2",
"sanitize-filename": "1.6.3",
"sanitize-html": "2.5.0",
"sanitize-html": "2.5.1",
"sax": "1.2.4",
"semver": "7.3.5",
"serve-favicon": "2.5.0",
@ -81,7 +81,7 @@
},
"devDependencies": {
"cross-env": "7.0.3",
"electron": "13.3.0",
"electron": "13.4.0",
"electron-builder": "22.11.7",
"electron-packager": "15.4.0",
"electron-rebuild": "3.2.3",

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>