jellyfin-web/dashboard-ui/scripts/moviesrecommended.js

260 lines
7.5 KiB
JavaScript
Raw Normal View History

2013-04-01 08:59:56 -07:00
(function ($, document) {
2015-05-12 21:55:19 -07:00
function getView() {
2015-05-16 12:09:02 -07:00
2015-05-29 16:51:33 -07:00
return 'Poster';
2015-05-12 21:55:19 -07:00
}
function getResumeView() {
2015-05-29 16:51:33 -07:00
return 'Thumb';
2015-05-12 21:55:19 -07:00
}
2015-05-16 12:09:02 -07:00
function enableScrollX() {
2015-06-04 13:27:46 -07:00
return $.browser.mobile && AppInfo.enableAppLayouts;
2015-05-16 12:09:02 -07:00
}
function getPortraitShape() {
return enableScrollX() ? 'overflowPortrait' : 'portrait';
}
function getThumbShape() {
return enableScrollX() ? 'overflowBackdrop' : 'backdrop';
}
2015-04-02 09:26:42 -07:00
function loadLatest(page, userId, parentId) {
2015-05-12 21:55:19 -07:00
var limit = 18;
2015-05-07 07:04:10 -07:00
2015-04-02 09:26:42 -07:00
var options = {
IncludeItemTypes: "Movie",
2015-05-07 07:04:10 -07:00
Limit: limit,
2015-04-02 09:26:42 -07:00
Fields: "PrimaryImageAspectRatio,MediaSourceCount,SyncInfo",
ParentId: parentId,
ImageTypeLimit: 1,
EnableImageTypes: "Primary,Backdrop,Banner,Thumb"
};
ApiClient.getJSON(ApiClient.getUrl('Users/' + userId + '/Items/Latest', options)).done(function (items) {
2015-05-12 21:55:19 -07:00
var view = getView();
var html = '';
if (view == 'PosterCard') {
html += LibraryBrowser.getPosterViewHtml({
items: items,
lazy: true,
2015-05-16 12:09:02 -07:00
shape: getPortraitShape(),
2015-05-12 21:55:19 -07:00
overlayText: false,
showTitle: true,
showYear: true,
2015-05-14 19:16:57 -07:00
cardLayout: true,
showDetailsMenu: true
2015-05-12 21:55:19 -07:00
});
} else if (view == 'Poster') {
2015-05-16 12:09:02 -07:00
2015-05-12 21:55:19 -07:00
html += LibraryBrowser.getPosterViewHtml({
items: items,
2015-05-16 12:09:02 -07:00
shape: getPortraitShape(),
2015-05-12 21:55:19 -07:00
centerText: true,
lazy: true,
2015-05-29 16:51:33 -07:00
overlayText: true,
showDetailsMenu: true
2015-05-12 21:55:19 -07:00
});
}
2015-04-02 09:26:42 -07:00
2015-05-12 21:55:19 -07:00
$('#recentlyAddedItems', page).html(html).lazyChildren().trigger('create');
2015-04-02 09:26:42 -07:00
});
}
2015-05-07 07:04:10 -07:00
function loadResume(page, userId, parentId) {
var screenWidth = $(window).width();
var options = {
SortBy: "DatePlayed",
SortOrder: "Descending",
IncludeItemTypes: "Movie",
Filters: "IsResumable",
Limit: screenWidth >= 1920 ? 6 : (screenWidth >= 1600 ? 4 : 3),
Recursive: true,
Fields: "PrimaryImageAspectRatio,MediaSourceCount,SyncInfo",
CollapseBoxSetItems: false,
ParentId: parentId,
ImageTypeLimit: 1,
EnableImageTypes: "Primary,Backdrop,Banner,Thumb"
};
ApiClient.getItems(userId, options).done(function (result) {
if (result.Items.length) {
$('#resumableSection', page).show();
} else {
$('#resumableSection', page).hide();
}
2015-05-12 21:55:19 -07:00
var view = getResumeView();
var html = '';
if (view == 'ThumbCard') {
html += LibraryBrowser.getPosterViewHtml({
items: result.Items,
preferThumb: true,
2015-05-16 12:09:02 -07:00
shape: getThumbShape(),
2015-05-12 21:55:19 -07:00
showTitle: true,
showYear: true,
lazy: true,
2015-05-14 19:16:57 -07:00
cardLayout: true,
showDetailsMenu: true
2015-05-07 07:04:10 -07:00
2015-05-12 21:55:19 -07:00
});
} else if (view == 'Thumb') {
html += LibraryBrowser.getPosterViewHtml({
items: result.Items,
preferThumb: true,
2015-05-16 12:09:02 -07:00
shape: getThumbShape(),
2015-05-12 21:55:19 -07:00
overlayText: true,
showTitle: true,
2015-05-14 19:16:57 -07:00
lazy: true,
showDetailsMenu: true
2015-05-12 21:55:19 -07:00
});
}
$('#resumableItems', page).html(html).lazyChildren().trigger('create');
2015-05-07 07:04:10 -07:00
});
}
function getRecommendationHtml(recommendation) {
2013-04-01 08:59:56 -07:00
var html = '';
2014-01-30 14:23:54 -07:00
var title = '';
2014-05-10 22:11:53 -07:00
switch (recommendation.RecommendationType) {
2014-05-10 22:11:53 -07:00
case 'SimilarToRecentlyPlayed':
2014-05-30 12:23:56 -07:00
title = Globalize.translate('RecommendationBecauseYouWatched').replace("{0}", recommendation.BaselineItemName);
break;
case 'SimilarToLikedItem':
2014-05-30 12:23:56 -07:00
title = Globalize.translate('RecommendationBecauseYouLike').replace("{0}", recommendation.BaselineItemName);
break;
case 'HasDirectorFromRecentlyPlayed':
case 'HasLikedDirector':
2014-05-30 12:23:56 -07:00
title = Globalize.translate('RecommendationDirectedBy').replace("{0}", recommendation.BaselineItemName);
break;
case 'HasActorFromRecentlyPlayed':
case 'HasLikedActor':
2014-05-30 12:23:56 -07:00
title = Globalize.translate('RecommendationStarring').replace("{0}", recommendation.BaselineItemName);
break;
}
2014-05-10 22:11:53 -07:00
2015-05-16 12:09:02 -07:00
html += '<div class="homePageSection">';
html += '<h1 class="listHeader">' + title + '</h1>';
2013-04-01 08:59:56 -07:00
2015-05-16 12:09:02 -07:00
if (enableScrollX()) {
html += '<div class="hiddenScrollX">';
} else {
html += '<div>';
}
2015-05-12 21:55:19 -07:00
var view = getView();
if (view == 'PosterCard') {
html += LibraryBrowser.getPosterViewHtml({
items: recommendation.Items,
lazy: true,
2015-05-16 12:09:02 -07:00
shape: getPortraitShape(),
2015-05-12 21:55:19 -07:00
overlayText: false,
showTitle: true,
showYear: true,
2015-05-14 19:16:57 -07:00
cardLayout: true,
showDetailsMenu: true
2015-05-12 21:55:19 -07:00
});
} else if (view == 'Poster') {
html += LibraryBrowser.getPosterViewHtml({
items: recommendation.Items,
2015-05-16 12:09:02 -07:00
shape: getPortraitShape(),
2015-05-12 21:55:19 -07:00
centerText: true,
lazy: true,
2015-05-14 19:16:57 -07:00
overlayText: true,
showDetailsMenu: true
2015-05-12 21:55:19 -07:00
});
}
html += '</div>';
2015-05-16 12:09:02 -07:00
html += '</div>';
return html;
}
2014-05-10 22:11:53 -07:00
2015-05-07 07:04:10 -07:00
function loadSuggestions(page, userId, parentId) {
2014-05-01 19:54:33 -07:00
var screenWidth = $(window).width();
2013-04-01 08:59:56 -07:00
var url = ApiClient.getUrl("Movies/Recommendations", {
2014-05-10 22:11:53 -07:00
2015-04-02 09:26:42 -07:00
userId: userId,
categoryLimit: screenWidth >= 1200 ? 4 : 3,
2015-04-15 20:23:13 -07:00
ItemLimit: screenWidth >= 1920 ? 9 : (screenWidth >= 1600 ? 8 : (screenWidth >= 1200 ? 7 : 6)),
2014-12-10 23:20:28 -07:00
Fields: "PrimaryImageAspectRatio,MediaSourceCount,SyncInfo",
2014-11-30 12:01:33 -07:00
ImageTypeLimit: 1,
2014-12-01 05:43:34 -07:00
EnableImageTypes: "Primary,Backdrop,Banner,Thumb"
});
2013-04-04 21:15:00 -07:00
2014-07-01 22:16:59 -07:00
ApiClient.getJSON(url).done(function (recommendations) {
2013-04-04 21:15:00 -07:00
if (!recommendations.length) {
2013-04-04 21:15:00 -07:00
2014-05-30 12:23:56 -07:00
$('.noItemsMessage', page).show();
$('.recommendations', page).html('');
return;
2013-04-04 21:15:00 -07:00
}
var html = recommendations.map(getRecommendationHtml).join('');
2013-04-04 21:15:00 -07:00
2014-05-30 12:23:56 -07:00
$('.noItemsMessage', page).hide();
2015-01-22 23:15:15 -07:00
$('.recommendations', page).html(html).lazyChildren();
2013-04-04 21:15:00 -07:00
});
2015-05-07 07:04:10 -07:00
}
2015-05-15 11:07:36 -07:00
$(document).on('pageinitdepends', "#moviesRecommendedPage", function () {
2015-05-07 07:04:10 -07:00
var page = this;
$('.recommendations', page).createCardMenus();
2015-05-19 12:15:40 -07:00
}).on('pageshowready', "#moviesRecommendedPage", function () {
2015-05-07 07:04:10 -07:00
var parentId = LibraryMenu.getTopParentId();
var page = this;
var userId = Dashboard.getCurrentUserId();
2015-05-16 12:09:02 -07:00
if (enableScrollX()) {
$('.itemsContainer', page).addClass('hiddenScrollX');
} else {
$('.itemsContainer', page).removeClass('hiddenScrollX');
}
2015-05-07 07:04:10 -07:00
loadResume(page, userId, parentId);
loadLatest(page, userId, parentId);
2015-05-16 12:09:02 -07:00
if (AppInfo.enableMovieHomeSuggestions) {
2015-05-07 07:04:10 -07:00
loadSuggestions(page, userId, parentId);
}
2014-05-10 22:11:53 -07:00
2013-04-01 08:59:56 -07:00
});
})(jQuery, document);