]> git.example.dev Git - binbsis50-sm.git/commitdiff
added: showing what songs are in what room
author2weiEmu <saalbach.robert@outlook.de>
Sat, 13 Jun 2026 15:13:49 +0000 (17:13 +0200)
committer2weiEmu <saalbach.robert@outlook.de>
Sat, 13 Jun 2026 15:13:49 +0000 (17:13 +0200)
main.go
public/js/room.js [new file with mode: 0644]
public/rooms.html
songmanager
testing/songs/Enigma_Sadeness.m4a [new file with mode: 0644]

diff --git a/main.go b/main.go
index 81e0af9f26ece177e7f7b11a59738af04a5879c1..d12e12c096d9463de7828ccbf4ac9e3b89413f74 100644 (file)
--- 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 (file)
index 0000000..279129b
--- /dev/null
@@ -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()
index 452c03eaee739b01d702f4ecce21b2dcf618ba3e..1a4ee4ae65098ebb5e00e5995361f161fbc24431 100644 (file)
@@ -7,6 +7,19 @@
        </head>
 
        <body>
+               <label for="rooms">Select a Room to View</label>
+               <select name="rooms" id="roomSelect">
+                       
+               </select>
+               <ul id="inRoomList">
+               </ul>
+
+               <hr>
+
+               <ul id="outRoomList">
+               </ul>
        </body>
+
+       <script src="/js/room.js"></script>
 </html>
 
index ade57ed9516ca967d429f12a0e1f59c50c4f6831..c6c154982959f6452351b40e5eeb3e61d5479a7a 100755 (executable)
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 (file)
index 0000000..e69de29