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

302 lines
9.7 KiB
JavaScript
Raw Normal View History

2016-10-06 11:55:01 -07:00
define(['libraryBrowser', 'dom', 'components/categorysyncbuttons', 'cardBuilder', 'apphost', 'scrollStyles', 'emby-itemscontainer', 'emby-tabs', 'emby-button'], function (libraryBrowser, dom, categorysyncbuttons, cardBuilder, appHost) {
2013-04-01 18:28:01 -07:00
2016-03-18 12:43:17 -07:00
return function (view, params) {
2015-05-12 21:55:19 -07:00
2016-03-18 12:43:17 -07:00
var self = this;
2015-05-12 21:55:19 -07:00
2016-03-18 12:43:17 -07:00
function reload() {
2016-03-18 12:43:17 -07:00
Dashboard.showLoadingMsg();
2013-04-30 20:28:26 -07:00
2016-03-18 12:43:17 -07:00
loadResume();
loadNextUp();
}
2015-05-07 07:04:10 -07:00
2016-03-18 12:43:17 -07:00
function loadNextUp() {
2014-02-22 22:52:30 -07:00
2016-03-18 12:43:17 -07:00
var query = {
2016-05-22 15:37:50 -07:00
Limit: 24,
2016-08-01 22:55:52 -07:00
Fields: "PrimaryImageAspectRatio,SeriesInfo,DateCreated,BasicSyncInfo",
2016-03-18 12:43:17 -07:00
UserId: Dashboard.getCurrentUserId(),
ImageTypeLimit: 1,
2016-07-04 22:40:18 -07:00
EnableImageTypes: "Primary,Backdrop,Thumb"
2016-03-18 12:43:17 -07:00
};
2013-04-30 20:28:26 -07:00
2016-03-18 12:43:17 -07:00
query.ParentId = LibraryMenu.getTopParentId();
2013-04-30 20:28:26 -07:00
2016-03-18 12:43:17 -07:00
ApiClient.getNextUpEpisodes(query).then(function (result) {
2014-09-29 21:47:30 -07:00
2016-03-18 12:43:17 -07:00
if (result.Items.length) {
view.querySelector('.noNextUpItems').classList.add('hide');
} else {
view.querySelector('.noNextUpItems').classList.remove('hide');
}
2015-06-29 22:45:20 -07:00
2016-07-29 13:06:58 -07:00
var container = view.querySelector('#nextUpItems');
2016-10-06 11:55:01 -07:00
var supportsImageAnalysis = appHost.supports('imageanalysis');
2016-07-29 13:06:58 -07:00
cardBuilder.buildCards(result.Items, {
itemsContainer: container,
preferThumb: true,
shape: "backdrop",
scalable: true,
showTitle: true,
showParentTitle: true,
overlayText: false,
2016-10-10 23:46:59 -07:00
centerText: !supportsImageAnalysis,
2016-10-06 11:55:01 -07:00
overlayPlayButton: true,
cardLayout: supportsImageAnalysis,
2016-10-10 23:46:59 -07:00
vibrant: supportsImageAnalysis
2016-07-29 13:06:58 -07:00
});
2016-03-18 12:43:17 -07:00
Dashboard.hideLoadingMsg();
});
}
2015-05-07 15:27:01 -07:00
2016-03-18 12:43:17 -07:00
function enableScrollX() {
return browserInfo.mobile && AppInfo.enableAppLayouts;
}
2016-03-18 12:43:17 -07:00
function getThumbShape() {
return enableScrollX() ? 'overflowBackdrop' : 'backdrop';
}
2016-03-18 12:43:17 -07:00
function loadResume() {
2016-03-18 12:43:17 -07:00
var parentId = LibraryMenu.getTopParentId();
2016-10-01 00:06:00 -07:00
var screenWidth = dom.getWindowSize().innerWidth;
var limit = screenWidth >= 1600 ? 5 : 6;
2016-03-18 12:43:17 -07:00
var options = {
2016-03-18 12:43:17 -07:00
SortBy: "DatePlayed",
SortOrder: "Descending",
IncludeItemTypes: "Episode",
Filters: "IsResumable",
2016-05-22 15:37:50 -07:00
Limit: limit,
2016-03-18 12:43:17 -07:00
Recursive: true,
2016-08-01 22:55:52 -07:00
Fields: "PrimaryImageAspectRatio,SeriesInfo,UserData,BasicSyncInfo",
2016-03-18 12:43:17 -07:00
ExcludeLocationTypes: "Virtual",
ParentId: parentId,
ImageTypeLimit: 1,
2016-07-04 22:40:18 -07:00
EnableImageTypes: "Primary,Backdrop,Thumb",
2016-05-19 10:27:39 -07:00
EnableTotalRecordCount: false
2016-03-18 12:43:17 -07:00
};
2015-09-21 10:46:02 -07:00
2016-03-18 12:43:17 -07:00
ApiClient.getItems(Dashboard.getCurrentUserId(), options).then(function (result) {
2015-09-28 20:35:50 -07:00
2016-03-18 12:43:17 -07:00
if (result.Items.length) {
view.querySelector('#resumableSection').classList.remove('hide');
} else {
view.querySelector('#resumableSection').classList.add('hide');
}
2015-09-21 10:46:02 -07:00
2016-08-12 08:54:37 -07:00
var allowBottomPadding = !enableScrollX();
2016-07-29 13:06:58 -07:00
var container = view.querySelector('#resumableItems');
2016-10-06 11:55:01 -07:00
2016-10-12 11:23:09 -07:00
var cardLayout = appHost.preferVisualCards;
2016-07-29 13:06:58 -07:00
cardBuilder.buildCards(result.Items, {
itemsContainer: container,
preferThumb: true,
shape: getThumbShape(),
scalable: true,
showTitle: true,
showParentTitle: true,
overlayText: false,
2016-10-12 11:23:09 -07:00
centerText: !cardLayout,
2016-08-12 08:54:37 -07:00
overlayPlayButton: true,
2016-10-10 23:46:59 -07:00
allowBottomPadding: allowBottomPadding,
2016-10-12 11:23:09 -07:00
cardLayout: cardLayout
2016-07-29 13:06:58 -07:00
});
2016-03-18 12:43:17 -07:00
});
2015-09-21 10:46:02 -07:00
}
2016-03-18 12:43:17 -07:00
self.initTab = function () {
2015-09-21 10:46:02 -07:00
2016-03-18 12:43:17 -07:00
var tabContent = self.tabContent;
2016-07-29 13:06:58 -07:00
var resumableItemsContainer = tabContent.querySelector('#resumableItems');
2016-03-18 12:43:17 -07:00
if (enableScrollX()) {
2016-07-29 13:06:58 -07:00
resumableItemsContainer.classList.add('hiddenScrollX');
2016-07-29 22:25:07 -07:00
resumableItemsContainer.classList.remove('vertical-wrap');
2016-03-18 12:43:17 -07:00
} else {
2016-07-29 13:06:58 -07:00
resumableItemsContainer.classList.remove('hiddenScrollX');
2016-07-29 22:25:07 -07:00
resumableItemsContainer.classList.add('vertical-wrap');
2016-03-18 12:43:17 -07:00
}
2016-07-18 20:57:55 -07:00
categorysyncbuttons.init(tabContent);
2016-03-18 12:43:17 -07:00
};
2015-09-21 10:46:02 -07:00
2016-03-18 12:43:17 -07:00
self.renderTab = function () {
2016-03-18 20:14:53 -07:00
reload();
2016-03-18 12:43:17 -07:00
};
2015-09-21 10:46:02 -07:00
2016-03-18 18:40:13 -07:00
var tabControllers = [];
2016-03-18 20:14:53 -07:00
var renderedTabs = [];
2016-06-29 10:43:34 -07:00
function getTabController(page, index, callback) {
2016-03-18 12:43:17 -07:00
var depends = [];
switch (index) {
case 0:
break;
case 1:
2016-05-22 15:37:50 -07:00
depends.push('scripts/tvlatest');
2016-03-18 12:43:17 -07:00
break;
2016-05-22 11:09:09 -07:00
case 2:
2016-05-22 15:37:50 -07:00
depends.push('scripts/tvupcoming');
2016-03-18 12:43:17 -07:00
break;
2016-05-22 11:09:09 -07:00
case 3:
2016-05-22 15:37:50 -07:00
depends.push('scripts/tvshows');
2016-03-18 12:43:17 -07:00
break;
2016-05-22 11:09:09 -07:00
case 4:
2016-05-22 15:37:50 -07:00
depends.push('scripts/episodes');
2016-03-18 12:43:17 -07:00
break;
2016-05-22 11:09:09 -07:00
case 5:
2016-05-22 15:37:50 -07:00
depends.push('scripts/tvgenres');
break;
case 6:
2016-03-18 12:43:17 -07:00
depends.push('scripts/tvstudios');
break;
default:
break;
}
2015-09-21 10:46:02 -07:00
2016-03-18 12:43:17 -07:00
require(depends, function (controllerFactory) {
2016-06-29 10:43:34 -07:00
var tabContent;
2016-03-18 12:43:17 -07:00
if (index == 0) {
2016-06-29 10:43:34 -07:00
tabContent = view.querySelector('.pageTabContent[data-index=\'' + index + '\']');
2016-03-18 12:43:17 -07:00
self.tabContent = tabContent;
}
2016-03-18 18:40:13 -07:00
var controller = tabControllers[index];
if (!controller) {
2016-06-29 10:43:34 -07:00
tabContent = view.querySelector('.pageTabContent[data-index=\'' + index + '\']');
2016-03-18 18:40:13 -07:00
controller = index ? new controllerFactory(view, params, tabContent) : self;
tabControllers[index] = controller;
if (controller.initTab) {
controller.initTab();
}
2016-03-18 12:43:17 -07:00
}
2015-09-21 10:46:02 -07:00
2016-06-29 10:43:34 -07:00
callback(controller);
});
}
function preLoadTab(page, index) {
getTabController(page, index, function (controller) {
if (renderedTabs.indexOf(index) == -1) {
if (controller.preRender) {
controller.preRender();
}
}
});
}
function loadTab(page, index) {
getTabController(page, index, function (controller) {
2016-03-18 20:14:53 -07:00
if (renderedTabs.indexOf(index) == -1) {
renderedTabs.push(index);
controller.renderTab();
}
2016-03-18 12:43:17 -07:00
});
2016-03-16 22:04:32 -07:00
}
2015-09-21 10:46:02 -07:00
2016-08-15 19:40:29 -07:00
var viewTabs = view.querySelector('.libraryViewNav');
2016-05-09 12:27:38 -07:00
2016-03-18 12:43:17 -07:00
function onPlaybackStop(e, state) {
if (state.NowPlayingItem && state.NowPlayingItem.MediaType == 'Video') {
2016-05-25 10:03:52 -07:00
renderedTabs = [];
2016-08-15 19:40:29 -07:00
viewTabs.triggerTabChange();
2016-03-18 12:43:17 -07:00
}
}
2016-03-16 22:04:32 -07:00
2016-05-22 15:37:50 -07:00
if (enableScrollX()) {
view.querySelector('#resumableItems').classList.add('hiddenScrollX');
} else {
view.querySelector('#resumableItems').classList.remove('hiddenScrollX');
}
2016-08-15 19:40:29 -07:00
libraryBrowser.configurePaperLibraryTabs(view, viewTabs, view.querySelectorAll('.pageTabContent'), [0, 1, 2, 4, 5, 6]);
2015-09-28 20:35:50 -07:00
2016-08-15 19:40:29 -07:00
viewTabs.addEventListener('beforetabchange', function (e) {
2016-06-29 10:43:34 -07:00
preLoadTab(view, parseInt(e.detail.selectedTabIndex));
});
2016-08-15 19:40:29 -07:00
viewTabs.addEventListener('tabchange', function (e) {
2016-03-24 11:11:03 -07:00
loadTab(view, parseInt(e.detail.selectedTabIndex));
2015-09-21 10:46:02 -07:00
});
2016-06-29 10:43:34 -07:00
function onWebSocketMessage(e, data) {
var msg = data;
if (msg.MessageType === "UserDataChanged") {
if (msg.Data.UserId == Dashboard.getCurrentUserId()) {
renderedTabs = [];
}
}
}
2016-03-16 22:04:32 -07:00
view.addEventListener('viewbeforeshow', function (e) {
2015-09-28 20:35:50 -07:00
2016-03-18 12:43:17 -07:00
if (!view.getAttribute('data-title')) {
2015-09-21 10:46:02 -07:00
2016-03-18 12:43:17 -07:00
var parentId = params.topParentId;
2015-09-21 10:46:02 -07:00
2016-03-16 22:04:32 -07:00
if (parentId) {
2015-09-21 10:46:02 -07:00
2016-03-16 22:04:32 -07:00
ApiClient.getItem(Dashboard.getCurrentUserId(), parentId).then(function (item) {
2015-09-21 10:46:02 -07:00
2016-03-18 12:43:17 -07:00
view.setAttribute('data-title', item.Name);
2016-03-16 22:04:32 -07:00
LibraryMenu.setTitle(item.Name);
});
2015-09-21 10:46:02 -07:00
2016-03-16 22:04:32 -07:00
} else {
2016-03-18 12:43:17 -07:00
view.setAttribute('data-title', Globalize.translate('TabShows'));
2016-03-16 22:04:32 -07:00
LibraryMenu.setTitle(Globalize.translate('TabShows'));
}
2015-09-21 10:46:02 -07:00
}
2016-03-16 22:04:32 -07:00
Events.on(MediaController, 'playbackstop', onPlaybackStop);
2016-06-29 10:43:34 -07:00
Events.on(ApiClient, "websocketmessage", onWebSocketMessage);
2016-03-16 22:04:32 -07:00
});
2015-09-21 10:46:02 -07:00
2016-03-16 22:04:32 -07:00
view.addEventListener('viewbeforehide', function (e) {
2013-04-01 18:28:01 -07:00
2016-03-16 22:04:32 -07:00
Events.off(MediaController, 'playbackstop', onPlaybackStop);
2016-06-29 10:43:34 -07:00
Events.off(ApiClient, "websocketmessage", onWebSocketMessage);
2016-03-16 22:04:32 -07:00
});
2016-09-01 09:36:11 -07:00
require(["headroom-window"], function (headroom) {
headroom.add(viewTabs);
self.headroom = headroom;
});
2016-08-15 19:40:29 -07:00
view.addEventListener('viewdestroy', function (e) {
2016-08-15 19:40:29 -07:00
if (self.headroom) {
self.headroom.remove(viewTabs);
}
tabControllers.forEach(function (t) {
if (t.destroy) {
t.destroy();
}
});
});
2016-03-16 22:04:32 -07:00
};
});