From 861387707ab7c8c2f78b84613680d00c5029331c Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Sun, 23 Sep 2018 19:33:44 +0100 Subject: [PATCH] CLI: Fixes #795: Display tree of notebooks correctly --- CliClient/app/gui/FolderListWidget.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/CliClient/app/gui/FolderListWidget.js b/CliClient/app/gui/FolderListWidget.js index ad5b61b06..011e5cd5e 100644 --- a/CliClient/app/gui/FolderListWidget.js +++ b/CliClient/app/gui/FolderListWidget.js @@ -32,8 +32,6 @@ class FolderListWidget extends ListWidget { output.push(_('Search:')); output.push(item.title); } - - // if (item && item.id) output.push(item.id.substr(0, 5)); return output.join(' '); }; @@ -85,7 +83,6 @@ class FolderListWidget extends ListWidget { } set notesParentType(v) { - //if (this.notesParentType_ === v) return; this.notesParentType_ = v; this.updateIndexFromSelectedItemId() this.invalidate(); @@ -123,6 +120,14 @@ class FolderListWidget extends ListWidget { this.updateIndexFromSelectedItemId() this.invalidate(); } + + folderHasChildren_(folders, folderId) { + for (let i = 0; i < folders.length; i++) { + let folder = folders[i]; + if (folder.parent_id === folderId) return true; + } + return false; + } render() { if (this.updateItems_) { @@ -130,7 +135,18 @@ class FolderListWidget extends ListWidget { const wasSelectedItemId = this.selectedJoplinItemId; const previousParentType = this.notesParentType; - let newItems = this.folders.slice(); + let newItems = []; + const orderFolders = (parentId) => { + for (let i = 0; i < this.folders.length; i++) { + const f = this.folders[i]; + if (f.parent_id === parentId) { + newItems.push(f); + if (this.folderHasChildren_(this.folders, f.id)) orderFolders(f.id); + } + } + } + + orderFolders(''); if (this.tags.length) { if (newItems.length) newItems.push('-');