From: Chris Fulljames Date: Sat, 15 Feb 2025 23:58:03 +0000 (-0500) Subject: Fix playlist editor bugs X-Git-Url: https://littlesong.place/gitweb/gitweb.cgi?a=commitdiff_plain;h=ffa9e4d7a6233eb646d2356ee7161fc83ef5c50c;p=littlesongplace.git Fix playlist editor bugs --- diff --git a/main.py b/main.py index aee0141..86987b2 100644 --- a/main.py +++ b/main.py @@ -821,6 +821,7 @@ def edit_playlist_post(playlistid): # Re-add songs with new positions for position, songid in enumerate(songids): + print(position, songid) query_db("insert into playlist_songs (playlistid, position, songid) values (?, ?, ?)", args=[playlistid, position, songid]) # Update private, name @@ -856,6 +857,7 @@ def playlists(playlistid): "playlist.html", name=plist_data["name"], playlistid=plist_data["playlistid"], + private=plist_data["private"], userid=plist_data["userid"], username=plist_data["username"], songs=songs, @@ -1034,8 +1036,9 @@ class Song: select * from playlist_songs inner join songs on playlist_songs.songid = songs.songid inner join users on songs.userid = users.userid + where playlistid = ? order by playlist_songs.position asc - """) + """, [playlistid]) @classmethod def _from_db(cls, query, args=()): diff --git a/templates/playlist.html b/templates/playlist.html index f2f622a..15e2d6e 100644 --- a/templates/playlist.html +++ b/templates/playlist.html @@ -47,9 +47,9 @@ function deletePlaylist() {
- + - +
@@ -58,12 +58,12 @@ function deletePlaylist() {
{%- for song in songs %} -
+
{{ song.title }} - {{ song.username }} - -
@@ -87,50 +87,56 @@ function deletePlaylist() { for (const entry of editList.children) { var songidSpan = entry.querySelector(".songid"); if (songidSpan) { - console.log(songidSpan.textContent); songids.push(songidSpan.textContent); } } songids = songids.join(","); - console.log(songids); var songidsInput = form.querySelector("#playlist-songids-input"); songidsInput.value = songids; } + function onSongDragStart(event) { var list = event.currentTarget.closest(".edit-list"); var index = [...list.children].indexOf(event.currentTarget); event.dataTransfer.setData("text", index.toString()); event.dataTransfer.effectAllowed = "move"; } + function onSongDragOver(event) { event.preventDefault(); event.dataTransfer.dropEffect = "move"; - var list = event.currentTarget.closest(".edit-list"); - for (const child of list.children) { - child.style.borderTop = ""; - child.style.borderBottom = ""; - } + clearDragMarker(event); if (event.currentTarget.previousElementSibling) { event.currentTarget.previousElementSibling.style.borderBottom = "3px solid var(--purple)"; } event.currentTarget.style.borderTop = "3px solid var(--purple)"; } + function onSongDrop(event) { event.preventDefault(); const data = event.dataTransfer.getData("text"); var sourceIndex = parseInt(data); var list = event.currentTarget.closest(".edit-list"); - for (const child of list.children) { - child.style.borderTop = ""; - child.style.borderBottom = ""; - } var sourceElement = list.children[sourceIndex]; + clearDragMarker(event); if (sourceElement !== event.currentTarget) { sourceElement.remove(); list.insertBefore(sourceElement, event.currentTarget); } } + + function clearDragMarker(event) { + var list = event.currentTarget.closest(".edit-list"); + for (const child of list.children) { + child.style.borderTop = ""; + child.style.borderBottom = ""; + } + } + + function removeSong(event) { + event.currentTarget.closest(".draggable-song").remove(); + }
{%- endif %} diff --git a/templates/song-list.html b/templates/song-list.html index 3ec4440..829176f 100644 --- a/templates/song-list.html +++ b/templates/song-list.html @@ -59,10 +59,10 @@
- {% for plist in current_user_playlists -%} - + {%- endfor %}