From: 2weiEmu Date: Thu, 28 May 2026 21:43:05 +0000 (+0200) Subject: updated: working edit menu X-Git-Url: https://git.saalbach.dev/?a=commitdiff_plain;h=bd3dd1bb82874a4db0f190bc0d5a387c024109c3;p=binbsis50-sm.git updated: working edit menu --- diff --git a/main.go b/main.go index b81cb5f..4822cca 100644 --- a/main.go +++ b/main.go @@ -54,7 +54,7 @@ func main() { // api/songs/ - api related to raw songs mux.HandleFunc("GET /api/songs/get", DBwrapper.SongsGet) mux.HandleFunc("POST /api/songs/create", DBwrapper.SongsCreate) - mux.HandleFunc("PUT /api/songs/update/{id}", DBwrapper.SongsUpdateById) + mux.HandleFunc("PUT /api/songs/update", DBwrapper.SongsUpdateById) mux.HandleFunc("DELETE /api/songs/delete/{id}", DBwrapper.SongsDeleteById) // api/rooms - api related to managaing rooms diff --git a/pkg/dbhandling/songsapi.go b/pkg/dbhandling/songsapi.go index 657a753..4022a4b 100644 --- a/pkg/dbhandling/songsapi.go +++ b/pkg/dbhandling/songsapi.go @@ -120,7 +120,6 @@ func (dbw *DBWrapper) SongsCreate(w http.ResponseWriter, r *http.Request) { * TODO: **/ func (dbw *DBWrapper) SongsUpdateById(w http.ResponseWriter, r *http.Request) { - // the ID should be as 'song:XX' in the KEY section of DB song // then all the non-zero / non-empty fields will be updated on that song newSong := DBSong{} err := json.NewDecoder(r.Body).Decode(&newSong) diff --git a/public/css/index.css b/public/css/index.css index 4dcfc54..486003d 100644 --- a/public/css/index.css +++ b/public/css/index.css @@ -51,6 +51,12 @@ margin: 5px; } + #editMenuUpdateButton { + .success { + background-color: rgb(106, 230, 130); + } + } + } diff --git a/public/index.html b/public/index.html index 29164c0..86007f3 100644 --- a/public/index.html +++ b/public/index.html @@ -41,7 +41,7 @@
- + diff --git a/public/js/index.js b/public/js/index.js index 653013f..473cebc 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -1,5 +1,10 @@ let songList = [] + +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); +} + /** * SONG FILE LIST SECTION */ @@ -209,6 +214,8 @@ let editMenuArtworkURL100 = document.getElementById("editMenuArtworkURL100") let editMenuDisplayArtistNames = document.getElementById("editMenuDisplayArtistNames") let editMenuDisplayTrackName = document.getElementById("editMenuDisplayTrackName") +let editMenuUpdateButton = document.getElementById("editMenuUpdateButton") + function openEditMenu(songId) { console.log("songid", songId) @@ -224,7 +231,7 @@ function openEditMenu(songId) { function openEditMenuWithSong(song) { editMenu.style.display = "block"; - editMenuSongKey.value = song.Key + editMenuSongKey.innerText = song.Key editMenuArtistName.value = song.ArtistName editMenuTrackName.value = song.TrackName editMenuTrackViewURL.value = song.TrackViewURL @@ -242,6 +249,37 @@ function closeEditMenu() { editMenu.style.display = "none"; } +async function updateSongUsingEditMenu() { + let songUpdate = { + Key: editMenuSongKey.innerText, + ArtistName: editMenuArtistName.value, + TrackName: editMenuTrackName.value, + TrackViewURL: editMenuTrackViewURL.value, + PreviewURL: editMenuPreviewURL.value, + ArtworkURL60: editMenuArtworkURL60.value, + ArtworkURL100: editMenuArtworkURL100.value, + DisplayArtistNames: editMenuDisplayArtistNames.value, + DisplayTrackName: editMenuDisplayTrackName.value + } + + let response = await fetch("/api/songs/update", { + method: "PUT", + body: JSON.stringify(songUpdate) + }) + + if (response.status != 200) { + alert("Failed to update the song... harass admin") + } else { + editMenuUpdateButton.innerText = "Success!" + editMenuUpdateButton.classList = "success" + + await sleep(500) + + editMenuUpdateButton.innerText = "Update" + editMenuUpdateButton.classList = "" + } +} + /** * SETUP / RUN AT START SECTION **/ diff --git a/songmanager b/songmanager index efd5226..2356cd3 100755 Binary files a/songmanager and b/songmanager differ