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

67 lines
1.8 KiB
JavaScript
Raw Normal View History

2016-09-07 13:11:16 -07:00
define(['datetime', 'listView'], function (datetime, listView) {
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);
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
2016-09-07 13:11:16 -07:00
html += '<h1>' + datetime.getLocaleDateStringParts(itemStartDate).join(' ') + '</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,
showProgramTimeColumn: 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",
Limit: 200
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
});
}
2015-08-17 21:22:45 -07:00
window.LiveTvChannelPage = {
renderPrograms: loadPrograms
};
});