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/favorites.js

311 lines
10 KiB
JavaScript
Raw Normal View History

2020-05-04 12:44:12 +02:00
define(['appRouter', 'cardBuilder', 'dom', 'globalize', 'connectionManager', 'apphost', 'layoutManager', 'focusManager', 'emby-itemscontainer', 'emby-scroller'], function (appRouter, cardBuilder, dom, globalize, connectionManager, appHost, layoutManager, focusManager) {
'use strict';
2018-10-23 01:05:09 +03:00
function enableScrollX() {
return true;
2018-10-23 01:05:09 +03:00
}
function getThumbShape() {
2020-05-04 12:44:12 +02:00
return enableScrollX() ? 'overflowBackdrop' : 'backdrop';
2018-10-23 01:05:09 +03:00
}
function getPosterShape() {
2020-05-04 12:44:12 +02:00
return enableScrollX() ? 'overflowPortrait' : 'portrait';
2018-10-23 01:05:09 +03:00
}
function getSquareShape() {
2020-05-04 12:44:12 +02:00
return enableScrollX() ? 'overflowSquare' : 'square';
2018-10-23 01:05:09 +03:00
}
function getSections() {
return [{
2020-05-04 12:44:12 +02:00
name: 'HeaderFavoriteMovies',
types: 'Movie',
2018-10-23 01:05:09 +03:00
shape: getPosterShape(),
2019-10-23 00:36:04 +03:00
showTitle: true,
showYear: true,
overlayPlayButton: true,
overlayText: false,
centerText: true
2018-10-23 01:05:09 +03:00
}, {
2020-05-04 12:44:12 +02:00
name: 'HeaderFavoriteShows',
types: 'Series',
2018-10-23 01:05:09 +03:00
shape: getPosterShape(),
2019-10-23 00:36:04 +03:00
showTitle: true,
showYear: true,
overlayPlayButton: true,
overlayText: false,
centerText: true
2018-10-23 01:05:09 +03:00
}, {
2020-05-04 12:44:12 +02:00
name: 'HeaderFavoriteEpisodes',
types: 'Episode',
2018-10-23 01:05:09 +03:00
shape: getThumbShape(),
2019-10-23 00:36:04 +03:00
preferThumb: false,
showTitle: true,
showParentTitle: true,
overlayPlayButton: true,
overlayText: false,
centerText: true
2018-10-23 01:05:09 +03:00
}, {
2020-05-04 12:44:12 +02:00
name: 'HeaderFavoriteVideos',
types: 'Video',
2018-10-23 01:05:09 +03:00
shape: getThumbShape(),
2019-10-23 00:36:04 +03:00
preferThumb: true,
showTitle: true,
overlayPlayButton: true,
overlayText: false,
centerText: true
2018-10-23 01:05:09 +03:00
}, {
2020-05-04 12:44:12 +02:00
name: 'HeaderFavoriteCollections',
types: 'BoxSet',
2018-10-23 01:05:09 +03:00
shape: getPosterShape(),
2019-10-23 00:36:04 +03:00
showTitle: true,
overlayPlayButton: true,
overlayText: false,
centerText: true
2018-10-23 01:05:09 +03:00
}, {
2020-05-04 12:44:12 +02:00
name: 'HeaderFavoritePlaylists',
types: 'Playlist',
2018-10-23 01:05:09 +03:00
shape: getSquareShape(),
2019-10-23 00:36:04 +03:00
preferThumb: false,
showTitle: true,
overlayText: false,
showParentTitle: false,
centerText: true,
overlayPlayButton: true,
coverImage: true
2019-10-23 01:14:32 +03:00
}, {
2020-05-04 12:44:12 +02:00
name: 'HeaderFavoritePeople',
types: 'Person',
2019-10-23 01:14:32 +03:00
shape: getPosterShape(),
preferThumb: false,
showTitle: true,
overlayText: false,
showParentTitle: false,
centerText: true,
overlayPlayButton: true,
coverImage: true
2018-10-23 01:05:09 +03:00
}, {
2020-05-04 12:44:12 +02:00
name: 'HeaderFavoriteArtists',
types: 'MusicArtist',
2018-10-23 01:05:09 +03:00
shape: getSquareShape(),
2019-10-23 00:36:04 +03:00
preferThumb: false,
showTitle: true,
overlayText: false,
showParentTitle: false,
centerText: true,
overlayPlayButton: true,
coverImage: true
2018-10-23 01:05:09 +03:00
}, {
2020-05-04 12:44:12 +02:00
name: 'HeaderFavoriteAlbums',
types: 'MusicAlbum',
2018-10-23 01:05:09 +03:00
shape: getSquareShape(),
2019-10-23 00:36:04 +03:00
preferThumb: false,
showTitle: true,
overlayText: false,
showParentTitle: true,
centerText: true,
overlayPlayButton: true,
coverImage: true
2018-10-23 01:05:09 +03:00
}, {
2020-05-04 12:44:12 +02:00
name: 'HeaderFavoriteSongs',
types: 'Audio',
2018-10-23 01:05:09 +03:00
shape: getSquareShape(),
2019-10-23 00:36:04 +03:00
preferThumb: false,
showTitle: true,
overlayText: false,
showParentTitle: true,
centerText: true,
overlayMoreButton: true,
2020-05-04 12:44:12 +02:00
action: 'instantmix',
2019-10-23 00:36:04 +03:00
coverImage: true
}, {
2020-05-04 12:44:12 +02:00
name: 'HeaderFavoriteBooks',
types: 'Book',
shape: getPosterShape(),
showTitle: true,
showYear: true,
overlayPlayButton: true,
overlayText: false,
centerText: true
2019-10-23 00:36:04 +03:00
}];
2018-10-23 01:05:09 +03:00
}
function getFetchDataFn(section) {
2019-10-23 00:36:04 +03:00
return function () {
var apiClient = this.apiClient;
var options = {
2020-05-04 12:44:12 +02:00
SortBy: (section.types, 'SeriesName,SortName'),
SortOrder: 'Ascending',
Filters: 'IsFavorite',
2019-10-23 00:36:04 +03:00
Recursive: true,
2020-05-04 12:44:12 +02:00
Fields: 'PrimaryImageAspectRatio,BasicSyncInfo',
2019-10-23 00:36:04 +03:00
CollapseBoxSetItems: false,
2020-05-04 12:44:12 +02:00
ExcludeLocationTypes: 'Virtual',
2019-10-23 00:36:04 +03:00
EnableTotalRecordCount: false
};
2018-10-23 01:05:09 +03:00
options.Limit = 20;
var userId = apiClient.getCurrentUserId();
2019-10-23 00:36:04 +03:00
2020-07-30 16:07:13 +02:00
if (section.types === 'MusicArtist') {
2019-10-23 00:36:04 +03:00
return apiClient.getArtists(userId, options);
}
2020-07-30 16:07:13 +02:00
if (section.types === 'Person') {
2019-10-23 01:14:32 +03:00
return apiClient.getPeople(userId, options);
}
2019-10-23 00:36:04 +03:00
options.IncludeItemTypes = section.types;
return apiClient.getItems(userId, options);
};
2018-10-23 01:05:09 +03:00
}
function getRouteUrl(section, serverId) {
2020-05-04 12:44:12 +02:00
return appRouter.getRouteUrl('list', {
2018-10-23 01:05:09 +03:00
serverId: serverId,
itemTypes: section.types,
2019-10-23 00:36:04 +03:00
isFavorite: true
});
2018-10-23 01:05:09 +03:00
}
function getItemsHtmlFn(section) {
2019-10-23 00:36:04 +03:00
return function (items) {
2020-07-19 16:15:11 +02:00
var cardLayout = appHost.preferVisualCards && section.autoCardLayout && section.showTitle;
2019-10-23 00:36:04 +03:00
cardLayout = false;
var serverId = this.apiClient.serverId();
var leadingButtons = layoutManager.tv ? [{
2020-05-04 12:44:12 +02:00
name: globalize.translate('All'),
id: 'more',
icon: 'favorite',
2019-10-23 00:36:04 +03:00
routeUrl: getRouteUrl(section, serverId)
}] : null;
var lines = 0;
if (section.showTitle) {
lines++;
}
if (section.showYear) {
lines++;
}
if (section.showParentTitle) {
lines++;
}
return cardBuilder.getCardsHtml({
2018-10-23 01:05:09 +03:00
items: items,
preferThumb: section.preferThumb,
shape: section.shape,
centerText: section.centerText && !cardLayout,
2020-07-30 16:07:13 +02:00
overlayText: section.overlayText !== false,
2018-10-23 01:05:09 +03:00
showTitle: section.showTitle,
showYear: section.showYear,
showParentTitle: section.showParentTitle,
2019-10-23 00:36:04 +03:00
scalable: true,
2018-10-23 01:05:09 +03:00
coverImage: section.coverImage,
overlayPlayButton: section.overlayPlayButton,
overlayMoreButton: section.overlayMoreButton && !cardLayout,
action: section.action,
allowBottomPadding: !enableScrollX(),
cardLayout: cardLayout,
leadingButtons: leadingButtons,
lines: lines
2019-10-23 00:36:04 +03:00
});
};
2018-10-23 01:05:09 +03:00
}
function FavoritesTab(view, params) {
2019-10-23 00:36:04 +03:00
this.view = view;
this.params = params;
this.apiClient = connectionManager.currentApiClient();
2020-05-04 12:44:12 +02:00
this.sectionsContainer = view.querySelector('.sections');
2019-10-23 00:36:04 +03:00
createSections(this, this.sectionsContainer, this.apiClient);
2018-10-23 01:05:09 +03:00
}
function createSections(instance, elem, apiClient) {
2019-10-23 00:36:04 +03:00
var i;
var length;
var sections = getSections();
2020-05-04 12:44:12 +02:00
var html = '';
2019-10-23 00:36:04 +03:00
2018-10-23 01:05:09 +03:00
for (i = 0, length = sections.length; i < length; i++) {
2019-10-23 00:36:04 +03:00
var section = sections[i];
2020-05-04 12:44:12 +02:00
var sectionClass = 'verticalSection';
2019-10-23 00:36:04 +03:00
if (!section.showTitle) {
2020-05-04 12:44:12 +02:00
sectionClass += ' verticalSection-extrabottompadding';
2019-10-23 00:36:04 +03:00
}
html += '<div class="' + sectionClass + ' hide">';
html += '<div class="sectionTitleContainer sectionTitleContainer-cards padded-left">';
if (layoutManager.tv) {
2020-05-04 12:44:12 +02:00
html += '<h2 class="sectionTitle sectionTitle-cards">' + globalize.translate(section.name) + '</h2>';
2019-10-23 00:36:04 +03:00
} else {
html += '<a is="emby-linkbutton" href="' + getRouteUrl(section, apiClient.serverId()) + '" class="more button-flat button-flat-mini sectionTitleTextButton">';
html += '<h2 class="sectionTitle sectionTitle-cards">';
html += globalize.translate(section.name);
2020-05-04 12:44:12 +02:00
html += '</h2>';
2020-04-26 02:37:28 +03:00
html += '<span class="material-icons chevron_right"></span>';
2020-05-04 12:44:12 +02:00
html += '</a>';
2019-10-23 00:36:04 +03:00
}
2020-05-04 12:44:12 +02:00
html += '</div>';
html += '<div is="emby-scroller" class="padded-top-focusscale padded-bottom-focusscale" data-centerfocus="true"><div is="emby-itemscontainer" class="itemsContainer scrollSlider focuscontainer-x" data-monitor="markfavorite"></div></div>';
2020-05-04 12:44:12 +02:00
html += '</div>';
2018-10-23 01:05:09 +03:00
}
2019-10-23 00:36:04 +03:00
2018-10-23 01:05:09 +03:00
elem.innerHTML = html;
2020-05-04 12:44:12 +02:00
var elems = elem.querySelectorAll('.itemsContainer');
2019-10-23 00:36:04 +03:00
2018-10-23 01:05:09 +03:00
for (i = 0, length = elems.length; i < length; i++) {
var itemsContainer = elems[i];
2019-10-23 00:36:04 +03:00
itemsContainer.fetchData = getFetchDataFn(sections[i]).bind(instance);
itemsContainer.getItemsHtml = getItemsHtmlFn(sections[i]).bind(instance);
2020-05-04 12:44:12 +02:00
itemsContainer.parentContainer = dom.parentWithClass(itemsContainer, 'verticalSection');
2018-10-23 01:05:09 +03:00
}
}
2019-10-23 00:36:04 +03:00
FavoritesTab.prototype.onResume = function (options) {
var promises = (this.apiClient, []);
var view = this.view;
2020-05-04 12:44:12 +02:00
var elems = this.sectionsContainer.querySelectorAll('.itemsContainer');
2019-10-23 00:36:04 +03:00
for (var i = 0, length = elems.length; i < length; i++) {
promises.push(elems[i].resume(options));
}
Promise.all(promises).then(function () {
if (options.autoFocus) {
focusManager.autoFocus(view);
}
});
};
FavoritesTab.prototype.onPause = function () {
2020-05-04 12:44:12 +02:00
var elems = this.sectionsContainer.querySelectorAll('.itemsContainer');
2019-10-23 00:36:04 +03:00
for (var i = 0, length = elems.length; i < length; i++) {
elems[i].pause();
}
};
FavoritesTab.prototype.destroy = function () {
this.view = null;
this.params = null;
this.apiClient = null;
2020-05-04 12:44:12 +02:00
var elems = this.sectionsContainer.querySelectorAll('.itemsContainer');
2019-10-23 00:36:04 +03:00
for (var i = 0, length = elems.length; i < length; i++) {
elems[i].fetchData = null;
elems[i].getItemsHtml = null;
elems[i].parentContainer = null;
}
this.sectionsContainer = null;
};
return FavoritesTab;
2019-01-27 22:10:07 +01:00
});