mirror of
https://github.com/SuperBFG7/ympd
synced 2025-04-11 05:06:47 +00:00
Save states of cards, tabs and views
This commit is contained in:
parent
de36d91ca9
commit
4805ae4f1f
@ -15,7 +15,6 @@ UI Components
|
||||
- Bootstrap Notify: http://bootstrap-notify.remabledesigns.com/
|
||||
- Bootstrap Slider: https://github.com/seiyria/bootstrap-slider
|
||||
- Material Design Icons: https://material.io/tools/icons/?style=baseline
|
||||
- Sammy.js: http://sammyjs.org/
|
||||
- jQuery: https://jquery.com/
|
||||
- js-cookie: https://github.com/js-cookie/js-cookie
|
||||
|
||||
|
@ -93,8 +93,8 @@ tbody {
|
||||
src: url(/assets/MaterialIcons-Regular.eot); /* For IE6-8 */
|
||||
src: local('Material Icons'),
|
||||
local('MaterialIcons-Regular'),
|
||||
url(/assets/MaterialIcons-Regular.woff2) format('woff2'),
|
||||
url(/assets/MaterialIcons-Regular.woff) format('woff'),
|
||||
url(/assets/MaterialIcons-Regular.woff2) format('woff2');
|
||||
src: url(/assets/MaterialIcons-Regular.woff) format('woff'),
|
||||
url(/assets/MaterialIcons-Regular.ttf) format('truetype');
|
||||
}
|
||||
|
||||
|
@ -291,7 +291,7 @@
|
||||
</div>
|
||||
|
||||
<div class="table-responsive-md">
|
||||
<table id="browseDatabaseList" class="table table-hover table-sm">
|
||||
<table id="browseDatabaseArtistList" class="table table-hover table-sm">
|
||||
<col class="tblnum"/>
|
||||
<col class="tbltitle"/>
|
||||
<col class="tblaction"/>
|
||||
@ -307,7 +307,7 @@
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div id="browseDatabaseCards" class="row"></div>
|
||||
<div id="browseDatabaseAlbumCards" class="row"></div>
|
||||
|
||||
<div class="btn-toolbar" id="browseDatabaseButtonsBottom" role="toolbar">
|
||||
<div class="btn-group mr-2">
|
||||
|
268
htdocs/js/mpd.js
268
htdocs/js/mpd.js
@ -42,14 +42,22 @@ var app = {};
|
||||
|
||||
app.apps = {"playback": { "state": "" },
|
||||
"queue": { "state": "0/Any Tag/" },
|
||||
"browsePlaylists": { "state": "0/!/" },
|
||||
"browseDatabase": { "state": "0/!/" },
|
||||
"browseDatabaseArtist": { "state": "0/!/" },
|
||||
"browseFilesystem": { "state": "0/!/" },
|
||||
"browse": { "active": "browseFilesystem",
|
||||
"tabs": { "Filesystem": {"state": "0/!/"},
|
||||
"Playlists": {"state": "0/!/" },
|
||||
"Database": { "active":"Artist",
|
||||
"views": {"Artist": {"state": "0/!/" },
|
||||
"Album": {"state": "0/!/" }
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"search": { "state": "0/Any Tag/" }
|
||||
};
|
||||
|
||||
app.currentApp='';
|
||||
app.currentTab='';
|
||||
app.currentView='';
|
||||
|
||||
app.prepare=function() {
|
||||
$('#navbar-bottom > div').removeClass('active');
|
||||
@ -66,29 +74,39 @@ app.prepare=function() {
|
||||
$('#cardBrowseNavFilesystem').removeClass('active');
|
||||
}
|
||||
|
||||
app.goto=function(a,p) {
|
||||
//use saved state if p is undefined
|
||||
location.hash = '/'+a+'/'+ encodeURI(p == undefined ? app.apps[a].state : p);
|
||||
app.goto=function(a,t,v,s) {
|
||||
if (app.apps[a].tabs) {
|
||||
if (t == undefined) t = app.apps[a].active;
|
||||
if (app.apps[a].tabs[t].views) {
|
||||
if (v == undefined) v = app.apps[a].tabs[t].active;
|
||||
location.hash = '/'+a+t+v+'/'+ (s == undefined ? app.apps[a].tabs[t].views[v].state : s);
|
||||
} else {
|
||||
location.hash = '/'+a+t+'/'+ (s == undefined ? app.apps[a].tabs[t].state : s);
|
||||
}
|
||||
} else {
|
||||
location.hash = '/'+a+'/'+ (s == undefined ? app.apps[a].state : s);
|
||||
}
|
||||
}
|
||||
|
||||
app.route=function() {
|
||||
var hash=decodeURI(location.hash);
|
||||
if (params=hash.match(/^\#\/(\w+)\/(.*)$/)) {
|
||||
app.currentApp=params[1];
|
||||
app.apps[app.currentApp].state=params[2];
|
||||
} else {
|
||||
app.currentApp='';
|
||||
}
|
||||
|
||||
if (params=hash.match(/^\#\/(playback)\//)) {
|
||||
app.prepare();
|
||||
app.currentApp=params[1];
|
||||
app.currentTab='';
|
||||
app.currentView='';
|
||||
$('#cardPlayback').removeClass('hide');
|
||||
$('#navPlayback').addClass('active');
|
||||
}
|
||||
else if (params=hash.match(/^\#\/(queue)\/(\d+)\/([^\/]+)\/(.*)$/)) {
|
||||
pagination = parseInt(params[2]);
|
||||
var mpdtag = params[3];
|
||||
var searchstr = params[4];
|
||||
else if (params=hash.match(/^\#\/(queue)\/((\d+)\/([^\/]+)\/(.*))$/)) {
|
||||
app.currentApp=params[1];
|
||||
app.currentTab='';
|
||||
app.currentView='';
|
||||
app.apps[app.currentApp].state=params[2];
|
||||
pagination = parseInt(params[3]);
|
||||
var mpdtag = params[4];
|
||||
var searchstr = params[5];
|
||||
|
||||
if ($('#cardQueue').hasClass('hide')) {
|
||||
app.prepare();
|
||||
@ -111,9 +129,14 @@ app.route=function() {
|
||||
socket.send('MPD_API_GET_QUEUE,'+pagination);
|
||||
}
|
||||
}
|
||||
else if (params=hash.match(/^\#\/(browsePlaylists)\/(\d+)\/(\w|\!)\/$/)) {
|
||||
pagination = parseInt(params[2]);
|
||||
filterLetter = params[3];
|
||||
else if (params=hash.match(/^\#\/(browse)(Playlists)\/((\d+)\/(\w|\!)\/)$/)) {
|
||||
app.currentApp=params[1];
|
||||
app.currentTab=params[2];
|
||||
app.currentView='';
|
||||
app.apps[app.currentApp].active=params[2];
|
||||
app.apps[app.currentApp].tabs[params[2]].state=params[3];
|
||||
pagination = parseInt(params[4]);
|
||||
filterLetter = params[5];
|
||||
app.prepare();
|
||||
$('#navBrowse').addClass('active');
|
||||
$('#cardBrowse').removeClass('hide');
|
||||
@ -122,10 +145,16 @@ app.route=function() {
|
||||
socket.send('MPD_API_GET_PLAYLISTS,'+pagination+','+filterLetter);
|
||||
doSetFilterLetter('#browsePlaylistsFilter');
|
||||
}
|
||||
else if (params=hash.match(/^\#\/(browseDatabase)\/(\d+)\/(\w|\!)\/$/)) {
|
||||
else if (params=hash.match(/^\#\/(browse)(Database)(Artist)\/((\d+)\/(\w|\!)\/)$/)) {
|
||||
app.currentApp=params[1];
|
||||
app.currentTab=params[2];
|
||||
app.currentView=params[3];
|
||||
app.apps[app.currentApp].active=params[2];
|
||||
app.apps[app.currentApp].tabs[params[2]].active=params[3];
|
||||
app.apps[app.currentApp].tabs[params[2]].views[params[3]].state=params[4];
|
||||
app.prepare();
|
||||
pagination = parseInt(params[2]);
|
||||
filterLetter = params[3];
|
||||
pagination = parseInt(params[5]);
|
||||
filterLetter = params[6];
|
||||
$('#navBrowse').addClass('active');
|
||||
$('#cardBrowse').removeClass('hide');
|
||||
$('#cardBrowseDatabase').removeClass('hide');
|
||||
@ -133,11 +162,17 @@ app.route=function() {
|
||||
socket.send('MPD_API_GET_ARTISTS,' + pagination + ',' + filterLetter);
|
||||
doSetFilterLetter('#browseDatabaseFilter');
|
||||
}
|
||||
else if (params=hash.match(/^\#\/(browseDatabaseArtist)\/(\d+)\/(\w|\!)\/(.*)$/)) {
|
||||
else if (params=hash.match(/^\#\/(browse)(Database)(Album)\/((\d+)\/(\w|\!)\/(.*))$/)) {
|
||||
app.currentApp=params[1];
|
||||
app.currentTab=params[2];
|
||||
app.currentView=params[3];
|
||||
app.apps[app.currentApp].active=params[2];
|
||||
app.apps[app.currentApp].tabs[params[2]].active=params[3];
|
||||
app.apps[app.currentApp].tabs[params[2]].views[params[3]].state=params[4];
|
||||
app.prepare();
|
||||
pagination = parseInt(params[2]);
|
||||
filterLetter = params[3];
|
||||
artist = params[4];
|
||||
pagination = parseInt(params[5]);
|
||||
filterLetter = params[6];
|
||||
artist = params[7];
|
||||
$('#navBrowse').addClass('active');
|
||||
$('#cardBrowse').removeClass('hide');
|
||||
$('#cardBrowseDatabase').removeClass('hide');
|
||||
@ -145,11 +180,16 @@ app.route=function() {
|
||||
socket.send('MPD_API_GET_ARTISTALBUMS,' + pagination+',' + filterLetter + ',' + decodeURI(artist));
|
||||
doSetFilterLetter('#browseDatabaseFilter');
|
||||
}
|
||||
else if (params=hash.match(/^\#\/(browseFilesystem)\/(\d+)\/(\w|\!)\/(.*)$/)) {
|
||||
else if (params=hash.match(/^\#\/(browse)(Filesystem)\/((\d+)\/(\w|\!)\/(.*))$/)) {
|
||||
app.prepare();
|
||||
pagination = parseInt(params[2]);
|
||||
filterLetter = params[3];
|
||||
browsepath = params[4];
|
||||
app.currentApp=params[1];
|
||||
app.currentTab=params[2];
|
||||
app.currentView='';
|
||||
app.apps[app.currentApp].active=params[2];
|
||||
app.apps[app.currentApp].tabs[params[2]].state=params[3];
|
||||
pagination = parseInt(params[4]);
|
||||
filterLetter = params[5];
|
||||
browsepath = params[6];
|
||||
$('#navBrowse').addClass('active');
|
||||
$('#cardBrowse').removeClass('hide');
|
||||
$('#cardBrowseFilesystem').removeClass('hide');
|
||||
@ -182,10 +222,14 @@ app.route=function() {
|
||||
full_path += "/";
|
||||
});
|
||||
}
|
||||
else if (params=hash.match(/^\#\/(search)\/(\d+)\/([^\/]+)\/(.*)$/)) {
|
||||
pagination = parseInt(params[2]);
|
||||
var mpdtag = params[3];
|
||||
var searchstr = params[4];
|
||||
else if (params=hash.match(/^\#\/(search)\/((\d+)\/([^\/]+)\/(.*))$/)) {
|
||||
app.currentApp=params[1];
|
||||
app.apps[app.currentApp].state=params[2];
|
||||
app.currentTab='';
|
||||
app.currentView='';
|
||||
pagination = parseInt(params[3]);
|
||||
var mpdtag = params[4];
|
||||
var searchstr = params[5];
|
||||
|
||||
if ($('#cardSearch').hasClass('hide')) {
|
||||
app.prepare();
|
||||
@ -390,10 +434,10 @@ function webSocketConnect() {
|
||||
});
|
||||
break;
|
||||
case 'playlists':
|
||||
if(app.currentApp !== 'browsePlaylists')
|
||||
if(app.currentApp !== 'browse' && app.currentTab !== 'Playlists')
|
||||
break;
|
||||
var nrItems=0;
|
||||
var tr=document.getElementById(app.currentApp+'List').getElementsByTagName('tbody')[0].getElementsByTagName('tr');
|
||||
var tr=document.getElementById(app.currentApp+app.currentTab+'List').getElementsByTagName('tbody')[0].getElementsByTagName('tr');
|
||||
for (var item in obj.data) {
|
||||
nrItems++;
|
||||
var d = new Date(obj.data[item].last_modified * 1000);
|
||||
@ -402,19 +446,19 @@ function webSocketConnect() {
|
||||
'<td><a>' + basename(obj.data[item].plist) + '</a></td>' +
|
||||
'<td>'+d.toUTCString()+'</td><td></td></tr>';
|
||||
if (nrItems <= tr.length) { $(tr[nrItems-1]).replaceWith(row); }
|
||||
else { $('#'+app.currentApp+'List > tbody').append(row); }
|
||||
else { $('#'+app.currentApp+app.currentTab+'List > tbody').append(row); }
|
||||
}
|
||||
for (var i=tr.length;i>nrItems;i--) {
|
||||
$(tr[tr.length-1]).remove();
|
||||
}
|
||||
setPagination(obj.totalEntities);
|
||||
if ( isTouch ) {
|
||||
$('#'+app.currentApp+'List > tbody > tr > td:last-child').append(
|
||||
$('#'+app.currentApp+app.currentTab+'List > tbody > tr > td:last-child').append(
|
||||
'<a class="pull-right btn-group-hover color-darkgrey" href="#/browse/playlists/' + pagination + '" '+
|
||||
'onclick="delPlaylist($(this).parents(\'tr\'));">' +
|
||||
'<span class="material-icons">delete</span></a>');
|
||||
} else {
|
||||
$('#'+app.currentApp+'List > tbody > tr').on({
|
||||
$('#'+app.currentApp+app.currentTab+'List > tbody > tr').on({
|
||||
mouseover: function(){
|
||||
if($(this).children().last().has('a').length == 0)
|
||||
$(this).children().last().append(
|
||||
@ -428,14 +472,14 @@ function webSocketConnect() {
|
||||
}
|
||||
});
|
||||
};
|
||||
$('#'+app.currentApp+'List > tbody > tr').on({
|
||||
$('#'+app.currentApp+app.currentTab+'List > tbody > tr').on({
|
||||
click: function() {
|
||||
socket.send('MPD_API_ADD_PLAYLIST,' + decodeURI($(this).attr('uri')));
|
||||
showNotification('"' + $('td:nth-last-child(3)', this).text() + '" added','','','success');
|
||||
}
|
||||
});
|
||||
if (nrItems == 0) {
|
||||
$('#'+app.currentApp+'List > tbody').append(
|
||||
$('#'+app.currentApp+app.currentTab+'List > tbody').append(
|
||||
'<tr><td><span class="material-icons">error_outline</span></td>' +
|
||||
'<td colspan="3">No playlists found.</td>' +
|
||||
'<td></td><td></td></tr>'
|
||||
@ -444,43 +488,43 @@ function webSocketConnect() {
|
||||
break;
|
||||
|
||||
case 'listDBtags':
|
||||
if(app.currentApp !== 'browseDatabase' && app.currentApp !== 'browseDatabaseArtist')
|
||||
if(app.currentApp !== 'browse' && app.currentTab !== 'Database')
|
||||
break;
|
||||
if (obj.tagtype == 'AlbumArtist') {
|
||||
$('#browseDatabaseCards').addClass('hide');
|
||||
$('#browseDatabaseList').removeClass('hide');
|
||||
$('#browseDatabaseAlbumCards').addClass('hide');
|
||||
$('#browseDatabaseArtistList').removeClass('hide');
|
||||
$('#btnBrowseDatabaseArtist').addClass('hide');
|
||||
var nrItems=0;
|
||||
var tr=document.getElementById(app.currentApp+'List').getElementsByTagName('tbody')[0].getElementsByTagName('tr');
|
||||
var tr=document.getElementById(app.currentApp+app.currentTab+app.currentView+'List').getElementsByTagName('tbody')[0].getElementsByTagName('tr');
|
||||
for (var item in obj.data) {
|
||||
nrItems++;
|
||||
var row='<tr uri="' + encodeURI(obj.data[item].value) + '">' +
|
||||
'<td><span class="material-icons">album</span></td>' +
|
||||
'<td><a>' + obj.data[item].value + '</a></td></tr>';
|
||||
if (nrItems <= tr.length) { $(tr[nrItems-1]).replaceWith(row); }
|
||||
else { $('#'+app.currentApp+'List > tbody').append(row); }
|
||||
else { $('#'+app.currentApp+app.currentTab+app.currentView+'List > tbody').append(row); }
|
||||
|
||||
}
|
||||
for (var i=tr.length;i>nrItems;i--) {
|
||||
$(tr[tr.length-1]).remove();
|
||||
}
|
||||
setPagination(obj.totalEntities);
|
||||
$('#'+app.currentApp+'List > tbody > tr').on({
|
||||
$('#'+app.currentApp+app.currentTab+app.currentView+'List > tbody > tr').on({
|
||||
click: function() {
|
||||
app.goto('browseDatabaseArtist','0/!/'+$(this).attr('uri'));
|
||||
app.goto('browse','Database','Album','0/!/'+$(this).attr('uri'));
|
||||
}
|
||||
});
|
||||
if (nrItems == 0) {
|
||||
$('#'+app.currentApp+'List > tbody').append(
|
||||
$('#'+app.currentApp+app.currentTab+app.currentView+'List > tbody').append(
|
||||
'<tr><td><span class="material-icons">error_outline</span></td>' +
|
||||
'<td colspan="3">No entries found.</td>' +
|
||||
'<td></td><td></td></tr>'
|
||||
);
|
||||
}
|
||||
} else if (obj.tagtype == 'Album') {
|
||||
$('#browseDatabaseList').addClass('hide');
|
||||
$('#browseDatabaseCards').empty();
|
||||
$('#browseDatabaseCards').removeClass('hide');
|
||||
$('#browseDatabaseArtistList').addClass('hide');
|
||||
$('#browseDatabaseAlbumCards').empty();
|
||||
$('#browseDatabaseAlbumCards').removeClass('hide');
|
||||
$('#btnBrowseDatabaseArtist').removeClass('hide');
|
||||
var nrItems=0;
|
||||
for (var item in obj.data) {
|
||||
@ -492,7 +536,7 @@ function webSocketConnect() {
|
||||
' <table class="table table-sm table-hover" id="tbl'+genId(obj.data[item].value)+'"><tbody></tbody></table'+
|
||||
' </div>'+
|
||||
'</div></div>';
|
||||
$('#browseDatabaseCards').append(card);
|
||||
$('#browseDatabaseAlbumCards').append(card);
|
||||
socket.send('MPD_API_GET_ARTISTALBUMTITLES,' + obj.searchstr + ','+obj.data[item].value);
|
||||
}
|
||||
setPagination(obj.totalEntities);
|
||||
@ -532,7 +576,7 @@ function webSocketConnect() {
|
||||
$('#searchAddAllSongs').attr('disabled','disabled').addClass('disabled');
|
||||
}
|
||||
case 'browse':
|
||||
if(app.currentApp !== 'browseFilesystem' && app.currentApp !== 'search')
|
||||
if(app.currentApp !== 'browse' && app.currentTab !== 'Filesystem' && app.currentApp !== 'search')
|
||||
break;
|
||||
|
||||
/* The use of encodeURI() below might seem useless, but it's not. It prevents
|
||||
@ -540,7 +584,7 @@ function webSocketConnect() {
|
||||
* URI from NFD to NFC, breaking our link with MPD.
|
||||
*/
|
||||
var nrItems=0;
|
||||
var tr=document.getElementById(app.currentApp+'List').getElementsByTagName('tbody')[0].getElementsByTagName('tr');
|
||||
var tr=document.getElementById(app.currentApp+app.currentTab+'List').getElementsByTagName('tbody')[0].getElementsByTagName('tr');
|
||||
for (var item in obj.data) {
|
||||
nrItems++;
|
||||
var row='';
|
||||
@ -570,7 +614,7 @@ function webSocketConnect() {
|
||||
break;
|
||||
}
|
||||
if (nrItems <= tr.length) { $(tr[nrItems-1]).replaceWith(row); }
|
||||
else { $('#'+app.currentApp+'List > tbody').append(row); }
|
||||
else { $('#'+app.currentApp+app.currentTab+'List > tbody').append(row); }
|
||||
}
|
||||
for (var i=tr.length;i>nrItems;i--) {
|
||||
$(tr[tr.length-1]).remove();
|
||||
@ -578,7 +622,7 @@ function webSocketConnect() {
|
||||
setPagination(obj.totalEntities);
|
||||
|
||||
if (nrItems == 0) {
|
||||
$('#'+app.currentApp+'List > tbody').append(
|
||||
$('#'+app.currentApp+app.currentTab+'List > tbody').append(
|
||||
'<tr><td><span class="material-icons">error_outline</span></td>' +
|
||||
'<td colspan="3">No results</td>' +
|
||||
'<td></td><td></td></tr>');
|
||||
@ -596,8 +640,8 @@ function webSocketConnect() {
|
||||
}
|
||||
|
||||
if ( isTouch ) {
|
||||
appendClickableIcon($('#'+app.currentApp+'List > tbody > tr.dir > td:last-child'), 'MPD_API_ADD_TRACK', 'playlist_add');
|
||||
appendClickableIcon($('#'+app.currentApp+'List > tbody > tr.song > td:last-child'), 'MPD_API_ADD_TRACK', 'playlist_add');
|
||||
appendClickableIcon($('#'+app.currentApp+app.currentTab+'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');
|
||||
} else {
|
||||
$('#'+app.currentApp+'List > tbody > tr').on({
|
||||
mouseenter: function() {
|
||||
@ -611,14 +655,14 @@ function webSocketConnect() {
|
||||
}
|
||||
});
|
||||
};
|
||||
$('#'+app.currentApp+'List > tbody > tr').on({
|
||||
$('#'+app.currentApp+app.currentTab+'List > tbody > tr').on({
|
||||
click: function() {
|
||||
switch($(this).attr('class')) {
|
||||
case 'dir':
|
||||
pagination = 0;
|
||||
browsepath = $(this).attr("uri");
|
||||
//$("#browseFilesystemList > a").attr("href", '#/browse/filesystem/'+pagination+'/'+filterLetter+'/'+browsepath);
|
||||
app.goto('browseFilesystem',pagination+'/'+filterLetter+'/'+browsepath);
|
||||
$("#browseFilesystemList > a").attr("href", '#/browseFilesystem/'+pagination+'/'+filterLetter+'/'+browsepath);
|
||||
app.goto('browse','Filesystem',undefined,pagination+'/'+filterLetter+'/'+browsepath);
|
||||
break;
|
||||
case 'song':
|
||||
socket.send("MPD_API_ADD_TRACK," + decodeURI($(this).attr("uri")));
|
||||
@ -636,8 +680,8 @@ function webSocketConnect() {
|
||||
click: function() {
|
||||
pagination = 0;
|
||||
browsepath = $(this).attr("uri");
|
||||
//$("#browseFilesystemList > a").attr("href", '#/browse/filesystem/'+pagination+'/'+filterLetter+'/'+browsepath);
|
||||
app.goto('browseFilesystem',pagination+'/'+filterLetter+'/'+browsepath);
|
||||
$("#browseFilesystemList > a").attr("href", '#/browseFilesystem/'+pagination+'/'+filterLetter+'/'+browsepath);
|
||||
app.goto('browse','Filesystem',undefined,pagination+'/'+filterLetter+'/'+browsepath);
|
||||
}
|
||||
});
|
||||
|
||||
@ -827,38 +871,38 @@ function get_appropriate_ws_url()
|
||||
function setPagination(number) {
|
||||
var totalPages=Math.ceil(number / MAX_ELEMENTS_PER_PAGE);
|
||||
if (totalPages==0) { totalPages=1; }
|
||||
$('#'+app.currentApp+'PaginationTopPage').text('Page '+(pagination / MAX_ELEMENTS_PER_PAGE + 1)+' / '+totalPages);
|
||||
$('#'+app.currentApp+'PaginationBottomPage').text('Page '+(pagination / MAX_ELEMENTS_PER_PAGE + 1)+' / '+totalPages);
|
||||
$('#'+app.currentApp+app.currentTab+'PaginationTopPage').text('Page '+(pagination / MAX_ELEMENTS_PER_PAGE + 1)+' / '+totalPages);
|
||||
$('#'+app.currentApp+app.currentTab+'PaginationBottomPage').text('Page '+(pagination / MAX_ELEMENTS_PER_PAGE + 1)+' / '+totalPages);
|
||||
if (totalPages > 1) {
|
||||
$('#'+app.currentApp+'PaginationTopPage').removeClass('disabled').removeAttr('disabled');
|
||||
$('#'+app.currentApp+'PaginationBottomPage').removeClass('disabled').removeAttr('disabled');
|
||||
$('#'+app.currentApp+'PaginationTopPages').empty();
|
||||
$('#'+app.currentApp+'PaginationBottomPages').empty();
|
||||
$('#'+app.currentApp+app.currentTab+'PaginationTopPage').removeClass('disabled').removeAttr('disabled');
|
||||
$('#'+app.currentApp+app.currentTab+'PaginationBottomPage').removeClass('disabled').removeAttr('disabled');
|
||||
$('#'+app.currentApp+app.currentTab+'PaginationTopPages').empty();
|
||||
$('#'+app.currentApp+app.currentTab+'PaginationBottomPages').empty();
|
||||
for (var i=0;i<totalPages;i++) {
|
||||
$('#'+app.currentApp+'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+'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>');
|
||||
$('#'+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>');
|
||||
$('#'+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>');
|
||||
}
|
||||
} else {
|
||||
$('#'+app.currentApp+'PaginationTopPage').addClass('disabled').attr('disabled','disabled');
|
||||
$('#'+app.currentApp+'PaginationBottomPage').addClass('disabled').attr('disabled','disabled');
|
||||
$('#'+app.currentApp+app.currentTab+'PaginationTopPage').addClass('disabled').attr('disabled','disabled');
|
||||
$('#'+app.currentApp+app.currentTab+'PaginationBottomPage').addClass('disabled').attr('disabled','disabled');
|
||||
}
|
||||
|
||||
if(number > pagination + MAX_ELEMENTS_PER_PAGE) {
|
||||
$('#'+app.currentApp+'PaginationTopNext').removeClass('disabled').removeAttr('disabled');
|
||||
$('#'+app.currentApp+'PaginationBottomNext').removeClass('disabled').removeAttr('disabled');
|
||||
$('#'+app.currentApp+'ButtonsBottom').removeClass('hide');
|
||||
$('#'+app.currentApp+app.currentTab+'PaginationTopNext').removeClass('disabled').removeAttr('disabled');
|
||||
$('#'+app.currentApp+app.currentTab+'PaginationBottomNext').removeClass('disabled').removeAttr('disabled');
|
||||
$('#'+app.currentApp+app.currentTab+'ButtonsBottom').removeClass('hide');
|
||||
} else {
|
||||
$('#'+app.currentApp+'PaginationTopNext').addClass('disabled').attr('disabled','disabled');
|
||||
$('#'+app.currentApp+'PaginationBottomNext').addClass('disabled').attr('disabled','disabled');
|
||||
$('#'+app.currentApp+'ButtonsBottom').addClass('hide');
|
||||
$('#'+app.currentApp+app.currentTab+'PaginationTopNext').addClass('disabled').attr('disabled','disabled');
|
||||
$('#'+app.currentApp+app.currentTab+'PaginationBottomNext').addClass('disabled').attr('disabled','disabled');
|
||||
$('#'+app.currentApp+app.currentTab+'ButtonsBottom').addClass('hide');
|
||||
}
|
||||
|
||||
if(pagination > 0) {
|
||||
$('#'+app.currentApp+'PaginationTopPrev').removeClass('disabled').removeAttr('disabled');
|
||||
$('#'+app.currentApp+'PaginationBottomPrev').removeClass('disabled').removeAttr('disabled');
|
||||
$('#'+app.currentApp+app.currentTab+'PaginationTopPrev').removeClass('disabled').removeAttr('disabled');
|
||||
$('#'+app.currentApp+app.currentTab+'PaginationBottomPrev').removeClass('disabled').removeAttr('disabled');
|
||||
} else {
|
||||
$('#'+app.currentApp+'PaginationTopPrev').addClass('disabled').attr('disabled','disabled');
|
||||
$('#'+app.currentApp+'PaginationBottomPrev').addClass('disabled').attr('disabled','disabled');
|
||||
$('#'+app.currentApp+app.currentTab+'PaginationTopPrev').addClass('disabled').attr('disabled','disabled');
|
||||
$('#'+app.currentApp+app.currentTab+'PaginationBottomPrev').addClass('disabled').attr('disabled','disabled');
|
||||
}
|
||||
}
|
||||
|
||||
@ -980,27 +1024,27 @@ $('#btnrepeat').on('click', function (e) {
|
||||
});
|
||||
|
||||
$('#cardBrowseNavFilesystem').on('click', function (e) {
|
||||
app.goto('browseFilesystem');
|
||||
app.goto('browse','Filesystem');
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$('#cardBrowseNavDatabase').on('click', function (e) {
|
||||
app.goto('browseDatabase');
|
||||
app.goto('browse','Database');
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$('#btnBrowseDatabaseArtist').on('click', function (e) {
|
||||
app.goto('browseDatabase');
|
||||
app.goto('browse','Database','Artist');
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$('#cardBrowseNavPlaylists').on('click', function (e) {
|
||||
app.goto('browsePlaylists');
|
||||
app.goto('browse','Playlists');
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$('#cardBrowseNavFilesystem').on('click', function (e) {
|
||||
app.goto('browseFilesystem');
|
||||
app.goto('browse','Filesystem');
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
@ -1015,7 +1059,7 @@ $('#navQueue').on('click', function (e) {
|
||||
});
|
||||
|
||||
$('#navBrowse').on('click', function (e) {
|
||||
app.goto('browseFilesystem');
|
||||
app.goto('browse');
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
@ -1120,7 +1164,7 @@ $('#search > input').keypress(function (event) {
|
||||
});
|
||||
|
||||
$('#search').submit(function () {
|
||||
app.goto('search',pagination + '/Any Tag/' + $('#search > input').val());
|
||||
app.goto('search',undefined,undefined,pagination + '/Any Tag/' + $('#search > input').val());
|
||||
return false;
|
||||
});
|
||||
|
||||
@ -1129,7 +1173,7 @@ function doSearch(searchstr) {
|
||||
$('#searchtags2 > button').each(function() {
|
||||
if ($(this).hasClass('btn-success')) { mpdtag=$(this).text(); }
|
||||
});
|
||||
app.goto('search',pagination + '/' + mpdtag + '/' + searchstr);
|
||||
app.goto('search',undefined,undefined,pagination + '/' + mpdtag + '/' + searchstr);
|
||||
}
|
||||
|
||||
$('#search2').submit(function () {
|
||||
@ -1179,7 +1223,7 @@ function doQueueSearch() {
|
||||
$('#searchqueuetag > button').each(function() {
|
||||
if ($(this).hasClass('btn-success')) { mpdtag=$(this).text(); }
|
||||
});
|
||||
app.goto('queue', pagination + '/' + mpdtag + '/' + searchstr);
|
||||
app.goto('queue',undefined,undefined,pagination + '/' + mpdtag + '/' + searchstr);
|
||||
}
|
||||
|
||||
$('#searchqueue').submit(function () {
|
||||
@ -1218,20 +1262,19 @@ function gotoPage(x,element,event) {
|
||||
$('#searchqueuetag > button').each(function() {
|
||||
if ($(this).hasClass('btn-success')) { mpdtag=$(this).text(); }
|
||||
});
|
||||
app.goto('queue', pagination+'/'+mpdtag+'/');
|
||||
app.goto('queue',undefined,undefined, pagination+'/'+mpdtag+'/');
|
||||
}
|
||||
break;
|
||||
case "search":
|
||||
doSearch($('#searchstr2').val());
|
||||
break;
|
||||
case "browseFilesystem":
|
||||
app.goto('browseFilesystem', pagination+'/'+filterLetter+'/'+browsepath);
|
||||
break;
|
||||
case "browsePlaylists":
|
||||
app.goto('browsePlaylists', pagination+'/'+filterLetter);
|
||||
break;
|
||||
case "browseDatabase":
|
||||
app.goto('browseDatabase', pagination+'/'+filterLetter+'/'+artist);
|
||||
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;
|
||||
}
|
||||
event.preventDefault();
|
||||
@ -1340,18 +1383,21 @@ $(document).keydown(function(e){
|
||||
});
|
||||
|
||||
function setFilterLetter(filter) {
|
||||
pagination = 0;
|
||||
switch(app.currentApp) {
|
||||
case 'browseFilesystem':
|
||||
app.goto('browseFilesystem', pagination+'/'+filter+'/'+browsepath);
|
||||
pagination = 0;
|
||||
if (app.currentApp == 'browse') {
|
||||
switch(app.currentTab) {
|
||||
case 'Filesystem':
|
||||
app.goto('browse','Filesystem',undefined, pagination+'/'+filter+'/'+browsepath);
|
||||
break;
|
||||
case 'browseDatabase':
|
||||
app.goto('browseDatabase', pagination+'/'+filter+'/'+artist);
|
||||
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 'browsePlaylists':
|
||||
app.goto('browsePlaylists', pagination+'/'+filter+'/'+artist);
|
||||
case 'Playlists':
|
||||
app.goto('browse','Playlists',undefined, pagination+'/'+filter+'/');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function doSetFilterLetter(x) {
|
||||
|
@ -516,6 +516,13 @@ static int mpd_notify_callback(struct mg_connection *c, enum mg_event ev) {
|
||||
{
|
||||
mg_websocket_write(c, 1, mpd.buf, mpd.buf_size);
|
||||
|
||||
if(s->queue_version != mpd.queue_version)
|
||||
{
|
||||
n = snprintf(mpd.buf, MAX_SIZE, "{\"type\":\"update_queue\"}");
|
||||
mg_websocket_write(c, 1, mpd.buf, n);
|
||||
s->queue_version = mpd.queue_version;
|
||||
}
|
||||
|
||||
if(s->song_id != mpd.song_id || s->queue_version != mpd.queue_version)
|
||||
{
|
||||
n = mpd_put_current_song(mpd.buf);
|
||||
@ -523,12 +530,7 @@ static int mpd_notify_callback(struct mg_connection *c, enum mg_event ev) {
|
||||
s->song_id = mpd.song_id;
|
||||
}
|
||||
|
||||
if(s->queue_version != mpd.queue_version)
|
||||
{
|
||||
n = snprintf(mpd.buf, MAX_SIZE, "{\"type\":\"update_queue\"}");
|
||||
mg_websocket_write(c, 1, mpd.buf, n);
|
||||
s->queue_version = mpd.queue_version;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return MG_TRUE;
|
||||
@ -704,7 +706,7 @@ int mpd_put_state(char *buffer, int *current_song_id, int *next_song_id, unsign
|
||||
"\"state\":%d, \"volume\":%d, \"songpos\": %d, \"elapsedTime\": %d, "
|
||||
"\"totalTime\":%d, \"currentsongid\": %d, \"kbitrate\": %d, "
|
||||
"\"audioformat\": { \"sample_rate\": %d, \"bits\": %d, \"channels\": %d}, "
|
||||
"\"queue_length\": %d, \"nextsongpos\": %d"
|
||||
"\"queue_length\": %d, \"nextsongpos\": %d, \"nextsongid\": %d"
|
||||
"}}",
|
||||
mpd_status_get_state(status),
|
||||
mpd_status_get_volume(status),
|
||||
@ -717,7 +719,8 @@ int mpd_put_state(char *buffer, int *current_song_id, int *next_song_id, unsign
|
||||
audioformat ? audioformat->bits : 0,
|
||||
audioformat ? audioformat->channels : 0,
|
||||
mpd_status_get_queue_length(status),
|
||||
mpd_status_get_next_song_pos(status)
|
||||
mpd_status_get_next_song_pos(status),
|
||||
mpd_status_get_next_song_id(status)
|
||||
);
|
||||
|
||||
*current_song_id = mpd_status_get_song_id(status);
|
||||
@ -825,7 +828,7 @@ int mpd_put_current_song(char *buffer)
|
||||
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, "}}");
|
||||
|
||||
|
||||
mpd_song_free(song);
|
||||
mpd_response_finish(mpd.conn);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user