]> git.example.dev Git - binbsis50-sm.git/commitdiff
filtering of the main song list should be a thing now
author2weiEmu <saalbach.robert@outlook.de>
Tue, 26 May 2026 20:58:04 +0000 (22:58 +0200)
committer2weiEmu <saalbach.robert@outlook.de>
Tue, 26 May 2026 20:58:04 +0000 (22:58 +0200)
public/index.html
public/js/index.js
songmanager

index d4de36d1c724518a1ea76dea73ed347025be443d..f388c4000a9305e6a2347b9fcbb0dd244c05a03e 100644 (file)
@@ -17,7 +17,6 @@
                                <input placeholder="Name of a song..." id="songFilterName"></input>
                                <input placeholder="Name of an artist..." id="songFilterArtist"></input>
                                <input id="songFilterInDB" type="checkbox">In DB</input>
-                               <input id="songFilterImageExist" type="checkbox">Image Exists</input>
                                <button id="" onclick="getSongList()">Update Songs</button>
                        </div>
                        <div id="innerSongList">
index 16bf3e575367003b7a6cf6ba0560a8be22ddd018..71e80ab8287130c5a5730b3639fe816e915b3d31 100644 (file)
@@ -13,7 +13,6 @@ async function getSongFileList() {
        await fetch("/api/files/get", {'Accept': 'application/json', 'Content-type': 'application/json'}).then(async (response) => {
                let body = await response.json()
                songFileList = body
-               console.log(body)
        })
 }
 
@@ -85,7 +84,6 @@ function NewSongElement(exists, songName, artistName, imageUrl, id) {
  * @param {*} url - The URL that should be checked for in the song file list
  */
 function SongURLExists(url) {
-       console.log(url)
        return songFileList.indexOf(url) != -1
 }
 
@@ -112,10 +110,10 @@ function makeSongList(listOfSongs, appendElement) {
 function getSongList() {
        // Empty the List
        innerSongList.innerHTML = ""
+       songList = []
 
        fetch("/api/songs/get", {'Accept': 'application/json', 'Content-type': 'application/json'}).then(async (response) => {
                let body = await response.json()
-               console.log(body)
 
                for (let i = 0; i < body.length; i++) {
                        let song = body[i]
@@ -124,6 +122,8 @@ function getSongList() {
                        innerSongList.appendChild(NewSongElement(
                                fileAvailable, song.DisplayTrackName, song.DisplayArtistNames, song.ArtworkURL60, song.Key
                        ))
+
+                       songList.push(song)
                }
 
                // using the elements in the body, create all the new songs in the list
@@ -143,23 +143,54 @@ let songFilterInput = document.getElementById("songFilterInput")
 let songFilterName = document.getElementById("songFilterName")
 let songFilterArtist = document.getElementById("songFilterArtist")
 let songFilterInDB = document.getElementById("songFilterInDB")
-let songFilterImageExist = document.getElementById("songFilterImageExist")
 
 /**
- * Get the current state of filters, with fields NameFilter, ArtistFilter, DBFilter, ImageFilter
+ * Get the current state of filters, with fields NameFilter, ArtistFilter, DBFilter
  * @returns filterstates with fields mentioned above
  **/
 function getFilterStates() {
-       let filterStates
+       let filterStates = {}
 
        filterStates.NameFilter = songFilterName.value.toLowerCase()
        filterStates.ArtistFilter = songFilterArtist.value.toLowerCase()
        filterStates.DBFilter = songFilterInDB.checked
-       filterStates.ImageExist = songFilterImageExist.checked
 
        return filterStates
 }
 
+function updateSongListWithFilter(_) {
+       // get the filter states
+       let filters = getFilterStates()
+
+       // deep copy
+       let filteredList = [...songList]
+
+       // filter the song list using that
+       if (filters.DBFilter) {
+               filteredList = filteredList.filter((v, _1, _2) => { return SongURLExists(v.PreviewURL)})
+       }
+
+       if (filters.NameFilter != "") {
+               filteredList = filteredList.filter((v, _1, _2) => {
+                       return v.TrackName.toLowerCase().includes(filters.NameFilter.toLowerCase())
+               })
+       }
+
+       if (filters.ArtistFilter != "") {
+               filteredList = filteredList.filter((v, _1, _2) => {
+                       return v.ArtistName.toLowerCase().includes(filters.ArtistFilter.toLowerCase())
+               })
+       }
+
+       // now we have the filtered song list
+       innerSongList.innerHTML = ""
+       makeSongList(filteredList, innerSongList)
+}
+
+songFilterName.oninput = (event) => {updateSongListWithFilter(event)}
+songFilterArtist.oninput = (event) => {updateSongListWithFilter(event)}
+songFilterInDB.oninput = (event) => {updateSongListWithFilter(event)}
+
 /**
  * SETUP / RUN AT START SECTION
  **/
index d2b0a64e37f80c50538b476c61348cadafdbacc4..d9ce5422021551868b17e070fdea63f3b6a99af2 100755 (executable)
Binary files a/songmanager and b/songmanager differ