fixes #632 - Show yesterday's episodes in upcoming view

This commit is contained in:
Luke Pulverenti 2013-11-19 12:17:14 -05:00
parent 7fe1a3311d
commit 38d90288e5
2 changed files with 61 additions and 8 deletions

View File

@ -911,6 +911,15 @@
return html; return html;
}, },
isYesterday: function (date1) {
var today = new Date();
today.setDate(today.getDate() - 1);
return date1.getFullYear() == today.getFullYear() && date1.getDate() == today.getDate();
},
isSameDay: function (date1, date2) { isSameDay: function (date1, date2) {
return date1.getFullYear() == date2.getFullYear() && date1.getDate() == date2.getDate(); return date1.getFullYear() == date2.getFullYear() && date1.getDate() == date2.getDate();
@ -934,6 +943,10 @@
return "Today"; return "Today";
} }
if (LibraryBrowser.isYesterday(date)) {
return "Yesterday";
}
return weekday[date.getDay()] + " " + date.toLocaleDateString(); return weekday[date.getDay()] + " " + date.toLocaleDateString();
}, },
@ -2396,7 +2409,7 @@
var counts = response1[0]; var counts = response1[0];
var liveTvServices = response2[0]; var liveTvServices = response2[0];
insertViews(page, user, counts, liveTvServices); insertViews(page, user, counts, liveTvServices);

View File

@ -1,28 +1,69 @@
(function ($, document) { (function ($, document) {
function formatDigit(i) {
return i < 10 ? "0" + i : i;
}
function getDateFormat(date) {
// yyyyMMddHHmmss
var d = date;
return "" + d.getFullYear() + formatDigit(d.getMonth() + 1) + formatDigit(d.getDate()) + formatDigit(d.getHours()) + formatDigit(d.getMinutes()) + formatDigit(d.getSeconds());
}
$(document).on('pagebeforeshow', "#tvUpcomingPage", function () { $(document).on('pagebeforeshow', "#tvUpcomingPage", function () {
var page = this; var page = this;
var options = { var query = {
SortBy: "PremiereDate,AirTime,SortName", SortBy: "PremiereDate,AirTime,SortName",
SortOrder: "Ascending", SortOrder: "Ascending",
IncludeItemTypes: "Episode", IncludeItemTypes: "Episode",
Limit: 30, Limit: 30,
Recursive: true, Recursive: true,
Fields: "SeriesInfo,UserData", Fields: "SeriesInfo,UserData"
IsUnaired: true
}; };
ApiClient.getItems(Dashboard.getCurrentUserId(), options).done(function (result) { var missedItemsQuery = $.extend({
if (!result.Items.length) { }, query);
var yesterday = new Date();
yesterday.setHours(23, 50, 0, 0);
yesterday.setDate(yesterday.getDate() - 1);
missedItemsQuery.MaxPremiereDate = getDateFormat(yesterday);
yesterday.setHours(0, 0, 0, 0);
missedItemsQuery.MinPremiereDate = getDateFormat(yesterday);
var unairedQuery = $.extend({
IsUnaired: true
}, query);
var promise1 = ApiClient.getItems(Dashboard.getCurrentUserId(), missedItemsQuery);
var promise2 = ApiClient.getItems(Dashboard.getCurrentUserId(), unairedQuery);
$.when(promise1, promise2).done(function (response1, response2) {
var missedItems = response1[0].Items;
var unairedItems = response2[0].Items;
for (var i = 0, length = unairedItems.length; i < length; i++) {
missedItems.push(unairedItems[i]);
}
if (!missedItems.length) {
$('#upcomingItems', page).html("<p>Nothing here. Please ensure <a href='metadata.html'>downloading of internet metadata</a> is enabled.</p>").trigger('create'); $('#upcomingItems', page).html("<p>Nothing here. Please ensure <a href='metadata.html'>downloading of internet metadata</a> is enabled.</p>").trigger('create');
return; return;
} }
$('#upcomingItems', page).html(LibraryBrowser.getPosterViewHtml({ $('#upcomingItems', page).html(LibraryBrowser.getPosterViewHtml({
items: result.Items, items: missedItems,
showLocationTypeIndicator: false, showLocationTypeIndicator: false,
showNewIndicator: false, showNewIndicator: false,
shape: "backdrop", shape: "backdrop",
@ -32,7 +73,6 @@
showPremiereDateIndex: true, showPremiereDateIndex: true,
preferThumb: true preferThumb: true
})); }));
}); });
}); });