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

112 lines
3.6 KiB
JavaScript
Raw Normal View History

2013-04-01 08:59:56 -07:00
(function ($, document) {
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
html += '<h1 class="listHeader">' + title + '</h1>';
2013-04-01 08:59:56 -07:00
2014-11-18 19:45:12 -07:00
html += '<div>';
html += LibraryBrowser.getPosterViewHtml({
items: recommendation.Items,
2014-08-01 19:34:45 -07:00
lazy: true,
shape: 'homePagePortrait',
overlayText: true
2013-04-01 08:59:56 -07:00
});
html += '</div>';
return html;
}
2014-05-10 22:11:53 -07:00
$(document).on('pagebeforeshow', "#moviesRecommendedPage", function () {
2013-04-01 08:59:56 -07:00
2014-05-01 19:54:33 -07:00
var parentId = LibraryMenu.getTopParentId();
var screenWidth = $(window).width();
2013-04-01 08:59:56 -07:00
var page = this;
2014-05-10 22:11:53 -07:00
var options = {
2013-04-01 08:59:56 -07:00
SortBy: "DatePlayed",
SortOrder: "Descending",
IncludeItemTypes: "Movie",
Filters: "IsResumable",
2014-12-01 05:43:34 -07:00
Limit: screenWidth >= 1920 ? 12 : (screenWidth >= 1600 ? 8 : (screenWidth >= 1200 ? 6 : 3)),
2013-04-01 08:59:56 -07:00
Recursive: true,
2014-11-30 12:01:33 -07:00
Fields: "PrimaryImageAspectRatio,MediaSourceCount",
2014-05-01 19:54:33 -07:00
CollapseBoxSetItems: false,
2014-11-30 12:01:33 -07:00
ParentId: parentId,
ImageTypeLimit: 1,
2014-12-01 05:43:34 -07:00
EnableImageTypes: "Primary,Backdrop,Banner,Thumb"
2013-04-01 08:59:56 -07:00
};
ApiClient.getItems(Dashboard.getCurrentUserId(), options).done(function (result) {
if (result.Items.length) {
$('#resumableSection', page).show();
} else {
$('#resumableSection', page).hide();
}
2014-05-10 22:11:53 -07:00
2013-04-01 22:14:37 -07:00
$('#resumableItems', page).html(LibraryBrowser.getPosterViewHtml({
2013-04-01 08:59:56 -07:00
items: result.Items,
2013-12-22 10:16:24 -07:00
preferBackdrop: true,
2014-08-01 19:34:45 -07:00
shape: 'homePageBackdrop',
overlayText: true,
showTitle: true,
lazy: true
2014-05-10 22:11:53 -07:00
2014-08-01 19:34:45 -07:00
})).trigger('create').createCardMenus();
2013-04-01 08:59:56 -07:00
});
var url = ApiClient.getUrl("Movies/Recommendations", {
2014-05-10 22:11:53 -07:00
userId: Dashboard.getCurrentUserId(),
categoryLimit: screenWidth >= 1200 ? 4 : 3,
2014-10-20 13:23:40 -07:00
ItemLimit: screenWidth >= 1920 ? 10 : (screenWidth >= 1600 ? 7 : (screenWidth >= 1200 ? 7 : 7)),
2014-11-30 12:01:33 -07:00
Fields: "PrimaryImageAspectRatio,MediaSourceCount",
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();
2014-08-01 19:34:45 -07:00
$('.recommendations', page).html(html).trigger('create').createCardMenus();
2013-04-04 21:15:00 -07:00
});
2014-05-10 22:11:53 -07:00
2013-04-01 08:59:56 -07:00
});
})(jQuery, document);