Use strict album-title-artist existence matching and add exists/missing result filter
This commit is contained in:
parent
a42e5e2542
commit
b021df31b4
3 changed files with 114 additions and 11 deletions
|
|
@ -1,6 +1,7 @@
|
|||
const queryInput = document.getElementById('query');
|
||||
const searchBtn = document.getElementById('searchBtn');
|
||||
const searchTypeSelect = document.getElementById('searchType');
|
||||
const existsFilterSelect = document.getElementById('existsFilter');
|
||||
const results = document.getElementById('results');
|
||||
const statusEl = document.getElementById('status');
|
||||
const dialog = document.getElementById('albumDialog');
|
||||
|
|
@ -23,6 +24,7 @@ let selectedAlbum = null;
|
|||
let sendContext = null;
|
||||
let playlistTracks = [];
|
||||
let jobs = [];
|
||||
let lastSearch = { type: null, items: [] };
|
||||
|
||||
const CLEANUP_KEY = 'cleanupExtras';
|
||||
cleanupToggle.checked = localStorage.getItem(CLEANUP_KEY) === 'true';
|
||||
|
|
@ -128,12 +130,14 @@ function createPlaylistTrackCard(track, idx) {
|
|||
}
|
||||
|
||||
function renderItems(type, items) {
|
||||
lastSearch = { type, items: Array.isArray(items) ? items : [] };
|
||||
results.innerHTML = '';
|
||||
if (!items.length) {
|
||||
const filtered = applyExistsFilter(lastSearch.items, type);
|
||||
if (!filtered.length) {
|
||||
results.innerHTML = '<p>Keine Treffer gefunden.</p>';
|
||||
return;
|
||||
}
|
||||
for (const item of items) {
|
||||
for (const item of filtered) {
|
||||
let card;
|
||||
if (type === 'track') card = createTrackCard(item);
|
||||
if (type === 'artist') card = createArtistCard(item);
|
||||
|
|
@ -142,6 +146,19 @@ function renderItems(type, items) {
|
|||
}
|
||||
}
|
||||
|
||||
function applyExistsFilter(items, type) {
|
||||
const mode = existsFilterSelect.value || 'all';
|
||||
if (mode === 'all') return items;
|
||||
if (type === 'artist') return items;
|
||||
|
||||
return (items || []).filter((item) => {
|
||||
const exists = Boolean(item.exists);
|
||||
if (mode === 'exists') return exists;
|
||||
if (mode === 'missing') return !exists;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
function updateDialogActionButton() {
|
||||
const rows = Array.from(trackList.querySelectorAll('input[type="checkbox"]'));
|
||||
const selected = rows.filter((x) => x.checked).map((x) => ({
|
||||
|
|
@ -344,13 +361,16 @@ async function updateFrontendFromGit() {
|
|||
}
|
||||
|
||||
function renderPlaylist() {
|
||||
lastSearch = { type: 'playlist-track', items: playlistTracks.slice() };
|
||||
results.innerHTML = '';
|
||||
if (!playlistTracks.length) {
|
||||
const filtered = applyExistsFilter(playlistTracks, 'track');
|
||||
if (!filtered.length) {
|
||||
results.innerHTML = '<p>Keine Playlist-Tracks gefunden.</p>';
|
||||
playlistActions.style.display = 'none';
|
||||
return;
|
||||
}
|
||||
playlistTracks.forEach((track, idx) => {
|
||||
filtered.forEach((track) => {
|
||||
const idx = playlistTracks.indexOf(track);
|
||||
const card = createPlaylistTrackCard(track, idx);
|
||||
const cb = card.querySelector('input[type="checkbox"]');
|
||||
cb.addEventListener('change', () => {
|
||||
|
|
@ -433,5 +453,14 @@ updateLibraryBtn.addEventListener('click', updateLibrary);
|
|||
updateFrontendBtn.addEventListener('click', updateFrontendFromGit);
|
||||
importPlaylistBtn.addEventListener('click', importPlaylist);
|
||||
sendPlaylistBtn.addEventListener('click', sendPlaylistSelection);
|
||||
existsFilterSelect.addEventListener('change', () => {
|
||||
if (lastSearch.type === 'playlist-track') {
|
||||
renderPlaylist();
|
||||
return;
|
||||
}
|
||||
if (lastSearch.type) {
|
||||
renderItems(lastSearch.type, lastSearch.items);
|
||||
}
|
||||
});
|
||||
|
||||
renderJobs();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue