2020-07-12 15:27:05 +01:00
|
|
|
import layoutManager from 'layoutManager';
|
|
|
|
import loading from 'loading';
|
|
|
|
import datetime from 'datetime';
|
|
|
|
import libraryBrowser from 'libraryBrowser';
|
|
|
|
import cardBuilder from 'cardBuilder';
|
|
|
|
import appHost from 'apphost';
|
|
|
|
import imageLoader from 'imageLoader';
|
|
|
|
import globalize from 'globalize';
|
|
|
|
import 'scrollStyles';
|
|
|
|
import 'emby-itemscontainer';
|
|
|
|
|
|
|
|
/* eslint-disable indent */
|
2018-10-23 01:05:09 +03:00
|
|
|
|
|
|
|
function getUpcomingPromise(context, params) {
|
|
|
|
loading.show();
|
2020-07-12 15:27:05 +01:00
|
|
|
const query = {
|
2018-10-23 01:05:09 +03:00
|
|
|
Limit: 48,
|
2020-05-04 12:44:12 +02:00
|
|
|
Fields: 'AirTime,UserData',
|
2018-10-23 01:05:09 +03:00
|
|
|
UserId: ApiClient.getCurrentUserId(),
|
|
|
|
ImageTypeLimit: 1,
|
2020-05-04 12:44:12 +02:00
|
|
|
EnableImageTypes: 'Primary,Backdrop,Banner,Thumb',
|
2019-11-06 13:43:39 +03:00
|
|
|
EnableTotalRecordCount: false
|
2018-10-23 01:05:09 +03:00
|
|
|
};
|
2019-11-06 13:43:39 +03:00
|
|
|
query.ParentId = params.topParentId;
|
2020-05-04 12:44:12 +02:00
|
|
|
return ApiClient.getJSON(ApiClient.getUrl('Shows/Upcoming', query));
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadUpcoming(context, params, promise) {
|
2019-11-06 13:43:39 +03:00
|
|
|
promise.then(function (result) {
|
2020-07-12 15:27:05 +01:00
|
|
|
const items = result.Items;
|
2019-11-06 13:43:39 +03:00
|
|
|
|
|
|
|
if (items.length) {
|
2020-05-04 12:44:12 +02:00
|
|
|
context.querySelector('.noItemsMessage').style.display = 'none';
|
2019-11-06 13:43:39 +03:00
|
|
|
} else {
|
2020-05-04 12:44:12 +02:00
|
|
|
context.querySelector('.noItemsMessage').style.display = 'block';
|
2019-11-06 13:43:39 +03:00
|
|
|
}
|
|
|
|
|
2020-05-04 12:44:12 +02:00
|
|
|
renderUpcoming(context.querySelector('#upcomingItems'), items);
|
2019-11-06 13:43:39 +03:00
|
|
|
loading.hide();
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function enableScrollX() {
|
2019-11-06 13:43:39 +03:00
|
|
|
return !layoutManager.desktop;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getThumbShape() {
|
2020-05-04 12:44:12 +02:00
|
|
|
return enableScrollX() ? 'overflowBackdrop' : 'backdrop';
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function renderUpcoming(elem, items) {
|
2020-07-12 15:27:05 +01:00
|
|
|
const groups = [];
|
|
|
|
let currentGroupName = '';
|
|
|
|
let currentGroup = [];
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2020-07-12 15:27:05 +01:00
|
|
|
for (let i = 0, length = items.length; i < length; i++) {
|
|
|
|
const item = items[i];
|
|
|
|
let dateText = '';
|
2019-11-06 13:43:39 +03:00
|
|
|
|
|
|
|
if (item.PremiereDate) {
|
|
|
|
try {
|
2020-07-12 15:27:05 +01:00
|
|
|
const premiereDate = datetime.parseISO8601Date(item.PremiereDate, true);
|
2020-05-04 12:44:12 +02:00
|
|
|
dateText = datetime.isRelativeDay(premiereDate, -1) ? globalize.translate('Yesterday') : datetime.toLocaleDateString(premiereDate, {
|
|
|
|
weekday: 'long',
|
|
|
|
month: 'short',
|
|
|
|
day: 'numeric'
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
2019-11-23 00:29:38 +09:00
|
|
|
} catch (err) {
|
2020-02-16 03:44:43 +01:00
|
|
|
console.error('error parsing timestamp for upcoming tv shows');
|
2019-11-23 00:29:38 +09:00
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (dateText != currentGroupName) {
|
|
|
|
if (currentGroup.length) {
|
|
|
|
groups.push({
|
|
|
|
name: currentGroupName,
|
|
|
|
items: currentGroup
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
currentGroupName = dateText;
|
|
|
|
currentGroup = [item];
|
|
|
|
} else {
|
|
|
|
currentGroup.push(item);
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2020-07-12 15:27:05 +01:00
|
|
|
let html = '';
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2020-07-12 15:27:05 +01:00
|
|
|
for (let i = 0, length = groups.length; i < length; i++) {
|
|
|
|
const group = groups[i];
|
2019-11-06 13:43:39 +03:00
|
|
|
html += '<div class="verticalSection">';
|
2020-05-04 12:44:12 +02:00
|
|
|
html += '<h2 class="sectionTitle sectionTitle-cards padded-left">' + group.name + '</h2>';
|
2020-07-12 15:27:05 +01:00
|
|
|
let allowBottomPadding = true;
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
if (enableScrollX()) {
|
2019-11-06 13:43:39 +03:00
|
|
|
allowBottomPadding = false;
|
2020-07-12 15:27:05 +01:00
|
|
|
let scrollXClass = 'scrollX hiddenScrollX';
|
2019-11-06 13:43:39 +03:00
|
|
|
|
|
|
|
if (layoutManager.tv) {
|
2020-05-04 12:44:12 +02:00
|
|
|
scrollXClass += ' smoothScrollX';
|
2019-11-06 13:43:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
html += '<div is="emby-itemscontainer" class="itemsContainer ' + scrollXClass + ' padded-left padded-right">';
|
|
|
|
} else {
|
|
|
|
html += '<div is="emby-itemscontainer" class="itemsContainer vertical-wrap padded-left padded-right">';
|
|
|
|
}
|
|
|
|
|
2020-07-12 15:27:05 +01:00
|
|
|
let supportsImageAnalysis = appHost.supports('imageanalysis');
|
2019-11-06 13:43:39 +03:00
|
|
|
supportsImageAnalysis = false;
|
|
|
|
html += cardBuilder.getCardsHtml({
|
2018-10-23 01:05:09 +03:00
|
|
|
items: group.items,
|
2019-11-06 13:43:39 +03:00
|
|
|
showLocationTypeIndicator: false,
|
2018-10-23 01:05:09 +03:00
|
|
|
shape: getThumbShape(),
|
2019-11-06 13:43:39 +03:00
|
|
|
showTitle: true,
|
|
|
|
preferThumb: true,
|
|
|
|
lazy: true,
|
|
|
|
showDetailsMenu: true,
|
2018-10-23 01:05:09 +03:00
|
|
|
centerText: !supportsImageAnalysis,
|
2019-11-06 13:43:39 +03:00
|
|
|
showParentTitle: true,
|
|
|
|
overlayText: false,
|
2018-10-23 01:05:09 +03:00
|
|
|
allowBottomPadding: allowBottomPadding,
|
|
|
|
cardLayout: supportsImageAnalysis,
|
2019-11-06 13:43:39 +03:00
|
|
|
overlayMoreButton: true,
|
|
|
|
missingIndicator: false
|
|
|
|
});
|
2020-05-04 12:44:12 +02:00
|
|
|
html += '</div>';
|
|
|
|
html += '</div>';
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
|
|
|
|
elem.innerHTML = html;
|
|
|
|
imageLoader.lazyChildren(elem);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2020-07-12 15:27:05 +01:00
|
|
|
export default function (view, params, tabContent) {
|
|
|
|
let upcomingPromise;
|
|
|
|
const self = this;
|
2019-11-06 13:43:39 +03:00
|
|
|
|
|
|
|
self.preRender = function () {
|
|
|
|
upcomingPromise = getUpcomingPromise(view, params);
|
|
|
|
};
|
|
|
|
|
|
|
|
self.renderTab = function () {
|
|
|
|
loadUpcoming(tabContent, params, upcomingPromise);
|
|
|
|
};
|
2020-07-12 15:27:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* eslint-enable indent */
|