From 6bc7063c68be760a52f621d2e3d77c89af21852b Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Sun, 23 Jul 2023 12:15:20 +0200 Subject: show votes and the time bonus in the song details --- TODO.md | 2 +- web/client.html | 15 +++++++++++++-- wrms.go | 4 ++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/TODO.md b/TODO.md index 2448bf4..b534b4e 100644 --- a/TODO.md +++ b/TODO.md @@ -18,7 +18,7 @@ - [X] support incremental search results - [X] distinguish different search queries - [X] do not apply obsolete events -- [ ] support timeBonus +- [X] support timeBonus ## Web Backend diff --git a/web/client.html b/web/client.html index 51ddf3b..bc49369 100644 --- a/web/client.html +++ b/web/client.html @@ -112,8 +112,8 @@ } function appendSongDetails(song, details) { - let possibleDetails = ['upvotes', 'downvotes', 'album', 'year']; - for (const detail of possibleDetails) { + let possibleSimpleDetails = ['album', 'year']; + for (const detail of possibleSimpleDetails) { if (Object.hasOwn(song, detail)) { let value = song[detail]; if (!value) { @@ -123,6 +123,17 @@ details.appendChild(document.createTextNode(label + ': ' + value + ' ')); } } + + if (Object.hasOwn(song, 'upvotes') && Object.hasOwn(song, 'downvotes')) { + let uvs = Object.keys(song['upvotes']).length + details.appendChild(document.createTextNode('Upvotes: ' + uvs + ' ')); + + let dvs = Object.keys(song['downvotes']).length + details.appendChild(document.createTextNode('Downvotes: ' + dvs + ' ')); + + let timeBonus = song.weight - uvs + dvs + details.appendChild(document.createTextNode('TimeBonus: ' + timeBonus.toFixed(1) + ' ')); + } } function newSong(song) { diff --git a/wrms.go b/wrms.go index f225b2a..c6d6086 100644 --- a/wrms.go +++ b/wrms.go @@ -22,8 +22,8 @@ type Song struct { Album string `json:"album"` Year int `json:"year"` index int `json:"-"` // used by heap.Interface - Upvotes map[uuid.UUID]struct{} `json:"-"` - Downvotes map[uuid.UUID]struct{} `json:"-"` + Upvotes map[uuid.UUID]struct{} `json:"upvotes"` + Downvotes map[uuid.UUID]struct{} `json:"downvotes"` } func NewSong(title, artist, source, uri string) *Song { -- cgit v1.2.3