diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2023-07-23 12:15:20 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2023-07-23 12:15:20 +0200 |
| commit | 6bc7063c68be760a52f621d2e3d77c89af21852b (patch) | |
| tree | 0bc472cd6dc88bcd444ee753ac939b5542ceb6b9 | |
| parent | 26f0033ebb5f8e7c204a042709e3dfa885eac868 (diff) | |
| download | WRMS-6bc7063c68be760a52f621d2e3d77c89af21852b.tar.gz WRMS-6bc7063c68be760a52f621d2e3d77c89af21852b.zip | |
show votes and the time bonus in the song details
| -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 { |
