Created
July 31, 2022 12:50
-
-
Save etd2w/6587a93776222b519da5bd48ce25cbdb to your computer and use it in GitHub Desktop.
dataview_shows_db.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```dataviewjs | |
const createButton = (name) => { | |
const btn = dv.el('button', name) | |
btn.addEventListener('click', (event) => { | |
event.preventDefault() | |
removeTable() | |
renderTable(name) | |
}) | |
btn.style.flexGrow = '1' | |
return btn | |
} | |
const renderTable = (name) => { | |
const pages = dv.pages('"Shows DB/Shows"').where(page => page.status == name) | |
dv.header(2, name) | |
const tabel = dv.table(['Title', 'Rating', 'Runtime', 'Seasons', 'Ep watched/total'], pages.map(page => { | |
let watchedEp = 0 | |
const totalEp = page.episodes | |
page.file.tasks.values.forEach(el => { | |
if(el.checked) { | |
watchedEp += 1 | |
} | |
}) | |
return [page.file.link, page.rating, page.runtime, page.seasons, `${watchedEp}/${totalEp}`] | |
})) | |
} | |
const removeTable = () => { | |
this.container.lastChild.remove() | |
this.container.lastChild.remove() | |
} | |
const cont = dv.el('div', null) | |
cont.style.display = 'flex' | |
cont.style.padding = '2px 0' | |
cont.firstChild.remove() | |
cont.append(createButton('Watching'), createButton('Going to watch'), createButton('Watched all'), createButton('Stopped watching')) | |
renderTable('Watching') | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment