]> git.example.dev Git - binbsis50-sm.git/commitdiff
updated: working edit menu
author2weiEmu <saalbach.robert@outlook.de>
Thu, 28 May 2026 21:43:05 +0000 (23:43 +0200)
committer2weiEmu <saalbach.robert@outlook.de>
Thu, 28 May 2026 21:43:05 +0000 (23:43 +0200)
main.go
pkg/dbhandling/songsapi.go
public/css/index.css
public/index.html
public/js/index.js
songmanager

diff --git a/main.go b/main.go
index b81cb5ff2e34b817de5a3873a405c46b0e9891f0..4822ccaeccb4b9c986647d37821e02ad1de2e6f4 100644 (file)
--- 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
index 657a7532b8ed4b31ceca95bde6a1f4384aed4ab5..4022a4bace2fa85e11983850bfb8ad158202e2dc 100644 (file)
@@ -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)
index 4dcfc54ac11cdf644c41142bbdf17e851abb60a2..486003dd3079a180c8c3135df0356fbf9669e487 100644 (file)
                margin: 5px;
        }
 
+       #editMenuUpdateButton {
+               .success {
+                       background-color: rgb(106, 230, 130);
+               }
+       }
+
 
 }
 
index 29164c0403486b5fe87260e6852f3b1962a266eb..86007f362dd5c0e694dd0748b750bcdcb4dad981 100644 (file)
@@ -41,7 +41,7 @@
 
                        <br>
                        <button onclick="closeEditMenu()" id="editMenuCloseButton">Close</button>
-                       <button onclick="" id="editMenuUpdateButton">Update</button>
+                       <button onclick="updateSongUsingEditMenu()" id="editMenuUpdateButton">Update</button>
                </div>
        </div>
 
index 653013f8e717bd191f461c8c1c605f698c3fa87e..473cebcedd241993cd3310e63cbade8043127835 100644 (file)
@@ -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
  **/
index efd5226de1363b753aa7e7791644c1d0a77133b5..2356cd3f43cc9c7b24c2702b74d5c94344736b79 100755 (executable)
Binary files a/songmanager and b/songmanager differ