1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/src/controllers/list.js

1299 lines
41 KiB
JavaScript
Raw Normal View History

2020-08-14 08:46:34 +02:00
import globalize from '../scripts/globalize';
import listView from '../components/listview/listview';
import * as userSettings from '../scripts/settings/userSettings';
import focusManager from '../components/focusManager';
import cardBuilder from '../components/cardbuilder/cardBuilder';
import loading from '../components/loading/loading';
import AlphaNumericShortcuts from '../scripts/alphanumericshortcuts';
2022-01-16 16:38:12 +03:00
import libraryBrowser from '../scripts/libraryBrowser';
2020-08-16 20:24:45 +02:00
import { playbackManager } from '../components/playback/playbackmanager';
2020-08-14 08:46:34 +02:00
import AlphaPicker from '../components/alphaPicker/alphaPicker';
import '../elements/emby-itemscontainer/emby-itemscontainer';
import '../elements/emby-scroller/emby-scroller';
import ServerConnections from '../components/ServerConnections';
2022-03-31 14:36:09 -04:00
import LibraryMenu from '../scripts/libraryMenu';
2023-12-06 17:57:35 +00:00
import { CollectionType } from '@jellyfin/sdk/lib/generated-client/';
2023-04-19 01:56:05 -04:00
function getInitialLiveTvQuery(instance, params, startIndex = 0, limit = 300) {
const query = {
UserId: ServerConnections.getApiClient(params.serverId).getCurrentUserId(),
StartIndex: startIndex,
Fields: 'ChannelInfo,PrimaryImageAspectRatio',
Limit: limit
};
if (params.type === 'Recordings') {
query.IsInProgress = false;
} else {
query.HasAired = false;
}
2018-10-23 01:05:09 +03:00
2023-04-19 01:56:05 -04:00
if (params.genreId) {
query.GenreIds = params.genreId;
}
2023-04-19 01:56:05 -04:00
if (params.IsMovie === 'true') {
query.IsMovie = true;
} else if (params.IsMovie === 'false') {
query.IsMovie = false;
}
2023-04-19 01:56:05 -04:00
if (params.IsSeries === 'true') {
query.IsSeries = true;
} else if (params.IsSeries === 'false') {
query.IsSeries = false;
}
2023-04-19 01:56:05 -04:00
if (params.IsNews === 'true') {
query.IsNews = true;
} else if (params.IsNews === 'false') {
query.IsNews = false;
}
2023-04-19 01:56:05 -04:00
if (params.IsSports === 'true') {
query.IsSports = true;
} else if (params.IsSports === 'false') {
query.IsSports = false;
}
2023-04-19 01:56:05 -04:00
if (params.IsKids === 'true') {
query.IsKids = true;
} else if (params.IsKids === 'false') {
query.IsKids = false;
}
2023-04-19 01:56:05 -04:00
if (params.IsAiring === 'true') {
query.IsAiring = true;
} else if (params.IsAiring === 'false') {
query.IsAiring = false;
}
2023-04-19 01:56:05 -04:00
return modifyQueryWithFilters(instance, query);
}
2023-04-19 01:56:05 -04:00
function modifyQueryWithFilters(instance, query) {
const sortValues = instance.getSortValues();
2023-04-19 01:56:05 -04:00
if (!query.SortBy) {
query.SortBy = sortValues.sortBy;
query.SortOrder = sortValues.sortOrder;
2018-10-23 01:05:09 +03:00
}
2023-04-19 01:56:05 -04:00
query.Fields = query.Fields ? query.Fields + ',PrimaryImageAspectRatio' : 'PrimaryImageAspectRatio';
query.ImageTypeLimit = 1;
let hasFilters;
const queryFilters = [];
const filters = instance.getFilters();
2023-04-19 01:56:05 -04:00
if (filters.IsPlayed) {
queryFilters.push('IsPlayed');
hasFilters = true;
}
2023-04-19 01:56:05 -04:00
if (filters.IsUnplayed) {
queryFilters.push('IsUnplayed');
hasFilters = true;
}
2023-04-19 01:56:05 -04:00
if (filters.IsFavorite) {
queryFilters.push('IsFavorite');
hasFilters = true;
}
2023-04-19 01:56:05 -04:00
if (filters.IsResumable) {
queryFilters.push('IsResumable');
hasFilters = true;
}
2023-04-19 01:56:05 -04:00
if (filters.VideoTypes) {
hasFilters = true;
query.VideoTypes = filters.VideoTypes;
}
2023-04-19 01:56:05 -04:00
if (filters.GenreIds) {
hasFilters = true;
query.GenreIds = filters.GenreIds;
}
2023-04-19 01:56:05 -04:00
if (filters.Is4K) {
query.Is4K = true;
hasFilters = true;
}
2023-04-19 01:56:05 -04:00
if (filters.IsHD) {
query.IsHD = true;
hasFilters = true;
}
2023-04-19 01:56:05 -04:00
if (filters.IsSD) {
query.IsHD = false;
hasFilters = true;
}
2023-04-19 01:56:05 -04:00
if (filters.Is3D) {
query.Is3D = true;
hasFilters = true;
}
2023-04-19 01:56:05 -04:00
if (filters.HasSubtitles) {
query.HasSubtitles = true;
hasFilters = true;
}
2023-04-19 01:56:05 -04:00
if (filters.HasTrailer) {
query.HasTrailer = true;
hasFilters = true;
}
2023-04-19 01:56:05 -04:00
if (filters.HasSpecialFeature) {
query.HasSpecialFeature = true;
hasFilters = true;
}
2023-04-19 01:56:05 -04:00
if (filters.HasThemeSong) {
query.HasThemeSong = true;
hasFilters = true;
}
2023-04-19 01:56:05 -04:00
if (filters.HasThemeVideo) {
query.HasThemeVideo = true;
hasFilters = true;
}
2023-04-19 01:56:05 -04:00
query.Filters = queryFilters.length ? queryFilters.join(',') : null;
instance.setFilterStatus(hasFilters);
2023-04-19 01:56:05 -04:00
if (instance.alphaPicker) {
const newValue = instance.alphaPicker.value();
if (newValue === '#') {
query.NameLessThan = 'A';
delete query.NameStartsWith;
} else {
query.NameStartsWith = newValue;
delete query.NameLessThan;
}
2018-10-23 01:05:09 +03:00
}
2023-04-19 01:56:05 -04:00
return query;
}
2023-04-19 01:56:05 -04:00
function setSortButtonIcon(btnSortIcon, icon) {
btnSortIcon.classList.remove('arrow_downward');
btnSortIcon.classList.remove('arrow_upward');
btnSortIcon.classList.add(icon);
}
2023-04-19 01:56:05 -04:00
function updateSortText(instance) {
const btnSortText = instance.btnSortText;
2023-04-19 01:56:05 -04:00
if (btnSortText) {
const options = instance.getSortMenuOptions();
const values = instance.getSortValues();
const sortBy = values.sortBy;
2023-04-19 01:56:05 -04:00
for (const option of options) {
if (sortBy === option.value) {
btnSortText.innerHTML = globalize.translate('SortByValue', option.name);
break;
}
2018-10-23 01:05:09 +03:00
}
2023-04-19 01:56:05 -04:00
const btnSortIcon = instance.btnSortIcon;
if (btnSortIcon) {
setSortButtonIcon(btnSortIcon, values.sortOrder === 'Descending' ? 'arrow_downward' : 'arrow_upward');
}
2018-10-23 01:05:09 +03:00
}
2023-04-19 01:56:05 -04:00
}
2018-10-23 01:05:09 +03:00
2023-04-19 01:56:05 -04:00
function updateItemsContainerForViewType(instance) {
if (instance.getViewSettings().imageType === 'list') {
instance.itemsContainer.classList.remove('vertical-wrap');
instance.itemsContainer.classList.add('vertical-list');
} else {
instance.itemsContainer.classList.add('vertical-wrap');
instance.itemsContainer.classList.remove('vertical-list');
2018-10-23 01:05:09 +03:00
}
2023-04-19 01:56:05 -04:00
}
2018-10-23 01:05:09 +03:00
2023-04-19 01:56:05 -04:00
function updateAlphaPickerState(instance) {
if (instance.alphaPicker) {
const alphaPicker = instance.alphaPickerElement;
2023-04-19 01:56:05 -04:00
if (alphaPicker) {
const values = instance.getSortValues();
2023-04-19 01:56:05 -04:00
if (values.sortBy.indexOf('SortName') !== -1) {
alphaPicker.classList.remove('hide');
instance.itemsContainer.parentNode.classList.add('padded-right-withalphapicker');
} else {
alphaPicker.classList.add('hide');
instance.itemsContainer.parentNode.classList.remove('padded-right-withalphapicker');
}
}
2023-04-19 01:56:05 -04:00
}
}
2023-04-19 01:56:05 -04:00
function getItems(instance, params, item, sortBy, startIndex, limit) {
const apiClient = ServerConnections.getApiClient(params.serverId);
2023-04-19 01:56:05 -04:00
instance.queryRecursive = false;
if (params.type === 'Recordings') {
return apiClient.getLiveTvRecordings(getInitialLiveTvQuery(instance, params, startIndex, limit));
}
2023-04-19 01:56:05 -04:00
if (params.type === 'Programs') {
if (params.IsAiring === 'true') {
return apiClient.getLiveTvRecommendedPrograms(getInitialLiveTvQuery(instance, params, startIndex, limit));
2018-10-23 01:05:09 +03:00
}
2023-04-19 01:56:05 -04:00
return apiClient.getLiveTvPrograms(getInitialLiveTvQuery(instance, params, startIndex, limit));
}
2023-04-19 01:56:05 -04:00
if (params.type === 'nextup') {
return apiClient.getNextUpEpisodes(modifyQueryWithFilters(instance, {
Limit: limit,
2024-01-11 02:24:16 -05:00
Fields: 'PrimaryImageAspectRatio,DateCreated,MediaSourceCount',
2023-04-19 01:56:05 -04:00
UserId: apiClient.getCurrentUserId(),
ImageTypeLimit: 1,
EnableImageTypes: 'Primary,Backdrop,Thumb',
EnableTotalRecordCount: false,
SortBy: sortBy,
EnableRewatching: userSettings.enableRewatchingInNextUp()
}));
}
2023-04-19 01:56:05 -04:00
if (!item) {
instance.queryRecursive = true;
let method = 'getItems';
2023-04-19 01:56:05 -04:00
if (params.type === 'MusicArtist') {
method = 'getArtists';
} else if (params.type === 'Person') {
method = 'getPeople';
2018-10-23 01:05:09 +03:00
}
2023-04-19 01:56:05 -04:00
return apiClient[method](apiClient.getCurrentUserId(), modifyQueryWithFilters(instance, {
2018-10-23 01:05:09 +03:00
StartIndex: startIndex,
Limit: limit,
2023-04-19 01:56:05 -04:00
Fields: 'PrimaryImageAspectRatio,SortName',
2018-10-23 01:05:09 +03:00
ImageTypeLimit: 1,
2023-04-19 01:56:05 -04:00
IncludeItemTypes: params.type === 'MusicArtist' || params.type === 'Person' ? null : params.type,
Recursive: true,
IsFavorite: params.IsFavorite === 'true' || null,
ArtistIds: params.artistId || null,
2018-10-23 01:05:09 +03:00
SortBy: sortBy
}));
2018-10-23 01:05:09 +03:00
}
2023-04-19 01:56:05 -04:00
if (item.Type === 'Genre' || item.Type === 'MusicGenre' || item.Type === 'Studio' || item.Type === 'Person') {
instance.queryRecursive = true;
const query = {
StartIndex: startIndex,
Limit: limit,
Fields: 'PrimaryImageAspectRatio,SortName',
Recursive: true,
parentId: params.parentId,
SortBy: sortBy
};
2023-04-19 01:56:05 -04:00
if (item.Type === 'Studio') {
query.StudioIds = item.Id;
} else if (item.Type === 'Genre' || item.Type === 'MusicGenre') {
query.GenreIds = item.Id;
} else if (item.Type === 'Person') {
query.PersonIds = item.Id;
}
2023-04-19 01:56:05 -04:00
if (item.Type === 'MusicGenre') {
query.IncludeItemTypes = 'MusicAlbum';
2023-12-06 17:57:35 +00:00
} else if (item.CollectionType === CollectionType.Movies) {
2023-04-19 01:56:05 -04:00
query.IncludeItemTypes = 'Movie';
2023-12-06 17:57:35 +00:00
} else if (item.CollectionType === CollectionType.TvShows) {
2023-04-19 01:56:05 -04:00
query.IncludeItemTypes = 'Series';
} else if (item.Type === 'Genre') {
query.IncludeItemTypes = 'Movie,Series,Video';
} else if (item.Type === 'Person') {
query.IncludeItemTypes = params.type;
}
2023-04-19 01:56:05 -04:00
return apiClient.getItems(apiClient.getCurrentUserId(), modifyQueryWithFilters(instance, query));
}
return apiClient.getItems(apiClient.getCurrentUserId(), modifyQueryWithFilters(instance, {
StartIndex: startIndex,
Limit: limit,
2024-01-06 13:48:03 -07:00
Fields: 'PrimaryImageAspectRatio,SortName,Path,ChildCount,MediaSourceCount',
2023-04-19 01:56:05 -04:00
ImageTypeLimit: 1,
ParentId: item.Id,
SortBy: sortBy
}));
}
function getItem(params) {
if (params.type === 'Recordings' || params.type === 'Programs' || params.type === 'nextup') {
return Promise.resolve(null);
2018-10-23 01:05:09 +03:00
}
2023-04-19 01:56:05 -04:00
const apiClient = ServerConnections.getApiClient(params.serverId);
const itemId = params.genreId || params.musicGenreId || params.studioId || params.personId || params.parentId;
if (itemId) {
return apiClient.getItem(apiClient.getCurrentUserId(), itemId);
2018-10-23 01:05:09 +03:00
}
2023-04-19 01:56:05 -04:00
return Promise.resolve(null);
}
function showViewSettingsMenu() {
const instance = this;
import('../components/viewSettings/viewSettings').then(({ default: ViewSettings }) => {
new ViewSettings().show({
settingsKey: instance.getSettingsKey(),
settings: instance.getViewSettings(),
visibleSettings: instance.getVisibleViewSettings()
}).then(function () {
updateItemsContainerForViewType(instance);
instance.itemsContainer.refreshItems();
});
2023-04-19 01:56:05 -04:00
});
}
2018-10-23 01:05:09 +03:00
2023-04-19 01:56:05 -04:00
function showFilterMenu() {
const instance = this;
import('../components/filtermenu/filtermenu').then(({ default: FilterMenu }) => {
new FilterMenu().show({
settingsKey: instance.getSettingsKey(),
settings: instance.getFilters(),
visibleSettings: instance.getVisibleFilters(),
onChange: instance.itemsContainer.refreshItems.bind(instance.itemsContainer),
parentId: instance.params.parentId,
itemTypes: instance.getItemTypes(),
serverId: instance.params.serverId,
filterMenuOptions: instance.getFilterMenuOptions()
}).then(function () {
instance.itemsContainer.refreshItems();
});
2023-04-19 01:56:05 -04:00
});
}
2018-10-23 01:05:09 +03:00
2023-04-19 01:56:05 -04:00
function showSortMenu() {
const instance = this;
import('../components/sortmenu/sortmenu').then(({ default: SortMenu }) => {
new SortMenu().show({
settingsKey: instance.getSettingsKey(),
settings: instance.getSortValues(),
onChange: instance.itemsContainer.refreshItems.bind(instance.itemsContainer),
serverId: instance.params.serverId,
sortOptions: instance.getSortMenuOptions()
}).then(function () {
updateSortText(instance);
updateAlphaPickerState(instance);
instance.itemsContainer.refreshItems();
});
});
}
2023-04-19 01:56:05 -04:00
function onNewItemClick() {
const instance = this;
2023-07-06 11:49:55 -04:00
import('../components/playlisteditor/playlisteditor').then(({ default: PlaylistEditor }) => {
new PlaylistEditor({
2023-04-19 01:56:05 -04:00
items: [],
serverId: instance.params.serverId
});
2023-04-19 01:56:05 -04:00
});
}
2018-10-23 01:05:09 +03:00
2023-04-19 01:56:05 -04:00
function hideOrShowAll(elems, hide) {
for (const elem of elems) {
if (hide) {
elem.classList.add('hide');
} else {
elem.classList.remove('hide');
}
2018-10-23 01:05:09 +03:00
}
2023-04-19 01:56:05 -04:00
}
2018-10-23 01:05:09 +03:00
2023-04-19 01:56:05 -04:00
function bindAll(elems, eventName, fn) {
for (const elem of elems) {
elem.addEventListener(eventName, fn);
2018-10-23 01:05:09 +03:00
}
2023-04-19 01:56:05 -04:00
}
2018-10-23 01:05:09 +03:00
class ItemsView {
constructor(view, params) {
2022-01-16 16:38:12 +03:00
const query = {
StartIndex: 0,
Limit: undefined
};
if (userSettings.libraryPageSize() > 0) {
query['Limit'] = userSettings.libraryPageSize();
}
let isLoading = false;
function onNextPageClick() {
if (!isLoading && query.Limit > 0) {
query.StartIndex += query.Limit;
self.itemsContainer.refreshItems().then(() => {
window.scrollTo(0, 0);
autoFocus();
});
}
}
function onPreviousPageClick() {
if (!isLoading && query.Limit > 0) {
query.StartIndex = Math.max(0, query.StartIndex - query.Limit);
self.itemsContainer.refreshItems().then(() => {
window.scrollTo(0, 0);
autoFocus();
});
}
}
function updatePaging(startIndex, totalRecordCount, limit) {
const pagingHtml = libraryBrowser.getQueryPagingHtml({
startIndex,
limit,
totalRecordCount,
showLimit: false,
updatePageSizeSetting: false,
addLayoutButton: false,
sortButton: false,
filterButton: false
});
for (const elem of view.querySelectorAll('.paging')) {
elem.innerHTML = pagingHtml;
}
for (const elem of view.querySelectorAll('.btnNextPage')) {
elem.addEventListener('click', onNextPageClick);
}
for (const elem of view.querySelectorAll('.btnPreviousPage')) {
elem.addEventListener('click', onPreviousPageClick);
}
}
2018-10-23 01:05:09 +03:00
function fetchData() {
2022-01-16 16:38:12 +03:00
isLoading = true;
return getItems(self, params, self.currentItem, null, query.StartIndex, query.Limit).then(function (result) {
2020-07-30 16:07:13 +02:00
if (self.totalItemCount == null) {
self.totalItemCount = result.Items ? result.Items.length : result.length;
}
updateAlphaPickerState(self);
2022-01-16 16:38:12 +03:00
updatePaging(result.StartIndex, result.TotalRecordCount, query.Limit);
return result;
2022-01-16 16:38:12 +03:00
}).finally(() => {
isLoading = false;
});
2018-10-23 01:05:09 +03:00
}
function getItemsHtml(items) {
const settings = self.getViewSettings();
2020-07-30 16:07:13 +02:00
if (settings.imageType === 'list') {
return listView.getListViewHtml({
items: items
});
}
let shape;
let preferThumb;
let preferDisc;
let preferLogo;
let defaultShape;
const item = self.currentItem;
let lines = settings.showTitle ? 2 : 0;
2020-07-30 16:07:13 +02:00
if (settings.imageType === 'banner') {
2020-05-04 12:44:12 +02:00
shape = 'banner';
2020-07-30 16:07:13 +02:00
} else if (settings.imageType === 'disc') {
2020-05-04 12:44:12 +02:00
shape = 'square';
preferDisc = true;
2020-07-30 16:07:13 +02:00
} else if (settings.imageType === 'logo') {
2020-05-04 12:44:12 +02:00
shape = 'backdrop';
preferLogo = true;
2020-07-30 16:07:13 +02:00
} else if (settings.imageType === 'thumb') {
2020-05-04 12:44:12 +02:00
shape = 'backdrop';
preferThumb = true;
2020-07-30 16:07:13 +02:00
} else if (params.type === 'nextup') {
2020-05-04 12:44:12 +02:00
shape = 'backdrop';
2020-07-30 16:07:13 +02:00
preferThumb = settings.imageType === 'thumb';
} else if (params.type === 'Programs' || params.type === 'Recordings') {
shape = params.IsMovie === 'true' ? 'portrait' : 'autoVertical';
preferThumb = params.IsMovie !== 'true' ? 'auto' : false;
defaultShape = params.IsMovie === 'true' ? 'portrait' : 'backdrop';
} else {
2020-05-04 12:44:12 +02:00
shape = 'autoVertical';
}
let posterOptions = {
2018-10-23 01:05:09 +03:00
shape: shape,
showTitle: settings.showTitle,
showYear: settings.showTitle,
centerText: true,
coverImage: true,
2018-10-23 01:05:09 +03:00
preferThumb: preferThumb,
preferDisc: preferDisc,
preferLogo: preferLogo,
overlayPlayButton: false,
overlayMoreButton: true,
2018-10-23 01:05:09 +03:00
overlayText: !settings.showTitle,
defaultShape: defaultShape,
2020-07-30 16:07:13 +02:00
action: params.type === 'Audio' ? 'playallfromhere' : null
2018-10-23 01:05:09 +03:00
};
2020-07-30 16:07:13 +02:00
if (params.type === 'nextup') {
posterOptions.showParentTitle = settings.showTitle;
2020-07-30 16:07:13 +02:00
} else if (params.type === 'Person') {
posterOptions.showYear = false;
posterOptions.showParentTitle = false;
lines = 1;
2020-07-30 16:07:13 +02:00
} else if (params.type === 'Audio') {
posterOptions.showParentTitle = settings.showTitle;
2020-07-30 16:07:13 +02:00
} else if (params.type === 'MusicAlbum') {
posterOptions.showParentTitle = settings.showTitle;
2020-07-30 16:07:13 +02:00
} else if (params.type === 'Episode') {
posterOptions.showParentTitle = settings.showTitle;
2020-07-30 16:07:13 +02:00
} else if (params.type === 'MusicArtist') {
posterOptions.showYear = false;
lines = 1;
2020-07-30 16:07:13 +02:00
} else if (params.type === 'Programs') {
2018-10-23 01:05:09 +03:00
lines = settings.showTitle ? 1 : 0;
const showParentTitle = settings.showTitle && params.IsMovie !== 'true';
if (showParentTitle) {
lines++;
}
const showAirTime = settings.showTitle && params.type !== 'Recordings';
if (showAirTime) {
lines++;
}
const showYear = settings.showTitle && params.IsMovie === 'true' && params.type === 'Recordings';
2020-08-02 18:06:40 +01:00
if (showYear) {
lines++;
}
posterOptions = Object.assign(posterOptions, {
2020-07-30 16:07:13 +02:00
inheritThumb: params.type === 'Recordings',
2020-05-04 12:44:12 +02:00
context: 'livetv',
2018-10-23 01:05:09 +03:00
showParentTitle: showParentTitle,
showAirTime: showAirTime,
showAirDateTime: showAirTime,
overlayPlayButton: false,
overlayMoreButton: true,
2018-10-23 01:05:09 +03:00
showYear: showYear,
coverImage: true
});
} else {
posterOptions.showParentTitle = settings.showTitle;
}
posterOptions.lines = lines;
posterOptions.items = items;
2023-12-06 17:57:35 +00:00
if (item && item.CollectionType === CollectionType.Folders) {
2020-05-04 12:44:12 +02:00
posterOptions.context = 'folders';
}
return cardBuilder.getCardsHtml(posterOptions);
2018-10-23 01:05:09 +03:00
}
function initAlphaPicker() {
2020-05-04 12:44:12 +02:00
self.scroller = view.querySelector('.scrollFrameY');
const alphaPickerElement = self.alphaPickerElement;
2020-05-04 12:44:12 +02:00
alphaPickerElement.classList.add('alphaPicker-fixed-right');
alphaPickerElement.classList.add('focuscontainer-right');
self.itemsContainer.parentNode.classList.add('padded-right-withalphapicker');
2020-08-02 17:58:21 +01:00
self.alphaPicker = new AlphaPicker({
2018-10-23 01:05:09 +03:00
element: alphaPickerElement,
2022-01-16 16:38:12 +03:00
valueChangeEvent: 'click'
});
2020-05-04 12:44:12 +02:00
self.alphaPicker.on('alphavaluechanged', onAlphaPickerValueChanged);
2018-10-23 01:05:09 +03:00
}
function onAlphaPickerValueChanged() {
2022-01-16 16:38:12 +03:00
query.StartIndex = 0;
self.itemsContainer.refreshItems();
2018-10-23 01:05:09 +03:00
}
function setTitle(item) {
2022-03-31 14:36:09 -04:00
LibraryMenu.setTitle(getTitle(item) || '');
2023-12-06 17:57:35 +00:00
if (item && item.CollectionType === CollectionType.Playlists) {
2020-05-04 12:44:12 +02:00
hideOrShowAll(view.querySelectorAll('.btnNewItem'), false);
} else {
2020-05-04 12:44:12 +02:00
hideOrShowAll(view.querySelectorAll('.btnNewItem'), true);
}
2018-10-23 01:05:09 +03:00
}
function getTitle(item) {
2020-07-30 16:07:13 +02:00
if (params.type === 'Recordings') {
2020-05-04 12:44:12 +02:00
return globalize.translate('Recordings');
}
2020-07-30 16:07:13 +02:00
if (params.type === 'Programs') {
if (params.IsMovie === 'true') {
2020-05-04 12:44:12 +02:00
return globalize.translate('Movies');
}
2020-07-30 16:07:13 +02:00
if (params.IsSports === 'true') {
2020-05-04 12:44:12 +02:00
return globalize.translate('Sports');
}
2020-07-30 16:07:13 +02:00
if (params.IsKids === 'true') {
2020-05-04 12:44:12 +02:00
return globalize.translate('HeaderForKids');
}
2020-07-30 16:07:13 +02:00
if (params.IsAiring === 'true') {
2020-05-04 12:44:12 +02:00
return globalize.translate('HeaderOnNow');
}
2020-07-30 16:07:13 +02:00
if (params.IsSeries === 'true') {
2020-05-04 12:44:12 +02:00
return globalize.translate('Shows');
}
2020-07-30 16:07:13 +02:00
if (params.IsNews === 'true') {
2020-05-04 12:44:12 +02:00
return globalize.translate('News');
}
2020-05-04 12:44:12 +02:00
return globalize.translate('Programs');
}
2020-07-30 16:07:13 +02:00
if (params.type === 'nextup') {
2020-05-04 12:44:12 +02:00
return globalize.translate('NextUp');
}
2020-07-30 16:07:13 +02:00
if (params.type === 'favoritemovies') {
2020-05-04 12:44:12 +02:00
return globalize.translate('FavoriteMovies');
}
if (item) {
return item.Name;
}
2020-07-30 16:07:13 +02:00
if (params.type === 'Movie') {
2020-05-04 12:44:12 +02:00
return globalize.translate('Movies');
}
2020-07-30 16:07:13 +02:00
if (params.type === 'Series') {
2020-05-04 12:44:12 +02:00
return globalize.translate('Shows');
}
2020-07-30 16:07:13 +02:00
if (params.type === 'Season') {
2020-05-04 12:44:12 +02:00
return globalize.translate('Seasons');
}
2020-07-30 16:07:13 +02:00
if (params.type === 'Episode') {
2020-05-04 12:44:12 +02:00
return globalize.translate('Episodes');
}
2020-07-30 16:07:13 +02:00
if (params.type === 'MusicArtist') {
2020-05-04 12:44:12 +02:00
return globalize.translate('Artists');
}
2020-07-30 16:07:13 +02:00
if (params.type === 'MusicAlbum') {
2020-05-04 12:44:12 +02:00
return globalize.translate('Albums');
}
2020-07-30 16:07:13 +02:00
if (params.type === 'Audio') {
2020-05-04 12:44:12 +02:00
return globalize.translate('Songs');
}
2020-07-30 16:07:13 +02:00
if (params.type === 'Video') {
2020-05-04 12:44:12 +02:00
return globalize.translate('Videos');
}
2018-10-23 01:05:09 +03:00
}
function play() {
const currentItem = self.currentItem;
if (currentItem && !self.hasFilters) {
const values = self.getSortValues();
2018-10-23 01:05:09 +03:00
playbackManager.play({
2021-09-09 00:06:09 +03:00
items: [currentItem],
queryOptions: {
SortBy: values.sortBy,
SortOrder: values.sortOrder
},
autoplay: true
});
} else {
2022-02-09 09:25:25 -05:00
getItems(self, self.params, currentItem, null, 0, 300).then(function (result) {
playbackManager.play({
2021-09-09 00:06:09 +03:00
items: result.Items,
autoplay: true
});
});
}
2018-10-23 01:05:09 +03:00
}
function queue() {
const currentItem = self.currentItem;
if (currentItem && !self.hasFilters) {
2018-10-23 01:05:09 +03:00
playbackManager.queue({
items: [currentItem]
});
} else {
2022-02-09 09:25:25 -05:00
getItems(self, self.params, currentItem, null, 0, 300).then(function (result) {
playbackManager.queue({
items: result.Items
});
});
}
2018-10-23 01:05:09 +03:00
}
function shuffle() {
const currentItem = self.currentItem;
if (currentItem && !self.hasFilters) {
playbackManager.shuffle(currentItem);
} else {
2022-02-09 09:25:25 -05:00
getItems(self, self.params, currentItem, 'Random', 0, 300).then(function (result) {
playbackManager.play({
2021-09-09 00:06:09 +03:00
items: result.Items,
autoplay: true
});
});
}
2018-10-23 01:05:09 +03:00
}
2022-01-16 16:38:12 +03:00
function autoFocus() {
2023-03-29 00:38:22 -04:00
import('../components/autoFocuser').then(({ default: autoFocuser }) => {
2022-01-16 16:38:12 +03:00
autoFocuser.autoFocus(view);
});
}
const self = this;
self.params = params;
2020-05-04 12:44:12 +02:00
this.itemsContainer = view.querySelector('.itemsContainer');
if (params.parentId) {
2020-05-04 12:44:12 +02:00
this.itemsContainer.setAttribute('data-parentid', params.parentId);
2020-07-30 16:07:13 +02:00
} else if (params.type === 'nextup') {
2020-05-04 12:44:12 +02:00
this.itemsContainer.setAttribute('data-monitor', 'videoplayback');
2020-07-30 16:07:13 +02:00
} else if (params.type === 'favoritemovies') {
2020-05-04 12:44:12 +02:00
this.itemsContainer.setAttribute('data-monitor', 'markfavorite');
2020-07-30 16:07:13 +02:00
} else if (params.type === 'Programs') {
2020-05-04 12:44:12 +02:00
this.itemsContainer.setAttribute('data-refreshinterval', '300000');
}
const btnViewSettings = view.querySelectorAll('.btnViewSettings');
2020-08-07 09:27:11 +01:00
for (const btnViewSetting of btnViewSettings) {
btnViewSetting.addEventListener('click', showViewSettingsMenu.bind(this));
}
const filterButtons = view.querySelectorAll('.btnFilter');
2018-10-23 01:05:09 +03:00
this.filterButtons = filterButtons;
const hasVisibleFilters = this.getVisibleFilters().length;
2020-08-07 09:27:11 +01:00
for (const btnFilter of filterButtons) {
2020-05-04 12:44:12 +02:00
btnFilter.addEventListener('click', showFilterMenu.bind(this));
if (hasVisibleFilters) {
2020-05-04 12:44:12 +02:00
btnFilter.classList.remove('hide');
} else {
2020-05-04 12:44:12 +02:00
btnFilter.classList.add('hide');
}
2018-10-23 01:05:09 +03:00
}
const sortButtons = view.querySelectorAll('.btnSort');
2020-08-07 09:27:11 +01:00
this.sortButtons = sortButtons;
for (const sortButton of sortButtons) {
2020-05-04 12:44:12 +02:00
sortButton.addEventListener('click', showSortMenu.bind(this));
2020-07-30 16:07:13 +02:00
if (params.type !== 'nextup') {
2020-05-04 12:44:12 +02:00
sortButton.classList.remove('hide');
}
2018-10-23 01:05:09 +03:00
}
2020-05-04 12:44:12 +02:00
this.btnSortText = view.querySelector('.btnSortText');
this.btnSortIcon = view.querySelector('.btnSortIcon');
bindAll(view.querySelectorAll('.btnNewItem'), 'click', onNewItemClick.bind(this));
this.alphaPickerElement = view.querySelector('.alphaPicker');
self.itemsContainer.fetchData = fetchData;
self.itemsContainer.getItemsHtml = getItemsHtml;
2020-05-04 12:44:12 +02:00
view.addEventListener('viewshow', function (e) {
const isRestored = e.detail.isRestored;
if (!isRestored) {
loading.show();
updateSortText(self);
updateItemsContainerForViewType(self);
}
setTitle(null);
getItem(params).then(function (item) {
setTitle(item);
self.currentItem = item;
const refresh = !isRestored;
2018-10-23 01:05:09 +03:00
self.itemsContainer.resume({
refresh: refresh
}).then(function () {
loading.hide();
if (refresh) {
focusManager.autoFocus(self.itemsContainer);
}
});
2020-07-30 16:07:13 +02:00
if (!isRestored && item && item.Type !== 'PhotoAlbum') {
initAlphaPicker();
}
const itemType = item ? item.Type : null;
if ((itemType === 'MusicGenre' || params.type !== 'Programs' && itemType !== 'Channel')
// Folder, Playlist views
&& itemType !== 'UserView'
// Only Photo (homevideos) CollectionFolders are supported
2023-12-06 17:57:35 +00:00
&& !(itemType === 'CollectionFolder' && item?.CollectionType !== CollectionType.HomeVideos)
) {
2021-09-15 14:34:58 -04:00
// Show Play All buttons
2020-05-04 12:44:12 +02:00
hideOrShowAll(view.querySelectorAll('.btnPlay'), false);
} else {
2021-09-15 14:34:58 -04:00
// Hide Play All buttons
2020-05-04 12:44:12 +02:00
hideOrShowAll(view.querySelectorAll('.btnPlay'), true);
}
if ((itemType === 'MusicGenre' || params.type !== 'Programs' && params.type !== 'nextup' && itemType !== 'Channel')
// Folder, Playlist views
&& itemType !== 'UserView'
// Only Photo (homevideos) CollectionFolders are supported
2023-12-06 17:57:35 +00:00
&& !(itemType === 'CollectionFolder' && item?.CollectionType !== CollectionType.HomeVideos)
) {
2021-09-15 14:34:58 -04:00
// Show Shuffle buttons
2020-05-04 12:44:12 +02:00
hideOrShowAll(view.querySelectorAll('.btnShuffle'), false);
} else {
2021-09-15 14:34:58 -04:00
// Hide Shuffle buttons
2020-05-04 12:44:12 +02:00
hideOrShowAll(view.querySelectorAll('.btnShuffle'), true);
}
if (item && playbackManager.canQueue(item)) {
2021-09-15 14:34:58 -04:00
// Show Queue button
2020-05-04 12:44:12 +02:00
hideOrShowAll(view.querySelectorAll('.btnQueue'), false);
} else {
2021-09-15 14:34:58 -04:00
// Hide Queue button
2020-05-04 12:44:12 +02:00
hideOrShowAll(view.querySelectorAll('.btnQueue'), true);
}
});
if (!isRestored) {
2020-05-04 12:44:12 +02:00
bindAll(view.querySelectorAll('.btnPlay'), 'click', play);
bindAll(view.querySelectorAll('.btnQueue'), 'click', queue);
bindAll(view.querySelectorAll('.btnShuffle'), 'click', shuffle);
}
2020-08-02 17:58:21 +01:00
self.alphaNumericShortcuts = new AlphaNumericShortcuts({
2018-10-23 01:05:09 +03:00
itemsContainer: self.itemsContainer
});
});
2021-01-26 22:20:12 -05:00
view.addEventListener('viewhide', function () {
const itemsContainer = self.itemsContainer;
if (itemsContainer) {
itemsContainer.pause();
}
const alphaNumericShortcuts = self.alphaNumericShortcuts;
if (alphaNumericShortcuts) {
2020-07-25 13:42:03 +02:00
alphaNumericShortcuts.destroy();
self.alphaNumericShortcuts = null;
}
});
2020-05-04 12:44:12 +02:00
view.addEventListener('viewdestroy', function () {
if (self.listController) {
self.listController.destroy();
}
if (self.alphaPicker) {
2020-05-04 12:44:12 +02:00
self.alphaPicker.off('alphavaluechanged', onAlphaPickerValueChanged);
self.alphaPicker.destroy();
}
self.currentItem = null;
self.scroller = null;
self.itemsContainer = null;
self.filterButtons = null;
self.sortButtons = null;
self.btnSortText = null;
self.btnSortIcon = null;
self.alphaPickerElement = null;
});
2018-10-23 01:05:09 +03:00
}
2020-08-02 18:06:40 +01:00
getFilters() {
const basekey = this.getSettingsKey();
2018-10-23 01:05:09 +03:00
return {
2020-07-30 16:07:13 +02:00
IsPlayed: userSettings.getFilter(basekey + '-filter-IsPlayed') === 'true',
IsUnplayed: userSettings.getFilter(basekey + '-filter-IsUnplayed') === 'true',
IsFavorite: userSettings.getFilter(basekey + '-filter-IsFavorite') === 'true',
IsResumable: userSettings.getFilter(basekey + '-filter-IsResumable') === 'true',
Is4K: userSettings.getFilter(basekey + '-filter-Is4K') === 'true',
IsHD: userSettings.getFilter(basekey + '-filter-IsHD') === 'true',
IsSD: userSettings.getFilter(basekey + '-filter-IsSD') === 'true',
Is3D: userSettings.getFilter(basekey + '-filter-Is3D') === 'true',
2020-05-04 12:44:12 +02:00
VideoTypes: userSettings.getFilter(basekey + '-filter-VideoTypes'),
SeriesStatus: userSettings.getFilter(basekey + '-filter-SeriesStatus'),
HasSubtitles: userSettings.getFilter(basekey + '-filter-HasSubtitles'),
HasTrailer: userSettings.getFilter(basekey + '-filter-HasTrailer'),
HasSpecialFeature: userSettings.getFilter(basekey + '-filter-HasSpecialFeature'),
HasThemeSong: userSettings.getFilter(basekey + '-filter-HasThemeSong'),
HasThemeVideo: userSettings.getFilter(basekey + '-filter-HasThemeVideo'),
GenreIds: userSettings.getFilter(basekey + '-filter-GenreIds')
};
}
2020-08-02 18:06:40 +01:00
getSortValues() {
const basekey = this.getSettingsKey();
return userSettings.getSortValuesLegacy(basekey, this.getDefaultSortBy());
}
2020-08-02 18:06:40 +01:00
getDefaultSortBy() {
2020-08-07 09:27:11 +01:00
const sortNameOption = this.getNameSortOption(this.params);
2020-08-07 09:27:11 +01:00
if (this.params.type) {
return sortNameOption.value;
2018-10-23 01:05:09 +03:00
}
2020-05-04 12:44:12 +02:00
return 'IsFolder,' + sortNameOption.value;
}
2020-08-02 18:06:40 +01:00
getSortMenuOptions() {
const sortBy = [];
2020-08-07 09:27:11 +01:00
if (this.params.type === 'Programs') {
sortBy.push({
2020-05-04 12:44:12 +02:00
name: globalize.translate('AirDate'),
value: 'StartDate,SortName'
});
}
2020-08-07 09:27:11 +01:00
let option = this.getNameSortOption(this.params);
if (option) {
sortBy.push(option);
}
option = this.getCommunityRatingSortOption();
if (option) {
sortBy.push(option);
}
option = this.getCriticRatingSortOption();
if (option) {
sortBy.push(option);
}
2020-08-07 09:27:11 +01:00
if (this.params.type !== 'Programs') {
sortBy.push({
2020-05-04 12:44:12 +02:00
name: globalize.translate('DateAdded'),
value: 'DateCreated,SortName'
});
}
option = this.getDatePlayedSortOption();
if (option) {
sortBy.push(option);
}
2020-08-07 09:27:11 +01:00
if (!this.params.type) {
option = this.getNameSortOption(this.params);
sortBy.push({
2020-05-04 12:44:12 +02:00
name: globalize.translate('Folders'),
value: 'IsFolder,' + option.value
});
}
sortBy.push({
2020-05-04 12:44:12 +02:00
name: globalize.translate('ParentalRating'),
value: 'OfficialRating,SortName'
});
option = this.getPlayCountSortOption();
if (option) {
sortBy.push(option);
}
sortBy.push({
2020-05-04 12:44:12 +02:00
name: globalize.translate('ReleaseDate'),
value: 'ProductionYear,PremiereDate,SortName'
});
sortBy.push({
2020-05-04 12:44:12 +02:00
name: globalize.translate('Runtime'),
value: 'Runtime,SortName'
});
return sortBy;
}
2020-08-02 18:06:40 +01:00
getNameSortOption(params) {
2020-07-30 16:07:13 +02:00
if (params.type === 'Episode') {
return {
2020-05-04 12:44:12 +02:00
name: globalize.translate('Name'),
value: 'SeriesName,SortName'
};
}
return {
2020-05-04 12:44:12 +02:00
name: globalize.translate('Name'),
value: 'SortName'
};
}
2020-08-02 18:06:40 +01:00
getPlayCountSortOption() {
2020-07-30 16:07:13 +02:00
if (this.params.type === 'Programs') {
return null;
2018-10-23 01:05:09 +03:00
}
return {
2020-05-04 12:44:12 +02:00
name: globalize.translate('PlayCount'),
value: 'PlayCount,SortName'
};
}
2020-08-02 18:06:40 +01:00
getDatePlayedSortOption() {
2020-07-30 16:07:13 +02:00
if (this.params.type === 'Programs') {
return null;
2018-10-23 01:05:09 +03:00
}
return {
2020-05-04 12:44:12 +02:00
name: globalize.translate('DatePlayed'),
value: 'DatePlayed,SortName'
};
}
2020-08-02 18:06:40 +01:00
getCriticRatingSortOption() {
if (this.params.type === 'Programs') {
return null;
2018-10-23 01:05:09 +03:00
}
return {
2020-05-04 12:44:12 +02:00
name: globalize.translate('CriticRating'),
value: 'CriticRating,SortName'
};
}
2020-08-02 18:06:40 +01:00
getCommunityRatingSortOption() {
2018-10-23 01:05:09 +03:00
return {
2020-05-04 12:44:12 +02:00
name: globalize.translate('CommunityRating'),
value: 'CommunityRating,SortName'
};
}
2020-08-02 18:06:40 +01:00
getVisibleFilters() {
const filters = [];
const params = this.params;
2022-12-16 16:02:11 -05:00
if (params.type !== 'nextup') {
2020-07-30 16:07:13 +02:00
if (params.type === 'Programs') {
2020-05-04 12:44:12 +02:00
filters.push('Genres');
} else {
2020-05-04 12:44:12 +02:00
filters.push('IsUnplayed');
filters.push('IsPlayed');
if (!params.IsFavorite) {
2020-05-04 12:44:12 +02:00
filters.push('IsFavorite');
}
2020-05-04 12:44:12 +02:00
filters.push('IsResumable');
filters.push('VideoType');
filters.push('HasSubtitles');
filters.push('HasTrailer');
filters.push('HasSpecialFeature');
filters.push('HasThemeSong');
filters.push('HasThemeVideo');
}
2018-10-23 01:05:09 +03:00
}
return filters;
}
2020-08-02 18:06:40 +01:00
setFilterStatus(hasFilters) {
2018-10-23 01:05:09 +03:00
this.hasFilters = hasFilters;
const filterButtons = this.filterButtons;
if (filterButtons.length) {
2020-08-07 09:27:11 +01:00
for (const btnFilter of filterButtons) {
let bubble = btnFilter.querySelector('.filterButtonBubble');
2018-10-23 01:05:09 +03:00
if (!bubble) {
if (!hasFilters) {
continue;
}
2020-05-04 12:44:12 +02:00
btnFilter.insertAdjacentHTML('afterbegin', '<div class="filterButtonBubble">!</div>');
btnFilter.classList.add('btnFilterWithBubble');
bubble = btnFilter.querySelector('.filterButtonBubble');
}
if (hasFilters) {
2020-05-04 12:44:12 +02:00
bubble.classList.remove('hide');
} else {
2020-05-04 12:44:12 +02:00
bubble.classList.add('hide');
2018-10-23 01:05:09 +03:00
}
}
}
}
2020-08-02 18:06:40 +01:00
getFilterMenuOptions() {
const params = this.params;
2018-10-23 01:05:09 +03:00
return {
IsAiring: params.IsAiring,
IsMovie: params.IsMovie,
IsSports: params.IsSports,
IsKids: params.IsKids,
IsNews: params.IsNews,
IsSeries: params.IsSeries,
Recursive: this.queryRecursive
};
}
2020-08-02 18:06:40 +01:00
getVisibleViewSettings() {
2022-06-09 07:00:43 -07:00
const item = this.currentItem;
const fields = ['showTitle'];
2020-07-30 16:07:13 +02:00
if (!item || item.Type !== 'PhotoAlbum' && item.Type !== 'ChannelFolderItem') {
2020-05-04 12:44:12 +02:00
fields.push('imageType');
}
2020-05-04 12:44:12 +02:00
fields.push('viewType');
return fields;
}
2020-08-02 18:06:40 +01:00
getViewSettings() {
const basekey = this.getSettingsKey();
const params = this.params;
const item = this.currentItem;
let showTitle = userSettings.get(basekey + '-showTitle');
2020-07-30 16:07:13 +02:00
if (showTitle === 'true') {
showTitle = true;
2020-07-30 16:07:13 +02:00
} else if (showTitle === 'false') {
showTitle = false;
2020-07-30 16:07:13 +02:00
} else if (params.type === 'Programs' || params.type === 'Recordings' || params.type === 'Person' || params.type === 'nextup' || params.type === 'Audio' || params.type === 'MusicAlbum' || params.type === 'MusicArtist') {
showTitle = true;
2020-07-30 16:07:13 +02:00
} else if (item && item.Type !== 'PhotoAlbum') {
showTitle = true;
2018-10-23 01:05:09 +03:00
}
let imageType = userSettings.get(basekey + '-imageType');
2020-07-30 16:07:13 +02:00
if (!imageType && params.type === 'nextup') {
if (userSettings.useEpisodeImagesInNextUpAndResume()) {
imageType = 'primary';
} else {
imageType = 'thumb';
}
}
return {
2018-10-23 01:05:09 +03:00
showTitle: showTitle,
2020-07-30 16:07:13 +02:00
showYear: userSettings.get(basekey + '-showYear') !== 'false',
2020-05-04 12:44:12 +02:00
imageType: imageType || 'primary',
viewType: userSettings.get(basekey + '-viewType') || 'images'
};
}
2020-08-02 18:06:40 +01:00
getItemTypes() {
const params = this.params;
2020-07-30 16:07:13 +02:00
if (params.type === 'nextup') {
2020-05-04 12:44:12 +02:00
return ['Episode'];
}
2020-07-30 16:07:13 +02:00
if (params.type === 'Programs') {
2020-05-04 12:44:12 +02:00
return ['Program'];
}
return [];
}
2020-08-02 18:06:40 +01:00
getSettingsKey() {
const values = [];
2020-05-04 12:44:12 +02:00
values.push('items');
const params = this.params;
if (params.type) {
values.push(params.type);
} else if (params.parentId) {
values.push(params.parentId);
}
if (params.IsAiring) {
2020-05-04 12:44:12 +02:00
values.push('IsAiring');
}
if (params.IsMovie) {
2020-05-04 12:44:12 +02:00
values.push('IsMovie');
}
if (params.IsKids) {
2020-05-04 12:44:12 +02:00
values.push('IsKids');
}
if (params.IsSports) {
2020-05-04 12:44:12 +02:00
values.push('IsSports');
}
if (params.IsNews) {
2020-05-04 12:44:12 +02:00
values.push('IsNews');
}
if (params.IsSeries) {
2020-05-04 12:44:12 +02:00
values.push('IsSeries');
}
if (params.IsFavorite) {
2020-05-04 12:44:12 +02:00
values.push('IsFavorite');
}
if (params.genreId) {
2020-05-04 12:44:12 +02:00
values.push('Genre');
}
if (params.musicGenreId) {
2020-05-04 12:44:12 +02:00
values.push('MusicGenre');
}
if (params.studioId) {
2020-05-04 12:44:12 +02:00
values.push('Studio');
}
if (params.personId) {
2020-05-04 12:44:12 +02:00
values.push('Person');
}
if (params.parentId) {
2020-05-04 12:44:12 +02:00
values.push('Folder');
}
2020-05-04 12:44:12 +02:00
return values.join('-');
}
}
export default ItemsView;