// 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)
--- /dev/null
+/**
+ * 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()