mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 14:11:10 +00:00
Adds playlist management and playback
This commit is contained in:
1 parent
009a0c8156
commit
9889c86c76
296 files changed
+18830
-367
No files matched your search
@@ -62,7 +62,8 @@
|
||||
const jsLocalizedStrings = {
|
||||
actions: @Json.Serialize(_localizer["Actions"].Value),
|
||||
play: @Json.Serialize(_localizer["Play"].Value),
|
||||
shuffle: @Json.Serialize(_localizer["Shuffle"].Value)
|
||||
shuffle: @Json.Serialize(_localizer["Shuffle"].Value),
|
||||
addToPlaylist: @Json.Serialize(_localizer["AddToPlaylist"].Value)
|
||||
};
|
||||
|
||||
// Closes the actions menus of all the music library cards.
|
||||
@@ -157,6 +158,20 @@
|
||||
shuffleAction.dataset.libraryId = library.id;
|
||||
menu.appendChild(shuffleAction);
|
||||
|
||||
const addToPlaylistAction = document.createElement('a');
|
||||
addToPlaylistAction.setAttribute('role', 'menuitem');
|
||||
addToPlaylistAction.href = '#';
|
||||
addToPlaylistAction.className = 'card-action-add-to-playlist';
|
||||
addToPlaylistAction.textContent = jsLocalizedStrings.addToPlaylist;
|
||||
addToPlaylistAction.addEventListener('click', async event => {
|
||||
event.preventDefault();
|
||||
event.stopImmediatePropagation();
|
||||
closeCardMenus();
|
||||
if (window.LuminaPlaylists)
|
||||
await window.LuminaPlaylists.showAddScopeDialogAsync({ libraryId: library.id, title: library.title || '', addToPlaylistLabel: jsLocalizedStrings.addToPlaylist, returnFocus: trigger });
|
||||
});
|
||||
menu.appendChild(addToPlaylistAction);
|
||||
|
||||
menu.addEventListener('click', event => {
|
||||
// The global audio player delegation handles the play and shuffle actions; the menu only closes here.
|
||||
if (event.target.closest('.card-action-play, .card-action-shuffle'))
|
||||
|
||||
+185
-3
@@ -133,10 +133,11 @@
|
||||
<div class="form-row">
|
||||
<table class="w-100 form-table tracks-table">
|
||||
<colgroup>
|
||||
<col />
|
||||
<col class="track-play-column" />
|
||||
<col class="track-number-column" />
|
||||
<col />
|
||||
<col class="track-duration-column" />
|
||||
<col class="track-actions-column" />
|
||||
</colgroup>
|
||||
<tbody id="tracks-body"></tbody>
|
||||
</table>
|
||||
@@ -658,6 +659,10 @@
|
||||
coverSaved: @Json.Serialize(_localizer["CoverSaved"].Value),
|
||||
coverUploadFailed: @Json.Serialize(_localizer["CoverUploadFailed"].Value),
|
||||
playTrack: @Json.Serialize(_localizer["PlayTrack"].Value),
|
||||
actions: @Json.Serialize(_localizer["Actions"].Value),
|
||||
addToPlaylist: @Json.Serialize(_localizer["AddToPlaylist"].Value),
|
||||
addToPlayQueue: @Json.Serialize(_localizer["AddToPlayQueue"].Value),
|
||||
playAllFromHere: @Json.Serialize(_localizer["PlayAllFromHere"].Value),
|
||||
remove: @Json.Serialize(_localizer["Remove"].Value)
|
||||
};
|
||||
|
||||
@@ -668,6 +673,10 @@
|
||||
|
||||
// The cover path the play affordances hand to the player, kept in step with the artwork the page currently displays.
|
||||
let currentCoverPath = normalizeCoverPath(@Json.Serialize(playCoverPath ?? string.Empty));
|
||||
// The ordered tracks of the album, kept for the "play all from here" action of the track menu.
|
||||
let albumTracks = [];
|
||||
// The track actions menu that is currently open, so the page opens one menu at a time and closes it on dismissal.
|
||||
let openTrackActionsMenu = null;
|
||||
|
||||
// Writes the cover of a play descriptor onto a trigger, dropping the attribute when the context has no artwork.
|
||||
function applyDescriptorCover(trigger, coverPath) {
|
||||
@@ -954,6 +963,7 @@
|
||||
return;
|
||||
tracksBody.innerHTML = '';
|
||||
const tracks = response.data;
|
||||
albumTracks = tracks;
|
||||
noTracksMessage.classList.toggle('hidden', tracks.length !== 0);
|
||||
// Only a successful empty list disables the play album trigger. The player can still build the queue itself when
|
||||
// the track list could not be loaded.
|
||||
@@ -966,7 +976,7 @@
|
||||
function createTrackPlayButton(track) {
|
||||
const button = document.createElement('button');
|
||||
button.type = 'button';
|
||||
button.className = 'confirm-button';
|
||||
button.className = 'confirm-button track-play-button';
|
||||
button.setAttribute('data-audio-player-play', '');
|
||||
button.dataset.libraryId = libraryId;
|
||||
button.dataset.trackId = track.id;
|
||||
@@ -984,12 +994,14 @@
|
||||
return button;
|
||||
}
|
||||
|
||||
// Creates a row of the tracks table, with the play trigger, the number, the name of the track linking to its own page and the duration.
|
||||
// Creates a row of the tracks table, with the play trigger, the number, the name of the track linking to its own page,
|
||||
// the duration and the actions menu of the track.
|
||||
function createTrackRow(track) {
|
||||
const row = document.createElement('tr');
|
||||
row.className = 'track-row';
|
||||
|
||||
const playCell = document.createElement('td');
|
||||
playCell.className = 'track-play-cell';
|
||||
playCell.appendChild(createTrackPlayButton(track));
|
||||
|
||||
const numberCell = document.createElement('td');
|
||||
@@ -1009,9 +1021,170 @@
|
||||
row.appendChild(numberCell);
|
||||
row.appendChild(nameCell);
|
||||
row.appendChild(durationCell);
|
||||
row.appendChild(createTrackActionsCell(track));
|
||||
return row;
|
||||
}
|
||||
|
||||
// Gets the singleton audio player, or null when the layout did not render it.
|
||||
function getAudioPlayer() {
|
||||
return window.LuminaAudioPlayer && window.LuminaAudioPlayer.instance
|
||||
? window.LuminaAudioPlayer.instance
|
||||
: null;
|
||||
}
|
||||
|
||||
// Builds the play descriptor of a track of this album, with the cover the page currently displays.
|
||||
function buildTrackDescriptor(track) {
|
||||
return {
|
||||
libraryId: libraryId,
|
||||
trackId: track.id,
|
||||
albumId: albumId,
|
||||
artistId: artistId,
|
||||
title: track.title || '',
|
||||
albumTitle: albumTitle,
|
||||
durationInSeconds: Number(track.durationInSeconds) || 0,
|
||||
coverArtPath: currentCoverPath
|
||||
};
|
||||
}
|
||||
|
||||
// Closes the open track actions menu, optionally returning the focus to its trigger.
|
||||
function closeTrackActionsMenu(shouldRestoreFocus) {
|
||||
if (!openTrackActionsMenu)
|
||||
return;
|
||||
const menu = openTrackActionsMenu.menu;
|
||||
const trigger = openTrackActionsMenu.trigger;
|
||||
openTrackActionsMenu = null;
|
||||
menu.remove();
|
||||
trigger.setAttribute('aria-expanded', 'false');
|
||||
if (shouldRestoreFocus && trigger.isConnected)
|
||||
trigger.focus();
|
||||
}
|
||||
|
||||
// Places the track actions menu next to its trigger, right aligned and below it when there is room.
|
||||
function positionTrackActionsMenu(menu, trigger) {
|
||||
const margin = 4;
|
||||
const triggerRect = trigger.getBoundingClientRect();
|
||||
const width = menu.offsetWidth;
|
||||
const height = menu.offsetHeight;
|
||||
const left = Math.min(Math.max(margin, triggerRect.right - width), Math.max(margin, window.innerWidth - width - margin));
|
||||
const below = triggerRect.bottom + margin;
|
||||
const top = below + height <= window.innerHeight - margin
|
||||
? below
|
||||
: Math.max(margin, triggerRect.top - height - margin);
|
||||
menu.style.left = `${left}px`;
|
||||
menu.style.top = `${top}px`;
|
||||
}
|
||||
|
||||
// Creates one entry of the track actions menu, using the same menu item markup as the card actions menus.
|
||||
function createTrackMenuAction(label, className, handler) {
|
||||
const link = document.createElement('a');
|
||||
link.href = '#';
|
||||
link.className = className;
|
||||
link.setAttribute('role', 'menuitem');
|
||||
link.textContent = label;
|
||||
link.addEventListener('click', event => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
closeTrackActionsMenu(false);
|
||||
handler();
|
||||
});
|
||||
return link;
|
||||
}
|
||||
|
||||
// Opens the actions menu of a track, or closes it when the same trigger is clicked again.
|
||||
function openTrackActionsMenuFor(trigger, track) {
|
||||
const wasOpen = openTrackActionsMenu && openTrackActionsMenu.trigger === trigger;
|
||||
closeTrackActionsMenu(false);
|
||||
if (wasOpen)
|
||||
return;
|
||||
const menu = document.createElement('nav');
|
||||
menu.className = 'card-actions-menu';
|
||||
menu.setAttribute('role', 'menu');
|
||||
menu.appendChild(createTrackMenuAction(jsLocalizedStrings.addToPlaylist, 'card-action-add-to-playlist', () => addTrackToPlaylist(track, trigger)));
|
||||
menu.appendChild(createTrackMenuAction(jsLocalizedStrings.addToPlayQueue, 'card-action-add-to-queue', () => addTrackToQueueAsync(track)));
|
||||
menu.appendChild(createTrackMenuAction(jsLocalizedStrings.playAllFromHere, 'card-action-play-all-from-here', () => playAllFromHereAsync(track)));
|
||||
document.body.appendChild(menu);
|
||||
menu.classList.add('open');
|
||||
positionTrackActionsMenu(menu, trigger);
|
||||
trigger.setAttribute('aria-expanded', 'true');
|
||||
openTrackActionsMenu = { trigger, menu };
|
||||
const firstAction = menu.querySelector('a[role="menuitem"]');
|
||||
if (firstAction)
|
||||
firstAction.focus();
|
||||
}
|
||||
|
||||
// Creates the actions cell of a track row, using the same trigger and dots as the card actions menus.
|
||||
function createTrackActionsCell(track) {
|
||||
const cell = document.createElement('td');
|
||||
cell.className = 'track-actions-cell';
|
||||
const trigger = document.createElement('button');
|
||||
trigger.type = 'button';
|
||||
trigger.className = 'card-actions-trigger track-actions-trigger';
|
||||
trigger.setAttribute('aria-haspopup', 'menu');
|
||||
trigger.setAttribute('aria-expanded', 'false');
|
||||
trigger.setAttribute('aria-label', jsLocalizedStrings.actions);
|
||||
trigger.title = jsLocalizedStrings.actions;
|
||||
trigger.addEventListener('click', event => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
openTrackActionsMenuFor(trigger, track);
|
||||
});
|
||||
cell.appendChild(trigger);
|
||||
return cell;
|
||||
}
|
||||
|
||||
// Closes the track actions menu when the user clicks elsewhere, presses Escape, scrolls or resizes the window.
|
||||
function handleTrackActionsMenuDismiss(event) {
|
||||
if (!openTrackActionsMenu)
|
||||
return;
|
||||
if (event.type === 'keydown') {
|
||||
if (event.key === 'Escape') {
|
||||
event.preventDefault();
|
||||
closeTrackActionsMenu(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (event.type === 'click' && event.target.closest('.card-actions-menu, .track-actions-trigger'))
|
||||
return;
|
||||
closeTrackActionsMenu(false);
|
||||
}
|
||||
|
||||
// Appends one track to the play queue, or starts it when the queue is empty.
|
||||
async function addTrackToQueueAsync(track) {
|
||||
const player = getAudioPlayer();
|
||||
if (!player || typeof player.appendToQueueAsync !== 'function')
|
||||
return;
|
||||
await player.appendToQueueAsync(buildTrackDescriptor(track));
|
||||
}
|
||||
|
||||
// Starts a new queue with the clicked track and every track that follows it in the album track list.
|
||||
async function playAllFromHereAsync(track) {
|
||||
const player = getAudioPlayer();
|
||||
if (!player)
|
||||
return;
|
||||
const index = albumTracks.findIndex(candidate => candidate.id === track.id);
|
||||
if (index < 0)
|
||||
return;
|
||||
const descriptors = albumTracks.slice(index).map(buildTrackDescriptor);
|
||||
if (descriptors.length === 0)
|
||||
return;
|
||||
await player.playAsync({ ...descriptors[0], queue: descriptors });
|
||||
}
|
||||
|
||||
// Opens the shared add-to-playlist dialog for this single track.
|
||||
function addTrackToPlaylist(track, trigger) {
|
||||
if (!window.LuminaPlaylists || typeof window.LuminaPlaylists.showAddScopeDialogAsync !== 'function')
|
||||
return;
|
||||
window.LuminaPlaylists.showAddScopeDialogAsync({
|
||||
libraryId: libraryId,
|
||||
artistId: artistId,
|
||||
albumId: albumId,
|
||||
trackId: track.id,
|
||||
title: track.title || '',
|
||||
addToPlaylistLabel: jsLocalizedStrings.addToPlaylist,
|
||||
returnFocus: trigger
|
||||
});
|
||||
}
|
||||
|
||||
// Sends the edited album data to the server.
|
||||
async function handleSaveAsync() {
|
||||
const result = await callApiPutAsync(`${saveUrl}?libraryId=${encodeURIComponent(libraryId)}`, buildPayload());
|
||||
@@ -1160,6 +1333,10 @@
|
||||
ratingsBody.addEventListener('click', handleRowRemoval);
|
||||
btnChangeCover.addEventListener('click', handleChangeCoverClick);
|
||||
coverInput.addEventListener('change', handleCoverChangeAsync);
|
||||
document.addEventListener('click', handleTrackActionsMenuDismiss);
|
||||
document.addEventListener('keydown', handleTrackActionsMenuDismiss);
|
||||
window.addEventListener('scroll', handleTrackActionsMenuDismiss, true);
|
||||
window.addEventListener('resize', handleTrackActionsMenuDismiss);
|
||||
document.addEventListener('DOMContentLoaded', InitializeAsync);
|
||||
|
||||
// Register cleanup for these listeners.
|
||||
@@ -1181,6 +1358,11 @@
|
||||
ratingsBody.removeEventListener('click', handleRowRemoval);
|
||||
btnChangeCover.removeEventListener('click', handleChangeCoverClick);
|
||||
coverInput.removeEventListener('change', handleCoverChangeAsync);
|
||||
closeTrackActionsMenu(false);
|
||||
document.removeEventListener('click', handleTrackActionsMenuDismiss);
|
||||
document.removeEventListener('keydown', handleTrackActionsMenuDismiss);
|
||||
window.removeEventListener('scroll', handleTrackActionsMenuDismiss, true);
|
||||
window.removeEventListener('resize', handleTrackActionsMenuDismiss);
|
||||
document.removeEventListener('DOMContentLoaded', InitializeAsync);
|
||||
});
|
||||
|
||||
|
||||
+16
-1
@@ -115,7 +115,8 @@
|
||||
shuffle: '@_localizer["Shuffle"]',
|
||||
deleteItem: '@_localizer["Delete"]',
|
||||
deleteConfirm: '@_localizer["DeleteConfirm"]',
|
||||
deleteFailed: '@_localizer["DeleteFailed"]'
|
||||
deleteFailed: '@_localizer["DeleteFailed"]',
|
||||
addToPlaylist: '@_localizer["AddToPlaylist"]'
|
||||
};
|
||||
|
||||
function buildItemsUrl() {
|
||||
@@ -252,6 +253,19 @@
|
||||
if (artist.coverPath)
|
||||
shuffleAction.dataset.coverArtPath = artist.coverPath;
|
||||
|
||||
const addToPlaylistAction = document.createElement('a');
|
||||
addToPlaylistAction.setAttribute('role', 'menuitem');
|
||||
addToPlaylistAction.href = '#';
|
||||
addToPlaylistAction.className = 'card-action-add-to-playlist';
|
||||
addToPlaylistAction.textContent = jsLocalizedStrings.addToPlaylist;
|
||||
addToPlaylistAction.addEventListener('click', async event => {
|
||||
event.preventDefault();
|
||||
event.stopImmediatePropagation();
|
||||
closeCardMenus();
|
||||
if (window.LuminaPlaylists)
|
||||
await window.LuminaPlaylists.showAddScopeDialogAsync({ libraryId: libraryId, artistId: artist.id, title: artist.name || '', addToPlaylistLabel: jsLocalizedStrings.addToPlaylist, returnFocus: trigger });
|
||||
});
|
||||
|
||||
const deleteAction = document.createElement('a');
|
||||
deleteAction.setAttribute('role', 'menuitem');
|
||||
deleteAction.href = '#';
|
||||
@@ -261,6 +275,7 @@
|
||||
menu.appendChild(detailsAction);
|
||||
menu.appendChild(playAction);
|
||||
menu.appendChild(shuffleAction);
|
||||
menu.appendChild(addToPlaylistAction);
|
||||
menu.appendChild(deleteAction);
|
||||
|
||||
menu.addEventListener('click', async event => {
|
||||
|
||||
+12
-1
@@ -674,7 +674,8 @@
|
||||
coverUploadFailed: @Json.Serialize(_localizer["CoverUploadFailed"].Value),
|
||||
play: @Json.Serialize(_localizer["Play"].Value),
|
||||
shuffle: @Json.Serialize(_localizer["Shuffle"].Value),
|
||||
remove: @Json.Serialize(_localizer["Remove"].Value)
|
||||
remove: @Json.Serialize(_localizer["Remove"].Value),
|
||||
addToPlaylist: @Json.Serialize(_localizer["AddToPlaylist"].Value)
|
||||
};
|
||||
|
||||
// Reads the trimmed value of the element with the provided id.
|
||||
@@ -1127,10 +1128,20 @@
|
||||
shuffleAction.setAttribute('data-audio-player-shuffle-scope', 'release');
|
||||
applyAlbumPlayDescriptor(shuffleAction, album);
|
||||
|
||||
const addToPlaylistAction = createAlbumMenuAction(jsLocalizedStrings.addToPlaylist, 'card-action-add-to-playlist');
|
||||
addToPlaylistAction.addEventListener('click', async event => {
|
||||
event.preventDefault();
|
||||
event.stopImmediatePropagation();
|
||||
closeCardMenus();
|
||||
if (window.LuminaPlaylists)
|
||||
await window.LuminaPlaylists.showAddScopeDialogAsync({ libraryId: libraryId, artistId: artistId, albumId: album.id, title: album.title || '', addToPlaylistLabel: jsLocalizedStrings.addToPlaylist, returnFocus: trigger });
|
||||
});
|
||||
|
||||
const deleteAction = createAlbumMenuAction(jsLocalizedStrings.remove, 'card-action-delete');
|
||||
|
||||
menu.appendChild(playAction);
|
||||
menu.appendChild(shuffleAction);
|
||||
menu.appendChild(addToPlaylistAction);
|
||||
menu.appendChild(deleteAction);
|
||||
|
||||
menu.addEventListener('click', async event => {
|
||||
|
||||
@@ -0,0 +1,207 @@
|
||||
@*
|
||||
FALLBACK PLAYLISTS PAGE - READ BEFORE EDITING
|
||||
|
||||
This view is the application fallback of the playlists page, rendered only when the theme template of the page cannot be
|
||||
loaded. On a healthy site the page comes from the theme's playlists/index template. It keeps the DOM contract and the client
|
||||
script the theme template mirrors, so that listing and deleting playlists keep working even without the theme.
|
||||
|
||||
The page only lists the playlists. Creating and editing a playlist happen on the dedicated playlist page, reached through
|
||||
the create button or through a playlist card, the same way every other manageable resource of the application is split between a list page and an add/edit page.
|
||||
|
||||
To restyle the page, edit the theme files. This fallback is intentionally plain, so that a broken theme is obvious to the user while the page still functions.
|
||||
|
||||
/playlists
|
||||
*@
|
||||
|
||||
@using Lumina.Presentation.Web.Common.Services
|
||||
@using Microsoft.AspNetCore.Mvc.Localization
|
||||
@using System
|
||||
@using System.Collections.Generic
|
||||
@using System.Text.Json
|
||||
@using System.Text.Json.Serialization
|
||||
|
||||
@inject IViewLocalizer _localizer
|
||||
@inject IUrlService _urlService
|
||||
|
||||
@{
|
||||
// Generate a unique id for the scripts section of this view, so it can be dynamically loaded/unloaded by the global AJAX navigator handler.
|
||||
var scriptId = ScriptIdentifierHelper.GenerateScriptId();
|
||||
var strings = new Dictionary<string, string>
|
||||
{
|
||||
["title"] = _localizer["Title"].Value,
|
||||
["noPlaylists"] = _localizer["NoPlaylists"].Value,
|
||||
["tracks"] = _localizer["Tracks"].Value,
|
||||
["delete"] = _localizer["Delete"].Value,
|
||||
["deleteConfirm"] = _localizer["DeleteConfirm"].Value,
|
||||
["deleteFailed"] = _localizer["DeleteFailed"].Value,
|
||||
["items"] = _localizer["Items"].Value
|
||||
};
|
||||
var jsonOptions = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
Converters = { new JsonStringEnumConverter() }
|
||||
};
|
||||
}
|
||||
|
||||
@Html.AntiForgeryToken()
|
||||
|
||||
<div class="cotton-candy">
|
||||
<div style="display: grid; grid-template-rows: auto 1fr;">
|
||||
<div style="min-height: 1rem;"></div>
|
||||
<div class="pl-10 pr-10 pb-10">
|
||||
<div class="text-center">
|
||||
<h1 class="text-light-two engraved-title">@_localizer["Title"]</h1>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<span id="playlist-count" class="text-light-two"></span>
|
||||
<button id="create-playlist-button" type="button" class="confirm-button h-22px">@_localizer["Create"]</button>
|
||||
</div>
|
||||
<div id="playlists-container" class="cards-container justify-start h-100"></div>
|
||||
<p id="no-playlists" class="hidden text-light-two text-center">@_localizer["NoPlaylists"]</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
<!-- The "text/plain" type is a design choice, not a mistake: it keeps the browser from executing this view script during HTML parsing, before site.js defines the API helpers it calls. site.js (which loads deferred) executes these scripts once it is loaded, both on the initial page load and during AJAX navigation. -->
|
||||
<script type="text/plain" data-form="@scriptId">
|
||||
const strings = @Html.Raw(JsonSerializer.Serialize(strings, jsonOptions));
|
||||
const getPlaylistsUrl = '@_urlService.GetAbsoluteUrl(WebRoutes.Playlists.GET_PLAYLISTS)';
|
||||
const addUrl = '@_urlService.GetAbsoluteUrl(WebRoutes.Playlists.ADD)';
|
||||
const itemUrlTemplate = '@_urlService.GetAbsoluteUrl(WebRoutes.Playlists.ITEM, new { playlistId = default(Guid) })';
|
||||
const deleteUrlTemplate = '@_urlService.GetAbsoluteUrl(WebRoutes.Playlists.DELETE_PLAYLIST, new { playlistId = default(Guid) })';
|
||||
const EMPTY_GUID = '00000000-0000-0000-0000-000000000000';
|
||||
const playlistsContainer = document.getElementById('playlists-container');
|
||||
const noPlaylistsMessage = document.getElementById('no-playlists');
|
||||
const playlistCount = document.getElementById('playlist-count');
|
||||
const createPlaylistButton = document.getElementById('create-playlist-button');
|
||||
let isInitialized = false;
|
||||
let requestSequence = 0;
|
||||
|
||||
function buildItemUrl(playlistId) {
|
||||
return itemUrlTemplate.replace(`/${EMPTY_GUID}`, `/${playlistId}`);
|
||||
}
|
||||
|
||||
function buildDeleteUrl(playlistId) {
|
||||
return deleteUrlTemplate.replace(`/${EMPTY_GUID}`, `/${playlistId}`);
|
||||
}
|
||||
|
||||
function renderPlaylists(playlists) {
|
||||
playlistsContainer.querySelectorAll('.media-card').forEach(card => card.remove());
|
||||
if (!Array.isArray(playlists) || playlists.length === 0) {
|
||||
noPlaylistsMessage.classList.remove('hidden');
|
||||
playlistCount.textContent = '';
|
||||
return;
|
||||
}
|
||||
noPlaylistsMessage.classList.add('hidden');
|
||||
playlistCount.textContent = `${playlists.length} ${strings.items}`;
|
||||
playlists.forEach(playlist => playlistsContainer.appendChild(createPlaylistCard(playlist)));
|
||||
}
|
||||
|
||||
function createPlaylistCard(playlist) {
|
||||
const card = document.createElement('div');
|
||||
card.className = 'media-card';
|
||||
card.dataset.playlistId = playlist.id;
|
||||
|
||||
const link = document.createElement('a');
|
||||
link.className = 'media-panel nav-link no-underline';
|
||||
link.href = buildItemUrl(playlist.id);
|
||||
link.style.width = '240px';
|
||||
link.style.height = 'auto';
|
||||
link.style.padding = '10px';
|
||||
|
||||
const title = document.createElement('strong');
|
||||
title.className = 'text-light-two';
|
||||
title.textContent = playlist.name || strings.title;
|
||||
title.style.display = 'block';
|
||||
title.style.whiteSpace = 'nowrap';
|
||||
title.style.overflow = 'hidden';
|
||||
title.style.textOverflow = 'ellipsis';
|
||||
link.appendChild(title);
|
||||
|
||||
if (playlist.description) {
|
||||
const description = document.createElement('span');
|
||||
description.className = 'text-light-two';
|
||||
description.style.display = 'block';
|
||||
description.style.opacity = '0.8';
|
||||
description.style.marginTop = '4px';
|
||||
description.style.whiteSpace = 'nowrap';
|
||||
description.style.overflow = 'hidden';
|
||||
description.style.textOverflow = 'ellipsis';
|
||||
description.textContent = playlist.description;
|
||||
link.appendChild(description);
|
||||
}
|
||||
|
||||
const count = document.createElement('span');
|
||||
count.className = 'text-light-two';
|
||||
count.style.display = 'block';
|
||||
count.style.marginTop = '8px';
|
||||
count.textContent = `${playlist.entryCount} ${strings.tracks}`;
|
||||
link.appendChild(count);
|
||||
|
||||
const deleteButton = document.createElement('button');
|
||||
deleteButton.type = 'button';
|
||||
deleteButton.className = 'abort-button h-22px';
|
||||
deleteButton.style.marginTop = '8px';
|
||||
deleteButton.textContent = strings.delete;
|
||||
deleteButton.addEventListener('click', async event => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
await deletePlaylistAsync(playlist.id);
|
||||
});
|
||||
|
||||
card.appendChild(link);
|
||||
card.appendChild(deleteButton);
|
||||
return card;
|
||||
}
|
||||
|
||||
async function loadPlaylistsAsync() {
|
||||
const requestId = ++requestSequence;
|
||||
const playlists = await callApiGetAsync(getPlaylistsUrl);
|
||||
if (requestId !== requestSequence)
|
||||
return;
|
||||
if (playlists)
|
||||
renderPlaylists(playlists);
|
||||
}
|
||||
|
||||
function handlePlaylistUpdated() {
|
||||
loadPlaylistsAsync();
|
||||
}
|
||||
|
||||
async function openCreatePlaylistAsync() {
|
||||
await updateContentAsync(addUrl, true);
|
||||
}
|
||||
|
||||
async function deletePlaylistAsync(playlistId) {
|
||||
if (await dialogService.show(strings.deleteConfirm, jsLocalizedDialogs.confirmation, DialogButtons.YES_NO, DialogIcon.QUESTION) !== DialogButton.YES)
|
||||
return;
|
||||
const deleted = await callApiDeleteAsync(buildDeleteUrl(playlistId));
|
||||
if (deleted)
|
||||
await loadPlaylistsAsync();
|
||||
else
|
||||
notificationService.show(strings.deleteFailed, NotificationType.ERROR);
|
||||
}
|
||||
|
||||
document.addEventListener('lumina:playlist-updated', handlePlaylistUpdated);
|
||||
if (createPlaylistButton)
|
||||
createPlaylistButton.addEventListener('click', openCreatePlaylistAsync);
|
||||
|
||||
async function InitializeAsync() {
|
||||
if (isInitialized)
|
||||
return;
|
||||
if (!playlistsContainer)
|
||||
return;
|
||||
isInitialized = true;
|
||||
await loadPlaylistsAsync();
|
||||
}
|
||||
|
||||
window.viewCleanups = window.viewCleanups || {};
|
||||
window.viewCleanups['@scriptId'] = () => {
|
||||
document.removeEventListener('lumina:playlist-updated', handlePlaylistUpdated);
|
||||
if (createPlaylistButton)
|
||||
createPlaylistButton.removeEventListener('click', openCreatePlaylistAsync);
|
||||
console.log(`Unloaded @scriptId`);
|
||||
};
|
||||
console.log(`Loaded @scriptId`);
|
||||
</script>
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -31,7 +31,11 @@
|
||||
- The hook attributes the audio player binds: 'data-audio-player-play-pause', '-stop', '-previous', '-next', '-repeat',
|
||||
'-progress', '-progress-played', '-progress-downloaded', '-progress-undownloaded', '-current-time', '-total-time',
|
||||
'-track-name', '-album-name', '-now-playing-title', '-now-playing-release-type', '-now-playing-release',
|
||||
'-now-playing-year', '-now-playing-artist', '-artwork-carousel', '-cover-thumbnail', '-cover-image', '-volume', '-volume-level', '-mute' and '-queue'.
|
||||
'-now-playing-year', '-now-playing-artist', '-artwork-carousel', '-cover-thumbnail', '-cover-image', '-volume', '-volume-level', '-mute', '-queue', '-playlist-combobox' and '-add-queue-to-playlist'.
|
||||
The queue-to-playlist action is a standard application combo box, so a theme renders the usual 'enlightenment-combobox'
|
||||
markup and puts the '-playlist-combobox' hook on its root. The player only reads the 'data-value' of the selected text
|
||||
when the add button is pressed. A theme that renders one half of the action gets a complete built-in pair, placed in a
|
||||
queue area wrapper above the queue so that it never becomes a new column of the expanded layout.
|
||||
The volume fill element ('-volume-level') is a styling hook the stylesheet drives from the custom properties below,
|
||||
not one the script writes to. The repeat toggle carries 'data-audio-player-repeat' and the player writes
|
||||
'data-audio-player-repeat-mode' ('off', 'all' or 'one') and toggles the 'is-active' and 'is-one' classes on it.
|
||||
@@ -80,7 +84,23 @@
|
||||
</div>
|
||||
<div class="audio-player-artwork-carousel artwork-carousel" data-audio-player-artwork-carousel role="group" aria-label="@localizer["AudioPlayerAlbumArtwork"]" hidden></div>
|
||||
</div>
|
||||
<ul class="audio-player-queue" data-audio-player-queue aria-label="@localizer["AudioPlayerQueue"]"></ul>
|
||||
<div class="audio-player-queue-area">
|
||||
<div class="audio-player-queue-actions">
|
||||
<div class="enlightenment-combobox audio-player-queue-playlist-combobox" id="audio-player-playlist-combobox" data-audio-player-playlist-combobox>
|
||||
<div class="shine-effect" style="top: 1px;"></div>
|
||||
<input type="checkbox" class="enlightenment-toggle-checkbox" id="audio-player-playlist-combobox-toggle" />
|
||||
<label class="enlightenment-toggle" for="audio-player-playlist-combobox-toggle">
|
||||
<span class="enlightenment-selected-text" data-value="">@localizer["AudioPlayerSelectPlaylist"]</span>
|
||||
</label>
|
||||
<div class="enlightenment-dropdown" id="audio-player-playlist-combobox-dropdown">
|
||||
<div class="shine-effect" style="top: -4px;"></div>
|
||||
<div class="enlightenment-option first-option disabled">@localizer["AudioPlayerSelectPlaylist"]</div>
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" class="confirm-button h-22px audio-player-add-queue-to-playlist" data-audio-player-add-queue-to-playlist aria-label="@localizer["AudioPlayerAddQueueToPlaylist"]">@localizer["PlaylistAddToPlaylist"]</button>
|
||||
</div>
|
||||
<ul class="audio-player-queue" data-audio-player-queue aria-label="@localizer["AudioPlayerQueue"]"></ul>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Condensed bar: transport controls, three state progress bar, volume, and track name. -->
|
||||
<div class="audio-player-bar">
|
||||
|
||||
@@ -56,6 +56,10 @@
|
||||
// The endpoint that draws a uniformly random batch of tracks of a library, artist or album. The server samples the
|
||||
// database, so a shuffle of a large library never has to enumerate its albums and tracks in the browser.
|
||||
shuffleTracksUrl: '@_urlService.GetRelativeUrl(WebRoutes.Music.SHUFFLE_TRACKS)',
|
||||
// The playlists of the user, and the route that appends the current queue to one of them. The queue action in the
|
||||
// expanded bar uses the first to fill its select and the second to send the ordered track Ids in one request.
|
||||
getPlaylistsUrl: '@_urlService.GetRelativeUrl(WebRoutes.Playlists.GET_PLAYLISTS)',
|
||||
addPlaylistEntriesRouteTemplate: '@_urlService.GetRelativeUrl(WebRoutes.Playlists.ADD_PLAYLIST_ENTRIES, new { playlistId = default(Guid) })',
|
||||
strings: {
|
||||
play: '@localizer["AudioPlayerPlay"]',
|
||||
pause: '@localizer["AudioPlayerPause"]',
|
||||
@@ -71,7 +75,33 @@
|
||||
repeatAll: '@localizer["AudioPlayerRepeatAll"]',
|
||||
repeatOne: '@localizer["AudioPlayerRepeatOne"]',
|
||||
queue: '@localizer["AudioPlayerQueue"]',
|
||||
albumArtwork: '@localizer["AudioPlayerAlbumArtwork"]'
|
||||
albumArtwork: '@localizer["AudioPlayerAlbumArtwork"]',
|
||||
addQueueToPlaylist: '@localizer["AudioPlayerAddQueueToPlaylist"]',
|
||||
selectPlaylist: '@localizer["AudioPlayerSelectPlaylist"]',
|
||||
playlistQueueAdded: '@localizer["AudioPlayerPlaylistQueueAdded"]',
|
||||
playlistQueueAddFailed: '@localizer["AudioPlayerPlaylistQueueAddFailed"]',
|
||||
noPlaylists: '@localizer["AudioPlayerNoPlaylists"]',
|
||||
add: '@localizer["AudioPlayerAdd"]',
|
||||
addToPlaylist: '@localizer["PlaylistAddToPlaylist"]'
|
||||
}
|
||||
};
|
||||
// The endpoints and dialog labels of the add-to-playlist actions that the music library, artist and album cards share. The route
|
||||
// that returns the track Ids of a scope lets a whole library, artist or album be added in one batch request, and the batch
|
||||
// route is the same one the player uses for its queue. The routes are culture aware web routes, so the pages never hardcode
|
||||
// a path, and the dialog labels come from the global resources.
|
||||
var playlistConfiguration = {
|
||||
getPlaylistsUrl: '@_urlService.GetRelativeUrl(WebRoutes.Playlists.GET_PLAYLISTS)',
|
||||
addPlaylistEntryUrl: '@_urlService.GetRelativeUrl(WebRoutes.Playlists.ADD_PLAYLIST_ENTRY, new { playlistId = default(Guid) })',
|
||||
addScopeEntriesUrl: '@_urlService.GetRelativeUrl(WebRoutes.Playlists.ADD_PLAYLIST_SCOPE_ENTRIES, new { playlistId = default(Guid) })',
|
||||
createPlaylistUrl: '@_urlService.GetRelativeUrl(WebRoutes.Playlists.ADD)',
|
||||
strings: {
|
||||
selectPlaylist: '@localizer["AudioPlayerSelectPlaylist"]',
|
||||
noPlaylists: '@localizer["AudioPlayerNoPlaylists"]',
|
||||
createPlaylist: '@localizer["PlaylistCreate"]',
|
||||
tracksAdded: '@localizer["PlaylistTracksAdded"]',
|
||||
tracksAddFailed: '@localizer["PlaylistTracksAddFailed"]',
|
||||
noTracksToAdd: '@localizer["PlaylistNoTracksToAdd"]',
|
||||
add: '@localizer["AudioPlayerAdd"]'
|
||||
}
|
||||
};
|
||||
</script>
|
||||
@@ -87,6 +117,7 @@
|
||||
<script defer src="~/js/dialogs.js" asp-append-version="true"></script>
|
||||
<script defer src="~/js/image-viewer.js" asp-append-version="true"></script>
|
||||
<script defer src="~/js/site.js" asp-append-version="true"></script>
|
||||
<script defer src="~/js/playlists.js" asp-append-version="true"></script>
|
||||
<script defer src="~/js/theme-client-template-engine.js" asp-append-version="true"></script>
|
||||
<script defer src="~/js/audio-player/audio-player-utils.js" asp-append-version="true"></script>
|
||||
<script defer src="~/js/audio-player/audio-player-errors.js" asp-append-version="true"></script>
|
||||
|
||||
Reference in new issue
Block a user