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

312 lines
10 KiB
JavaScript
Raw Normal View History

2019-10-23 00:36:04 +03:00
define(["appRouter", "cardBuilder", "dom", "globalize", "connectionManager", "apphost", "layoutManager", "focusManager", "emby-itemscontainer", "emby-scroller"], function (appRouter, cardBuilder, dom, globalize, connectionManager, appHost, layoutManager, focusManager) {
2018-10-23 01:05:09 +03:00
"use strict";
function enableScrollX() {
return true;
2018-10-23 01:05:09 +03:00
}
function getThumbShape() {
return enableScrollX() ? "overflowBackdrop" : "backdrop";
2018-10-23 01:05:09 +03:00
}
function getPosterShape() {
return enableScrollX() ? "overflowPortrait" : "portrait";
2018-10-23 01:05:09 +03:00
}
function getSquareShape() {
return enableScrollX() ? "overflowSquare" : "square";
2018-10-23 01:05:09 +03:00
}
function getSections() {
return [{
name: "HeaderFavoriteMovies",
2018-10-23 01:05:09 +03:00
types: "Movie",
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
}, {
name: "HeaderFavoriteShows",
2018-10-23 01:05:09 +03:00
types: "Series",
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
}, {
name: "HeaderFavoriteEpisodes",
2018-10-23 01:05:09 +03:00
types: "Episode",
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
}, {
name: "HeaderFavoriteVideos",
2018-10-23 01:05:09 +03:00
types: "Video",
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
}, {
name: "HeaderFavoriteCollections",
2018-10-23 01:05:09 +03:00
types: "BoxSet",
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
}, {
name: "HeaderFavoritePlaylists",
2018-10-23 01:05:09 +03:00
types: "Playlist",
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
}, {
name: "HeaderFavoritePeople",
types: "Person",
shape: getPosterShape(),
preferThumb: false,
showTitle: true,
overlayText: false,
showParentTitle: false,
centerText: true,
overlayPlayButton: true,
coverImage: true
2018-10-23 01:05:09 +03:00
}, {
name: "HeaderFavoriteArtists",
2018-10-23 01:05:09 +03:00
types: "MusicArtist",
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
}, {
name: "HeaderFavoriteAlbums",
2018-10-23 01:05:09 +03:00
types: "MusicAlbum",
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
}, {
name: "HeaderFavoriteSongs",
2018-10-23 01:05:09 +03:00
types: "Audio",
shape: getSquareShape(),
2019-10-23 00:36:04 +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-23 00:36:04 +03:00
coverImage: true
}, {
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 = {
SortBy: (section.types, "SeriesName,SortName"),
SortOrder: "Ascending",
Filters: "IsFavorite",
Recursive: true,
Fields: "PrimaryImageAspectRatio,BasicSyncInfo",
CollapseBoxSetItems: false,
ExcludeLocationTypes: "Virtual",
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
if ("MusicArtist" === section.types) {
return apiClient.getArtists(userId, options);
}
2019-10-23 01:14:32 +03:00
if ("Person" === section.types) {
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) {
return appRouter.getRouteUrl("list", {
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) {
var supportsImageAnalysis = appHost.supports("imageanalysis");
var cardLayout = (appHost.preferVisualCards || supportsImageAnalysis) && section.autoCardLayout && section.showTitle;
cardLayout = false;
var serverId = this.apiClient.serverId();
var leadingButtons = layoutManager.tv ? [{
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,
2019-10-23 00:36:04 +03:00
overlayText: false !== section.overlayText,
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();
this.sectionsContainer = view.querySelector(".sections");
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();
var html = "";
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];
var sectionClass = "verticalSection";
if (!section.showTitle) {
sectionClass += " verticalSection-extrabottompadding";
}
html += '<div class="' + sectionClass + ' hide">';
html += '<div class="sectionTitleContainer sectionTitleContainer-cards padded-left">';
if (layoutManager.tv) {
html += '<h2 class="sectionTitle sectionTitle-cards">' + globalize.translate(section.name) + "</h2>";
} 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);
html += "</h2>";
html += '<i class="md-icon">chevron_right</i>';
2019-10-23 00:36:04 +03:00
html += "</a>";
}
html += "</div>";
2019-11-22 00:04:02 +03:00
html += '<div is="emby-scroller" class="padded-top-focusscale padded-bottom-focusscale" data-mousewheel="false" data-centerfocus="true"><div is="emby-itemscontainer" class="itemsContainer scrollSlider focuscontainer-x" data-monitor="markfavorite"></div></div>';
2019-10-23 00:36:04 +03: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;
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);
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;
var elems = this.sectionsContainer.querySelectorAll(".itemsContainer");
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 () {
var elems = this.sectionsContainer.querySelectorAll(".itemsContainer");
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;
var elems = this.sectionsContainer.querySelectorAll(".itemsContainer");
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
});