From d7c5e3ab604d6ce2f8649cce146d4b5393ceed9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois-Xavier=20Thomas?= Date: Thu, 5 Dec 2019 18:52:34 +0100 Subject: [PATCH] Add 'add to play queue' actions to playlist pages (#1226) --- .../player/ajax/PlayQueueService.java | 29 +++++++++++++++++++ .../src/main/webapp/WEB-INF/jsp/coverArt.jsp | 5 +++- .../src/main/webapp/WEB-INF/jsp/playQueue.jsp | 3 ++ .../src/main/webapp/WEB-INF/jsp/playlist.jsp | 6 +++- 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/airsonic-main/src/main/java/org/airsonic/player/ajax/PlayQueueService.java b/airsonic-main/src/main/java/org/airsonic/player/ajax/PlayQueueService.java index c95ae5e0..161066fd 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/ajax/PlayQueueService.java +++ b/airsonic-main/src/main/java/org/airsonic/player/ajax/PlayQueueService.java @@ -250,6 +250,33 @@ public class PlayQueueService { return doPlayInternetRadio(request, player, radio).setStartPlayerAt(0); } + /** + * @param index Start playing at this index, or play whole playlist if {@code null}. + */ + public PlayQueueInfo addPlaylist(int id, Integer index) throws Exception { + HttpServletRequest request = WebContextFactory.get().getHttpServletRequest(); + HttpServletResponse response = WebContextFactory.get().getHttpServletResponse(); + + String username = securityService.getCurrentUsername(request); + boolean queueFollowingSongs = settingsService.getUserSettings(username).isQueueFollowingSongs(); + + List files = playlistService.getFilesInPlaylist(id, true); + if (!files.isEmpty() && index != null) { + if (queueFollowingSongs) { + files = files.subList(index, files.size()); + } else { + files = Arrays.asList(files.get(index)); + } + } + + // Remove non-present files + files.removeIf(file -> !file.isPresent()); + + // Add to the play queue + int[] ids = files.stream().mapToInt(f -> f.getId()).toArray(); + return doAdd(request, response, ids, index); + } + /** * @param index Start playing at this index, or play whole playlist if {@code null}. */ @@ -271,6 +298,8 @@ public class PlayQueueService { // Remove non-present files files.removeIf(file -> !file.isPresent()); + + // Play now Player player = getCurrentPlayer(request, response); return doPlay(request, player, files).setStartPlayerAt(0); } diff --git a/airsonic-main/src/main/webapp/WEB-INF/jsp/coverArt.jsp b/airsonic-main/src/main/webapp/WEB-INF/jsp/coverArt.jsp index baa44859..86a55200 100644 --- a/airsonic-main/src/main/webapp/WEB-INF/jsp/coverArt.jsp +++ b/airsonic-main/src/main/webapp/WEB-INF/jsp/coverArt.jsp @@ -76,7 +76,7 @@ PARAMETERS style="position: relative; top: 8px; left: 8px; z-index: 2; display:none" > - +
@@ -154,5 +154,8 @@ PARAMETERS top.playQueue.onAdd(${param.albumId}); + + top.playQueue.onAddPlaylist(${param.playlistId}); + }); diff --git a/airsonic-main/src/main/webapp/WEB-INF/jsp/playQueue.jsp b/airsonic-main/src/main/webapp/WEB-INF/jsp/playQueue.jsp index 1b37f4ce..7a0bb778 100644 --- a/airsonic-main/src/main/webapp/WEB-INF/jsp/playQueue.jsp +++ b/airsonic-main/src/main/webapp/WEB-INF/jsp/playQueue.jsp @@ -380,6 +380,9 @@ function onAddNext(id) { playQueueService.addAt(id, getCurrentSongIndex() + 1, playQueueCallback); } + function onAddPlaylist(id, index) { + playQueueService.addPlaylist(id, index, playQueueCallback); + } function onShuffle() { playQueueService.shuffle(playQueueCallback); } diff --git a/airsonic-main/src/main/webapp/WEB-INF/jsp/playlist.jsp b/airsonic-main/src/main/webapp/WEB-INF/jsp/playlist.jsp index f2cbdf15..9c332949 100644 --- a/airsonic-main/src/main/webapp/WEB-INF/jsp/playlist.jsp +++ b/airsonic-main/src/main/webapp/WEB-INF/jsp/playlist.jsp @@ -134,6 +134,9 @@ function onPlayAll() { top.playQueue.onPlayPlaylist(playlist.id); } + function onAddAll() { + top.playQueue.onAddPlaylist(playlist.id); + } function onAdd(index) { top.playQueue.onAdd(songs[index].id); $().toastmessage('showSuccessToast', '') @@ -184,7 +187,8 @@

» ${fn:escapeXml(model.playlist.name)}

- + | +