From 208a9b2e97d6c79218799cd7995d4d83a2bc5e99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Mart=C3=ADnez=20Portela?= Date: Sun, 30 Oct 2022 23:58:44 +0100 Subject: [PATCH] Show notes TO-DO on search, mark them as such. --- static/search-box.js | 37 ++++++++++++++++++++++--------------- static/style.css | 5 +++++ 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/static/search-box.js b/static/search-box.js index 6531fce..3bac4a5 100644 --- a/static/search-box.js +++ b/static/search-box.js @@ -80,22 +80,29 @@ function _codigoparallevar_enable_search_box(selector, options) { } resultsList.innerHTML = ''; - for (const note of body.results.notes) { - if (note.is_todo === "1") { - continue; + for (const list of [ + body.results.notes.filter(n => n.is_todo !== "1"), + body.results.notes.filter(n => n.is_todo === "1"), + ]){ + for (const note of list) { + const resultCard = document.createElement('li'); + + const resultContents = document.createElement('a'); + resultContents.setAttribute('href', './' + note.id + '.node.html'); + + const resultTitle = document.createElement('h2'); + resultTitle.innerText = `${note.title} (${note.top_level_title})`; + if (note.is_todo === "1") { + resultTitle.setAttribute('class', 'is-todo'); + } + else if (note.is_done === "1") { + resultTitle.setAttribute('class', 'is-done'); + } + + resultContents.appendChild(resultTitle); + resultCard.appendChild(resultContents); + resultsList.appendChild(resultCard); } - - const resultCard = document.createElement('li'); - - const resultContents = document.createElement('a'); - resultContents.setAttribute('href', './' + note.id + '.node.html'); - - const resultTitle = document.createElement('h2'); - resultTitle.innerText = `${note.title} (${note.top_level_title})`; - - resultContents.appendChild(resultTitle); - resultCard.appendChild(resultContents); - resultsList.appendChild(resultCard); } if (body.results.notes.length == 0) { noResultsBox.classList.remove('hidden'); diff --git a/static/style.css b/static/style.css index a4ad7ac..8c9550b 100644 --- a/static/style.css +++ b/static/style.css @@ -87,6 +87,11 @@ body nav input { margin: 0; } +.results-box li h2.is-todo::before { + content: ' [TODO] '; + color: #D00; +} + .no-results-box { padding: 1rem; }