jellyfish-web/src/components/favoriteitems.js

231 lines
7.9 KiB
JavaScript
Raw Normal View History

2019-10-09 19:23:47 +03:00
define(["loading", "libraryBrowser", "cardBuilder", "dom", "apphost", "imageLoader", "globalize", "layoutManager", "scrollStyles", "emby-itemscontainer"], function (loading, libraryBrowser, cardBuilder, dom, appHost, imageLoader, globalize, layoutManager) {
2018-10-23 01:05:09 +03:00
"use strict";
function enableScrollX() {
2019-10-09 19:23:47 +03:00
return !layoutManager.desktop;
2018-10-23 01:05:09 +03:00
}
function getThumbShape() {
2019-10-15 20:16:58 +03:00
return enableScrollX() ? "overflowBackdrop" : "backdrop";
2018-10-23 01:05:09 +03:00
}
function getPosterShape() {
2019-10-15 20:16:58 +03:00
return enableScrollX() ? "overflowPortrait" : "portrait";
2018-10-23 01:05:09 +03:00
}
function getSquareShape() {
2019-10-15 20:16:58 +03:00
return enableScrollX() ? "overflowSquare" : "square";
2018-10-23 01:05:09 +03:00
}
function getSections() {
return [{
name: "HeaderFavoriteMovies",
types: "Movie",
id: "favoriteMovies",
shape: getPosterShape(),
2019-10-09 19:23:47 +03:00
showTitle: false,
overlayPlayButton: true
2018-10-23 01:05:09 +03:00
}, {
name: "HeaderFavoriteShows",
types: "Series",
id: "favoriteShows",
shape: getPosterShape(),
2019-10-09 19:23:47 +03:00
showTitle: false,
overlayPlayButton: true
2018-10-23 01:05:09 +03:00
}, {
name: "HeaderFavoriteEpisodes",
types: "Episode",
id: "favoriteEpisode",
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
}, {
name: "HeaderFavoriteVideos",
types: "Video,MusicVideo",
id: "favoriteVideos",
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
}, {
name: "HeaderFavoriteArtists",
types: "MusicArtist",
id: "favoriteArtists",
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
}, {
name: "HeaderFavoriteAlbums",
types: "MusicAlbum",
id: "favoriteAlbums",
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
}, {
name: "HeaderFavoriteSongs",
types: "Audio",
id: "favoriteSongs",
shape: getSquareShape(),
2019-10-09 19:23:47 +03:00
preferThumb: false,
showTitle: true,
overlayText: false,
showParentTitle: true,
centerText: true,
overlayMoreButton: true,
2018-10-23 01:05:09 +03: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 = {
SortBy: "SortName",
SortOrder: "Ascending",
Filters: "IsFavorite",
Recursive: true,
Fields: "PrimaryImageAspectRatio,BasicSyncInfo",
CollapseBoxSetItems: false,
ExcludeLocationTypes: "Virtual",
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
if ("MusicArtist" === section.types) {
promise = ApiClient.getArtists(userId, options);
} else {
options.IncludeItemTypes = section.types;
promise = ApiClient.getItems(userId, options);
}
return promise.then(function (result) {
2018-10-23 01:05:09 +03: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) {
2019-10-09 19:23:47 +03: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">';
html += '<h2 class="sectionTitle sectionTitle-cards">';
html += globalize.translate(section.name);
html += "</h2>";
html += '<i class="material-icons chevron_right"></i>';
2019-10-09 19:23:47 +03:00
html += "</a>";
} else {
html += '<h2 class="sectionTitle sectionTitle-cards">' + globalize.translate(section.name) + "</h2>";
}
2019-10-15 20:16:58 +03:00
html += "</div>";
if (enableScrollX()) {
2018-10-23 01:05:09 +03:00
var scrollXClass = "scrollX hiddenScrollX";
2019-10-09 19:23:47 +03:00
if (layoutManager.tv) {
scrollXClass += " smoothScrollX";
}
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">';
}
var supportsImageAnalysis = appHost.supports("imageanalysis");
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
});
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();
var sectionid = getParameterByName("sectionid");
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;
var elem = page.querySelector(".favoriteSections");
2018-10-23 01:05:09 +03:00
if (!elem.innerHTML) {
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];
2019-10-09 19:23:47 +03:00
elem = page.querySelector(".section" + section.id);
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
});