From 78c1aae4e42d10380aad3319aaead47505505b0b Mon Sep 17 00:00:00 2001 From: jcorporation Date: Fri, 25 May 2018 00:08:33 +0100 Subject: [PATCH] Queue Search --- htdocs/js/mpd.js | 23 +++++++++++++---------- src/mpd_client.c | 12 +++++++----- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/htdocs/js/mpd.js b/htdocs/js/mpd.js index 0478c83..24db04c 100644 --- a/htdocs/js/mpd.js +++ b/htdocs/js/mpd.js @@ -46,6 +46,7 @@ var app = $.sammy(function() { $('#cardBrowse').addClass('hide'); $('#cardSearch').addClass('hide'); $('.pagination').addClass('hide'); + $('#searchqueue > input').val(''); pagination = 0; browsepath = ''; } @@ -223,7 +224,7 @@ function webSocketConnect() { $('#queueList > tbody').empty(); for (var song in obj.data) { if (obj.data[song].type == 'wrap') { - $('#'+current_app+'List > tbody').append( + $('#queueList > tbody').append( "error_outline" + "Too many results, please refine your search!" + "" @@ -251,7 +252,9 @@ function webSocketConnect() { $('#queuePrev').removeClass('disabled'); $('#queuePagination').removeClass('hide'); } - } + } else { + $('#queuePagination').addClass('hide'); + } if ( isTouch ) { $('#queueList > tbody > tr > td:last-child').append( @@ -726,15 +729,15 @@ $('#search').submit(function () { }); $('#searchqueue > input').keyup(function (event) { -// if ( event.which == 13 ) { - var searchstr=$('#searchqueue > input').val(); - if (searchstr.length > 3) { - socket.send('MPD_API_SEARCH_QUEUE,' + searchstr); + var searchstr=$('#searchqueue > input').val(); + if ( event.which == 13 ) { + if (searchstr.length >= 3) { + socket.send('MPD_API_SEARCH_QUEUE,' + searchstr); } - else if (searchstr.length == 0) { - socket.send('MPD_API_GET_QUEUE,0'); - } -// } + } + if (searchstr.length == 0) { + socket.send('MPD_API_GET_QUEUE,0'); + } }); $('#searchqueue').submit(function () { diff --git a/src/mpd_client.c b/src/mpd_client.c index 0eb45bf..dc0c8fb 100644 --- a/src/mpd_client.c +++ b/src/mpd_client.c @@ -760,8 +760,9 @@ int mpd_search(char *buffer, char *searchstr) cur += json_emit_raw_str(cur, end - cur, "{\"type\":\"search\",\"data\":[ "); while((song = mpd_recv_song(mpd.conn)) != NULL) { - cur += json_emit_raw_str(cur, end - cur, "{\"type\":\"song\",\"uri\":"); - cur += json_emit_quoted_str(cur, end - cur, mpd_song_get_uri(song)); + cur += json_emit_raw_str(cur, end - cur, "{\"type\":\"song\""); +// cur += json_emit_raw_str(cur, end - cur, ",\"uri\":"); +// cur += json_emit_quoted_str(cur, end - cur, mpd_song_get_uri(song)); cur += json_emit_raw_str(cur, end - cur, ",\"album\":"); cur += json_emit_quoted_str(cur, end - cur, mpd_get_album(song)); cur += json_emit_raw_str(cur, end - cur, ",\"artist\":"); @@ -808,8 +809,9 @@ int mpd_search_queue(char *buffer, char *searchstr) cur += json_emit_raw_str(cur, end - cur, "{\"type\":\"queuesearch\",\"data\":[ "); while((song = mpd_recv_song(mpd.conn)) != NULL) { - cur += json_emit_raw_str(cur, end - cur, "{\"type\":\"song\",\"uri\":"); - cur += json_emit_quoted_str(cur, end - cur, mpd_song_get_uri(song)); + cur += json_emit_raw_str(cur, end - cur, "{\"type\":\"song\""); +// cur += json_emit_raw_str(cur, end - cur, ",\"uri\":"); +// cur += json_emit_quoted_str(cur, end - cur, mpd_song_get_uri(song)); cur += json_emit_raw_str(cur, end - cur, ",\"id\":"); cur += json_emit_int(cur, end - cur, mpd_song_get_id(song)); cur += json_emit_raw_str(cur, end - cur, ",\"pos\":"); @@ -828,7 +830,7 @@ int mpd_search_queue(char *buffer, char *searchstr) mpd_song_free(song); /* Maximum results */ - if(i++ >= 300) + if(i++ >= 100) { cur += json_emit_raw_str(cur, end - cur, "{\"type\":\"wrap\"},"); break;