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

231 lines
7.9 KiB
JavaScript
Raw Normal View History

2020-05-04 12:44:12 +02:00
define(['loading', 'libraryBrowser', 'cardBuilder', 'dom', 'apphost', 'imageLoader', 'globalize', 'layoutManager', 'scrollStyles', 'emby-itemscontainer'], function (loading, libraryBrowser, cardBuilder, dom, appHost, imageLoader, globalize, layoutManager) {
'use strict';
2018-10-23 01:05:09 +03:00
function enableScrollX() {
2019-10-09 19:23:47 +03:00
return !layoutManager.desktop;
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',
id: 'favoriteMovies',
2018-10-23 01:05:09 +03:00
shape: getPosterShape(),
2019-10-09 19:23:47 +03:00
showTitle: false,
overlayPlayButton: true
2018-10-23 01:05:09 +03:00
}, {
2020-05-04 12:44:12 +02:00
name: 'HeaderFavoriteShows',
types: 'Series',
id: 'favoriteShows',
2018-10-23 01:05:09 +03:00
shape: getPosterShape(),
2019-10-09 19:23:47 +03:00
showTitle: false,
overlayPlayButton: true
2018-10-23 01:05:09 +03:00
}, {
2020-05-04 12:44:12 +02:00
name: 'HeaderFavoriteEpisodes',
types: 'Episode',
id: 'favoriteEpisode',
2018-10-23 01:05:09 +03:00
shape: getThumbShape(),
2019-10-09 19:23:47 +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,MusicVideo',
id: 'favoriteVideos',
2018-10-23 01:05:09 +03:00
shape: getThumbShape(),
2019-10-09 19:23:47 +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: 'HeaderFavoriteArtists',
types: 'MusicArtist',
id: 'favoriteArtists',
2018-10-23 01:05:09 +03:00
shape: getSquareShape(),
2019-10-09 19:23:47 +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',
id: 'favoriteAlbums',
2018-10-23 01:05:09 +03:00
shape: getSquareShape(),
2019-10-09 19:23:47 +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',
id: 'favoriteSongs',
2018-10-23 01:05:09 +03:00
shape: getSquareShape(),
2019-10-09 19:23:47 +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-09 19:23:47 +03:00
coverImage: true
}];
2018-10-23 01:05:09 +03:00
}
function loadSection(elem, userId, topParentId, section, isSingleSection) {
2019-10-09 19:23:47 +03:00
var screenWidth = dom.getWindowSize().innerWidth;
var options = {
2020-05-04 12:44:12 +02:00
SortBy: 'SortName',
SortOrder: 'Ascending',
Filters: 'IsFavorite',
2019-10-09 19:23:47 +03:00
Recursive: true,
2020-05-04 12:44:12 +02:00
Fields: 'PrimaryImageAspectRatio,BasicSyncInfo',
2019-10-09 19:23:47 +03:00
CollapseBoxSetItems: false,
2020-05-04 12:44:12 +02:00
ExcludeLocationTypes: 'Virtual',
2019-10-09 19:23:47 +03:00
EnableTotalRecordCount: false
};
if (topParentId) {
options.ParentId = topParentId;
}
if (!isSingleSection) {
options.Limit = screenWidth >= 1920 ? 10 : screenWidth >= 1440 ? 8 : 6;
if (enableScrollX()) {
options.Limit = 20;
}
}
2018-10-23 01:05:09 +03:00
var promise;
2019-10-09 19:23:47 +03:00
2020-05-04 12:44:12 +02:00
if ('MusicArtist' === section.types) {
2019-10-09 19:23:47 +03:00
promise = ApiClient.getArtists(userId, options);
} else {
options.IncludeItemTypes = section.types;
promise = ApiClient.getItems(userId, options);
}
return promise.then(function (result) {
2020-05-04 12:44:12 +02:00
var html = '';
2019-10-09 19:23:47 +03:00
2018-10-23 01:05:09 +03:00
if (result.Items.length) {
if (html += '<div class="sectionTitleContainer sectionTitleContainer-cards padded-left">', !layoutManager.tv && options.Limit && result.Items.length >= options.Limit) {
2020-05-04 12:44:12 +02:00
html += '<a is="emby-linkbutton" href="' + ('list.html?serverId=' + ApiClient.serverId() + '&type=' + section.types + '&IsFavorite=true') + '" class="more button-flat button-flat-mini sectionTitleTextButton">';
2019-10-09 19:23:47 +03:00
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-09 19:23:47 +03:00
} else {
2020-05-04 12:44:12 +02:00
html += '<h2 class="sectionTitle sectionTitle-cards">' + globalize.translate(section.name) + '</h2>';
2019-10-09 19:23:47 +03:00
}
2020-05-04 12:44:12 +02:00
html += '</div>';
2019-10-15 20:16:58 +03:00
if (enableScrollX()) {
2020-05-04 12:44:12 +02:00
var scrollXClass = 'scrollX hiddenScrollX';
2019-10-09 19:23:47 +03:00
if (layoutManager.tv) {
2020-05-04 12:44:12 +02:00
scrollXClass += ' smoothScrollX';
2019-10-09 19:23:47 +03:00
}
html += '<div is="emby-itemscontainer" class="itemsContainer ' + scrollXClass + ' padded-left padded-right">';
} else {
html += '<div is="emby-itemscontainer" class="itemsContainer vertical-wrap padded-left padded-right">';
}
2020-05-04 12:44:12 +02:00
var supportsImageAnalysis = appHost.supports('imageanalysis');
2019-10-09 19:23:47 +03:00
var cardLayout = (appHost.preferVisualCards || supportsImageAnalysis) && section.autoCardLayout && section.showTitle;
cardLayout = false;
html += cardBuilder.getCardsHtml(result.Items, {
2018-10-23 01:05:09 +03:00
preferThumb: section.preferThumb,
shape: section.shape,
centerText: section.centerText && !cardLayout,
2019-10-09 19:23:47 +03:00
overlayText: false !== section.overlayText,
2018-10-23 01:05:09 +03:00
showTitle: section.showTitle,
showParentTitle: section.showParentTitle,
2019-10-09 19:23:47 +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
2019-10-09 19:23:47 +03:00
});
2020-05-04 12:44:12 +02:00
html += '</div>';
2018-10-23 01:05:09 +03:00
}
2019-10-09 19:23:47 +03:00
elem.innerHTML = html;
imageLoader.lazyChildren(elem);
});
2018-10-23 01:05:09 +03:00
}
function loadSections(page, userId, topParentId, types) {
loading.show();
2019-10-09 19:23:47 +03:00
var sections = getSections();
2020-05-04 12:44:12 +02:00
var sectionid = getParameterByName('sectionid');
2019-10-09 19:23:47 +03:00
if (sectionid) {
sections = sections.filter(function (s) {
return s.id === sectionid;
});
}
if (types) {
sections = sections.filter(function (s) {
return -1 !== types.indexOf(s.id);
});
}
var i;
var length;
2020-05-04 12:44:12 +02:00
var elem = page.querySelector('.favoriteSections');
2019-10-09 19:23:47 +03:00
2018-10-23 01:05:09 +03:00
if (!elem.innerHTML) {
2020-05-04 12:44:12 +02:00
var html = '';
2019-10-09 19:23:47 +03:00
for (i = 0, length = sections.length; i < length; i++) {
html += '<div class="verticalSection section' + sections[i].id + '"></div>';
}
elem.innerHTML = html;
2018-10-23 01:05:09 +03:00
}
2019-10-09 19:23:47 +03:00
2018-10-23 01:05:09 +03:00
var promises = [];
2019-10-09 19:23:47 +03:00
2018-10-23 01:05:09 +03:00
for (i = 0, length = sections.length; i < length; i++) {
var section = sections[i];
2020-05-04 12:44:12 +02:00
elem = page.querySelector('.section' + section.id);
2019-10-09 19:23:47 +03:00
promises.push(loadSection(elem, userId, topParentId, section, 1 === sections.length));
2018-10-23 01:05:09 +03:00
}
2019-10-09 19:23:47 +03:00
Promise.all(promises).then(function () {
loading.hide();
});
2018-10-23 01:05:09 +03:00
}
2019-10-09 19:23:47 +03:00
2018-10-23 01:05:09 +03:00
return {
render: loadSections
2019-10-09 19:23:47 +03:00
};
2019-01-27 22:10:07 +01:00
});