From: 2weiEmu Date: Tue, 26 May 2026 20:58:04 +0000 (+0200) Subject: filtering of the main song list should be a thing now X-Git-Url: https://git.saalbach.dev/?a=commitdiff_plain;h=fea9df345c3c9033dfc505c2e5772521568f585d;p=binbsis50-sm.git filtering of the main song list should be a thing now --- diff --git a/public/index.html b/public/index.html index d4de36d..f388c40 100644 --- a/public/index.html +++ b/public/index.html @@ -17,7 +17,6 @@ In DB - Image Exists
diff --git a/public/js/index.js b/public/js/index.js index 16bf3e5..71e80ab 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -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 **/ diff --git a/songmanager b/songmanager index d2b0a64..d9ce542 100755 Binary files a/songmanager and b/songmanager differ