From 489e064932289b36097a025eb6b2913e2a264b87 Mon Sep 17 00:00:00 2001 From: zadam Date: Thu, 22 Oct 2020 23:07:35 +0200 Subject: [PATCH] expand/collapse all --- src/public/app/services/note_list_renderer.js | 55 ++++++++++++------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/src/public/app/services/note_list_renderer.js b/src/public/app/services/note_list_renderer.js index beeb338dd..f415d36e7 100644 --- a/src/public/app/services/note_list_renderer.js +++ b/src/public/app/services/note_list_renderer.js @@ -99,6 +99,12 @@ const TPL = `
+ + +   + @@ -119,27 +125,36 @@ const TPL = `
`; +async function toggleCards(cards, expand) { + for (const card of cards) { + const $card = $(card); + const noteId = $card.attr('data-note-id'); + const note = await treeCache.getNote(noteId); + + await toggleContent($card, note, expand); + } +} + async function renderList(notes, parentNote = null) { const $noteList = $(TPL); - // $zoomInButton.on('click', () => this.setZoom(this.zoomLevel - 1)); - // $zoomOutButton.on('click', () => this.setZoom(this.zoomLevel + 1)); - // - // $expandChildrenButton.on('click', async () => { - // for (let i = 1; i < 30; i++) { // protection against infinite cycle - // const $unexpandedLinks = this.$content.find('.note-book-open-children-button:visible'); - // - // if ($unexpandedLinks.length === 0) { - // break; - // } - // - // for (const link of $unexpandedLinks) { - // const $card = $(link).closest(".note-book-card"); - // - // await this.expandCard($card); - // } - // } - // }); + $noteList.find('.expand-children-button').on('click', async () => { + for (let i = 1; i < 30; i++) { // protection against infinite cycle + const $unexpandedCards = $noteList.find('.note-book-card:not(.expanded)'); + + if ($unexpandedCards.length === 0) { + break; + } + + await toggleCards($unexpandedCards, true); + } + }); + + $noteList.find('.collapse-all-button').on('click', async () => { + const $expandedCards = $noteList.find('.note-book-card.expanded'); + + await toggleCards($expandedCards, false); + }); $noteList.on('click', '.note-book-hide-children-button', async ev => { const $card = $(ev.target).closest('.note-book-card'); @@ -198,7 +213,7 @@ async function renderNoteContent(note) { async function renderNote(note, expand) { const notePath = /*this.notePath + '/' + */ note.noteId; - const $expander = $(''); + const $expander = $(''); const $card = $('
') .attr('data-note-id', note.noteId) @@ -209,7 +224,7 @@ async function renderNote(note, expand) { .append(await linkService.createNoteLink(notePath, {showTooltip: false})) ); - $expander.on('click', async () => await toggleContent($card, note, !$expander.hasClass("expanded"))); + $expander.on('click', () => toggleContent($card, note, !$card.hasClass("expanded"))); await toggleContent($card, note, expand);