Cleaner management of MPD search filters on the frontend

This commit is contained in:
Fabio Manganiello 2018-04-15 10:03:34 +02:00
parent 73c74654d1
commit 400943b74b

View file

@ -649,39 +649,10 @@ $(document).ready(function() {
return obj; return obj;
}, {}); }, {});
var args = {}; var filter = [];
var searchFilters = {}; for (var searchItem of Object.keys(searchData)) {
filter.push(searchItem);
if ('any' in searchData) { filter.push(searchData[searchItem]);
args = {
filter: ['any', searchData.any]
};
searchFilters.any = searchData.any;
} else {
if ('title' in searchData) {
args = {
filter: ['title', searchData.title]
};
searchFilters.title = searchData.title;
}
if ('album' in searchData) {
args = {
filter: ['album', searchData.album]
};
searchFilters.album = searchData.album;
}
if ('albumartist' in searchData) {
args = {
filter: ['albumartist', searchData.albumartist]
};
searchFilters.albumartist = searchData.albumartist;
}
} }
$(this).find('input').prop('disabled', true); $(this).find('input').prop('disabled', true);
@ -690,7 +661,9 @@ $(document).ready(function() {
{ {
type: 'request', type: 'request',
action: 'music.mpd.search', action: 'music.mpd.search',
args: args args: {
filter: filter
}
}, },
onSuccess = function(response) { onSuccess = function(response) {
@ -699,20 +672,20 @@ $(document).ready(function() {
return false; return false;
} }
if (Object.keys(searchFilters).length > 1) { if (Object.keys(searchData).length > 1) {
results = results.filter(function(item) { results = results.filter(function(item) {
return ( return (
('title' in searchFilters ('title' in searchData
? (item.title || '').toLowerCase().indexOf( ? (item.title || '').toLowerCase().indexOf(
searchFilters.title.toLowerCase()) >= 0 searchData.title.toLowerCase()) >= 0
: true) && : true) &&
('album' in searchFilters ('album' in searchData
? (item.album || '').toLowerCase().indexOf( ? (item.album || '').toLowerCase().indexOf(
searchFilters.album.toLowerCase()) >= 0 searchData.album.toLowerCase()) >= 0
: true) && : true) &&
('albumartist' in searchFilters ('albumartist' in searchData
? (item.artist || '').toLowerCase().indexOf( ? (item.artist || '').toLowerCase().indexOf(
searchFilters.albumartist.toLowerCase()) >= 0 searchData.albumartist.toLowerCase()) >= 0
: true) : true)
); );
}); });