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 ('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 ('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 ('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'); 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 // 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 // on the next page since those are older
if (listing.data.after && importedComments > 0) { if (listing.data.after && importedComments > 0) {
log.info("Reddit: Importing from next page of comments ...");
importedComments += await importComments(accountName, listing.data.after); importedComments += await importComments(accountName, listing.data.after);
} }

View File

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

View File

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

View File

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

View File

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

View File

@ -243,6 +243,12 @@ async function updateNote(noteId, newNote, dataKey, sourceId) {
} }
async function deleteNote(noteTreeId, 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(); const now = utils.nowDate();
await sql.execute("UPDATE notes_tree SET is_deleted = 1, date_modified = ? WHERE note_tree_id = ?", [now, noteTreeId]); await sql.execute("UPDATE notes_tree SET is_deleted = 1, date_modified = ? WHERE note_tree_id = ?", [now, noteTreeId]);