mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 12:11:10 +00:00
Adds music page play affordances and shuffle playback
Adds play and shuffle actions to music library, artist, and album cards. Adds the library play context and the uniform shuffle endpoint. Expands the player bar with queue covers, now playing details, and release type. Updates the bundled themes, API documentation, and the user manual.
This commit is contained in:
1 parent
93821a2776
commit
067e9a21d0
132 files changed
+2935
-715
No files matched your search
@@ -59,6 +59,123 @@
|
||||
const librariesContainer = document.getElementById('libraries-container');
|
||||
const noLibrariesMessage = document.getElementById('no-libraries');
|
||||
|
||||
const jsLocalizedStrings = {
|
||||
actions: @Json.Serialize(_localizer["Actions"].Value),
|
||||
play: @Json.Serialize(_localizer["Play"].Value),
|
||||
shuffle: @Json.Serialize(_localizer["Shuffle"].Value)
|
||||
};
|
||||
|
||||
// Closes the actions menus of all the music library cards.
|
||||
function closeCardMenus() {
|
||||
librariesContainer.querySelectorAll('.media-card.open').forEach(card => {
|
||||
card.classList.remove('open');
|
||||
const menu = card.querySelector('.card-actions-menu');
|
||||
if (menu)
|
||||
menu.classList.remove('open');
|
||||
});
|
||||
}
|
||||
|
||||
// Toggles the actions menu of a music library card, opening it with its top left corner at the given viewport position.
|
||||
function toggleCardMenu(card, anchor) {
|
||||
const wasOpen = card.classList.contains('open');
|
||||
closeCardMenus();
|
||||
if (wasOpen)
|
||||
return;
|
||||
card.classList.add('open');
|
||||
const menu = card.querySelector('.card-actions-menu');
|
||||
if (menu) {
|
||||
menu.classList.add('open');
|
||||
positionActionsMenu(menu, anchor);
|
||||
}
|
||||
}
|
||||
|
||||
// Resolves the viewport point where the card actions menu opens.
|
||||
function resolveMenuAnchor(event) {
|
||||
if (event.clientX !== 0 || event.clientY !== 0)
|
||||
return { x: event.clientX, y: event.clientY };
|
||||
const triggerRect = event.currentTarget.getBoundingClientRect();
|
||||
return { x: triggerRect.left, y: triggerRect.bottom };
|
||||
}
|
||||
|
||||
// Places the card actions menu with its top left corner at the requested viewport point.
|
||||
function positionActionsMenu(menu, anchor) {
|
||||
const margin = 4;
|
||||
const maxLeft = Math.max(margin, window.innerWidth - menu.offsetWidth - margin);
|
||||
const maxTop = Math.max(margin, window.innerHeight - menu.offsetHeight - margin);
|
||||
menu.style.position = 'fixed';
|
||||
menu.style.left = `${Math.min(Math.max(margin, anchor.x), maxLeft)}px`;
|
||||
menu.style.top = `${Math.min(Math.max(margin, anchor.y), maxTop)}px`;
|
||||
}
|
||||
|
||||
// Closes the actions menus when clicking or pressing a key outside them.
|
||||
function handleCardMenuDismiss(event) {
|
||||
if (event.type === 'keydown' && event.key !== 'Escape')
|
||||
return;
|
||||
if (event.type === 'click' && event.target.closest('.card-actions-menu, .card-actions-trigger'))
|
||||
return;
|
||||
closeCardMenus();
|
||||
}
|
||||
|
||||
// Adds the actions menu of a music library card, with the play and shuffle actions that start the whole library.
|
||||
function createMusicLibraryMenu(card, library) {
|
||||
const libraryCoverPath = library.coverImage
|
||||
? `/media/libraries/${library.id}/${library.coverImage.substring(library.coverImage.lastIndexOf('cover.'))}`
|
||||
: '';
|
||||
const trigger = document.createElement('button');
|
||||
trigger.type = 'button';
|
||||
trigger.className = 'card-actions-trigger';
|
||||
trigger.setAttribute('aria-haspopup', 'menu');
|
||||
trigger.setAttribute('aria-label', jsLocalizedStrings.actions);
|
||||
trigger.addEventListener('click', event => {
|
||||
event.preventDefault();
|
||||
event.stopImmediatePropagation();
|
||||
toggleCardMenu(card, resolveMenuAnchor(event));
|
||||
});
|
||||
|
||||
const menu = document.createElement('nav');
|
||||
menu.className = 'card-actions-menu';
|
||||
menu.setAttribute('role', 'menu');
|
||||
|
||||
const playAction = document.createElement('a');
|
||||
playAction.setAttribute('role', 'menuitem');
|
||||
playAction.href = '#';
|
||||
playAction.className = 'card-action-play';
|
||||
playAction.textContent = jsLocalizedStrings.play;
|
||||
playAction.setAttribute('data-audio-player-play-library', '');
|
||||
playAction.dataset.libraryId = library.id;
|
||||
playAction.dataset.title = library.title || '';
|
||||
if (libraryCoverPath)
|
||||
playAction.dataset.coverArtPath = libraryCoverPath;
|
||||
menu.appendChild(playAction);
|
||||
|
||||
const shuffleAction = document.createElement('a');
|
||||
shuffleAction.setAttribute('role', 'menuitem');
|
||||
shuffleAction.href = '#';
|
||||
shuffleAction.className = 'card-action-shuffle';
|
||||
shuffleAction.textContent = jsLocalizedStrings.shuffle;
|
||||
shuffleAction.setAttribute('data-audio-player-play-library-shuffled', '');
|
||||
shuffleAction.dataset.libraryId = library.id;
|
||||
menu.appendChild(shuffleAction);
|
||||
|
||||
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'))
|
||||
closeCardMenus();
|
||||
});
|
||||
|
||||
card.appendChild(trigger);
|
||||
card.appendChild(menu);
|
||||
card.addEventListener('contextmenu', event => {
|
||||
event.preventDefault();
|
||||
event.stopImmediatePropagation();
|
||||
toggleCardMenu(card, resolveMenuAnchor(event));
|
||||
});
|
||||
card.addEventListener('click', event => {
|
||||
if (card.classList.contains('open') && !event.target.closest('.card-actions-menu'))
|
||||
closeCardMenus();
|
||||
});
|
||||
}
|
||||
|
||||
async function InitializeAsync() {
|
||||
if (isInitialized)
|
||||
return;
|
||||
@@ -95,7 +212,15 @@
|
||||
<span class="text-light-two"><strong>${library.title}</strong></span>
|
||||
`;
|
||||
|
||||
librariesContainer.appendChild(libraryElement);
|
||||
// A music library gets a card actions menu with the play and shuffle actions for the whole library.
|
||||
if (library.libraryType === 'Music') {
|
||||
const card = document.createElement('div');
|
||||
card.className = 'media-card';
|
||||
card.appendChild(libraryElement);
|
||||
createMusicLibraryMenu(card, library);
|
||||
librariesContainer.appendChild(card);
|
||||
} else
|
||||
librariesContainer.appendChild(libraryElement);
|
||||
});
|
||||
// Bind the AJAX navigation behavior to the library links, which were created after the initial navigation binding.
|
||||
bindNavigationLinks();
|
||||
@@ -107,10 +232,14 @@
|
||||
}
|
||||
|
||||
// Add listeners.
|
||||
document.addEventListener('click', handleCardMenuDismiss);
|
||||
document.addEventListener('keydown', handleCardMenuDismiss);
|
||||
document.addEventListener('DOMContentLoaded', InitializeAsync);
|
||||
|
||||
// Register cleanup for these listeners.
|
||||
cleanupFunctions.push(() => {
|
||||
document.removeEventListener('click', handleCardMenuDismiss);
|
||||
document.removeEventListener('keydown', handleCardMenuDismiss);
|
||||
document.removeEventListener('DOMContentLoaded', InitializeAsync);
|
||||
});
|
||||
|
||||
|
||||
+90
-5
@@ -8,6 +8,10 @@
|
||||
The tracks of the album are NOT edited inline: they are listed as cards that navigate to their own pages,
|
||||
and the update request never changes the tracks.
|
||||
|
||||
The album header and every track row the script renders expose a play trigger for the global audio player. The player
|
||||
handles those triggers by event delegation, so this view binds no playback listener; the trigger attribute contract
|
||||
lives in docs/technical/theming/Theming.md.
|
||||
|
||||
To change the behavior of the page, edit this script (and the theme template, when present). To restyle
|
||||
the page, edit the theme files. This fallback keeps every feature working without styling, so that a
|
||||
broken theme is obvious to the user while the page still functions.
|
||||
@@ -73,6 +77,13 @@
|
||||
})
|
||||
.ToList();
|
||||
var artworkItemsJson = System.Text.Json.JsonSerializer.Serialize(artworkItems);
|
||||
// The cover the play affordances hand to the player, resolved exactly like the cover this page displays: the stored cover, or the first stored artwork when the album has no cover.
|
||||
var playCoverPath = Model.CoverPath;
|
||||
if (string.IsNullOrWhiteSpace(playCoverPath))
|
||||
playCoverPath = (Model.Artwork ?? []).FirstOrDefault(artwork => !string.IsNullOrWhiteSpace(artwork.Path))?.Path ?? string.Empty;
|
||||
// The play album trigger starts disabled when the album is already known to hold no tracks, so an empty release cannot be
|
||||
// clicked before the track list request resolves. A failed request never changes this state.
|
||||
var hasTracks = (Model.Tracks?.Count ?? 0) > 0;
|
||||
}
|
||||
|
||||
@inject IViewLocalizer _localizer
|
||||
@@ -88,6 +99,16 @@
|
||||
<div class="shine-effect"></div>
|
||||
<div class="form-row">
|
||||
<button id="btn-back-to-artist" type="button" class="abort-button">@_localizer["BackToArtist"]</button>
|
||||
<!-- The play album trigger is handled by the global audio player script through event delegation, so this page binds no click handler of its own. -->
|
||||
<button id="btn-play-album" type="button" class="confirm-button" @(hasTracks ? string.Empty : "disabled")
|
||||
data-audio-player-play
|
||||
data-library-id="@libraryId"
|
||||
data-album-id="@albumId"
|
||||
data-artist-id="@artistId"
|
||||
data-title="@(metadata?.Title ?? string.Empty)"
|
||||
data-cover-art-path="@(playCoverPath ?? string.Empty)">
|
||||
@_localizer["PlayAlbum"]
|
||||
</button>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<h1 class="text-light-two w-100 text-center pt-0 pb-0 engraved-title">@_localizer["EditAlbum"]</h1>
|
||||
@@ -112,6 +133,7 @@
|
||||
<div class="form-row">
|
||||
<table class="w-100 form-table tracks-table">
|
||||
<colgroup>
|
||||
<col />
|
||||
<col class="track-number-column" />
|
||||
<col />
|
||||
<col class="track-duration-column" />
|
||||
@@ -589,6 +611,7 @@
|
||||
|
||||
const artistId = '@artistId';
|
||||
const albumId = '@albumId';
|
||||
const albumTitle = @Json.Serialize(metadata?.Title ?? string.Empty);
|
||||
const libraryId = '@libraryId';
|
||||
const saveUrl = '@_urlService.GetAbsoluteUrl(WebRoutes.Music.SAVE_ALBUM, new { artistId = default(Guid), albumId = default(Guid) })'.replace('/@(default(Guid))', `/${artistId}`).replace('/@(default(Guid))', `/${albumId}`);
|
||||
const deleteUrl = '@_urlService.GetAbsoluteUrl(WebRoutes.Music.DELETE_ALBUM, new { artistId = default(Guid), albumId = default(Guid) })'.replace('/@(default(Guid))', `/${artistId}`).replace('/@(default(Guid))', `/${albumId}`);
|
||||
@@ -601,6 +624,7 @@
|
||||
const btnBackToArtist = document.getElementById('btn-back-to-artist');
|
||||
const btnSaveAlbum = document.getElementById('btn-save-album');
|
||||
const btnDeleteAlbum = document.getElementById('btn-delete-album');
|
||||
const btnPlayAlbum = document.getElementById('btn-play-album');
|
||||
const btnAddCatalogNumber = document.getElementById('btn-add-catalog-number');
|
||||
const btnAddReleaseType = document.getElementById('btn-add-release-type');
|
||||
const btnAddGenre = document.getElementById('btn-add-genre');
|
||||
@@ -633,9 +657,34 @@
|
||||
noCover: @Json.Serialize(_localizer["NoCover"].Value),
|
||||
coverSaved: @Json.Serialize(_localizer["CoverSaved"].Value),
|
||||
coverUploadFailed: @Json.Serialize(_localizer["CoverUploadFailed"].Value),
|
||||
playTrack: @Json.Serialize(_localizer["PlayTrack"].Value),
|
||||
remove: @Json.Serialize(_localizer["Remove"].Value)
|
||||
};
|
||||
|
||||
// Normalizes a cover path with the same rule the server uses: a missing or whitespace only path means no artwork.
|
||||
function normalizeCoverPath(coverPath) {
|
||||
return typeof coverPath === 'string' ? coverPath.trim() : '';
|
||||
}
|
||||
|
||||
// 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));
|
||||
|
||||
// Writes the cover of a play descriptor onto a trigger, dropping the attribute when the context has no artwork.
|
||||
function applyDescriptorCover(trigger, coverPath) {
|
||||
const normalizedCoverPath = normalizeCoverPath(coverPath);
|
||||
if (normalizedCoverPath)
|
||||
trigger.dataset.coverArtPath = normalizedCoverPath;
|
||||
else
|
||||
delete trigger.dataset.coverArtPath;
|
||||
}
|
||||
|
||||
// Hands every play trigger the cover the page currently displays, so a play started after choosing or uploading an artwork shows that artwork in the player bar.
|
||||
function applyPlayAffordanceCover(coverPath) {
|
||||
currentCoverPath = normalizeCoverPath(coverPath);
|
||||
applyDescriptorCover(btnPlayAlbum, currentCoverPath);
|
||||
tracksBody.querySelectorAll('[data-audio-player-play]').forEach(trigger => applyDescriptorCover(trigger, currentCoverPath));
|
||||
}
|
||||
|
||||
// Reads the trimmed value of the element with the provided id.
|
||||
function readValue(id) {
|
||||
const element = document.getElementById(id);
|
||||
@@ -898,20 +947,51 @@
|
||||
return `${minutes}:${paddedSeconds}`;
|
||||
}
|
||||
|
||||
// Renders a row of the tracks table per track, or shows the empty message when the album has no tracks.
|
||||
// Renders a row of the tracks table per track, or shows the empty message when the album has no tracks. A failed
|
||||
// request returns undefined, which is not an empty album: it leaves the existing rows and the play album state intact.
|
||||
function renderTracks(response) {
|
||||
if (!response || !Array.isArray(response.data))
|
||||
return;
|
||||
tracksBody.innerHTML = '';
|
||||
const tracks = response && response.data ? response.data : [];
|
||||
const tracks = response.data;
|
||||
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.
|
||||
btnPlayAlbum.disabled = tracks.length === 0;
|
||||
tracks.forEach(track => tracksBody.appendChild(createTrackRow(track)));
|
||||
bindNavigationLinks();
|
||||
}
|
||||
|
||||
// Creates a row of the tracks table, with the name of the track linking to its own page.
|
||||
// Creates the play trigger of a track row. It describes a track context, so the player plays exactly this track.
|
||||
function createTrackPlayButton(track) {
|
||||
const button = document.createElement('button');
|
||||
button.type = 'button';
|
||||
button.className = 'confirm-button';
|
||||
button.setAttribute('data-audio-player-play', '');
|
||||
button.dataset.libraryId = libraryId;
|
||||
button.dataset.trackId = track.id;
|
||||
button.dataset.albumId = albumId;
|
||||
button.dataset.artistId = artistId;
|
||||
button.dataset.title = track.title || '';
|
||||
button.dataset.albumTitle = albumTitle;
|
||||
button.dataset.duration = String(track.durationInSeconds || '');
|
||||
applyDescriptorCover(button, currentCoverPath);
|
||||
// The button carries no visible text, so its accessible name names both the action and the track it plays.
|
||||
const label = `${jsLocalizedStrings.playTrack}: ${track.title || ''}`;
|
||||
button.setAttribute('aria-label', label);
|
||||
button.title = label;
|
||||
button.textContent = '\u25B6';
|
||||
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.
|
||||
function createTrackRow(track) {
|
||||
const row = document.createElement('tr');
|
||||
row.className = 'track-row';
|
||||
|
||||
const playCell = document.createElement('td');
|
||||
playCell.appendChild(createTrackPlayButton(track));
|
||||
|
||||
const numberCell = document.createElement('td');
|
||||
numberCell.textContent = track.trackNumber;
|
||||
|
||||
@@ -925,6 +1005,7 @@
|
||||
const durationCell = document.createElement('td');
|
||||
durationCell.textContent = formatDuration(track.durationInSeconds);
|
||||
|
||||
row.appendChild(playCell);
|
||||
row.appendChild(numberCell);
|
||||
row.appendChild(nameCell);
|
||||
row.appendChild(durationCell);
|
||||
@@ -1007,6 +1088,8 @@
|
||||
coverImage.dataset.coverPath = storedPath;
|
||||
coverPathLabel.textContent = storedPath ? storedPath : jsLocalizedStrings.noCover;
|
||||
coverPathLabel.title = storedPath;
|
||||
// The player shows the cover the page displays, so the uploaded cover is handed to the play triggers too.
|
||||
applyPlayAffordanceCover(storedPath);
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
notificationService.show(jsLocalizedStrings.coverSaved, NotificationType.SUCCESS);
|
||||
@@ -1042,12 +1125,14 @@
|
||||
artworkCarousel.querySelectorAll('.artwork-carousel-item').forEach(item => {
|
||||
item.classList.toggle('selected', item.dataset.artworkPath === artworkPath);
|
||||
});
|
||||
// The play affordances hand the player the cover the page currently displays, so a play started after choosing an artwork shows that artwork in the player bar.
|
||||
applyPlayAffordanceCover(artworkPath);
|
||||
}
|
||||
|
||||
// Shows the cover image of the album, or the first stored artwork when there is no cover, or a placeholder when the album has neither.
|
||||
function showCover() {
|
||||
const coverPath = coverImage.dataset.coverPath || '';
|
||||
const artworkPath = coverPath || (artworkItems.length > 0 ? artworkItems[0].path : '');
|
||||
const coverPath = normalizeCoverPath(coverImage.dataset.coverPath);
|
||||
const artworkPath = coverPath || (artworkItems.length > 0 ? normalizeCoverPath(artworkItems[0].path) : '');
|
||||
if (artworkPath) {
|
||||
selectArtwork(artworkPath);
|
||||
} else {
|
||||
|
||||
+50
-4
@@ -110,6 +110,9 @@
|
||||
sortAscending: '@_localizer["SortAscending"]',
|
||||
sortDescending: '@_localizer["SortDescending"]',
|
||||
viewDetails: '@_localizer["ViewDetails"]',
|
||||
actions: '@_localizer["Actions"]',
|
||||
play: '@_localizer["Play"]',
|
||||
shuffle: '@_localizer["Shuffle"]',
|
||||
deleteItem: '@_localizer["Delete"]',
|
||||
deleteConfirm: '@_localizer["DeleteConfirm"]',
|
||||
deleteFailed: '@_localizer["DeleteFailed"]'
|
||||
@@ -208,7 +211,7 @@
|
||||
trigger.type = 'button';
|
||||
trigger.className = 'card-actions-trigger';
|
||||
trigger.setAttribute('aria-haspopup', 'menu');
|
||||
trigger.setAttribute('aria-label', jsLocalizedStrings.viewDetails);
|
||||
trigger.setAttribute('aria-label', jsLocalizedStrings.actions);
|
||||
trigger.addEventListener('click', event => {
|
||||
event.preventDefault();
|
||||
event.stopImmediatePropagation();
|
||||
@@ -218,11 +221,54 @@
|
||||
const menu = document.createElement('nav');
|
||||
menu.className = 'card-actions-menu';
|
||||
menu.setAttribute('role', 'menu');
|
||||
menu.innerHTML = `
|
||||
<a role="menuitem" href="${artistUrl}">${jsLocalizedStrings.viewDetails}</a>
|
||||
<a role="menuitem" href="#" class="card-action-delete">${jsLocalizedStrings.deleteItem}</a>`;
|
||||
|
||||
const detailsAction = document.createElement('a');
|
||||
detailsAction.setAttribute('role', 'menuitem');
|
||||
detailsAction.href = artistUrl;
|
||||
detailsAction.textContent = jsLocalizedStrings.viewDetails;
|
||||
|
||||
const playAction = document.createElement('a');
|
||||
playAction.setAttribute('role', 'menuitem');
|
||||
playAction.href = '#';
|
||||
playAction.className = 'card-action-play';
|
||||
playAction.textContent = jsLocalizedStrings.play;
|
||||
playAction.setAttribute('data-audio-player-play', '');
|
||||
playAction.dataset.libraryId = libraryId;
|
||||
playAction.dataset.artistId = artist.id;
|
||||
playAction.dataset.title = artist.name || '';
|
||||
if (artist.coverPath)
|
||||
playAction.dataset.coverArtPath = artist.coverPath;
|
||||
|
||||
const shuffleAction = document.createElement('a');
|
||||
shuffleAction.setAttribute('role', 'menuitem');
|
||||
shuffleAction.href = '#';
|
||||
shuffleAction.className = 'card-action-shuffle';
|
||||
shuffleAction.textContent = jsLocalizedStrings.shuffle;
|
||||
shuffleAction.setAttribute('data-audio-player-play-shuffled', '');
|
||||
shuffleAction.setAttribute('data-audio-player-shuffle-scope', 'artist');
|
||||
shuffleAction.dataset.libraryId = libraryId;
|
||||
shuffleAction.dataset.artistId = artist.id;
|
||||
shuffleAction.dataset.title = artist.name || '';
|
||||
if (artist.coverPath)
|
||||
shuffleAction.dataset.coverArtPath = artist.coverPath;
|
||||
|
||||
const deleteAction = document.createElement('a');
|
||||
deleteAction.setAttribute('role', 'menuitem');
|
||||
deleteAction.href = '#';
|
||||
deleteAction.className = 'card-action-delete';
|
||||
deleteAction.textContent = jsLocalizedStrings.deleteItem;
|
||||
|
||||
menu.appendChild(detailsAction);
|
||||
menu.appendChild(playAction);
|
||||
menu.appendChild(shuffleAction);
|
||||
menu.appendChild(deleteAction);
|
||||
|
||||
menu.addEventListener('click', async 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')) {
|
||||
closeCardMenus();
|
||||
return;
|
||||
}
|
||||
const deleteItem = event.target.closest('.card-action-delete');
|
||||
const menuItem = event.target.closest('a[role="menuitem"]');
|
||||
if (!menuItem)
|
||||
|
||||
+73
-3
@@ -9,6 +9,9 @@
|
||||
The albums of the artist are NOT edited inline: they are listed as cards that navigate to their own pages,
|
||||
and the update request only round-trips the albums unchanged, so that updating the artist never drops them.
|
||||
|
||||
The artist header exposes a play all trigger for the global audio player. The player handles the trigger by event
|
||||
delegation, so this view binds no playback listener; the trigger attribute contract lives in docs/technical/theming/Theming.md.
|
||||
|
||||
To change the behavior of the page, edit this script (and the theme template, when present). To restyle
|
||||
the page, edit the theme files. This fallback keeps every feature working without styling, so that a
|
||||
broken theme is obvious to the user while the page still functions.
|
||||
@@ -36,6 +39,9 @@
|
||||
var aliases = metadata?.Aliases ?? [];
|
||||
var contributors = Model.Contributors ?? [];
|
||||
var ratings = Model.Ratings ?? [];
|
||||
// The play all trigger starts disabled when the artist is already known to hold no releases, so an empty discography
|
||||
// cannot be clicked before the release list request resolves. A failed request never changes this state.
|
||||
var hasReleases = (Model.Albums?.Count ?? 0) > 0;
|
||||
var genres = metadata?.Genres ?? [];
|
||||
var tags = metadata?.Tags ?? [];
|
||||
var area = metadata?.Area;
|
||||
@@ -110,6 +116,15 @@
|
||||
<div class="shine-effect"></div>
|
||||
<div class="form-row">
|
||||
<button id="btn-back-to-artists" type="button" class="abort-button">@_localizer["BackToArtists"]</button>
|
||||
<!-- The play all trigger is handled by the global audio player script through event delegation, so this page binds no click handler of its own. -->
|
||||
<button id="btn-play-artist" type="button" class="confirm-button" @(hasReleases ? string.Empty : "disabled")
|
||||
data-audio-player-play
|
||||
data-library-id="@libraryId"
|
||||
data-artist-id="@artistId"
|
||||
data-title="@(metadata?.Name ?? string.Empty)"
|
||||
data-cover-art-path="@(Model.CoverPath ?? string.Empty)">
|
||||
@_localizer["PlayAll"]
|
||||
</button>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<h1 class="text-light-two w-100 text-center pt-0 pb-0 engraved-title">@_localizer["EditArtist"]</h1>
|
||||
@@ -624,6 +639,7 @@
|
||||
const btnBackToArtists = document.getElementById('btn-back-to-artists');
|
||||
const btnSaveArtist = document.getElementById('btn-save-artist');
|
||||
const btnDeleteArtist = document.getElementById('btn-delete-artist');
|
||||
const btnPlayArtist = document.getElementById('btn-play-artist');
|
||||
const btnAddAlias = document.getElementById('btn-add-alias');
|
||||
const btnAddIpi = document.getElementById('btn-add-ipi');
|
||||
const btnAddIsni = document.getElementById('btn-add-isni');
|
||||
@@ -656,6 +672,8 @@
|
||||
noCover: @Json.Serialize(_localizer["NoCover"].Value),
|
||||
coverSaved: @Json.Serialize(_localizer["CoverSaved"].Value),
|
||||
coverUploadFailed: @Json.Serialize(_localizer["CoverUploadFailed"].Value),
|
||||
play: @Json.Serialize(_localizer["Play"].Value),
|
||||
shuffle: @Json.Serialize(_localizer["Shuffle"].Value),
|
||||
remove: @Json.Serialize(_localizer["Remove"].Value)
|
||||
};
|
||||
|
||||
@@ -932,6 +950,28 @@
|
||||
return deleteAlbumUrlTemplate.replace('/@(default(Guid))', `/${artistId}`).replace('/@(default(Guid))', `/${albumId}`) + `?libraryId=${libraryId}`;
|
||||
}
|
||||
|
||||
// Writes the play descriptor of an album onto an album card menu action.
|
||||
function applyAlbumPlayDescriptor(trigger, album) {
|
||||
trigger.dataset.libraryId = libraryId;
|
||||
trigger.dataset.artistId = artistId;
|
||||
trigger.dataset.albumId = album.id;
|
||||
trigger.dataset.title = album.title || '';
|
||||
if (album.coverPath)
|
||||
trigger.dataset.coverArtPath = album.coverPath;
|
||||
else
|
||||
delete trigger.dataset.coverArtPath;
|
||||
}
|
||||
|
||||
// Creates an action of the album card actions menu.
|
||||
function createAlbumMenuAction(label, className) {
|
||||
const action = document.createElement('a');
|
||||
action.setAttribute('role', 'menuitem');
|
||||
action.href = '#';
|
||||
action.className = className;
|
||||
action.textContent = label;
|
||||
return action;
|
||||
}
|
||||
|
||||
// The localized labels of the release types, keyed by their canonical enum name.
|
||||
const releaseTypeLabels = {
|
||||
'Album': '@_localizer["Album"].Value',
|
||||
@@ -962,11 +1002,16 @@
|
||||
renderReleases(response);
|
||||
}
|
||||
|
||||
// Renders the releases of the artist, grouped by their primary release type, each group ordered by release year.
|
||||
// Renders the releases of the artist, grouped by their primary release type, each group ordered by release year. A
|
||||
// failed request returns undefined, which is not an empty discography: it leaves the existing list and play state intact.
|
||||
function renderReleases(response) {
|
||||
if (!response || !Array.isArray(response.data))
|
||||
return;
|
||||
albumsContainer.querySelectorAll('.release-group').forEach(group => group.remove());
|
||||
const releases = response && response.data ? response.data : [];
|
||||
const releases = response.data;
|
||||
noAlbumsMessage.classList.toggle('hidden', releases.length !== 0);
|
||||
// Only a successful empty list disables the play all trigger. The player can still build the queue itself when the release list could not be loaded.
|
||||
btnPlayArtist.disabled = releases.length === 0;
|
||||
|
||||
// The releases are grouped by their first release type, falling back to "Other" when the type is not known.
|
||||
const groups = new Map();
|
||||
@@ -1072,8 +1117,28 @@
|
||||
const menu = document.createElement('nav');
|
||||
menu.className = 'card-actions-menu';
|
||||
menu.setAttribute('role', 'menu');
|
||||
menu.innerHTML = `<a role="menuitem" href="#" class="card-action-delete">${jsLocalizedStrings.remove}</a>`;
|
||||
|
||||
const playAction = createAlbumMenuAction(jsLocalizedStrings.play, 'card-action-play');
|
||||
playAction.setAttribute('data-audio-player-play', '');
|
||||
applyAlbumPlayDescriptor(playAction, album);
|
||||
|
||||
const shuffleAction = createAlbumMenuAction(jsLocalizedStrings.shuffle, 'card-action-shuffle');
|
||||
shuffleAction.setAttribute('data-audio-player-play-shuffled', '');
|
||||
shuffleAction.setAttribute('data-audio-player-shuffle-scope', 'release');
|
||||
applyAlbumPlayDescriptor(shuffleAction, album);
|
||||
|
||||
const deleteAction = createAlbumMenuAction(jsLocalizedStrings.remove, 'card-action-delete');
|
||||
|
||||
menu.appendChild(playAction);
|
||||
menu.appendChild(shuffleAction);
|
||||
menu.appendChild(deleteAction);
|
||||
|
||||
menu.addEventListener('click', async event => {
|
||||
// Play and shuffle are handled by the global audio player delegation, so the menu only closes here.
|
||||
if (event.target.closest('.card-action-play, .card-action-shuffle')) {
|
||||
closeCardMenus();
|
||||
return;
|
||||
}
|
||||
const deleteItem = event.target.closest('.card-action-delete');
|
||||
if (!deleteItem)
|
||||
return;
|
||||
@@ -1237,6 +1302,11 @@
|
||||
coverImage.dataset.coverPath = storedPath;
|
||||
coverPathLabel.textContent = storedPath ? storedPath : jsLocalizedStrings.noCover;
|
||||
coverPathLabel.title = storedPath;
|
||||
// The player shows the cover the page displays, so the uploaded cover is handed to the play trigger too.
|
||||
if (storedPath)
|
||||
btnPlayArtist.dataset.coverArtPath = storedPath;
|
||||
else
|
||||
delete btnPlayArtist.dataset.coverArtPath;
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
notificationService.show(jsLocalizedStrings.coverSaved, NotificationType.SUCCESS);
|
||||
|
||||
+20
-2
@@ -10,6 +10,9 @@
|
||||
The audio properties, the release information, the language and original language, the work, the
|
||||
contributors, the ratings, the moods and the ISRCs are all editable, and they are all round-tripped on save.
|
||||
|
||||
The track header exposes a play trigger for the global audio player. The player handles the trigger by event
|
||||
delegation, so this view binds no playback listener; the trigger attribute contract lives in docs/technical/theming/Theming.md.
|
||||
|
||||
To change the behavior of the page, edit this script (and the theme template, when present). To restyle
|
||||
the page, edit the theme files. This fallback keeps every feature working without styling, so that a
|
||||
broken theme is obvious to the user while the page still functions.
|
||||
@@ -35,8 +38,10 @@
|
||||
var libraryId = Model.LibraryId.ToString();
|
||||
// The cover shown on the left is the cover of the album the track belongs to, passed in by the endpoint.
|
||||
var albumCoverPath = ViewData["AlbumCoverPath"]?.ToString() ?? string.Empty;
|
||||
// The track DTO does not carry the Id of its artist, so it is taken from the route that rendered the view.
|
||||
var artistId = Context.Request.RouteValues["artistId"]?.ToString() ?? string.Empty;
|
||||
var albumTitle = ViewData["AlbumTitle"]?.ToString() ?? string.Empty;
|
||||
// The track DTO does not carry the Id of its artist, so the endpoint passes the normalized route value it used to load
|
||||
// the track and its album. Both render paths therefore hand the player the same artist Id.
|
||||
var artistId = ViewData["ArtistId"]?.ToString() ?? string.Empty;
|
||||
var metadata = Model.Metadata;
|
||||
var work = Model.Work;
|
||||
var releaseInfo = metadata?.ReleaseInfo;
|
||||
@@ -82,6 +87,19 @@
|
||||
<div class="shine-effect"></div>
|
||||
<div class="form-row">
|
||||
<button id="btn-back-to-album" type="button" class="abort-button">@_localizer["BackToAlbum"]</button>
|
||||
<!-- The play trigger is handled by the global audio player script through event delegation, so this page binds no click handler of its own. -->
|
||||
<button id="btn-play-track" type="button" class="confirm-button"
|
||||
data-audio-player-play
|
||||
data-library-id="@libraryId"
|
||||
data-track-id="@trackId"
|
||||
data-album-id="@Model.AlbumId"
|
||||
data-artist-id="@artistId"
|
||||
data-title="@(metadata?.Title ?? string.Empty)"
|
||||
data-album-title="@albumTitle"
|
||||
data-duration="@(metadata?.DurationInSeconds?.ToString(CultureInfo.InvariantCulture) ?? string.Empty)"
|
||||
data-cover-art-path="@albumCoverPath">
|
||||
@_localizer["PlayTrack"]
|
||||
</button>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<h1 class="text-light-two w-100 text-center pt-0 pb-0 engraved-title">@_localizer["EditTrack"]</h1>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@using Microsoft.Extensions.Localization
|
||||
@using Microsoft.Extensions.Localization
|
||||
|
||||
@inject IStringLocalizerFactory _stringLocalizerFactory
|
||||
|
||||
@@ -20,27 +20,25 @@
|
||||
|
||||
The DOM contract a theme must preserve is:
|
||||
- The container element with the 'audio-player-container' class, carrying 'not-shown' while the bar is hidden,
|
||||
and 'full-height' while it is expanded. The audio player toggles both classes. While the bar is hidden the
|
||||
player also sets the 'inert' attribute on it, and removes it when the bar is shown, so a collapsed bar keeps
|
||||
none of its focusable controls in the tab order.
|
||||
- The main content element, carrying 'audio-player-not-shown' while the bar is hidden, and 'audio-player-full-height'
|
||||
while it is expanded. The audio player toggles both classes on it as well.
|
||||
- The elements with the ids 'audio-player-full-height-toggle' and 'audio-player-close', which the global site script
|
||||
binds and routes to the audio player.
|
||||
- The hook attributes the audio player binds: 'data-audio-player-play-pause', '-previous', '-next', '-shuffle',
|
||||
'-shuffle-control', '-shuffle-menu', '-repeat', '-progress', '-progress-played', '-progress-downloaded',
|
||||
'-progress-undownloaded', '-current-time', '-total-time', '-track-name', '-cover-thumbnail', '-cover-image',
|
||||
'-volume', '-volume-level', '-mute' and '-queue'. 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 shuffle scope items carry 'data-audio-player-shuffle-scope' ('off', 'release', 'artist' or 'library'), inside
|
||||
the menu element carrying 'data-audio-player-shuffle-menu'. The shuffle control carries 'data-audio-player-shuffle'
|
||||
and is wrapped by 'data-audio-player-shuffle-control', so the player can open the menu near it and close it on an
|
||||
outside click. It is a menu button: it carries 'aria-haspopup' and 'aria-expanded', gets the 'is-active' class while
|
||||
shuffle is on, and does not carry 'aria-pressed'. The scope items get 'aria-checked' and the 'is-selected' class, and
|
||||
the 'off' item is selected while shuffle is off. 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.
|
||||
and 'expanded' while it is expanded. The audio player toggles both classes. While the bar is hidden the player
|
||||
also sets the 'inert' attribute on it, and removes it when the bar is shown, so a collapsed bar keeps none of
|
||||
its focusable controls in the tab order. The position and orientation of the container are entirely theme-owned:
|
||||
this fallback stylesheet uses a flex column with the bar at the bottom, but a theme may place the bar vertically
|
||||
on a side and expand its queue horizontally.
|
||||
- The main content element, carrying 'audio-player-not-shown' while the bar is hidden, and
|
||||
'audio-player-bar-expanded' while it is expanded. The audio player toggles these classes on it as well.
|
||||
- The element with the id 'audio-player-expand-toggle', which the global site script binds and routes to the audio player.
|
||||
- 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'.
|
||||
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.
|
||||
A queue item root rendered by the player always carries 'data-audio-player-queue-entry-id', whether it comes from the
|
||||
theme sub template or from the built-in markup, so clicking it starts that entry.
|
||||
theme sub template or from the built-in markup, so clicking it starts that entry. The queue element stays the scroll
|
||||
container of the list, because the player scrolls the current entry to the start of whichever axis the theme makes
|
||||
scrollable when playback advances or the bar expands.
|
||||
- The three state progress bar: the played part carries 'audio-player-progress-played', the downloaded but not
|
||||
played part carries 'audio-player-progress-downloaded', and the not yet downloaded part carries
|
||||
'audio-player-progress-undownloaded'. Each layer also carries 'data-audio-player-progress-layer' ('played',
|
||||
@@ -57,22 +55,40 @@
|
||||
'audio-player-template-queue-item' and 'audio-player-template-playlist-item'. This application fallback partial
|
||||
renders neither element; it intentionally uses the built-in queue item markup.
|
||||
|
||||
The play affordances the pages hand to the player use the 'data-audio-player-play' trigger attribute, and a play next
|
||||
affordance uses 'data-audio-player-play-next'. A track trigger must carry libraryId, trackId, albumId and artistId,
|
||||
because the playback manifest route needs all four Ids. The 'The Audio Player Bar' section of
|
||||
The play affordances the pages hand to the player use the 'data-audio-player-play' trigger attribute, a shuffled play
|
||||
affordance uses 'data-audio-player-play-shuffled' together with 'data-audio-player-shuffle-scope' ('release', 'artist' or
|
||||
'library'), a whole library play affordance uses 'data-audio-player-play-library' with 'data-library-id', a whole library
|
||||
shuffle affordance uses 'data-audio-player-play-library-shuffled' with 'data-library-id', and a play next affordance uses
|
||||
'data-audio-player-play-next'. A track trigger must carry libraryId, trackId, albumId and artistId, because the playback
|
||||
manifest route needs all four Ids. The 'Play Affordances on the Music Pages' section of
|
||||
docs/technical/theming/Theming.md documents this contract for theme authors.
|
||||
*@
|
||||
|
||||
<div class="audio-player-container not-shown" hidden>
|
||||
<!-- Expanded area: cover art, and the queue when the play context holds more than one track. -->
|
||||
<!-- Expanded area: current track details and album artwork beside the current queue, including a single track. -->
|
||||
<div class="audio-player-expanded">
|
||||
<img class="audio-player-cover-image" data-audio-player-cover-image alt="" />
|
||||
<div class="audio-player-now-playing">
|
||||
<img class="audio-player-cover-image" data-audio-player-cover-image alt="" />
|
||||
<div class="audio-player-now-playing-labels">
|
||||
<span class="audio-player-now-playing-title" data-audio-player-now-playing-title></span>
|
||||
<div class="audio-player-now-playing-release-line">
|
||||
<span class="audio-player-now-playing-release-type" data-audio-player-now-playing-release-type></span>
|
||||
<span class="audio-player-now-playing-release" data-audio-player-now-playing-release></span>
|
||||
<span class="audio-player-now-playing-year" data-audio-player-now-playing-year></span>
|
||||
</div>
|
||||
<span class="audio-player-now-playing-artist" data-audio-player-now-playing-artist></span>
|
||||
</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>
|
||||
<!-- Condensed bar: transport controls, three state progress bar, volume, and track name. -->
|
||||
<div class="audio-player-bar">
|
||||
<img class="audio-player-cover-thumbnail" data-audio-player-cover-thumbnail alt="" />
|
||||
<span class="audio-player-track-name" data-audio-player-track-name></span>
|
||||
<div class="audio-player-track-labels">
|
||||
<span class="audio-player-track-name" data-audio-player-track-name></span>
|
||||
<span class="audio-player-album-name" data-audio-player-album-name></span>
|
||||
</div>
|
||||
<span class="audio-player-time audio-player-current-time" data-audio-player-current-time>0:00</span>
|
||||
<div class="audio-player-progress" data-audio-player-progress data-audio-player-progress-state="idle" role="slider" tabindex="0"
|
||||
aria-label="@localizer["AudioPlayerSeek"]" aria-valuemin="0" aria-valuemax="1" aria-valuenow="0" aria-busy="false">
|
||||
@@ -82,24 +98,15 @@
|
||||
</div>
|
||||
<span class="audio-player-time audio-player-total-time" data-audio-player-total-time>--:--</span>
|
||||
<div class="audio-player-queue-controls">
|
||||
<div class="audio-player-shuffle-control" data-audio-player-shuffle-control>
|
||||
<button type="button" class="audio-player-button audio-player-shuffle" data-audio-player-shuffle
|
||||
aria-haspopup="menu" aria-expanded="false" aria-label="@localizer["AudioPlayerShuffle"]">
|
||||
<span class="audio-player-shuffle-icon" aria-hidden="true">⇆</span>
|
||||
</button>
|
||||
<div class="audio-player-shuffle-menu" data-audio-player-shuffle-menu role="menu" hidden>
|
||||
<button type="button" role="menuitemradio" aria-checked="true" data-audio-player-shuffle-scope="off">@localizer["AudioPlayerShuffleOff"]</button>
|
||||
<button type="button" role="menuitemradio" aria-checked="false" data-audio-player-shuffle-scope="release">@localizer["AudioPlayerShuffleRelease"]</button>
|
||||
<button type="button" role="menuitemradio" aria-checked="false" data-audio-player-shuffle-scope="artist">@localizer["AudioPlayerShuffleArtist"]</button>
|
||||
<button type="button" role="menuitemradio" aria-checked="false" data-audio-player-shuffle-scope="library">@localizer["AudioPlayerShuffleLibrary"]</button>
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" class="audio-player-button audio-player-previous" data-audio-player-previous aria-label="@localizer["AudioPlayerPrevious"]">
|
||||
<span class="audio-player-previous-icon" aria-hidden="true"></span>
|
||||
</button>
|
||||
<button type="button" class="audio-player-button audio-player-play-pause" data-audio-player-play-pause aria-label="@localizer["AudioPlayerPlay"]">
|
||||
<span class="audio-player-play-pause-icon" aria-hidden="true"></span>
|
||||
</button>
|
||||
<button type="button" class="audio-player-button audio-player-stop" data-audio-player-stop aria-label="@localizer["AudioPlayerStop"]">
|
||||
<span class="audio-player-stop-icon" aria-hidden="true"></span>
|
||||
</button>
|
||||
<button type="button" class="audio-player-button audio-player-next" data-audio-player-next aria-label="@localizer["AudioPlayerNext"]">
|
||||
<span class="audio-player-next-icon" aria-hidden="true"></span>
|
||||
</button>
|
||||
@@ -119,8 +126,9 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="audio-player-controls">
|
||||
<button type="button" id="audio-player-full-height-toggle">@localizer["ToggleFullHeight"]</button>
|
||||
<button type="button" id="audio-player-close">@localizer["ToggleVisibility"]</button>
|
||||
<button type="button" id="audio-player-expand-toggle" aria-label="@localizer["ToggleExpanded"]">
|
||||
<span class="audio-player-expand-icon" aria-hidden="true"></span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -50,6 +50,12 @@
|
||||
getArtistsUrl: '@_urlService.GetRelativeUrl(WebRoutes.Music.GET_ARTISTS)',
|
||||
getArtistAlbumsUrl: '@_urlService.GetRelativeUrl(WebRoutes.Music.GET_ARTIST_ALBUMS)',
|
||||
getAlbumTracksUrl: '@_urlService.GetRelativeUrl(WebRoutes.Music.GET_ALBUM_TRACKS)',
|
||||
// The full album details, used by the expanded player for the release labels and the artwork carousel of the
|
||||
// current track's album. The route carries the artist and album Ids, and the library Id is a query parameter.
|
||||
getAlbumUrl: '@_urlService.GetRelativeUrl(WebRoutes.Music.GET_ALBUM)',
|
||||
// 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)',
|
||||
strings: {
|
||||
play: '@localizer["AudioPlayerPlay"]',
|
||||
pause: '@localizer["AudioPlayerPause"]',
|
||||
@@ -60,16 +66,12 @@
|
||||
buffering: '@localizer["AudioPlayerBuffering"]',
|
||||
previous: '@localizer["AudioPlayerPrevious"]',
|
||||
next: '@localizer["AudioPlayerNext"]',
|
||||
shuffle: '@localizer["AudioPlayerShuffle"]',
|
||||
shuffleOff: '@localizer["AudioPlayerShuffleOff"]',
|
||||
shuffleRelease: '@localizer["AudioPlayerShuffleRelease"]',
|
||||
shuffleArtist: '@localizer["AudioPlayerShuffleArtist"]',
|
||||
shuffleLibrary: '@localizer["AudioPlayerShuffleLibrary"]',
|
||||
repeat: '@localizer["AudioPlayerRepeat"]',
|
||||
repeatOff: '@localizer["AudioPlayerRepeatOff"]',
|
||||
repeatAll: '@localizer["AudioPlayerRepeatAll"]',
|
||||
repeatOne: '@localizer["AudioPlayerRepeatOne"]',
|
||||
queue: '@localizer["AudioPlayerQueue"]'
|
||||
queue: '@localizer["AudioPlayerQueue"]',
|
||||
albumArtwork: '@localizer["AudioPlayerAlbumArtwork"]'
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
Reference in new issue
Block a user