delete now works with multi-select

This commit is contained in:
azivner 2018-01-14 21:39:21 -05:00
parent 45a92313d5
commit d30a57d388
7 changed files with 31 additions and 30 deletions

View file

@ -1,5 +1,5 @@
INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('root', 'root', 'root', 0, 0, '2017-12-22T11:41:07.000Z', '2017-12-22T11:41:07.000Z');
INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('1Heh2acXfPNt', 'Trilium Demo', '<figure class="image image-style-side"><img src="/api/images/ed64aET6i379/trilium-small.png"></figure><p><strong>Welcome to Trilium Notes!</strong></p><p>&nbsp;</p><p>This is initial document provided by default Trilium to showcase some of its features and also give you some ideas how you might structure your notes. You can play with it, modify note content and tree structure as you wish.</p><p>&nbsp;</p><p>If you need any help, visit Trilium wesite: <a href="https://github.com/zadam/trilium">https://github.com/zadam/trilium</a></p><h3>Cleanup</h3><p>Once you''re finished with experimenting and want to cleanup these pages, you can simply delete them all.</p><h3>Formatting</h3><p>Trilium supports classic formatting like <i>italic</i>, <strong>bold</strong>, <i><strong>bold and italic</strong></i>. Of course you can add links like this one pointing to <a href="http://www.google.com">google.com</a></p><h4>Lists</h4><p><strong>Ordered:</strong></p><ol><li>First Item</li><li>Second item<ol><li>First sub-item</li><li>Second sub-item</li></ol></li></ol><p>&nbsp;</p><p><strong>Unordered:</strong></p><ul><li>Item</li><li>Another item<ul><li>Sub-item<ul><li>Sub-sub-item</li></ul></li></ul></li></ul><h4>Block quotes</h4><blockquote><p>Whereof one cannot speak, thereof one must be silent”</p><p> Ludwig Wittgenstein</p></blockquote><p>&nbsp;</p>', 0, 0, '2017-12-23T00:46:39.304Z', '2017-12-23T04:08:45.445Z');
INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('1Heh2acXfPNt', 'Trilium Demo', '<figure class="image image-style-side"><img src="/api/images/ed64aET6i379/trilium-small.png"></figure><p><strong>Welcome to Trilium Notes!</strong></p><p>&nbsp;</p><p>This is initial document provided by default Trilium to showcase some of its features and also give you some ideas how you might structure your notes. You can play with it, modify note content and tree structure as you wish.</p><p>&nbsp;</p><p>If you need any help, visit Trilium website: <a href="https://github.com/zadam/trilium">https://github.com/zadam/trilium</a></p><h3>Cleanup</h3><p>Once you''re finished with experimenting and want to cleanup these pages, you can simply delete them all.</p><h3>Formatting</h3><p>Trilium supports classic formatting like <i>italic</i>, <strong>bold</strong>, <i><strong>bold and italic</strong></i>. Of course you can add links like this one pointing to <a href="http://www.google.com">google.com</a></p><h4>Lists</h4><p><strong>Ordered:</strong></p><ol><li>First Item</li><li>Second item<ol><li>First sub-item</li><li>Second sub-item</li></ol></li></ol><p>&nbsp;</p><p><strong>Unordered:</strong></p><ul><li>Item</li><li>Another item<ul><li>Sub-item<ul><li>Sub-sub-item</li></ul></li></ul></li></ul><h4>Block quotes</h4><blockquote><p>Whereof one cannot speak, thereof one must be silent”</p><p> Ludwig Wittgenstein</p></blockquote><p>&nbsp;</p>', 0, 0, '2017-12-23T00:46:39.304Z', '2017-12-23T04:08:45.445Z');
INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('3RkyK9LI18dO', 'Journal', '<p>Expand note on the left pane to see content.</p>', 0, 0, '2017-12-23T01:20:04.181Z', '2017-12-23T18:07:55.377Z');
INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('L1Ox40M1aEyy', '2016', '<p>No content.</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>', 0, 0, '2017-12-23T01:20:45.365Z', '2017-12-23T16:40:43.129Z');
INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('HJusZTbBU494', '2017', '<p>No content.</p>', 0, 0, '2017-12-23T01:20:50.709Z', '2017-12-23T16:41:03.119Z');

View file

@ -176,8 +176,6 @@ karma: ${comment.score}, created at ${dateTimeStr}</p><p></p>`
// if there have been no imported comments on this page, there shouldn't be any to import
// on the next page since those are older
if (listing.data.after && importedComments > 0) {
log.info("Reddit: Importing from next page of comments ...");
importedComments += await importComments(accountName, listing.data.after);
}

View file

@ -141,7 +141,7 @@ const contextMenu = (function() {
pasteInto(node);
}
else if (ui.cmd === "delete") {
treeChanges.deleteNode(node);
treeChanges.deleteNodes(noteTree.getSelectedNodes(true));
}
else if (ui.cmd === "collapse-sub-tree") {
noteTree.collapseTree(node);

View file

@ -382,8 +382,8 @@ const noteTree = (function() {
recentNotes.addRecentNote(currentNoteTreeId, currentNotePath);
}
function getSelectedNodes() {
return getTree().getSelectedNodes();
function getSelectedNodes(stopOnParents = false) {
return getTree().getSelectedNodes(stopOnParents);
}
function clearSelectedNodes() {
@ -403,7 +403,7 @@ const noteTree = (function() {
const keybindings = {
"del": node => {
treeChanges.deleteNode(node);
treeChanges.deleteNodes(getSelectedNodes(true));
},
"ctrl+up": node => {
const beforeNode = node.getPrevSibling();
@ -803,7 +803,7 @@ const noteTree = (function() {
$(document).bind('keydown', 'ctrl+del', e => {
const node = getCurrentNode();
treeChanges.deleteNode(node);
treeChanges.deleteNodes([node]);
e.preventDefault();
});

View file

@ -53,30 +53,27 @@ const treeChanges = (function() {
}
}
async function deleteNode(node) {
if (!confirm('Are you sure you want to delete note "' + node.title + '" and all its sub-notes?')) {
async function deleteNodes(nodes) {
if (nodes.length === 0 || !confirm('Are you sure you want to delete select note(s) and all the sub-notes?')) {
return;
}
await server.remove('tree/' + node.data.note_tree_id);
if (!isTopLevelNode(node) && node.getParent().getChildren().length <= 1) {
node.getParent().folder = false;
node.getParent().renderTitle();
for (const node of nodes) {
await server.remove('tree/' + node.data.note_tree_id);
}
let next = node.getNextSibling();
// following code assumes that nodes contain only top-most selected nodes - getSelectedNodes has been
// called with stopOnParent=true
let next = nodes[nodes.length - 1].getNextSibling();
if (!next) {
next = node.getPrevSibling();
next = nodes[0].getPrevSibling();
}
if (!next && !isTopLevelNode(node)) {
next = node.getParent();
if (!next && !isTopLevelNode(nodes[0])) {
next = nodes[0].getParent();
}
node.remove();
if (next) {
// activate next element after this one is deleted so we don't lose focus
next.setActive();
@ -86,7 +83,7 @@ const treeChanges = (function() {
noteTree.reload();
showMessage("Note has been deleted.");
showMessage("Note(s) has been deleted.");
}
async function moveNodeUpInHierarchy(node) {
@ -127,7 +124,7 @@ const treeChanges = (function() {
moveBeforeNode,
moveAfterNode,
moveToNode,
deleteNode,
deleteNodes,
moveNodeUpInHierarchy
};
})();

View file

@ -121,15 +121,15 @@ async function runAllChecks() {
await runCheck(`
SELECT
child.note_id
child.note_tree_id
FROM
notes_tree
JOIN notes AS child ON child.note_id = notes_tree.note_id
JOIN notes AS parent ON notes_tree.parent_note_id = parent.note_id
notes_tree AS child
WHERE
parent.is_deleted = 1
AND child.is_deleted = 0`,
"Parent note is deleted but child note is not for these child note IDs", errorList);
child.is_deleted = 0
AND child.parent_note_id != 'root'
AND (SELECT COUNT(*) FROM notes_tree AS parent WHERE parent.note_id = child.parent_note_id
AND parent.is_deleted = 0) = 0`,
"All parent note trees are deleted but child note tree is not for these child note tree IDs", errorList);
// we do extra JOIN to eliminate orphan notes without note tree (which are reported separately)
await runCheck(`

View file

@ -243,6 +243,12 @@ async function updateNote(noteId, newNote, dataKey, sourceId) {
}
async function deleteNote(noteTreeId, sourceId) {
const noteTree = await sql.getFirstOrNull("SELECT * FROM notes_tree WHERE note_tree_id = ?", [noteTreeId]);
if (!noteTree || noteTree.is_deleted === 1) {
return;
}
const now = utils.nowDate();
await sql.execute("UPDATE notes_tree SET is_deleted = 1, date_modified = ? WHERE note_tree_id = ?", [now, noteTreeId]);