From 71ecff688711520508d976385dbf89d924c52ef5 Mon Sep 17 00:00:00 2001 From: 2weiEmu Date: Mon, 15 Jun 2026 15:52:44 +0200 Subject: [PATCH] updated: remove the old code --- public/js/index.js | 273 --------------------------------------------- 1 file changed, 273 deletions(-) diff --git a/public/js/index.js b/public/js/index.js index f5f4da1..84586d4 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -472,276 +472,3 @@ async function uploadFileWithDataAndName() { getSongFileList() getSongList() -// ============================================================== -/* -let AllSongs = null -let AllFilenames = null -let currentEditSong = null -let dbSongList = document.getElementById("db_status_song_list") -let editElement = document.getElementById("editElement") - - -let songFileList = document.getElementById("song_file_list") - - -let updateSongFile = document.getElementById("updateSongFile") -let editArtistName = document.getElementById("editArtistName") -let editTrackName = document.getElementById("editTrackName") -let editTrackViewUrl = document.getElementById("editTrackViewUrl") -let editPreviewUrl = document.getElementById("editPreviewUrl") -let editArtworkUrl60 = document.getElementById("editArtworkUrl60") -let editArtworkUrl100 = document.getElementById("editArtworkUrl100") -let editDisplayArtistNames = document.getElementById("editDisplayArtistNames") -let editDisplayTrackName = document.getElementById("editDisplayTrackName") - -updateSongFile.onclick = (event) => { sendUpdateSongName(event) } - -function getSongUsingKey(key) { - for (let song of AllSongs) { - if (song.Key == key) { - return song - } - } - return null -} - -function songHasValidFilename(song) { - return AllFilenames.includes(song.PreviewURL) -} - -function openEditElement(song) { - editElement.style.display = "block" - editArtistName.value = song.ArtistName - editTrackName.value = song.TrackName - editTrackViewUrl.value = song.TrackViewURL - editPreviewUrl.value = song.PreviewURL - editArtworkUrl60.value = song.ArtworkURL60 - editArtworkUrl100.value = song.ArtworkURL100 - editDisplayArtistNames.value = song.DisplayArtistNames - editDisplayTrackName.value = song.DisplayTrackName - - updateSongFile.className = song.Key - - editArtistName.focus() -} - - -function closeEditElement() { - editElement.style.display = "none" -} - -function editSong(event) { - console.log(event.srcElement.parentNode.id) - let id = event.srcElement.parentNode.id - let songKey = id.split("=")[1] - - let song = getSongUsingKey(songKey) - currentEditSong = songKey - console.log(song) - - openEditElement(song) -} - -async function sendUpdateSongName(event) { - let key = event.srcElement.className - let NewFilename = editPreviewUrl.value - console.log("updating song name") - console.log(key, NewFilename) - - await fetch("/api/renameSong", { - method: "POST", - body: JSON.stringify({ - Key: key, - NewFilename: NewFilename - }) - }) - - get_updated_status() -} - -function newSongDisplayWithEdit(song) { - let wrap = document.createElement("div") - wrap.id = "key=" + song.Key - let info = document.createElement("p") - info.style.display = "inline-block" - info.style.margin = "7px 5px 7px 5px" - info.style.padding = "2px 5px 2px 5px" - info.style.minWidth = "400px" - - let check = "❌" - - if (songHasValidFilename(song)) { - check = "✅" - } - - info.innerText = check + "(" + song.Key + ") " + song.DisplayTrackName + " by " + song.DisplayArtistNames.replace("~", ", ") - - let but = document.createElement("button") - but.innerText = "Edit" - - but.onclick = (event) => {editSong(event)} - - - wrap.appendChild(info) - wrap.appendChild(but) - - return wrap -} - - -let allSongFilterList = document.getElementById("allSongFilterList") -allSongFilterList.oninput = (event) => {filterAllSongs(event)} - -function filterSongByAllAttrs(filter, song) { - return song.Key.includes(filter) || song.ArtistName.toLowerCase().includes(filter) || - song.TrackName.toLowerCase().includes(filter) -} - -function filterAllSongs(_) { - console.log("Firing input trigger") - let filterBy = allSongFilterList.value.toLowerCase() - let filters = filterBy.split(" ") - - if (AllSongs == null) { - console.log("all songs was null") - return - } - - if (filterBy == "") { - get_updated_status() - return - } - - dbSongList.innerHTML = "" - let addSong = true - - for (let song of AllSongs) { - addSong = true - for (let filter of filters) { - addSong = addSong && filterSongByAllAttrs(filter, song) - } - - if (addSong) { - let li = document.createElement("li") - li.appendChild(newSongDisplayWithEdit(song)) - dbSongList.appendChild(li) - } - } - - console.log("function done") -} - - -async function get_updated_status() { - console.log("updating database status...") - dbSongList.innerHTML = "" - - fetch("/api/db_status_update", {'Accept': 'application/json', 'Content-type': 'application/json'}).then(async (response) => { - const body = await response.json() - - // update total song list - AllSongs = body.AllSongs - for (let song of body.AllSongs) { - let li = document.createElement("li") - li.appendChild(newSongDisplayWithEdit(song)) - dbSongList.appendChild(li) - } - - // update list of rooms - let room_list = document.getElementById("list_of_rooms") - room_list.innerHTML = "" - - for (let room of body.Rooms) { - let header = document.createElement("h3") - header.innerText = room.Name - let new_list = document.createElement("ul") - new_list.id = "room:" + room.Name - - room_list.appendChild(header) - room_list.appendChild(new_list) - } - }) - - fetch("/api/getSongFiles", - {'Accept': 'application/json', 'Content-type': 'application/json'} - ).then(async (response) => { - const body = await response.json() - songFileList.innerHTML = "" - AllFilenames = body.SongFileList - - for (let filename of body.SongFileList) { - let li = document.createElement("li") - li.innerText = filename - li.onclick = (event) => { renameFileItself(event) } - songFileList.appendChild(li) - } - - }) -} - -window.onload = () => { - get_updated_status() -} - -async function setNewSongValue() { - let newArtistName = editArtistName.value - let newTrackName = editTrackName.value - let newTrackViewUrl = editTrackViewUrl.value - let newPreviewUrl = editPreviewUrl.value - let newArtworkUrl60 = editArtworkUrl60.value - let newArtworkUrl100 = editArtworkUrl100.value - let newDisplayArtistNames = editDisplayArtistNames.value - let newDisplayTrackName = editDisplayTrackName.value - - await fetch("/api/updateSong", { - method: "POST", - body: JSON.stringify({ - Key: currentEditSong, - ArtistName: newArtistName, - TrackName: newTrackName, - TrackViewURL: newTrackViewUrl, - PreviewURL: newPreviewUrl, - ArtworkURL60: newArtworkUrl60, - ArtworkURL100: newArtworkUrl100, - DisplayArtistNames: newDisplayArtistNames, - DisplayTrackName: newDisplayTrackName, - }) - }) - - get_updated_status() - //await fetch("https://binb.sis50.nl/reloadRooms") -} - -async function renameFileItself(event) { - let oldFilename = event.srcElement.innerText - let newFile = prompt("Change the file name", oldFilename) - - await fetch("/api/renameSongRaw", { - method: "POST", - body: JSON.stringify({ - OldFileName: oldFilename, - NewFileName: newFile - }) - }) - - get_updated_status() -} - -function closeIfNotInEditor(event) { - console.log("Focus has changd") - if (!editElement.contains(event.relatedTarget)) { - console.log("Closing Element") - closeEditElement() - } -} - -editElement.addEventListener("focusout", closeIfNotInEditor) -editArtistName.addEventListener("focusout", closeIfNotInEditor) -editTrackName.addEventListener("focusout", closeIfNotInEditor) -editTrackViewUrl.addEventListener("focusout", closeIfNotInEditor) -editPreviewUrl.addEventListener("focusout", closeIfNotInEditor) -editArtworkUrl60.addEventListener("focusout", closeIfNotInEditor) -editArtworkUrl100.addEventListener("focusout", closeIfNotInEditor) -editDisplayArtistNames.addEventListener("focusout", closeIfNotInEditor) - -*/ -- 2.54.0