mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
fix deleting notes
This commit is contained in:
parent
aeeb35101e
commit
4c0315d2bf
@ -1,38 +1,37 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const treeChanges = (function() {
|
const treeChanges = (function() {
|
||||||
function moveBeforeNode(node, beforeNode) {
|
async function moveBeforeNode(node, beforeNode) {
|
||||||
$.ajax({
|
await $.ajax({
|
||||||
url: baseApiUrl + 'notes/' + node.data.note_tree_id + '/moveBefore/' + beforeNode.data.note_tree_id,
|
url: baseApiUrl + 'notes/' + node.data.note_tree_id + '/moveBefore/' + beforeNode.data.note_tree_id,
|
||||||
type: 'PUT',
|
type: 'PUT',
|
||||||
contentType: "application/json",
|
contentType: "application/json"
|
||||||
success: () => {
|
});
|
||||||
|
|
||||||
node.moveTo(beforeNode, 'before');
|
node.moveTo(beforeNode, 'before');
|
||||||
|
|
||||||
noteTree.setCurrentNotePathToHash(node);
|
noteTree.setCurrentNotePathToHash(node);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function moveAfterNode(node, afterNode) {
|
async function moveAfterNode(node, afterNode) {
|
||||||
$.ajax({
|
await $.ajax({
|
||||||
url: baseApiUrl + 'notes/' + node.data.note_tree_id + '/moveAfter/' + afterNode.data.note_tree_id,
|
url: baseApiUrl + 'notes/' + node.data.note_tree_id + '/moveAfter/' + afterNode.data.note_tree_id,
|
||||||
type: 'PUT',
|
type: 'PUT',
|
||||||
contentType: "application/json",
|
contentType: "application/json"
|
||||||
success: () => {
|
});
|
||||||
|
|
||||||
node.moveTo(afterNode, 'after');
|
node.moveTo(afterNode, 'after');
|
||||||
|
|
||||||
noteTree.setCurrentNotePathToHash(node);
|
noteTree.setCurrentNotePathToHash(node);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function moveToNode(node, toNode) {
|
async function moveToNode(node, toNode) {
|
||||||
$.ajax({
|
await $.ajax({
|
||||||
url: baseApiUrl + 'notes/' + node.data.note_tree_id + '/moveTo/' + toNode.data.note_id,
|
url: baseApiUrl + 'notes/' + node.data.note_tree_id + '/moveTo/' + toNode.data.note_id,
|
||||||
type: 'PUT',
|
type: 'PUT',
|
||||||
contentType: "application/json",
|
contentType: "application/json"
|
||||||
success: () => {
|
});
|
||||||
|
|
||||||
node.moveTo(toNode);
|
node.moveTo(toNode);
|
||||||
|
|
||||||
toNode.setExpanded(true);
|
toNode.setExpanded(true);
|
||||||
@ -42,15 +41,17 @@ const treeChanges = (function() {
|
|||||||
|
|
||||||
noteTree.setCurrentNotePathToHash(node);
|
noteTree.setCurrentNotePathToHash(node);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
async function deleteNode(node) {
|
||||||
|
if (!confirm('Are you sure you want to delete note "' + node.title + '"?')) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteNode(node) {
|
await $.ajax({
|
||||||
if (confirm('Are you sure you want to delete note "' + node.title + '"?')) {
|
url: baseApiUrl + 'notes/' + node.data.note_tree_id,
|
||||||
$.ajax({
|
type: 'DELETE'
|
||||||
url: baseApiUrl + 'notes/' + node.key,
|
});
|
||||||
type: 'DELETE',
|
|
||||||
success: () => {
|
|
||||||
if (node.getParent() !== null && node.getParent().getChildren().length <= 1) {
|
if (node.getParent() !== null && node.getParent().getChildren().length <= 1) {
|
||||||
node.getParent().folder = false;
|
node.getParent().folder = false;
|
||||||
node.getParent().renderTitle();
|
node.getParent().renderTitle();
|
||||||
@ -70,11 +71,8 @@ const treeChanges = (function() {
|
|||||||
|
|
||||||
noteTree.setCurrentNotePathToHash(next);
|
noteTree.setCurrentNotePathToHash(next);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function moveNodeUp(node) {
|
async function moveNodeUp(node) {
|
||||||
if (node.getParent() !== null) {
|
if (node.getParent() !== null) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: baseApiUrl + 'notes/' + node.data.note_tree_id + '/moveAfter/' + node.getParent().data.note_tree_id,
|
url: baseApiUrl + 'notes/' + node.data.note_tree_id + '/moveAfter/' + node.getParent().data.note_tree_id,
|
||||||
|
@ -52,11 +52,11 @@ router.put('/:noteId', async (req, res, next) => {
|
|||||||
res.send({});
|
res.send({});
|
||||||
});
|
});
|
||||||
|
|
||||||
router.delete('/:noteId', async (req, res, next) => {
|
router.delete('/:noteTreeId', async (req, res, next) => {
|
||||||
const browserId = utils.browserId(req);
|
const browserId = utils.browserId(req);
|
||||||
|
|
||||||
await sql.doInTransaction(async () => {
|
await sql.doInTransaction(async () => {
|
||||||
await notes.deleteNote(req.params.noteId, browserId);
|
await notes.deleteNote(req.params.noteTreeId, browserId);
|
||||||
});
|
});
|
||||||
|
|
||||||
res.send({});
|
res.send({});
|
||||||
|
@ -218,22 +218,27 @@ async function addNoteAudits(origNote, newNote, browserId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function deleteNote(noteId, browserId) {
|
async function deleteNote(noteTreeId, browserId) {
|
||||||
const now = utils.nowTimestamp();
|
const now = utils.nowTimestamp();
|
||||||
|
await sql.execute("update notes_tree set is_deleted = 1, date_modified = ? where note_tree_id = ?", [now, noteTreeId]);
|
||||||
|
await sync_table.addNoteTreeSync(noteTreeId);
|
||||||
|
|
||||||
const children = await sql.getResults("select note_id from notes_tree where note_pid = ? and is_deleted = 0", [noteId]);
|
const noteId = await sql.getSingleValue("SELECT note_id FROM notes_tree WHERE note_tree_id = ?", [noteTreeId]);
|
||||||
|
|
||||||
|
const notDeletedNoteTreesCount = await sql.getSingleValue("SELECT COUNT(*) FROM notes_tree WHERE note_id = ?", [noteId]);
|
||||||
|
|
||||||
|
if (!notDeletedNoteTreesCount) {
|
||||||
|
await sql.execute("update notes set is_deleted = 1, date_modified = ? where note_id = ?", [now, noteTreeId]);
|
||||||
|
await sync_table.addNoteSync(noteTreeId);
|
||||||
|
|
||||||
|
const children = await sql.getResults("select note_tree_id from notes_tree where note_pid = ? and is_deleted = 0", [noteTreeId]);
|
||||||
|
|
||||||
for (const child of children) {
|
for (const child of children) {
|
||||||
await deleteNote(child.note_id, browserId);
|
await deleteNote(child.note_tree_id, browserId);
|
||||||
}
|
}
|
||||||
|
|
||||||
await sql.execute("update notes_tree set is_deleted = 1, date_modified = ? where note_id = ?", [now, noteId]);
|
await sql.addAudit(audit_category.DELETE_NOTE, browserId, noteTreeId);
|
||||||
await sql.execute("update notes set is_deleted = 1, date_modified = ? where note_id = ?", [now, noteId]);
|
}
|
||||||
|
|
||||||
await sync_table.addNoteTreeSync(noteId);
|
|
||||||
await sync_table.addNoteSync(noteId);
|
|
||||||
|
|
||||||
await sql.addAudit(audit_category.DELETE_NOTE, browserId, noteId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user