From: 2weiEmu Date: Sat, 13 Jun 2026 15:13:49 +0000 (+0200) Subject: added: showing what songs are in what room X-Git-Url: https://git.saalbach.dev/?a=commitdiff_plain;h=365ff04d45f91f17170588223b8d2631bf099e30;p=binbsis50-sm.git added: showing what songs are in what room --- diff --git a/main.go b/main.go index 81e0af9..d12e12c 100644 --- a/main.go +++ b/main.go @@ -59,7 +59,7 @@ func main() { // api/rooms - api related to managaing rooms mux.HandleFunc("GET /api/rooms/get/{name}", DBwrapper.RoomsGetByName) - mux.HandleFunc("GET /api/rooms/get/all", DBwrapper.RoomsGet) + mux.HandleFunc("GET /api/rooms/all", DBwrapper.RoomsGet) mux.HandleFunc("PUT /api/rooms/add/{name}", DBwrapper.RoomsAddByNameAndId) mux.HandleFunc("PUT /api/rooms/remove/{name}", DBwrapper.RoomsRemoveByNameAndId) mux.HandleFunc("DELETE /api/rooms/delete/{name}", DBwrapper.RoomsDeleteByName) diff --git a/public/js/room.js b/public/js/room.js new file mode 100644 index 0000000..279129b --- /dev/null +++ b/public/js/room.js @@ -0,0 +1,104 @@ +/** + * SONG LIST + **/ +let songList = [] + +async function getSongList() { + let response = await fetch("/api/songs/get", { + method: "GET" + }) + + if (response.status != 200) { + alert("Failed to get the list of songs... harass admin") + return + } + + songList = await response.json() +} + +/** + * LIST ELEMENTS + **/ + +function makeListElementWithSong(song) { + let el = document.createElement("div") + el.id = song.Key // should be unique on page + + let text = document.createElement("p") + text.innerText = song.DisplayTrackName + " by " + song.DisplayArtistNames + el.appendChild(text) + + return el +} + + +/** + * ROOM SELECTION + **/ +let roomSelect = document.getElementById("roomSelect") + + +async function populateRoomSelect() { + // first get all the rooms + + let response = await fetch("/api/rooms/all", { + method: "GET", + }) + + if (response.status != 200) { + alert("Could not get room names... harass admin") + return + } + + let roomNames = await response.json() + roomSelect.innerHTML = "" + + for (let i = 0; i < roomNames.length; i++) { + let newOption = document.createElement("option") + let roomName = roomNames[i] + newOption.value = roomName + newOption.text = roomName + roomSelect.appendChild(newOption) + } +} + +let inRoomList = document.getElementById("inRoomList") +let outRoomList = document.getElementById("outRoomList") + +roomSelect.addEventListener("change", async (event) => { + let room = event.target.value + + // fuck caching, it should be fast enough so we always fetch anew + let response = await fetch("/api/rooms/get/" + room, { + method: "GET", + }) + + if (response.status != 200) { + alert("Failed to get the songs for a corresponding room: ", room, "... harass admin.") + return + } + let ids = await response.json() + + // now that we have the songs and their ID's we can arrange the lists correctly + let inList = songList.filter((v, _i, _a) => { return ids.includes(v.Key.replace("song:", "")) }) + + inRoomList.innerHTML = "" + for (let i = 0; i < inList.length; i++) { + let song = inList[i] + inRoomList.appendChild(makeListElementWithSong(song)) + } + + let outList = songList.filter((v, _i, _a) => { return !ids.includes(v.Key.replace("song:", "")) }) + + outRoomList.innerHTML = "" + for (let i = 0; i < outList.length; i++) { + let song = outList[i] + outRoomList.appendChild(makeListElementWithSong(song)) + } +}) + +/** + * ON LOAD + **/ +getSongList() +populateRoomSelect() diff --git a/public/rooms.html b/public/rooms.html index 452c03e..1a4ee4a 100644 --- a/public/rooms.html +++ b/public/rooms.html @@ -7,6 +7,19 @@ + + + + +
+ + + + diff --git a/songmanager b/songmanager index ade57ed..c6c1549 100755 Binary files a/songmanager and b/songmanager differ diff --git a/testing/songs/Enigma_Sadeness.m4a b/testing/songs/Enigma_Sadeness.m4a new file mode 100644 index 0000000..e69de29