Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sort options to playback requests #4786

Merged
merged 16 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,4 @@
- [jomp16](https://github.com/jomp16)
- [Leon de Klerk](https://github.com/leondeklerk)
- [CrispyBaguette](https://github.com/CrispyBaguette)
- [v0idMrK](https://github.com/v0idMrK)
v0idMrK marked this conversation as resolved.
Show resolved Hide resolved
16 changes: 14 additions & 2 deletions src/components/playback/playbackmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -1806,12 +1806,18 @@ class PlaybackManager {
MediaTypes: 'Audio'
});
} else if (firstItem.MediaType === 'Photo') {
const sortOptions = options.sortOptions || {};
let sortByValue = options.shuffle ? 'Random' : sortOptions.sortBy;
if (sortByValue == null) {
sortByValue = 'SortName';
}
v0idMrK marked this conversation as resolved.
Show resolved Hide resolved
promise = getItemsForPlayback(serverId, {
ParentId: firstItem.ParentId,
Filters: 'IsNotFolder',
// Setting this to true may cause some incorrect sorting
Recursive: false,
SortBy: options.shuffle ? 'Random' : 'SortName',
SortBy: sortByValue,
SortOrder: sortOptions.sortOrder,
MediaTypes: 'Photo,Video',
Limit: UNLIMITED_ITEMS
}).then(function (result) {
Expand Down Expand Up @@ -1849,11 +1855,17 @@ class PlaybackManager {
MediaTypes: 'Audio'
});
} else if (firstItem.IsFolder && firstItem.CollectionType === 'homevideos') {
const sortOptions = options.sortOptions || {};
let sortByValue = options.shuffle ? 'Random' : sortOptions.sortBy;
if (sortByValue == null) {
sortByValue = 'SortName';
}
promise = getItemsForPlayback(serverId, mergePlaybackQueries({
ParentId: firstItem.Id,
Filters: 'IsNotFolder',
Recursive: true,
SortBy: options.shuffle ? 'Random' : 'SortName',
SortBy: sortByValue,
SortOrder: sortOptions.sortOrder,
// Only include Photos because we do not handle mixed queues currently
MediaTypes: 'Photo',
Limit: UNLIMITED_ITEMS
Expand Down
17 changes: 15 additions & 2 deletions src/components/shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import dom from '../scripts/dom';
import recordingHelper from './recordingcreator/recordinghelper';
import ServerConnections from './ServerConnections';
import toast from './toast/toast';
import * as userSettings from '../scripts/settings/userSettings';

function playAllFromHere(card, serverId, queue) {
const parent = card.parentNode;
Expand Down Expand Up @@ -165,6 +166,14 @@ function showPlayMenu(card, target) {
});
}

function getSortValues(parentId) {
const basekey = 'items-' + parentId + '-Folder';
return {
sortBy: userSettings.getFilter(basekey + '-sortby'),
sortOrder: userSettings.getFilter(basekey + '-sortorder') === 'Descending' ? 'Descending' : 'Ascending'
};
}
v0idMrK marked this conversation as resolved.
Show resolved Hide resolved

function executeAction(card, target, action) {
target = target || card;

Expand All @@ -175,6 +184,10 @@ function executeAction(card, target, action) {
id = card.getAttribute('data-id');
}

const itemsContainer = dom.parentWithClass(card, 'itemsContainer');

const parentId = itemsContainer.getAttribute('data-parentid');

const item = getItemInfoFromCard(card);
v0idMrK marked this conversation as resolved.
Show resolved Hide resolved

const serverId = item.ServerId;
Expand All @@ -200,12 +213,12 @@ function executeAction(card, target, action) {
});
} else if (action === 'play' || action === 'resume') {
const startPositionTicks = parseInt(card.getAttribute('data-positionticks') || '0', 10);

v0idMrK marked this conversation as resolved.
Show resolved Hide resolved
if (playbackManager.canPlay(item)) {
playbackManager.play({
ids: [playableItemId],
startPositionTicks: startPositionTicks,
serverId: serverId
serverId: serverId,
sortOptions: getSortValues(parentId)
});
} else {
console.warn('Unable to play item', item);
Expand Down
4 changes: 3 additions & 1 deletion src/controllers/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -722,11 +722,13 @@ class ItemsView {

function play() {
const currentItem = self.currentItem;
const values = self.getSortValues();

if (currentItem && !self.hasFilters) {
playbackManager.play({
items: [currentItem],
autoplay: true
autoplay: true,
sortOptions: values
});
} else {
getItems(self, self.params, currentItem, null, 0, 300).then(function (result) {
Expand Down