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

104 lines
3.2 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
html += '<div>';
html += LibraryBrowser.getPosterViewHtml({
2014-04-03 15:50:04 -07:00
items: recommendation.Items
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-05-21 09:45:42 -07:00
Limit: screenWidth >= 1920 ? 4 : (screenWidth >= 1440 ? 4 : 3),
2013-04-01 08:59:56 -07:00
Recursive: true,
2014-04-26 20:42:05 -07:00
Fields: "PrimaryImageAspectRatio",
2014-05-01 19:54:33 -07:00
CollapseBoxSetItems: false,
ParentId: parentId
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,
shape: 'backdrop',
2014-05-09 12:43:06 -07:00
overlayText: screenWidth >= 600,
2013-12-22 10:16:24 -07:00
showTitle: true
2014-05-10 22:11:53 -07:00
})).createPosterItemMenus();
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 ? 6 : 3,
2014-06-17 09:03:14 -07:00
itemLimit: screenWidth >= 1920 ? 8 : (screenWidth >= 1440 ? 8 : 7),
2014-06-04 19:32:40 -07:00
Fields: "PrimaryImageAspectRatio"
});
2013-04-04 21:15:00 -07:00
2014-05-10 22:11:53 -07:00
$.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();
$('.recommendations', page).html(html).createPosterItemMenus();
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);