jellyfin-web/dashboard-ui/components/favoriteitems.js

169 lines
6.3 KiB
JavaScript
Raw Normal View History

2016-08-20 14:58:28 -07:00
define(['libraryBrowser', 'cardBuilder', 'dom', 'scrollStyles', 'emby-itemscontainer'], function (libraryBrowser, cardBuilder, dom) {
2016-03-30 23:33:37 -07:00
function enableScrollX() {
return browserInfo.mobile && AppInfo.enableAppLayouts;
}
function getThumbShape() {
return enableScrollX() ? 'overflowBackdrop' : 'backdrop';
}
function getPosterShape() {
return enableScrollX() ? 'overflowPortrait' : 'portrait';
}
function getSquareShape() {
return enableScrollX() ? 'overflowSquare' : 'square';
}
function getSections() {
return [
{ name: 'HeaderFavoriteMovies', types: "Movie", id: "favoriteMovies", shape: getPosterShape(), showTitle: false, overlayPlayButton: true },
{ name: 'HeaderFavoriteShows', types: "Series", id: "favoriteShows", shape: getPosterShape(), showTitle: false, overlayPlayButton: true },
{ name: 'HeaderFavoriteEpisodes', types: "Episode", id: "favoriteEpisode", shape: getThumbShape(), preferThumb: false, showTitle: true, showParentTitle: true, overlayPlayButton: true },
{ name: 'HeaderFavoriteGames', types: "Game", id: "favoriteGames", shape: getSquareShape(), preferThumb: false, showTitle: true },
{ name: 'HeaderFavoriteArtists', types: "MusicArtist", id: "favoriteArtists", shape: getSquareShape(), preferThumb: false, showTitle: true, overlayText: false, showParentTitle: true, centerText: true, overlayPlayButton: true },
{ name: 'HeaderFavoriteAlbums', types: "MusicAlbum", id: "favoriteAlbums", shape: getSquareShape(), preferThumb: false, showTitle: true, overlayText: false, showParentTitle: true, centerText: true, overlayPlayButton: true },
2016-07-29 23:23:56 -07:00
{ name: 'HeaderFavoriteSongs', types: "Audio", id: "favoriteSongs", shape: getSquareShape(), preferThumb: false, showTitle: true, overlayText: false, showParentTitle: true, centerText: true, overlayMoreButton: true, action: 'instantmix' }
2016-03-30 23:33:37 -07:00
];
}
function loadSection(elem, userId, topParentId, section, isSingleSection) {
2016-08-20 14:58:28 -07:00
var screenWidth = dom.getWindowSize().innerWidth;
2016-03-30 23:33:37 -07:00
var options = {
SortBy: "SortName",
SortOrder: "Ascending",
Filters: "IsFavorite",
Recursive: true,
2016-08-01 22:55:52 -07:00
Fields: "PrimaryImageAspectRatio,BasicSyncInfo",
2016-03-30 23:33:37 -07:00
CollapseBoxSetItems: false,
2016-06-16 06:18:52 -07:00
ExcludeLocationTypes: "Virtual",
EnableTotalRecordCount: false
2016-03-30 23:33:37 -07:00
};
if (topParentId) {
options.ParentId = topParentId;
}
if (!isSingleSection) {
options.Limit = screenWidth >= 1920 ? 10 : (screenWidth >= 1440 ? 8 : 6);
if (enableScrollX()) {
2016-04-20 21:04:57 -07:00
options.Limit = 20;
2016-03-30 23:33:37 -07:00
}
}
var promise;
if (section.types == 'MusicArtist') {
promise = ApiClient.getArtists(userId, options);
} else {
options.IncludeItemTypes = section.types;
promise = ApiClient.getItems(userId, options);
}
return promise.then(function (result) {
var html = '';
if (result.Items.length) {
html += '<div>';
html += '<h1 style="display:inline-block; vertical-align:middle;" class="listHeader">' + Globalize.translate(section.name) + '</h1>';
2016-06-16 06:18:52 -07:00
if (options.Limit && result.Items.length >= options.Limit) {
var href = "secondaryitems.html?type=" + section.types + "&filters=IsFavorite";
2016-03-30 23:33:37 -07:00
2016-06-04 20:50:07 -07:00
html += '<a class="clearLink" href="' + href + '" style="margin-left:2em;"><button is="emby-button" type="button" class="raised more mini">' + Globalize.translate('ButtonMore') + '</button></a>';
2016-03-30 23:33:37 -07:00
}
html += '</div>';
if (enableScrollX()) {
2016-07-17 11:55:07 -07:00
html += '<div is="emby-itemscontainer" class="itemsContainer hiddenScrollX">';
2016-03-30 23:33:37 -07:00
} else {
2016-07-29 22:25:07 -07:00
html += '<div is="emby-itemscontainer" class="itemsContainer vertical-wrap">';
2016-03-30 23:33:37 -07:00
}
2016-07-29 13:06:58 -07:00
html += cardBuilder.getCardsHtml(result.Items, {
2016-03-30 23:33:37 -07:00
preferThumb: section.preferThumb,
shape: section.shape,
2016-07-29 13:06:58 -07:00
centerText: section.centerText,
2016-03-30 23:33:37 -07:00
overlayText: section.overlayText !== false,
showTitle: section.showTitle,
showParentTitle: section.showParentTitle,
2016-07-29 13:06:58 -07:00
scalable: true,
2016-03-30 23:33:37 -07:00
overlayPlayButton: section.overlayPlayButton,
overlayMoreButton: section.overlayMoreButton,
action: section.action,
allowBottomPadding: !enableScrollX()
2016-03-30 23:33:37 -07:00
});
html += '</div>';
}
elem.innerHTML = html;
ImageLoader.lazyChildren(elem);
});
}
function loadSections(page, userId, topParentId, types) {
Dashboard.showLoadingMsg();
var sections = getSections();
var sectionid = getParameterByName('sectionid');
if (sectionid) {
sections = sections.filter(function (s) {
return s.id == sectionid;
});
}
if (types) {
sections = sections.filter(function (s) {
return types.indexOf(s.id) != -1;
});
}
var i, length;
var elem = page.querySelector('.favoriteSections');
if (!elem.innerHTML) {
var html = '';
for (i = 0, length = sections.length; i < length; i++) {
html += '<div class="homePageSection section' + sections[i].id + '"></div>';
}
elem.innerHTML = html;
}
var promises = [];
for (i = 0, length = sections.length; i < length; i++) {
var section = sections[i];
elem = page.querySelector('.section' + section.id);
promises.push(loadSection(elem, userId, topParentId, section, sections.length == 1));
}
Promise.all(promises).then(function () {
Dashboard.hideLoadingMsg();
});
}
return {
render: loadSections
};
});