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

73 lines
2.0 KiB
JavaScript
Raw Normal View History

2016-09-07 13:11:16 -07:00
define(['datetime', 'listView'], function (datetime, listView) {
2016-10-22 22:11:46 -07:00
'use strict';
2016-09-07 13:11:16 -07:00
function isSameDay(date1, date2) {
2013-11-25 13:39:23 -07:00
2016-09-07 13:11:16 -07:00
return date1.toDateString() === date2.toDateString();
}
2013-11-25 13:39:23 -07:00
2016-09-07 13:11:16 -07:00
function renderPrograms(page, result) {
2013-11-25 13:39:23 -07:00
2016-09-07 13:11:16 -07:00
var html = '';
var currentItems = [];
var currentStartDate = null;
2013-11-25 13:39:23 -07:00
for (var i = 0, length = result.Items.length; i < length; i++) {
2016-09-07 13:11:16 -07:00
var item = result.Items[i];
2013-11-25 14:53:06 -07:00
2016-09-07 13:11:16 -07:00
var itemStartDate = datetime.parseISO8601Date(item.StartDate);
2016-09-07 13:11:16 -07:00
if (!currentStartDate || !isSameDay(currentStartDate, itemStartDate)) {
2013-11-25 13:39:23 -07:00
2016-09-07 13:11:16 -07:00
if (currentItems.length) {
2013-11-25 13:39:23 -07:00
html += '<h1>' + datetime.toLocaleDateString(currentStartDate, { weekday: 'long', month: 'long', day: 'numeric' }) + '</h1>';
2016-09-07 13:11:16 -07:00
html += '<div is="emby-itemscontainer" class="vertical-list">' + listView.getListViewHtml({
items: currentItems,
enableUserDataButtons: false,
showParentTitle: true,
image: false,
2016-10-02 23:28:45 -07:00
showProgramTime: true,
mediaInfo: false,
parentTitleWithTitle: true
2016-09-07 13:11:16 -07:00
}) + '</div>';
}
2013-11-25 13:39:23 -07:00
2016-09-07 13:11:16 -07:00
currentStartDate = itemStartDate;
currentItems = [];
2013-11-25 13:39:23 -07:00
}
2013-12-16 23:08:06 -07:00
2016-09-07 13:11:16 -07:00
currentItems.push(item);
2013-12-20 13:09:49 -07:00
}
2016-03-19 15:31:00 -07:00
2016-05-05 19:55:15 -07:00
page.querySelector('#childrenContent').innerHTML = html;
2013-11-25 13:39:23 -07:00
}
2015-08-17 21:22:45 -07:00
function loadPrograms(page, channelId) {
2013-11-25 13:39:23 -07:00
ApiClient.getLiveTvPrograms({
2013-12-16 23:08:06 -07:00
2015-08-17 21:22:45 -07:00
ChannelIds: channelId,
2015-08-25 19:13:28 -07:00
UserId: Dashboard.getCurrentUserId(),
HasAired: false,
2016-09-07 13:11:16 -07:00
SortBy: "StartDate",
2016-09-17 10:01:58 -07:00
EnableTotalRecordCount: false,
EnableImages: false,
ImageTypeLimit: 0,
EnableUserData: false
2013-11-25 13:39:23 -07:00
2015-12-14 08:43:03 -07:00
}).then(function (result) {
2013-11-25 13:39:23 -07:00
renderPrograms(page, result);
2013-11-26 14:36:11 -07:00
Dashboard.hideLoadingMsg();
2013-11-25 13:39:23 -07:00
});
}
return {
2015-08-17 21:22:45 -07:00
renderPrograms: loadPrograms
};
});