1
0
mirror of https://github.com/SuperBFG7/ympd synced 2024-06-28 23:53:15 +00:00

Central page, filter and search states in app object

This commit is contained in:
jcorporation 2018-06-10 21:31:40 +02:00
parent ad58095efa
commit bb641a878f

View File

@ -25,11 +25,6 @@
var socket; var socket;
var last_state; var last_state;
var last_outputs; var last_outputs;
var pagination = 0;
var filterLetter = '!'
var browsepath = '';
var artist = '';
var lastSongTitle = '';
var current_song = new Object(); var current_song = new Object();
var MAX_ELEMENTS_PER_PAGE = 100; var MAX_ELEMENTS_PER_PAGE = 100;
var isTouch = Modernizr.touch ? 1 : 0; var isTouch = Modernizr.touch ? 1 : 0;
@ -42,7 +37,7 @@ var app = {};
app.apps = {"playback": { "state": "" }, app.apps = {"playback": { "state": "" },
"queue": { "state": "0/Any Tag/" }, "queue": { "state": "0/Any Tag/" },
"browse": { "active": "browseDatabase", "browse": { "active": "Database",
"tabs": { "Filesystem": {"state": "0/!/"}, "tabs": { "Filesystem": {"state": "0/!/"},
"Playlists": {"state": "0/!/" }, "Playlists": {"state": "0/!/" },
"Database": { "active":"Artist", "Database": { "active":"Artist",
@ -55,9 +50,7 @@ app.apps = {"playback": { "state": "" },
"search": { "state": "0/Any Tag/" } "search": { "state": "0/Any Tag/" }
}; };
app.currentApp=''; app.current = { "app": "playback", "tab": undefined, "view": undefined, "page": 0, "filter": "", "search": "" }
app.currentTab='';
app.currentView='';
app.prepare=function() { app.prepare=function() {
$('#navbar-bottom > div').removeClass('active'); $('#navbar-bottom > div').removeClass('active');
@ -93,28 +86,28 @@ app.route=function() {
if (params=hash.match(/^\#\/(playback)\//)) { if (params=hash.match(/^\#\/(playback)\//)) {
app.prepare(); app.prepare();
app.currentApp=params[1]; app.current.app=params[1];
app.currentTab=''; app.current.tab=undefined;
app.currentView=''; app.current.view=undefined;
$('#cardPlayback').removeClass('hide'); $('#cardPlayback').removeClass('hide');
$('#navPlayback').addClass('active'); $('#navPlayback').addClass('active');
} }
else if (params=hash.match(/^\#\/(queue)\/((\d+)\/([^\/]+)\/(.*))$/)) { else if (params=hash.match(/^\#\/(queue)\/((\d+)\/([^\/]+)\/(.*))$/)) {
app.currentApp=params[1]; app.current.app = params[1];
app.currentTab=''; app.current.tab = undefined;
app.currentView=''; app.current.view = undefined;
app.apps[app.currentApp].state=params[2]; app.apps[app.current.app].state = params[2];
pagination = parseInt(params[3]); app.current.page = parseInt(params[3]);
var mpdtag = params[4]; app.current.filter = params[4];
var searchstr = params[5]; app.current.search = params[5];
if ($('#cardQueue').hasClass('hide')) { if ($('#cardQueue').hasClass('hide')) {
app.prepare(); app.prepare();
if (searchstr == '') { if (app.current.search == '') {
setPagination(pagination); setPagination(app.current.page);
} }
$('#searchqueuetag > button').each(function() { $('#searchqueuetag > button').each(function() {
if ($(this).text == mpdtag) { if ($(this).text == app.current.filter) {
$(this).removeClass('btn-secondary').addClass('btn-success'); $(this).removeClass('btn-secondary').addClass('btn-success');
$('#searchqueuetagdesc').text($(this).text()); $('#searchqueuetagdesc').text($(this).text());
} }
@ -122,94 +115,94 @@ app.route=function() {
$('#cardQueue').removeClass('hide'); $('#cardQueue').removeClass('hide');
$('#navQueue').addClass('active'); $('#navQueue').addClass('active');
} }
if (searchstr.length >= 2) { if (app.current.search.length >= 2) {
socket.send('MPD_API_SEARCH_QUEUE,' + mpdtag + ','+pagination+',' + searchstr); socket.send('MPD_API_SEARCH_QUEUE,' + app.current.filter + ','+app.current.page+',' + app.current.search);
} }
else { else {
socket.send('MPD_API_GET_QUEUE,'+pagination); socket.send('MPD_API_GET_QUEUE,'+app.current.page);
} }
} }
else if (params=hash.match(/^\#\/(browse)(Playlists)\/((\d+)\/(\w|\!)\/)$/)) { else if (params=hash.match(/^\#\/(browse)(Playlists)\/((\d+)\/(\w|\!)\/)$/)) {
app.currentApp=params[1]; app.current.app=params[1];
app.currentTab=params[2]; app.current.tab=params[2];
app.currentView=''; app.current.view=undefined;
app.apps[app.currentApp].active=params[2]; app.apps[app.current.app].active=params[2];
app.apps[app.currentApp].tabs[params[2]].state=params[3]; app.apps[app.current.app].tabs[params[2]].state=params[3];
pagination = parseInt(params[4]); app.current.page = parseInt(params[4]);
filterLetter = params[5]; app.current.filter = params[5];
app.prepare(); app.prepare();
$('#navBrowse').addClass('active'); $('#navBrowse').addClass('active');
$('#cardBrowse').removeClass('hide'); $('#cardBrowse').removeClass('hide');
$('#cardBrowsePlaylists').removeClass('hide'); $('#cardBrowsePlaylists').removeClass('hide');
$('#cardBrowseNavPlaylists').addClass('active'); $('#cardBrowseNavPlaylists').addClass('active');
socket.send('MPD_API_GET_PLAYLISTS,'+pagination+','+filterLetter); socket.send('MPD_API_GET_PLAYLISTS,'+app.current.page+','+app.current.filter);
doSetFilterLetter('#browsePlaylistsFilter'); doSetFilterLetter('#browsePlaylistsFilter');
} }
else if (params=hash.match(/^\#\/(browse)(Database)(Artist)\/((\d+)\/(\w|\!)\/)$/)) { else if (params=hash.match(/^\#\/(browse)(Database)(Artist)\/((\d+)\/(\w|\!)\/)$/)) {
app.currentApp=params[1]; app.current.app=params[1];
app.currentTab=params[2]; app.current.tab=params[2];
app.currentView=params[3]; app.current.view=params[3];
app.apps[app.currentApp].active=params[2]; app.apps[app.current.app].active=params[2];
app.apps[app.currentApp].tabs[params[2]].active=params[3]; app.apps[app.current.app].tabs[params[2]].active=params[3];
app.apps[app.currentApp].tabs[params[2]].views[params[3]].state=params[4]; app.apps[app.current.app].tabs[params[2]].views[params[3]].state=params[4];
app.prepare(); app.prepare();
pagination = parseInt(params[5]); app.current.page = parseInt(params[5]);
filterLetter = params[6]; app.current.filter = params[6];
$('#navBrowse').addClass('active'); $('#navBrowse').addClass('active');
$('#cardBrowse').removeClass('hide'); $('#cardBrowse').removeClass('hide');
$('#cardBrowseDatabase').removeClass('hide'); $('#cardBrowseDatabase').removeClass('hide');
$('#cardBrowseNavDatabase').addClass('active'); $('#cardBrowseNavDatabase').addClass('active');
socket.send('MPD_API_GET_ARTISTS,' + pagination + ',' + filterLetter); socket.send('MPD_API_GET_ARTISTS,' + app.current.page + ',' + app.current.filter);
doSetFilterLetter('#browseDatabaseFilter'); doSetFilterLetter('#browseDatabaseFilter');
} }
else if (params=hash.match(/^\#\/(browse)(Database)(Album)\/((\d+)\/(\w|\!)\/(.*))$/)) { else if (params=hash.match(/^\#\/(browse)(Database)(Album)\/((\d+)\/(\w|\!)\/(.*))$/)) {
app.currentApp=params[1]; app.current.app=params[1];
app.currentTab=params[2]; app.current.tab=params[2];
app.currentView=params[3]; app.current.view=params[3];
app.apps[app.currentApp].active=params[2]; app.apps[app.current.app].active=params[2];
app.apps[app.currentApp].tabs[params[2]].active=params[3]; app.apps[app.current.app].tabs[params[2]].active=params[3];
app.apps[app.currentApp].tabs[params[2]].views[params[3]].state=params[4]; app.apps[app.current.app].tabs[params[2]].views[params[3]].state=params[4];
app.prepare(); app.prepare();
pagination = parseInt(params[5]); app.current.page = parseInt(params[5]);
filterLetter = params[6]; app.current.filter = params[6];
artist = params[7]; artist = params[7];
$('#navBrowse').addClass('active'); $('#navBrowse').addClass('active');
$('#cardBrowse').removeClass('hide'); $('#cardBrowse').removeClass('hide');
$('#cardBrowseDatabase').removeClass('hide'); $('#cardBrowseDatabase').removeClass('hide');
$('#cardBrowseNavDatabase').addClass('active'); $('#cardBrowseNavDatabase').addClass('active');
socket.send('MPD_API_GET_ARTISTALBUMS,' + pagination+',' + filterLetter + ',' + decodeURI(artist)); socket.send('MPD_API_GET_ARTISTALBUMS,' + app.current.page+',' + app.current.filter + ',' + decodeURI(artist));
doSetFilterLetter('#browseDatabaseFilter'); doSetFilterLetter('#browseDatabaseFilter');
} }
else if (params=hash.match(/^\#\/(browse)(Filesystem)\/((\d+)\/(\w|\!)\/(.*))$/)) { else if (params=hash.match(/^\#\/(browse)(Filesystem)\/((\d+)\/(\w|\!)\/(.*))$/)) {
app.prepare(); app.prepare();
app.currentApp=params[1]; app.current.app=params[1];
app.currentTab=params[2]; app.current.tab=params[2];
app.currentView=''; app.current.view=undefined;
app.apps[app.currentApp].active=params[2]; app.apps[app.current.app].active=params[2];
app.apps[app.currentApp].tabs[params[2]].state=params[3]; app.apps[app.current.app].tabs[params[2]].state=params[3];
pagination = parseInt(params[4]); app.current.page = parseInt(params[4]);
filterLetter = params[5]; app.current.filter = params[5];
browsepath = params[6]; app.current.search = params[6];
$('#navBrowse').addClass('active'); $('#navBrowse').addClass('active');
$('#cardBrowse').removeClass('hide'); $('#cardBrowse').removeClass('hide');
$('#cardBrowseFilesystem').removeClass('hide'); $('#cardBrowseFilesystem').removeClass('hide');
$('#cardBrowseNavFilesystem').addClass('active'); $('#cardBrowseNavFilesystem').addClass('active');
$('#browseBreadcrumb').empty().append("<li class=\"breadcrumb-item\"><a uri=\"\">root</a></li>"); $('#browseBreadcrumb').empty().append("<li class=\"breadcrumb-item\"><a uri=\"\">root</a></li>");
socket.send('MPD_API_GET_BROWSE,'+pagination+','+(browsepath ? browsepath : "/")+','+filterLetter); socket.send('MPD_API_GET_BROWSE,'+app.current.page+','+(app.current.search ? app.current.search : "/")+','+app.current.filter);
doSetFilterLetter('#browseFilesystemFilter'); doSetFilterLetter('#browseFilesystemFilter');
// Don't add all songs from root // Don't add all songs from root
var add_all_songs = $('#browseFilesystemAddAllSongs'); var add_all_songs = $('#browseFilesystemAddAllSongs');
if (browsepath) { if (app.current.search) {
add_all_songs.off(); // remove previous binds add_all_songs.off(); // remove previous binds
add_all_songs.on('click', function() { add_all_songs.on('click', function() {
socket.send('MPD_API_ADD_TRACK,'+browsepath); socket.send('MPD_API_ADD_TRACK,'+app.current.search);
}); });
add_all_songs.removeAttr('disabled').removeClass('disabled'); add_all_songs.removeAttr('disabled').removeClass('disabled');
} else { } else {
add_all_songs.attr('disabled','disabled').addClass('disabled'); add_all_songs.attr('disabled','disabled').addClass('disabled');
} }
var path_array = browsepath.split('/'); var path_array = app.current.search.split('/');
var full_path = ""; var full_path = "";
$.each(path_array, function(index, chunk) { $.each(path_array, function(index, chunk) {
if(path_array.length - 1 == index) { if(path_array.length - 1 == index) {
@ -223,29 +216,29 @@ app.route=function() {
}); });
} }
else if (params=hash.match(/^\#\/(search)\/((\d+)\/([^\/]+)\/(.*))$/)) { else if (params=hash.match(/^\#\/(search)\/((\d+)\/([^\/]+)\/(.*))$/)) {
app.currentApp=params[1]; app.current.app=params[1];
app.apps[app.currentApp].state=params[2]; app.apps[app.current.app].state=params[2];
app.currentTab=''; app.current.tab=undefined;
app.currentView=''; app.current.view=undefined;
pagination = parseInt(params[3]); app.current.page = parseInt(params[3]);
var mpdtag = params[4]; app.current.filter = params[4];
var searchstr = params[5]; app.current.search = params[5];
if ($('#cardSearch').hasClass('hide')) { if ($('#cardSearch').hasClass('hide')) {
app.prepare(); app.prepare();
if (searchstr != '') { if (app.current.search != '') {
$('#searchList > tbody').append( $('#searchList > tbody').append(
"<tr><td><span class=\"material-icons\">search</span></td>" + "<tr><td><span class=\"material-icons\">search</span></td>" +
"<td colspan=\"3\">Searching</td>" + "<td colspan=\"3\">Searching</td>" +
"<td></td><td></td></tr>"); "<td></td><td></td></tr>");
} }
else { else {
setPagination(pagination); setPagination(app.current.page);
} }
$('#search > input').val(searchstr); $('#search > input').val(app.current.search);
$('#searchstr2').val(searchstr); $('#searchstr2').val(app.current.search);
$('#searchtags2 > button').each(function() { $('#searchtags2 > button').each(function() {
if ($(this).text == mpdtag) { if ($(this).text == app.current.filter) {
$(this).removeClass('btn-secondary').addClass('btn-success'); $(this).removeClass('btn-secondary').addClass('btn-success');
$('#searchtags2desc').text($(this).text); $('#searchtags2desc').text($(this).text);
} }
@ -253,8 +246,8 @@ app.route=function() {
$('#cardSearch').removeClass('hide'); $('#cardSearch').removeClass('hide');
$('#navSearch').addClass('active'); $('#navSearch').addClass('active');
} }
if (searchstr.length >= 2) { if (app.current.search.length >= 2) {
socket.send('MPD_API_SEARCH,' + mpdtag + ','+pagination+',' + searchstr); socket.send('MPD_API_SEARCH,' + app.current.filter + ','+app.current.page+',' + app.current.search);
} else { } else {
$('#searchList > tbody').empty(); $('#searchList > tbody').empty();
$('#searchAddAllSongs').attr('disabled','disabled').addClass('disabled'); $('#searchAddAllSongs').attr('disabled','disabled').addClass('disabled');
@ -353,7 +346,7 @@ function webSocketConnect() {
case 'queuesearch': case 'queuesearch':
//Do the same as queue //Do the same as queue
case 'queue': case 'queue':
if(app.currentApp !== 'queue') if(app.current.app !== 'queue')
break; break;
$('#panel-heading-queue').empty(); $('#panel-heading-queue').empty();
if (obj.totalEntities > 0) { if (obj.totalEntities > 0) {
@ -364,7 +357,7 @@ function webSocketConnect() {
} }
var nrItems=0; var nrItems=0;
var tr=document.getElementById(app.currentApp+'List').getElementsByTagName('tbody')[0].getElementsByTagName('tr'); var tr=document.getElementById(app.current.app+'List').getElementsByTagName('tbody')[0].getElementsByTagName('tr');
for (var song in obj.data) { for (var song in obj.data) {
nrItems++; nrItems++;
var minutes = Math.floor(obj.data[song].duration / 60); var minutes = Math.floor(obj.data[song].duration / 60);
@ -377,7 +370,7 @@ function webSocketConnect() {
"<td>"+ minutes + ":" + (seconds < 10 ? '0' : '') + seconds + "<td>"+ minutes + ":" + (seconds < 10 ? '0' : '') + seconds +
"</td><td></td></tr>"; "</td><td></td></tr>";
if (nrItems <= tr.length) { $(tr[nrItems-1]).replaceWith(row); } if (nrItems <= tr.length) { $(tr[nrItems-1]).replaceWith(row); }
else { $('#'+app.currentApp+'List > tbody').append(row); } else { $('#'+app.current.app+'List > tbody').append(row); }
} }
for (var i=tr.length;i>nrItems;i--) { for (var i=tr.length;i>nrItems;i--) {
$(tr[tr.length-1]).remove(); $(tr[tr.length-1]).remove();
@ -394,7 +387,7 @@ function webSocketConnect() {
if ( isTouch ) { if ( isTouch ) {
$('#queueList > tbody > tr > td:last-child').append( $('#queueList > tbody > tr > td:last-child').append(
'<a class="pull-right btn-group-hover color-darkgrey" href="#/queue/' + pagination + '" '+ '<a class="pull-right btn-group-hover color-darkgrey" href="#/queue/' + app.current.page + '" '+
'onclick="delQueueSong($(this).parents(\'tr\'));">' + 'onclick="delQueueSong($(this).parents(\'tr\'));">' +
'<span class="material-icons">delete</span></a>'); '<span class="material-icons">delete</span></a>');
} else { } else {
@ -408,7 +401,7 @@ function webSocketConnect() {
$.each(doomed, function(){ $.each(doomed, function(){
if($(this).children().last().has('a').length == 0) if($(this).children().last().has('a').length == 0)
$(this).children().last().append( $(this).children().last().append(
'<a class="pull-right btn-group-hover color-darkgrey" href="#/queue/' + pagination + '" ' + '<a class="pull-right btn-group-hover color-darkgrey" href="#/queue/' + app.current.page + '" ' +
'onclick="delQueueSong($(this).parents(\'tr\'));">' + 'onclick="delQueueSong($(this).parents(\'tr\'));">' +
'<span class="material-icons">delete</span></a>') '<span class="material-icons">delete</span></a>')
.find('a').fadeTo('fast',1); .find('a').fadeTo('fast',1);
@ -434,10 +427,10 @@ function webSocketConnect() {
}); });
break; break;
case 'playlists': case 'playlists':
if(app.currentApp !== 'browse' && app.currentTab !== 'Playlists') if(app.current.app !== 'browse' && app.current.tab !== 'Playlists')
break; break;
var nrItems=0; var nrItems=0;
var tr=document.getElementById(app.currentApp+app.currentTab+'List').getElementsByTagName('tbody')[0].getElementsByTagName('tr'); var tr=document.getElementById(app.current.app+app.current.tab+'List').getElementsByTagName('tbody')[0].getElementsByTagName('tr');
for (var item in obj.data) { for (var item in obj.data) {
nrItems++; nrItems++;
var d = new Date(obj.data[item].last_modified * 1000); var d = new Date(obj.data[item].last_modified * 1000);
@ -446,23 +439,23 @@ function webSocketConnect() {
'<td><a>' + basename(obj.data[item].plist) + '</a></td>' + '<td><a>' + basename(obj.data[item].plist) + '</a></td>' +
'<td>'+d.toUTCString()+'</td><td></td></tr>'; '<td>'+d.toUTCString()+'</td><td></td></tr>';
if (nrItems <= tr.length) { $(tr[nrItems-1]).replaceWith(row); } if (nrItems <= tr.length) { $(tr[nrItems-1]).replaceWith(row); }
else { $('#'+app.currentApp+app.currentTab+'List > tbody').append(row); } else { $('#'+app.current.app+app.current.tab+'List > tbody').append(row); }
} }
for (var i=tr.length;i>nrItems;i--) { for (var i=tr.length;i>nrItems;i--) {
$(tr[tr.length-1]).remove(); $(tr[tr.length-1]).remove();
} }
setPagination(obj.totalEntities); setPagination(obj.totalEntities);
if ( isTouch ) { if ( isTouch ) {
$('#'+app.currentApp+app.currentTab+'List > tbody > tr > td:last-child').append( $('#'+app.current.app+app.current.tab+'List > tbody > tr > td:last-child').append(
'<a class="pull-right btn-group-hover color-darkgrey" href="#/browse/playlists/' + pagination + '" '+ '<a class="pull-right btn-group-hover color-darkgrey" href="#/browse/playlists/' + app.current.page + '" '+
'onclick="delPlaylist($(this).parents(\'tr\'));">' + 'onclick="delPlaylist($(this).parents(\'tr\'));">' +
'<span class="material-icons">delete</span></a>'); '<span class="material-icons">delete</span></a>');
} else { } else {
$('#'+app.currentApp+app.currentTab+'List > tbody > tr').on({ $('#'+app.current.app+app.current.tab+'List > tbody > tr').on({
mouseover: function(){ mouseover: function(){
if($(this).children().last().has('a').length == 0) if($(this).children().last().has('a').length == 0)
$(this).children().last().append( $(this).children().last().append(
'<a class="pull-right btn-group-hover color-darkgrey" href="#/browse/playlists/' + pagination + '" '+ '<a class="pull-right btn-group-hover color-darkgrey" href="#/browse/playlists/' + app.current.page + '" '+
'onclick="delPlaylist($(this).parents(\'tr\'));">' + 'onclick="delPlaylist($(this).parents(\'tr\'));">' +
'<span class="material-icons">delete</span></a>'); '<span class="material-icons">delete</span></a>');
}, },
@ -472,14 +465,14 @@ function webSocketConnect() {
} }
}); });
}; };
$('#'+app.currentApp+app.currentTab+'List > tbody > tr').on({ $('#'+app.current.app+app.current.tab+'List > tbody > tr').on({
click: function() { click: function() {
socket.send('MPD_API_ADD_PLAYLIST,' + decodeURI($(this).attr('uri'))); socket.send('MPD_API_ADD_PLAYLIST,' + decodeURI($(this).attr('uri')));
showNotification('"' + $('td:nth-last-child(3)', this).text() + '" added','','','success'); showNotification('"' + $('td:nth-last-child(3)', this).text() + '" added','','','success');
} }
}); });
if (nrItems == 0) { if (nrItems == 0) {
$('#'+app.currentApp+app.currentTab+'List > tbody').append( $('#'+app.current.app+app.current.tab+'List > tbody').append(
'<tr><td><span class="material-icons">error_outline</span></td>' + '<tr><td><span class="material-icons">error_outline</span></td>' +
'<td colspan="3">No playlists found.</td>' + '<td colspan="3">No playlists found.</td>' +
'<td></td><td></td></tr>' '<td></td><td></td></tr>'
@ -488,34 +481,34 @@ function webSocketConnect() {
break; break;
case 'listDBtags': case 'listDBtags':
if(app.currentApp !== 'browse' && app.currentTab !== 'Database') if(app.current.app !== 'browse' && app.current.tab !== 'Database')
break; break;
if (obj.tagtype == 'AlbumArtist') { if (obj.tagtype == 'AlbumArtist') {
$('#browseDatabaseAlbumCards').addClass('hide'); $('#browseDatabaseAlbumCards').addClass('hide');
$('#browseDatabaseArtistList').removeClass('hide'); $('#browseDatabaseArtistList').removeClass('hide');
$('#btnBrowseDatabaseArtist').addClass('hide'); $('#btnBrowseDatabaseArtist').addClass('hide');
var nrItems=0; var nrItems=0;
var tr=document.getElementById(app.currentApp+app.currentTab+app.currentView+'List').getElementsByTagName('tbody')[0].getElementsByTagName('tr'); var tr=document.getElementById(app.current.app+app.current.tab+app.current.view+'List').getElementsByTagName('tbody')[0].getElementsByTagName('tr');
for (var item in obj.data) { for (var item in obj.data) {
nrItems++; nrItems++;
var row='<tr uri="' + encodeURI(obj.data[item].value) + '">' + var row='<tr uri="' + encodeURI(obj.data[item].value) + '">' +
'<td><span class="material-icons">album</span></td>' + '<td><span class="material-icons">album</span></td>' +
'<td><a>' + obj.data[item].value + '</a></td></tr>'; '<td><a>' + obj.data[item].value + '</a></td></tr>';
if (nrItems <= tr.length) { $(tr[nrItems-1]).replaceWith(row); } if (nrItems <= tr.length) { $(tr[nrItems-1]).replaceWith(row); }
else { $('#'+app.currentApp+app.currentTab+app.currentView+'List > tbody').append(row); } else { $('#'+app.current.app+app.current.tab+app.current.view+'List > tbody').append(row); }
} }
for (var i=tr.length;i>nrItems;i--) { for (var i=tr.length;i>nrItems;i--) {
$(tr[tr.length-1]).remove(); $(tr[tr.length-1]).remove();
} }
setPagination(obj.totalEntities); setPagination(obj.totalEntities);
$('#'+app.currentApp+app.currentTab+app.currentView+'List > tbody > tr').on({ $('#'+app.current.app+app.current.tab+app.current.view+'List > tbody > tr').on({
click: function() { click: function() {
app.goto('browse','Database','Album','0/!/'+$(this).attr('uri')); app.goto('browse','Database','Album','0/!/'+$(this).attr('uri'));
} }
}); });
if (nrItems == 0) { if (nrItems == 0) {
$('#'+app.currentApp+app.currentTab+app.currentView+'List > tbody').append( $('#'+app.current.app+app.current.tab+app.current.view+'List > tbody').append(
'<tr><td><span class="material-icons">error_outline</span></td>' + '<tr><td><span class="material-icons">error_outline</span></td>' +
'<td colspan="3">No entries found.</td>' + '<td colspan="3">No entries found.</td>' +
'<td></td><td></td></tr>' '<td></td><td></td></tr>'
@ -576,7 +569,7 @@ function webSocketConnect() {
$('#searchAddAllSongs').attr('disabled','disabled').addClass('disabled'); $('#searchAddAllSongs').attr('disabled','disabled').addClass('disabled');
} }
case 'browse': case 'browse':
if(app.currentApp !== 'browse' && app.currentTab !== 'Filesystem' && app.currentApp !== 'search') if(app.current.app !== 'browse' && app.current.tab !== 'Filesystem' && app.current.app !== 'search')
break; break;
/* The use of encodeURI() below might seem useless, but it's not. It prevents /* The use of encodeURI() below might seem useless, but it's not. It prevents
@ -584,7 +577,7 @@ function webSocketConnect() {
* URI from NFD to NFC, breaking our link with MPD. * URI from NFD to NFC, breaking our link with MPD.
*/ */
var nrItems=0; var nrItems=0;
var tr=document.getElementById(app.currentApp+app.currentTab+'List').getElementsByTagName('tbody')[0].getElementsByTagName('tr'); var tr=document.getElementById(app.current.app+(app.current.tab==undefined ? '' : app.current.tab)+'List').getElementsByTagName('tbody')[0].getElementsByTagName('tr');
for (var item in obj.data) { for (var item in obj.data) {
nrItems++; nrItems++;
var row=''; var row='';
@ -614,7 +607,7 @@ function webSocketConnect() {
break; break;
} }
if (nrItems <= tr.length) { $(tr[nrItems-1]).replaceWith(row); } if (nrItems <= tr.length) { $(tr[nrItems-1]).replaceWith(row); }
else { $('#'+app.currentApp+app.currentTab+'List > tbody').append(row); } else { $('#'+app.current.app+(app.current.tab==undefined ? '' : app.current.tab)+'List > tbody').append(row); }
} }
for (var i=tr.length;i>nrItems;i--) { for (var i=tr.length;i>nrItems;i--) {
$(tr[tr.length-1]).remove(); $(tr[tr.length-1]).remove();
@ -622,7 +615,7 @@ function webSocketConnect() {
setPagination(obj.totalEntities); setPagination(obj.totalEntities);
if (nrItems == 0) { if (nrItems == 0) {
$('#'+app.currentApp+app.currentTab+'List > tbody').append( $('#'+app.current.app+app.current.tab+'List > tbody').append(
'<tr><td><span class="material-icons">error_outline</span></td>' + '<tr><td><span class="material-icons">error_outline</span></td>' +
'<td colspan="3">No results</td>' + '<td colspan="3">No results</td>' +
'<td></td><td></td></tr>'); '<td></td><td></td></tr>');
@ -640,10 +633,10 @@ function webSocketConnect() {
} }
if ( isTouch ) { if ( isTouch ) {
appendClickableIcon($('#'+app.currentApp+app.currentTab+'List > tbody > tr.dir > td:last-child'), 'MPD_API_ADD_TRACK', 'playlist_add'); appendClickableIcon($('#'+app.current.app+app.current.tab+'List > tbody > tr.dir > td:last-child'), 'MPD_API_ADD_TRACK', 'playlist_add');
appendClickableIcon($('#'+app.currentApp+app.currentTab+'List > tbody > tr.song > td:last-child'), 'MPD_API_ADD_TRACK', 'playlist_add'); appendClickableIcon($('#'+app.current.app+app.current.tab+'List > tbody > tr.song > td:last-child'), 'MPD_API_ADD_TRACK', 'playlist_add');
} else { } else {
$('#'+app.currentApp+app.currentTab+'List > tbody > tr').on({ $('#'+app.current.app+app.current.tab+'List > tbody > tr').on({
mouseenter: function() { mouseenter: function() {
if($(this).is(".dir")) if($(this).is(".dir"))
appendClickableIcon($(this).children().last(), 'MPD_API_ADD_TRACK', 'playlist_add'); appendClickableIcon($(this).children().last(), 'MPD_API_ADD_TRACK', 'playlist_add');
@ -655,14 +648,14 @@ function webSocketConnect() {
} }
}); });
}; };
$('#'+app.currentApp+app.currentTab+'List > tbody > tr').on({ $('#'+app.current.app+app.current.tab+'List > tbody > tr').on({
click: function() { click: function() {
switch($(this).attr('class')) { switch($(this).attr('class')) {
case 'dir': case 'dir':
pagination = 0; app.current.page = 0;
browsepath = $(this).attr("uri"); app.current.search = $(this).attr("uri");
$("#browseFilesystemList > a").attr("href", '#/browseFilesystem/'+pagination+'/'+filterLetter+'/'+browsepath); $("#browseFilesystemList > a").attr("href", '#/browseFilesystem/'+app.current.page+'/'+app.current.filter+'/'+app.current.search);
app.goto('browse','Filesystem',undefined,pagination+'/'+filterLetter+'/'+browsepath); app.goto('browse','Filesystem',undefined,app.current.page+'/'+app.current.filter+'/'+app.current.search);
break; break;
case 'song': case 'song':
socket.send("MPD_API_ADD_TRACK," + decodeURI($(this).attr("uri"))); socket.send("MPD_API_ADD_TRACK," + decodeURI($(this).attr("uri")));
@ -678,10 +671,10 @@ function webSocketConnect() {
$('#browseBreadcrumb > li > a').on({ $('#browseBreadcrumb > li > a').on({
click: function() { click: function() {
pagination = 0; app.current.page = 0;
browsepath = $(this).attr("uri"); app.current.search = $(this).attr("uri");
$("#browseFilesystemList > a").attr("href", '#/browseFilesystem/'+pagination+'/'+filterLetter+'/'+browsepath); $("#browseFilesystemList > a").attr("href", '#/browseFilesystem/'+app.current.page+'/'+app.current.filter+'/'+app.current.search);
app.goto('browse','Filesystem',undefined,pagination+'/'+filterLetter+'/'+browsepath); app.goto('browse','Filesystem',undefined,app.current.page+'/'+app.current.filter+'/'+app.current.search);
} }
}); });
@ -753,8 +746,8 @@ function webSocketConnect() {
showNotification('myMPD lost connection to MPD','','','danger'); showNotification('myMPD lost connection to MPD','','','danger');
break; break;
case 'update_queue': case 'update_queue':
if(app.currentApp === 'queue') if(app.current.app === 'queue')
socket.send('MPD_API_GET_QUEUE,'+pagination); socket.send('MPD_API_GET_QUEUE,'+app.current.page);
break; break;
case "song_change": case "song_change":
songChange(obj.data.title, obj.data.artist, obj.data.album, obj.data.uri); songChange(obj.data.title, obj.data.artist, obj.data.album, obj.data.uri);
@ -870,39 +863,40 @@ function get_appropriate_ws_url()
function setPagination(number) { function setPagination(number) {
var totalPages=Math.ceil(number / MAX_ELEMENTS_PER_PAGE); var totalPages=Math.ceil(number / MAX_ELEMENTS_PER_PAGE);
var cat=app.current.app+(app.current.tab==undefined ? '': app.current.tab);
if (totalPages==0) { totalPages=1; } if (totalPages==0) { totalPages=1; }
$('#'+app.currentApp+app.currentTab+'PaginationTopPage').text('Page '+(pagination / MAX_ELEMENTS_PER_PAGE + 1)+' / '+totalPages); $('#'+cat+'PaginationTopPage').text('Page '+(app.current.page / MAX_ELEMENTS_PER_PAGE + 1)+' / '+totalPages);
$('#'+app.currentApp+app.currentTab+'PaginationBottomPage').text('Page '+(pagination / MAX_ELEMENTS_PER_PAGE + 1)+' / '+totalPages); $('#'+cat+'PaginationBottomPage').text('Page '+(app.current.page / MAX_ELEMENTS_PER_PAGE + 1)+' / '+totalPages);
if (totalPages > 1) { if (totalPages > 1) {
$('#'+app.currentApp+app.currentTab+'PaginationTopPage').removeClass('disabled').removeAttr('disabled'); $('#'+cat+'PaginationTopPage').removeClass('disabled').removeAttr('disabled');
$('#'+app.currentApp+app.currentTab+'PaginationBottomPage').removeClass('disabled').removeAttr('disabled'); $('#'+cat+'PaginationBottomPage').removeClass('disabled').removeAttr('disabled');
$('#'+app.currentApp+app.currentTab+'PaginationTopPages').empty(); $('#'+cat+'PaginationTopPages').empty();
$('#'+app.currentApp+app.currentTab+'PaginationBottomPages').empty(); $('#'+cat+'PaginationBottomPages').empty();
for (var i=0;i<totalPages;i++) { for (var i=0;i<totalPages;i++) {
$('#'+app.currentApp+app.currentTab+'PaginationTopPages').append('<button onclick="gotoPage('+(i * MAX_ELEMENTS_PER_PAGE)+',this,event)" type="button" class="mr-1 mb-1 btn-sm btn btn-secondary">'+(i+1)+'</button>'); $('#'+cat+'PaginationTopPages').append('<button onclick="gotoPage('+(i * MAX_ELEMENTS_PER_PAGE)+',this,event)" type="button" class="mr-1 mb-1 btn-sm btn btn-secondary">'+(i+1)+'</button>');
$('#'+app.currentApp+app.currentTab+'PaginationBottomPages').append('<button onclick="gotoPage('+(i * MAX_ELEMENTS_PER_PAGE)+',this,event)" type="button" class="mr-1 mb-1 btn-sm btn btn-secondary">'+(i+1)+'</button>'); $('#'+cat+'PaginationBottomPages').append('<button onclick="gotoPage('+(i * MAX_ELEMENTS_PER_PAGE)+',this,event)" type="button" class="mr-1 mb-1 btn-sm btn btn-secondary">'+(i+1)+'</button>');
} }
} else { } else {
$('#'+app.currentApp+app.currentTab+'PaginationTopPage').addClass('disabled').attr('disabled','disabled'); $('#'+cat+'PaginationTopPage').addClass('disabled').attr('disabled','disabled');
$('#'+app.currentApp+app.currentTab+'PaginationBottomPage').addClass('disabled').attr('disabled','disabled'); $('#'+cat+'PaginationBottomPage').addClass('disabled').attr('disabled','disabled');
} }
if(number > pagination + MAX_ELEMENTS_PER_PAGE) { if(number > app.current.page + MAX_ELEMENTS_PER_PAGE) {
$('#'+app.currentApp+app.currentTab+'PaginationTopNext').removeClass('disabled').removeAttr('disabled'); $('#'+cat+'PaginationTopNext').removeClass('disabled').removeAttr('disabled');
$('#'+app.currentApp+app.currentTab+'PaginationBottomNext').removeClass('disabled').removeAttr('disabled'); $('#'+cat+'PaginationBottomNext').removeClass('disabled').removeAttr('disabled');
$('#'+app.currentApp+app.currentTab+'ButtonsBottom').removeClass('hide'); $('#'+cat+'ButtonsBottom').removeClass('hide');
} else { } else {
$('#'+app.currentApp+app.currentTab+'PaginationTopNext').addClass('disabled').attr('disabled','disabled'); $('#'+cat+'PaginationTopNext').addClass('disabled').attr('disabled','disabled');
$('#'+app.currentApp+app.currentTab+'PaginationBottomNext').addClass('disabled').attr('disabled','disabled'); $('#'+cat+'PaginationBottomNext').addClass('disabled').attr('disabled','disabled');
$('#'+app.currentApp+app.currentTab+'ButtonsBottom').addClass('hide'); $('#'+cat+'ButtonsBottom').addClass('hide');
} }
if(pagination > 0) { if(app.current.page > 0) {
$('#'+app.currentApp+app.currentTab+'PaginationTopPrev').removeClass('disabled').removeAttr('disabled'); $('#'+cat+'PaginationTopPrev').removeClass('disabled').removeAttr('disabled');
$('#'+app.currentApp+app.currentTab+'PaginationBottomPrev').removeClass('disabled').removeAttr('disabled'); $('#'+cat+'PaginationBottomPrev').removeClass('disabled').removeAttr('disabled');
} else { } else {
$('#'+app.currentApp+app.currentTab+'PaginationTopPrev').addClass('disabled').attr('disabled','disabled'); $('#'+cat+'PaginationTopPrev').addClass('disabled').attr('disabled','disabled');
$('#'+app.currentApp+app.currentTab+'PaginationBottomPrev').addClass('disabled').attr('disabled','disabled'); $('#'+cat+'PaginationBottomPrev').addClass('disabled').attr('disabled','disabled');
} }
} }
@ -1168,68 +1162,49 @@ $('#search > input').keypress(function (event) {
}); });
$('#search').submit(function () { $('#search').submit(function () {
app.goto('search',undefined,undefined,pagination + '/Any Tag/' + $('#search > input').val()); app.goto('search',undefined,undefined,app.current.page + '/Any Tag/' + $('#search > input').val());
return false; return false;
}); });
function doSearch(searchstr) {
var mpdtag='Any Tag';
$('#searchtags2 > button').each(function() {
if ($(this).hasClass('btn-success')) { mpdtag=$(this).text(); }
});
app.goto('search',undefined,undefined,pagination + '/' + mpdtag + '/' + searchstr);
}
$('#search2').submit(function () { $('#search2').submit(function () {
return false; return false;
}); });
function addAllFromSearch() { function addAllFromSearch() {
var mpdtag='Any Tag'; if (app.current.search.length >= 2) {
$('#searchtags2 > button').each(function() { socket.send('MPD_API_SEARCH_ADD,' + app.current.filter + ',' + app.current.search);
if ($(this).hasClass('btn-success')) { mpdtag=$(this).text(); }
});
var searchstr=$('#searchstr2').val();
if (searchstr.length >= 2) {
socket.send('MPD_API_SEARCH_ADD,' + mpdtag + ',' + searchstr);
var rowCount = $('#searchList >tbody >tr').length; var rowCount = $('#searchList >tbody >tr').length;
showNotification('Added '+rowCount+' songs from search','','','success'); showNotification('Added '+rowCount+' songs from search','','','success');
} }
} }
$('#searchstr2').keyup(function (event) { $('#searchstr2').keyup(function (event) {
pagination=0; app.current.page=0;
doSearch($(this).val()); app.current.search=$(this).val();
app.goto('search',undefined,undefined,app.current.page + '/' + app.current.filter + '/' + app.current.search);
}); });
$('#searchtags2 > button').on('click',function (e) { $('#searchtags2 > button').on('click',function (e) {
$('#searchtags2 > button').removeClass('btn-success').addClass('btn-secondary'); $('#searchtags2 > button').removeClass('btn-success').addClass('btn-secondary');
$(this).removeClass('btn-secondary').addClass('btn-success'); $(this).removeClass('btn-secondary').addClass('btn-success');
$('#searchtags2desc').text($(this).text()); app.current.filter=$(this).text();
doSearch($('#searchstr2').val()); app.goto(app.current.app,app.current.tab,app.current.view,app.current.page + '/' + app.current.filter + '/' + app.current.search);
}); });
$('#searchqueuestr').keyup(function (event) { $('#searchqueuestr').keyup(function (event) {
pagination=0; app.current.page=0;
doQueueSearch(); app.current.search=$(this).val();
app.goto(app.current.app,app.current.tab,app.current.view,app.current.page + '/' + app.current.filter + '/' + app.current.search);
}); });
$('#searchqueuetag > button').on('click',function (e) { $('#searchqueuetag > button').on('click',function (e) {
$('#searchqueuetag > button').removeClass('btn-success').addClass('btn-secondary'); $('#searchqueuetag > button').removeClass('btn-success').addClass('btn-secondary');
$(this).removeClass('btn-secondary').addClass('btn-success'); $(this).removeClass('btn-secondary').addClass('btn-success');
$('#searchqueuetagdesc').text($(this).text()); app.current.filter=$(this).text();
doQueueSearch(); $('#searchqueuetagdesc').text(app.current.filter);
app.goto(app.current.app,app.current.tab,app.current.view,app.current.page + '/' + app.current.filter + '/' + app.current.search);
}); });
function doQueueSearch() {
var searchstr=$('#searchqueuestr').val();
var mpdtag='Any Tag';
$('#searchqueuetag > button').each(function() {
if ($(this).hasClass('btn-success')) { mpdtag=$(this).text(); }
});
app.goto('queue',undefined,undefined,pagination + '/' + mpdtag + '/' + searchstr);
}
$('#searchqueue').submit(function () { $('#searchqueue').submit(function () {
return false; return false;
}); });
@ -1246,41 +1221,17 @@ function scrollToTop() {
function gotoPage(x,element,event) { function gotoPage(x,element,event) {
switch (x) { switch (x) {
case "next": case "next":
pagination += MAX_ELEMENTS_PER_PAGE; app.current.page += MAX_ELEMENTS_PER_PAGE;
break; break;
case "prev": case "prev":
pagination -= MAX_ELEMENTS_PER_PAGE; app.current.page -= MAX_ELEMENTS_PER_PAGE;
if(pagination <= 0) if(app.current.page <= 0)
pagination = 0; app.current.page = 0;
break; break;
default: default:
pagination = x; app.current.page = x;
}
switch(app.currentApp) {
case "queue":
if ($('#searchqueuestr').val().length >=3) {
doQueueSearch();
} else {
var mpdtag='Any Tag';
$('#searchqueuetag > button').each(function() {
if ($(this).hasClass('btn-success')) { mpdtag=$(this).text(); }
});
app.goto('queue',undefined,undefined, pagination+'/'+mpdtag+'/');
}
break;
case "search":
doSearch($('#searchstr2').val());
break;
case "browse":
if (app.currentTab == 'Filesystem') app.goto('browse','Filesystem',undefined, pagination+'/'+filterLetter+'/'+browsepath)
else if (app.currentTab == 'Playlists') app.goto('browse','Playlists',undefined, pagination+'/'+filterLetter)
else if (app.currentTab == 'Database') {
if (app.currentView == 'Artist') app.goto('browse','Database','Artist', pagination+'/'+filterLetter+'/')
else if (app.currentView == 'Album') app.goto('browse','Database','Album', pagination+'/'+filterLetter+'/'+artist)
}
break;
} }
app.goto(app.current.app,app.current.tab,app.current.view,app.current.page+'/'+app.current.filter+'/'+app.current.search);
event.preventDefault(); event.preventDefault();
} }
@ -1387,36 +1338,22 @@ $(document).keydown(function(e){
}); });
function setFilterLetter(filter) { function setFilterLetter(filter) {
pagination = 0; app.goto(app.current.app,app.current.tab,app.current.view, '0/'+filter+'/'+app.current.search);
if (app.currentApp == 'browse') {
switch(app.currentTab) {
case 'Filesystem':
app.goto('browse','Filesystem',undefined, pagination+'/'+filter+'/'+browsepath);
break;
case 'Database':
if (app.currentView == 'Artist') app.goto('browse','Database','Artist', pagination+'/'+filter+'/');
else if (app.currentView == 'Album') app.goto('browse','Database','Album', pagination+'/'+filter+'/'+artist);
break;
case 'Playlists':
app.goto('browse','Playlists',undefined, pagination+'/'+filter+'/');
break;
}
}
} }
function doSetFilterLetter(x) { function doSetFilterLetter(x) {
$(x+'Letters > button').removeClass('btn-success').addClass('btn-secondary'); $(x+'Letters > button').removeClass('btn-success').addClass('btn-secondary');
if (filterLetter == '0') { if (app.current.filter == '0') {
$(x).text('Filter: #'); $(x).text('Filter: #');
$(x+'Letters > button').each(function() { $(x+'Letters > button').each(function() {
if ($(this).text() == '#') { if ($(this).text() == '#') {
$(this).addClass('btn-success'); $(this).addClass('btn-success');
} }
}); });
} else if (filterLetter != '!') { } else if (app.current.filter != '!') {
$(x).text('Filter: '+filterLetter); $(x).text('Filter: '+app.current.filter);
$(x+'Letters > button').each(function() { $(x+'Letters > button').each(function() {
if ($(this).text() == filterLetter) { if ($(this).text() == app.current.filter) {
$(this).addClass('btn-success'); $(this).addClass('btn-success');
} }
}); });