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

118 lines
3.7 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,
2015-01-22 23:15:15 -07:00
shape: 'portrait',
2014-08-01 19:34:45 -07:00
overlayText: true
2013-04-01 08:59:56 -07:00
});
html += '</div>';
return html;
}
2014-05-10 22:11:53 -07:00
2015-01-22 23:15:15 -07:00
$(document).on('pageinit', "#moviesRecommendedPage", function () {
var page = this;
$('.recommendations', page).createCardMenus();
}).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-12 20:56:30 -07:00
Limit: screenWidth >= 1920 ? 12 : (screenWidth >= 1600 ? 8 : 6),
2013-04-01 08:59:56 -07:00
Recursive: true,
2014-12-10 23:20:28 -07:00
Fields: "PrimaryImageAspectRatio,MediaSourceCount,SyncInfo",
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,
2015-02-26 11:24:38 -07:00
preferThumb: true,
2015-01-22 23:15:15 -07:00
shape: 'backdrop',
2014-08-01 19:34:45 -07:00
overlayText: true,
showTitle: true,
lazy: true
2014-05-10 22:11:53 -07:00
2015-01-22 23:15:15 -07:00
})).lazyChildren().trigger('create');
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-12-12 20:56:30 -07:00
ItemLimit: screenWidth >= 1920 ? 10 : (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
});
2014-05-10 22:11:53 -07:00
2013-04-01 08:59:56 -07:00
});
})(jQuery, document);