1
0
mirror of https://github.com/SuperBFG7/ympd synced 2024-12-25 10:30:26 +00:00

Feat: configurable tags in playback card

This commit is contained in:
jcorporation 2018-11-04 23:26:59 +00:00
parent 5920d66909
commit 65c5d6486d
5 changed files with 76 additions and 70 deletions

View File

@ -89,13 +89,8 @@
<div class="card-body">
<div class="album-cover featCoverimage" id="currentCover"></div>
<div class="album-desc">
<h2 id="currentTrack" data-href='{"cmd": "songClick", "options": []}'></h2>
<div class="featTags">
<small>Artist</small>
<h4 id="currentArtist" data-href='{"cmd": "artistClick", "options": []}'></h4>
<small>Album</small>
<h4 id="currentAlbum" data-href='{"cmd": "albumClick", "options": []}'></h4>
</div>
<h2 id="currentTitle" data-href='{"cmd": "titleClick", "options": []}'></h2>
<div class="featTags" id="cardPlaybackTags"></div>
</div>
</div>
<div class="card-footer card-footer-playback">

View File

@ -77,10 +77,8 @@ domCache.progressBar = document.getElementById('progressBar');
domCache.volumeBar = document.getElementById('volumeBar');
domCache.outputs = document.getElementById('outputs');
domCache.btnAdd = document.getElementById('nav-add2homescreen');
domCache.currentTrack = document.getElementById('currentTrack');
domCache.currentArtist = document.getElementById('currentArtist');
domCache.currentAlbum = document.getElementById('currentAlbum');
domCache.currentCover = document.getElementById('currentCover');
domCache.currentTitle = document.getElementById('currentTitle');
domCache.btnVoteUp = document.getElementById('btnVoteUp');
domCache.btnVoteDown = document.getElementById('btnVoteDown');
@ -416,6 +414,11 @@ function appInit() {
}, false);
}
document.getElementById('cardPlaybackTags').addEventListener('click', function(event) {
if (event.target.nodeName == 'H4')
gotoBrowse(event.target);
}, false);
document.getElementById('outputs').addEventListener('click', function(event) {
if (event.target.nodeName == 'BUTTON')
event.stopPropagation();
@ -1061,6 +1064,18 @@ function parseSettings(obj) {
settings.colsBrowseFilesystem = ["Type", "Title", "Duration"];
settings.colsBrowseDatabase = ["Track", "Title", "Duration"];
}
else {
var pbtl = '';
for (var i = 0; i < settings.colsPlayback.length; i++) {
pbtl += '<small>' + settings.colsPlayback[i] + '</small>' +
'<h4 ';
if (settings.browsetags.includes(settings.colsPlayback[i]))
pbtl += 'class="clickable" ';
pbtl += 'id="current' + settings.colsPlayback[i] + '" data-tag="' + settings.colsPlayback[i] + '">' +
( lastSong ? lastSong[settings.colsPlayback[i]] : '') + '</h4>';
}
document.getElementById('cardPlaybackTags').innerHTML = pbtl;
}
if (settings.mixramp == true)
document.getElementsByClassName('mixramp')[0].style.display = '';
@ -1100,6 +1115,7 @@ function parseSettings(obj) {
filterCols('colsBrowsePlaylistsDetail');
filterCols('colsBrowseFilesystem');
filterCols('colsBrowseDatabase');
filterCols('colsPlayback');
if (settings.featLocalplayer) {
if (settings.streamurl == '') {
@ -1350,10 +1366,11 @@ function parseState(obj) {
sendAPI({"cmd": "MPD_API_PLAYER_CURRENT_SONG"}, songChange);
//clear playback card if not playing
if (obj.data.songPos == '-1') {
domCache.currentTrack.innerText = 'Not playing';
domCache.currentAlbum.innerText = '';
domCache.currentArtist.innerText = '';
domCache.currentTitle.innerText = 'Not playing';
domCache.currentCover.style.backgroundImage = '';
var pb = document.getElementById('cardPlaybackTags').getElementsByTagName('h4');
for (var i = 0; i < pb.length; i++)
pb[i].innerText = '';
}
lastState = obj;
@ -1881,26 +1898,17 @@ function replaceQueue(type, uri, name) {
}
}
function songClick() {
var uri = domCache.currentTrack.getAttribute('data-uri')
function titleClick() {
var uri = decodeURI(domCache.currentTitle.getAttribute('data-uri'));
if (uri != '')
songDetails(uri);
}
function artistClick() {
var albumartist = domCache.currentArtist.getAttribute('data-albumartist');
if (albumartist != '') {
if (settings.tags.includes('AlbumArtist'))
appGoto('Browse', 'Database', 'AlbumArtist', '0/-/' + albumartist);
else if (settings.tags.includes('Artist'))
appGoto('Browse', 'Database', 'Artist', '0/-/' + albumartist);
}
}
function albumClick() {
var album = domCache.currentAlbum.getAttribute('data-album');
if (album != '')
appGoto('Browse', 'Database', 'Album', '0/-/' + album);
function gotoBrowse(x) {
var tag = x.getAttribute('data-tag');
var name = decodeURI(x.getAttribute('data-name'));
if (tag != '' && name != '' && settings.browsetags.includes(tag))
appGoto('Browse', 'Database', tag, '0/-/' + name);
}
function songDetails(uri) {
@ -2685,39 +2693,33 @@ function songChange(obj) {
textNotification += obj.data.Artist;
htmlNotification += obj.data.Artist;
pageTitle += obj.data.Artist + ' - ';
domCache.currentArtist.innerText = obj.data.Artist;
if (obj.data.AlbumArtist != undefined)
domCache.currentArtist.setAttribute('data-albumartist', obj.data.AlbumArtist);
else if (obj.data.Artist != undefined)
domCache.currentArtist.setAttribute('data-albumartist', obj.data.Artist);
else
domCache.currentArtist.setAttribute('data-albumartist', '');
} else
domCache.currentArtist.innerText = '';
}
if (typeof obj.data.Album != 'undefined' && obj.data.Album.length > 0 && obj.data.Album != '-') {
textNotification += ' - ' + obj.data.Album;
htmlNotification += '<br/>' + obj.data.Album;
domCache.currentAlbum.innerText = obj.data.Album;
domCache.currentAlbum.setAttribute('data-album', obj.data.Album);
}
else
domCache.currentAlbum.innerText = '';
if (typeof obj.data.Title != 'undefined' && obj.data.Title.length > 0) {
pageTitle += obj.data.Title;
domCache.currentTrack.innerText = obj.data.Title;
domCache.currentTrack.setAttribute('data-uri', obj.data.uri);
} else {
domCache.currentTrack.innerText = '';
domCache.currentTrack.setAttribute('data-uri', '');
domCache.currentTitle.innerText = obj.data.Title;
domCache.currentTitle.setAttribute('data-uri', encodeURI(obj.data.uri));
}
else {
domCache.currentTitle.innerText = '';
domCache.currentTitle.setAttribute('data-uri', '');
}
document.title = pageTitle;
if (settings.featStickers == true) {
setVoteSongBtns(obj.data.like, obj.data.uri);
}
for (var i = 0; i < settings.colsPlayback.length; i++) {
var c = document.getElementById('current' + settings.colsPlayback[i]);
c.innerText = obj.data[settings.colsPlayback[i]];
c.setAttribute('data-name', encodeURI(obj.data[settings.colsPlayback[i]]));
}
//Update Artist in queue view for http streams
var playingTr = document.getElementById('queueTrackId' + obj.data.currentSongId);

View File

@ -786,7 +786,7 @@ void mympd_mpd_features() {
printf("\nmyMPD enabled searchtags: ");
token = strtok(searchtaglist, s);
while (token != NULL) {
if (list_get_value(&mpd_tags, token) == 1) {
if (list_get_value(&mympd_tags, token) == 1) {
list_push(&mympd_searchtags, token, 1);
printf("%s ", token);
}
@ -795,7 +795,7 @@ void mympd_mpd_features() {
printf("\nmyMPD enabled browsetags: ");
token = strtok(browsetaglist, s);
while (token != NULL) {
if (list_get_value(&mpd_tags, token) == 1) {
if (list_get_value(&mympd_tags, token) == 1) {
list_push(&mympd_browsetags, token, 1);
printf("%s ", token);
}
@ -1442,6 +1442,7 @@ int mympd_put_settings(char *buffer) {
len += json_printf(&out, ", colsBrowseDatabase: %s", mympd_state.colsBrowseDatabase);
len += json_printf(&out, ", colsBrowsePlaylistsDetail: %s", mympd_state.colsBrowsePlaylistsDetail);
len += json_printf(&out, ", colsBrowseFilesystem: %s", mympd_state.colsBrowseFilesystem);
len += json_printf(&out, ", colsPlayback: %s", mympd_state.colsPlayback);
len += json_printf(&out, "}}");
CHECK_RETURN_LEN();

View File

@ -176,29 +176,29 @@ struct list syscmds;
typedef struct {
long mpdport;
const char* mpdhost;
const char* mpdpass;
const char* webport;
const char *mpdhost;
const char *mpdpass;
const char *webport;
bool ssl;
const char* sslport;
const char* sslcert;
const char* sslkey;
const char* user;
const char *sslport;
const char *sslcert;
const char *sslkey;
const char *user;
bool coverimage;
const char* coverimagename;
const char *coverimagename;
bool stickers;
bool mixramp;
const char* taglist;
const char* searchtaglist;
const char* browsetaglist;
const char *taglist;
const char *searchtaglist;
const char *browsetaglist;
bool smartpls;
const char* varlibdir;
const char* etcdir;
const char *varlibdir;
const char *etcdir;
unsigned long max_elements_per_page;
bool syscmds;
bool localplayer;
long streamport;
const char* streamurl;
const char *streamurl;
} t_config;
t_config config;
@ -214,13 +214,14 @@ typedef struct {
bool notificationWeb;
bool notificationPage;
int jukeboxMode;
const char* jukeboxPlaylist;
const char *jukeboxPlaylist;
int jukeboxQueueLength;
char* colsQueue;
char* colsSearch;
char* colsBrowseDatabase;
char* colsBrowsePlaylistsDetail;
char* colsBrowseFilesystem;
char *colsQueue;
char *colsSearch;
char *colsBrowseDatabase;
char *colsBrowsePlaylistsDetail;
char *colsBrowseFilesystem;
char *colsPlayback;
} t_mympd_state;
t_mympd_state mympd_state;

View File

@ -311,6 +311,13 @@ void read_statefiles() {
mympd_state.colsBrowseFilesystem = strdup("[\"Type\",\"Title\",\"Artist\",\"Album\",\"Duration\"]");
mympd_state_set("colsBrowseFilesystem", mympd_state.colsBrowseFilesystem);
}
if (mympd_state_get("colsPlayback", value))
mympd_state.colsPlayback = strdup(value);
else {
mympd_state.colsPlayback = strdup("[\"Artist\",\"Album\",\"Genre\"]");
mympd_state_set("colsPlayback", mympd_state.colsPlayback);
}
}
bool testdir(char *name, char *dirname) {