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

98 lines
3.0 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 = '';
2013-04-01 08:59:56 -07:00
switch (recommendation.RecommendationType) {
case 'SimilarToRecentlyPlayed':
title = 'Because you watched ' + recommendation.BaselineItemName;
break;
case 'SimilarToLikedItem':
title = 'Because you like ' + recommendation.BaselineItemName;
break;
case 'HasDirectorFromRecentlyPlayed':
case 'HasLikedDirector':
title = 'Directed by ' + recommendation.BaselineItemName;
break;
case 'HasActorFromRecentlyPlayed':
case 'HasLikedActor':
title = 'Starring ' + recommendation.BaselineItemName;
break;
}
html += '<h1 class="listHeader">' + title + '</h1>';
2013-04-01 08:59:56 -07:00
html += '<div>';
html += LibraryBrowser.getPosterViewHtml({
items: recommendation.Items,
useAverageAspectRatio: true
2013-04-01 08:59:56 -07:00
});
html += '</div>';
return html;
}
$(document).on('pagebeforeshow', "#moviesRecommendedPage", function () {
2013-04-01 08:59:56 -07:00
var screenWidth = $(window).width();
2013-04-01 08:59:56 -07:00
var page = this;
var options = {
2013-04-01 08:59:56 -07:00
SortBy: "DatePlayed",
SortOrder: "Descending",
IncludeItemTypes: "Movie",
Filters: "IsResumable",
2014-02-21 11:48:15 -07:00
Limit: screenWidth >= 1920 ? 4 : (screenWidth >= 1440 ? 4 : 3),
2013-04-01 08:59:56 -07:00
Recursive: true,
Fields: "PrimaryImageAspectRatio"
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();
}
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',
overlayText: true,
showTitle: true
2014-01-14 08:50:39 -07:00
})).createPosterItemMenus();
2013-04-01 08:59:56 -07:00
});
var url = ApiClient.getUrl("Movies/Recommendations", {
userId: Dashboard.getCurrentUserId(),
categoryLimit: screenWidth >= 1200 ? 6 : 3,
itemLimit: screenWidth >= 1920 ? 8 : (screenWidth >= 1440 ? 8 : 6),
Fields: "PrimaryImageAspectRatio"
});
2013-04-04 21:15:00 -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
$('.recommendations', page).html('<br/><p>No movie suggestions are currently available. Start watching and rating your movies, and then come back to view your recommendations.</p>');
return;
2013-04-04 21:15:00 -07:00
}
var html = recommendations.map(getRecommendationHtml).join('');
2013-04-04 21:15:00 -07:00
$('.recommendations', page).html(html).createPosterItemMenus();
2013-04-04 21:15:00 -07:00
});
2013-04-01 08:59:56 -07:00
});
})(jQuery, document);