diff options
| -rw-r--r-- | TODO.md | 2 | ||||
| -rw-r--r-- | web/client.html | 15 | ||||
| -rw-r--r-- | wrms.go | 4 |
3 files changed, 16 insertions, 5 deletions
@@ -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) { @@ -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 { |
