Skip to content

Commit

Permalink
Upd: Show friendly album names instead of ids
Browse files Browse the repository at this point in the history
Fix: Add album to home
  • Loading branch information
jcorporation committed Sep 18, 2024
1 parent 2e29f91 commit df5ead0
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 54 deletions.
34 changes: 0 additions & 34 deletions htdocs/js/album.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,6 @@

/** @module album_js */

/**
* Handles album filtered by tag
* @param {string} action action to perform
* @param {string} albumId the album id
* @param {string} tag MPD tag
* @param {string} value MPD tag value
* @returns {void}
*/
//eslint-disable-next-line no-unused-vars
function addAlbumTag(action, albumId, tag, value) {
switch(action) {
case 'appendQueue':
appendQueue(tag, [albumId, value]);
break;
case 'appendPlayQueue':
appendPlayQueue(tag, [albumId, value]);
break;
case 'insertAfterCurrentQueue':
insertAfterCurrentQueue(tag, [albumId, value]);
break;
case 'replaceQueue':
replaceQueue(tag, [albumId, value]);
break;
case 'replacePlayQueue':
replacePlayQueue(tag, [albumId, value]);
break;
case 'addPlaylist':
showAddToPlaylist(tag, [albumId, value]);
break;
default:
logError('Invalid action: ' + action);
}
}

/**
* Resume album API implementation.
* Load the album from last played song and start playing.
Expand Down
30 changes: 19 additions & 11 deletions htdocs/js/contextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,19 +208,20 @@ function addMenuItemsAlbumTagActions(target, contextMenuTitle, contextMenuBody)
const type = getData(dataNode, 'type');
const value = getData(dataNode, ucFirst(type));
const albumId = getData(dataNode, 'AlbumId');
const albumName = getData(dataNode, 'name');

addMenuItem(contextMenuBody, {"cmd": "addAlbumTag", "options": ["appendQueue", albumId, type, value]}, 'Append to queue');
addMenuItem(contextMenuBody, {"cmd": "addAlbumTag", "options": ["appendPlayQueue", albumId, type, value]}, 'Append to queue and play');
addMenuItem(contextMenuBody, {"cmd": "appendQueue", "options": [type, [albumId, value]]}, 'Append to queue');
addMenuItem(contextMenuBody, {"cmd": "appendPlayQueue", "options": [type, [albumId, value]]}, 'Append to queue and play');
if (features.featWhence === true &&
currentState.currentSongId !== -1)
{
addMenuItem(contextMenuBody, {"cmd": "addAlbumTag", "options": ["insertAfterCurrentQueue", albumId, type, value]}, 'Insert after current playing song');
addMenuItem(contextMenuBody, {"cmd": "insertAfterCurrentQueue", "options": [type, [albumId, value]]}, 'Insert after current playing song');
}
addMenuItem(contextMenuBody, {"cmd": "addAlbumTag", "options": ["replaceQueue", albumId, type, value]}, 'Replace queue');
addMenuItem(contextMenuBody, {"cmd": "addAlbumTag", "options": ["replacePlayQueue", albumId, type, value]}, 'Replace queue and play');
addMenuItem(contextMenuBody, {"cmd": "replaceQueue", "options": [type, [albumId, value]]}, 'Replace queue');
addMenuItem(contextMenuBody, {"cmd": "replacePlayQueue", "options": [type, [albumId, value]]}, 'Replace queue and play');
if (features.featPlaylists === true) {
addDivider(contextMenuBody);
addMenuItem(contextMenuBody, {"cmd": "addAlbumTag", "options": ["addPlaylist", albumId, type, value]}, 'Add to playlist');
addMenuItem(contextMenuBody, {"cmd": "showAddToPlaylist", "options": [type, [albumId, value], [albumName]]}, 'Add to playlist');
}
}

Expand Down Expand Up @@ -275,8 +276,15 @@ function addMenuItemsConsumeActions(contextMenuBody) {
* @returns {void}
*/
function addMenuItemsAlbumActions(dataNode, contextMenuTitle, contextMenuBody, albumId) {
const albumName = [];
if (dataNode !== null) {
albumId = getData(dataNode, 'AlbumId');
if (albumId === undefined) {
albumId = getData(dataNode, 'AlbumId');
}
const name = getData(dataNode, 'name');
if (name !== null) {
albumName.push(name);
}
}
if (contextMenuTitle !== null) {
contextMenuTitle.textContent = tn('Album');
Expand All @@ -294,7 +302,7 @@ function addMenuItemsAlbumActions(dataNode, contextMenuTitle, contextMenuBody, a
}
if (features.featPlaylists === true) {
addDivider(contextMenuBody);
addMenuItem(contextMenuBody, {"cmd": "showAddToPlaylist", "options": ["album", [albumId]]}, 'Add to playlist');
addMenuItem(contextMenuBody, {"cmd": "showAddToPlaylist", "options": ["album", [albumId], albumName]}, 'Add to playlist');
}
addDivider(contextMenuBody);
if (app.id !== 'BrowseDatabaseAlbumDetail') {
Expand Down Expand Up @@ -322,10 +330,10 @@ function addMenuItemsAlbumActions(dataNode, contextMenuTitle, contextMenuBody, a
? getData(dataNode, 'name')
: '';
const image = dataNode !== null
? getData(dataNode, 'image')
? getData(dataNode, 'cssImageUrl')
: '';
addDivider(contextMenuBody);
addMenuItem(contextMenuBody, {"cmd": "addAlbumToHome", "options": [albumId, name, image]}, 'Add to homescreen');
addMenuItem(contextMenuBody, {"cmd": "addAlbumToHome", "options": [albumId, name, image.substr(5,image.length-7)]}, 'Add to homescreen');
}
}

Expand Down Expand Up @@ -809,7 +817,7 @@ function createMenuHomeIcon(target, contextMenuTitle, contextMenuBody) {
addMenuItemsSearchActions(contextMenuBody, href.options[1][0], href.options[1][1], href.options[1][2]);
break;
case 'album':
addMenuItemsAlbumActions(null, null, contextMenuBody, href.options[1][0]);
addMenuItemsAlbumActions(target, null, contextMenuBody, href.options[1][0]);
break;
case 'view':
case 'externalLink':
Expand Down
10 changes: 8 additions & 2 deletions htdocs/js/modalPlaylistAddTo.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ function initModalPlaylistAddTo() {
* Shows the add to playlist modal
* @param {string} type one off album, disc, search, song, stream, searchdir
* @param {Array} entities entities to add
* @param {Array} [entityNames] entity names to add (only for display)
* @returns {void}
*/
function showAddToPlaylist(type, entities) {
function showAddToPlaylist(type, entities, entityNames) {
cleanupModalId('modalPlaylistAddTo');
setDataId('modalPlaylistAddToUrisInput', 'type', type);
setDataId('modalPlaylistAddToUrisInput', 'entities', entities);
Expand All @@ -41,7 +42,12 @@ function showAddToPlaylist(type, entities) {
elHideId('modalPlaylistAddToAddStreamFrm');
elShowId('modalPlaylistAddToSrcRow');
const names = [];
if (type === 'searchdir') {
if (entityNames !== undefined &&
entityNames.length > 0)
{
names.push(... entityNames);
}
else if (type === 'searchdir') {
names.push(tn('Path') + ': ' + entities[0]);
if (entities[1] !== '') {
names.push(tn('Search') + ': ' + entities[1]);
Expand Down
3 changes: 2 additions & 1 deletion htdocs/js/selectActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ function execSelectAction(type, action) {
const parent = elGetById(app.id + 'List');
const attribute = getExecSelectActionAttribute(type, action);
const data = getSelectionData(parent, attribute);
const names = getSelectionData(parent, 'name');
switch(action) {
case 'appendQueue':
appendQueue(type, data);
Expand All @@ -190,7 +191,7 @@ function execSelectAction(type, action) {
removeFromQueueIDs(data);
break;
case 'showAddToPlaylist':
showAddToPlaylist(type, data);
showAddToPlaylist(type, data, names);
break;
case 'showMoveToPlaylist': {
const plist = getData(parent, 'uri');
Expand Down
1 change: 1 addition & 0 deletions htdocs/js/viewHome.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ function createHomeIcon(data, pos) {
}

setData(card, 'type', 'icon');
setData(card, 'name', data.name);
setData(card, 'href', {"cmd": data.cmd, "options": data.options});
setData(card, 'pos', pos);
const cardTitle = elCreateText('div', {"class": ["card-title", "mi", "rounded", "clickable"]}, data.ligature);
Expand Down
16 changes: 10 additions & 6 deletions htdocs/js/viewsTables.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,11 @@ function replaceTblRow(mode, row, el) {
* Adds a row with discnumber to the table
* @param {number} disc discnumber
* @param {string} albumId the albumid
* @param {string} albumName the album name
* @param {number} colspan column count
* @returns {HTMLElement} the created row
*/
function addDiscRow(disc, albumId, colspan) {
function addDiscRow(disc, albumId, albumName, colspan) {
const actionTd = elCreateEmpty('td', {"data-col": "Action"});
addActionLinks(actionTd, 'disc');
const row = elCreateNodes('tr', {"class": ["not-clickable"]}, [
Expand All @@ -171,6 +172,7 @@ function addDiscRow(disc, albumId, colspan) {
setData(row, 'Disc', disc);
setData(row, 'AlbumId', albumId);
setData(row, 'type', 'disc');
setData(row, 'name', albumName + ' (' + tn('Disc') + ' ' + disc + ')');
return row;
}

Expand All @@ -188,10 +190,11 @@ function showWorkRow(view) {
* Adds a row with the work to the table.
* @param {string} work The work name
* @param {string} albumId the albumid
* @param {string} albumName the album name
* @param {number} colspan column count
* @returns {HTMLElement} the created row
*/
function addWorkRow(work, albumId, colspan) {
function addWorkRow(work, albumId, albumName, colspan) {
const actionTd = elCreateEmpty('td', {"data-col": "Action"});
addActionLinks(actionTd, 'work');
const row = elCreateNodes('tr', {"class": ["not-clickable"]}, [
Expand All @@ -204,6 +207,7 @@ function addWorkRow(work, albumId, colspan) {
setData(row, 'Work', work);
setData(row, 'AlbumId', albumId);
setData(row, 'type', 'work');
setData(row, 'name', albumName + ' (' + work + ')');
return row;
}

Expand Down Expand Up @@ -249,7 +253,7 @@ function updateTable(obj, list, perRowCallback, createRowCellsCallback) {
if (obj.result.Discs !== undefined &&
obj.result.Discs > 1)
{
const row = addDiscRow(1, obj.result.AlbumId, colspan);
const row = addDiscRow(1, obj.result.AlbumId, obj.result.Album, colspan);
if (z < tr.length) {
replaceTblRow(mode, tr[z], row);
}
Expand All @@ -260,7 +264,7 @@ function updateTable(obj, list, perRowCallback, createRowCellsCallback) {
}

if (showWorkRow(list) && lastWork !== '') {
const row = addWorkRow(lastWork, obj.result.AlbumId, colspan);
const row = addWorkRow(lastWork, obj.result.AlbumId, obj.result.Album, colspan);
if (z < tr.length) {
replaceTblRow(mode, tr[z], row);
}
Expand All @@ -275,7 +279,7 @@ function updateTable(obj, list, perRowCallback, createRowCellsCallback) {
if (obj.result.data[0].Disc !== undefined &&
lastDisc < Number(obj.result.data[i].Disc))
{
const row = addDiscRow(obj.result.data[i].Disc, obj.result.AlbumId, colspan);
const row = addDiscRow(obj.result.data[i].Disc, obj.result.AlbumId, obj.result.Album, colspan);
if (i + z < tr.length) {
replaceTblRow(mode, tr[i + z], row);
}
Expand All @@ -288,7 +292,7 @@ function updateTable(obj, list, perRowCallback, createRowCellsCallback) {

if (showWorkRow(list) && obj.result.data[0].Work !== undefined &&
lastWork !== obj.result.data[i].Work) {
const row = addWorkRow(obj.result.data[i].Work, obj.result.AlbumId, colspan);
const row = addWorkRow(obj.result.data[i].Work, obj.result.AlbumId, obj.result.Album, colspan);
if (i + z < tr.length) {
replaceTblRow(mode, tr[i + z], row);
} else {
Expand Down

0 comments on commit df5ead0

Please sign in to comment.