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

384 lines
12 KiB
JavaScript
Raw Normal View History

2016-10-06 11:55:01 -07:00
define(['libraryBrowser', 'cardBuilder', 'apphost', 'scrollStyles', 'emby-itemscontainer', 'emby-tabs', 'emby-button'], function (libraryBrowser, cardBuilder, appHost) {
2016-10-22 22:11:46 -07:00
'use strict';
2014-01-12 08:58:47 -07:00
2015-12-14 08:43:03 -07:00
function enableScrollX() {
return browserInfo.mobile && AppInfo.enableAppLayouts;
}
2016-10-10 23:46:59 -07:00
function renderRecordings(elem, recordings, cardOptions) {
if (recordings.length) {
elem.classList.remove('hide');
} else {
elem.classList.add('hide');
}
var recordingItems = elem.querySelector('.recordingItems');
if (enableScrollX()) {
recordingItems.classList.add('hiddenScrollX');
recordingItems.classList.remove('vertical-wrap');
} else {
recordingItems.classList.remove('hiddenScrollX');
recordingItems.classList.add('vertical-wrap');
}
recordingItems.innerHTML = cardBuilder.getCardsHtml(Object.assign({
items: recordings,
shape: (enableScrollX() ? 'autooverflow' : 'auto'),
showTitle: true,
showParentTitle: true,
coverImage: true,
lazy: true,
cardLayout: true,
vibrant: true,
allowBottomPadding: !enableScrollX(),
preferThumb: 'auto'
}, cardOptions || {}));
ImageLoader.lazyChildren(recordingItems);
}
function getBackdropShape() {
return enableScrollX() ? 'overflowBackdrop' : 'backdrop';
}
function renderActiveRecordings(context, promise) {
promise.then(function (result) {
// The IsActive param is new, so handle older servers that don't support it
if (result.Items.length && result.Items[0].Status != 'InProgress') {
result.Items = [];
}
renderRecordings(context.querySelector('#activeRecordings'), result.Items, {
shape: getBackdropShape(),
showParentTitle: false,
showTitle: true,
showAirTime: true,
showAirEndTime: true,
showChannelName: true,
cardLayout: true,
vibrant: true,
preferThumb: true,
coverImage: true,
overlayText: false
});
});
}
2015-12-14 08:43:03 -07:00
function getPortraitShape() {
return enableScrollX() ? 'overflowPortrait' : 'portrait';
}
function getLimit() {
return enableScrollX() ? 12 : 8;
}
2015-05-15 11:28:34 -07:00
function loadRecommendedPrograms(page) {
2015-07-24 08:20:11 -07:00
2014-01-12 08:58:47 -07:00
Dashboard.showLoadingMsg();
2016-09-05 22:02:05 -07:00
var limit = getLimit();
if (enableScrollX()) {
limit *= 2;
}
2014-10-15 20:26:39 -07:00
ApiClient.getLiveTvRecommendedPrograms({
2014-01-12 08:58:47 -07:00
userId: Dashboard.getCurrentUserId(),
IsAiring: true,
2016-09-05 22:02:05 -07:00
limit: limit,
2015-08-03 17:09:54 -07:00
ImageTypeLimit: 1,
2016-09-16 22:47:49 -07:00
EnableImageTypes: "Primary,Thumb,Backdrop",
2016-10-01 00:06:00 -07:00
EnableTotalRecordCount: false,
2016-09-05 13:07:36 -07:00
Fields: "ChannelInfo"
2014-01-12 08:58:47 -07:00
2015-12-14 08:43:03 -07:00
}).then(function (result) {
2015-06-29 22:45:20 -07:00
2016-10-16 10:11:32 -07:00
renderItems(page, result.Items, 'activeProgramItems', 'play', {
showAirDateTime: false,
showAirEndTime: true
});
2015-12-14 08:43:03 -07:00
Dashboard.hideLoadingMsg();
2014-01-12 08:58:47 -07:00
});
2015-05-15 11:28:34 -07:00
}
2016-10-13 14:13:30 -07:00
function reload(page, enableFullRender) {
2014-01-12 08:58:47 -07:00
2016-10-10 23:46:59 -07:00
renderActiveRecordings(page, ApiClient.getLiveTvRecordings({
UserId: Dashboard.getCurrentUserId(),
IsInProgress: true,
Fields: 'CanDelete,PrimaryImageAspectRatio,BasicSyncInfo',
EnableTotalRecordCount: false,
EnableImageTypes: "Primary,Thumb,Backdrop"
}));
2016-10-13 14:13:30 -07:00
if (!enableFullRender) {
2016-10-13 08:07:21 -07:00
return;
}
loadRecommendedPrograms(page);
2014-10-15 20:26:39 -07:00
ApiClient.getLiveTvRecommendedPrograms({
2014-01-12 08:58:47 -07:00
userId: Dashboard.getCurrentUserId(),
IsAiring: false,
HasAired: false,
2015-12-14 08:43:03 -07:00
limit: getLimit(),
2015-04-03 09:31:56 -07:00
IsMovie: false,
2015-08-04 07:26:36 -07:00
IsSports: false,
IsKids: false,
2016-05-08 20:13:38 -07:00
IsSeries: true,
2016-09-05 13:07:36 -07:00
EnableTotalRecordCount: false,
2016-09-14 09:20:03 -07:00
Fields: "ChannelInfo",
EnableImageTypes: "Primary,Thumb"
2014-01-12 08:58:47 -07:00
2015-12-14 08:43:03 -07:00
}).then(function (result) {
2014-01-12 08:58:47 -07:00
2015-12-14 08:43:03 -07:00
renderItems(page, result.Items, 'upcomingProgramItems');
2014-01-12 08:58:47 -07:00
});
2015-03-14 13:56:50 -07:00
ApiClient.getLiveTvRecommendedPrograms({
userId: Dashboard.getCurrentUserId(),
IsAiring: false,
HasAired: false,
2015-12-14 08:43:03 -07:00
limit: getLimit(),
2016-05-08 20:13:38 -07:00
IsMovie: true,
2016-09-05 13:07:36 -07:00
EnableTotalRecordCount: false,
2016-09-14 09:20:03 -07:00
Fields: "ChannelInfo",
EnableImageTypes: "Primary,Thumb"
2015-03-14 13:56:50 -07:00
2015-12-14 08:43:03 -07:00
}).then(function (result) {
2016-10-16 10:11:32 -07:00
renderItems(page, result.Items, 'upcomingTvMovieItems', null, {
shape: getPortraitShape(),
preferThumb: null
});
2015-03-14 13:56:50 -07:00
});
2015-04-03 09:31:56 -07:00
ApiClient.getLiveTvRecommendedPrograms({
userId: Dashboard.getCurrentUserId(),
IsAiring: false,
HasAired: false,
2015-12-14 08:43:03 -07:00
limit: getLimit(),
2016-05-08 20:13:38 -07:00
IsSports: true,
2016-09-05 13:07:36 -07:00
EnableTotalRecordCount: false,
2016-09-14 09:20:03 -07:00
Fields: "ChannelInfo",
EnableImageTypes: "Primary,Thumb"
2015-04-03 09:31:56 -07:00
2015-12-14 08:43:03 -07:00
}).then(function (result) {
renderItems(page, result.Items, 'upcomingSportsItems');
2015-04-03 09:31:56 -07:00
});
2015-08-18 23:12:58 -07:00
ApiClient.getLiveTvRecommendedPrograms({
userId: Dashboard.getCurrentUserId(),
IsAiring: false,
HasAired: false,
2015-12-14 08:43:03 -07:00
limit: getLimit(),
2016-05-08 20:13:38 -07:00
IsKids: true,
2016-09-05 13:07:36 -07:00
EnableTotalRecordCount: false,
2016-09-14 09:20:03 -07:00
Fields: "ChannelInfo",
EnableImageTypes: "Primary,Thumb"
2015-08-18 23:12:58 -07:00
2015-12-14 08:43:03 -07:00
}).then(function (result) {
renderItems(page, result.Items, 'upcomingKidsItems');
2015-08-18 23:12:58 -07:00
});
2014-01-12 08:58:47 -07:00
}
2016-10-16 10:11:32 -07:00
function renderItems(page, items, sectionClass, overlayButton, cardOptions) {
2015-12-14 08:43:03 -07:00
2016-10-06 11:55:01 -07:00
var supportsImageAnalysis = appHost.supports('imageanalysis');
2016-10-16 10:11:32 -07:00
cardOptions = cardOptions || {};
var html = cardBuilder.getCardsHtml(Object.assign({
2015-12-14 08:43:03 -07:00
items: items,
2016-10-16 10:11:32 -07:00
preferThumb: true,
2016-09-16 22:47:49 -07:00
inheritThumb: false,
2016-10-16 10:11:32 -07:00
shape: (enableScrollX() ? 'overflowBackdrop' : 'backdrop'),
2016-09-16 05:21:22 -07:00
showParentTitleOrTitle: true,
showTitle: false,
2016-10-10 23:46:59 -07:00
centerText: !supportsImageAnalysis,
2015-12-14 08:43:03 -07:00
coverImage: true,
overlayText: false,
lazy: true,
2016-10-06 11:55:01 -07:00
overlayMoreButton: overlayButton != 'play' && !supportsImageAnalysis,
2016-08-12 08:54:37 -07:00
overlayPlayButton: overlayButton == 'play',
2016-09-04 22:39:14 -07:00
allowBottomPadding: !enableScrollX(),
2016-09-30 11:43:59 -07:00
showAirTime: true,
showAirDateTime: true,
2016-10-06 11:55:01 -07:00
showChannelName: true,
vibrant: true,
cardLayout: supportsImageAnalysis
2016-10-16 10:11:32 -07:00
}, cardOptions));
2015-12-14 08:43:03 -07:00
var elem = page.querySelector('.' + sectionClass);
elem.innerHTML = html;
ImageLoader.lazyChildren(elem);
}
2016-05-15 10:11:26 -07:00
return function (view, params) {
2015-12-14 08:43:03 -07:00
2016-05-15 10:11:26 -07:00
var self = this;
2016-10-13 14:13:30 -07:00
var lastFullRender = 0;
function enableFullRender() {
return (new Date().getTime() - lastFullRender) > 300000;
}
2015-08-02 16:47:31 -07:00
2016-05-15 10:11:26 -07:00
self.initTab = function () {
2015-08-18 08:52:48 -07:00
2016-05-15 10:11:26 -07:00
var tabContent = view.querySelector('.pageTabContent[data-index=\'' + 0 + '\']');
2016-06-01 23:08:47 -07:00
var containers = tabContent.querySelectorAll('.itemsContainer');
for (var i = 0, length = containers.length; i < length; i++) {
if (enableScrollX()) {
containers[i].classList.add('hiddenScrollX');
2016-07-29 22:25:07 -07:00
containers[i].classList.remove('vertical-wrap');
2016-06-01 23:08:47 -07:00
} else {
containers[i].classList.remove('hiddenScrollX');
2016-07-29 22:25:07 -07:00
containers[i].classList.add('vertical-wrap');
2016-06-01 23:08:47 -07:00
}
2016-05-15 10:11:26 -07:00
}
};
self.renderTab = function () {
var tabContent = view.querySelector('.pageTabContent[data-index=\'' + 0 + '\']');
2016-10-13 14:13:30 -07:00
if (enableFullRender()) {
reload(tabContent, true);
lastFullRender = new Date().getTime();
} else {
reload(tabContent);
}
2016-05-15 10:11:26 -07:00
};
var tabControllers = [];
var renderedTabs = [];
2016-10-02 23:28:45 -07:00
function getTabController(page, index, callback) {
2016-05-15 10:11:26 -07:00
var depends = [];
switch (index) {
case 0:
break;
case 1:
depends.push('scripts/livetvguide');
break;
case 2:
depends.push('scripts/livetvchannels');
break;
case 3:
depends.push('scripts/livetvrecordings');
break;
case 4:
2016-09-04 08:01:31 -07:00
depends.push('scripts/livetvschedule');
break;
case 5:
2016-05-15 10:11:26 -07:00
depends.push('scripts/livetvseriestimers');
break;
default:
break;
2015-08-18 08:52:48 -07:00
}
2016-05-15 10:11:26 -07:00
require(depends, function (controllerFactory) {
2016-10-02 23:28:45 -07:00
var tabContent;
2016-05-15 10:11:26 -07:00
if (index == 0) {
2016-10-02 23:28:45 -07:00
tabContent = view.querySelector('.pageTabContent[data-index=\'' + index + '\']');
2016-05-15 10:11:26 -07:00
self.tabContent = tabContent;
}
var controller = tabControllers[index];
if (!controller) {
2016-10-02 23:28:45 -07:00
tabContent = view.querySelector('.pageTabContent[data-index=\'' + index + '\']');
2016-05-15 10:11:26 -07:00
controller = index ? new controllerFactory(view, params, tabContent) : self;
tabControllers[index] = controller;
if (controller.initTab) {
controller.initTab();
}
}
2016-10-02 23:28:45 -07:00
callback(controller);
});
}
function preLoadTab(page, index) {
getTabController(page, index, function (controller) {
2016-05-15 10:11:26 -07:00
if (renderedTabs.indexOf(index) == -1) {
2016-10-02 23:28:45 -07:00
if (controller.preRender) {
controller.preRender();
}
}
});
}
function loadTab(page, index) {
getTabController(page, index, function (controller) {
if (index === 1) {
document.body.classList.add('autoScrollY');
} else {
document.body.classList.remove('autoScrollY');
}
if (renderedTabs.indexOf(index) == -1) {
2016-10-10 23:46:59 -07:00
if (index === 1) {
2016-10-02 23:28:45 -07:00
renderedTabs.push(index);
}
2016-05-15 10:11:26 -07:00
controller.renderTab();
}
});
}
2015-08-02 16:47:31 -07:00
2016-08-15 19:40:29 -07:00
var viewTabs = view.querySelector('.libraryViewNav');
2015-08-02 16:47:31 -07:00
2016-09-04 08:01:31 -07:00
libraryBrowser.configurePaperLibraryTabs(view, viewTabs, view.querySelectorAll('.pageTabContent'), [0, 2, 3, 4, 5]);
2015-08-02 16:47:31 -07:00
2016-10-02 23:28:45 -07:00
viewTabs.addEventListener('beforetabchange', function (e) {
preLoadTab(view, parseInt(e.detail.selectedTabIndex));
});
2016-08-15 19:40:29 -07:00
viewTabs.addEventListener('tabchange', function (e) {
2016-05-15 10:11:26 -07:00
loadTab(view, parseInt(e.detail.selectedTabIndex));
2015-08-02 16:47:31 -07:00
});
2014-01-12 08:58:47 -07:00
2016-05-15 10:11:26 -07:00
view.addEventListener('viewbeforehide', function (e) {
2016-04-26 11:28:04 -07:00
2016-05-15 10:11:26 -07:00
document.body.classList.remove('autoScrollY');
});
2016-04-26 11:28:04 -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
2016-05-15 10:11:26 -07:00
view.addEventListener('viewdestroy', function (e) {
2016-04-26 11:28:04 -07:00
2016-08-15 19:40:29 -07:00
if (self.headroom) {
self.headroom.remove(viewTabs);
}
2016-05-15 10:11:26 -07:00
tabControllers.forEach(function (t) {
if (t.destroy) {
t.destroy();
}
});
});
2015-08-18 08:52:48 -07:00
};
});