From 080e2e9eff12c9a402c4e11309c647b046475385 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Wed, 21 Sep 2016 00:28:36 +0200 Subject: [PATCH] New: Added query parameter to ical feed to list premiers only. fixes #1463 fixes #1442 --- .../Calendar/CalendarFeedModule.cs | 14 +++++- src/UI/Calendar/CalendarFeedView.js | 34 ++++++++++++-- src/UI/Calendar/CalendarFeedViewTemplate.hbs | 46 +++++++++++++++++-- 3 files changed, 83 insertions(+), 11 deletions(-) diff --git a/src/NzbDrone.Api/Calendar/CalendarFeedModule.cs b/src/NzbDrone.Api/Calendar/CalendarFeedModule.cs index a4d62a80e..b65ec3f1e 100644 --- a/src/NzbDrone.Api/Calendar/CalendarFeedModule.cs +++ b/src/NzbDrone.Api/Calendar/CalendarFeedModule.cs @@ -23,10 +23,11 @@ namespace NzbDrone.Api.Calendar private Response GetCalendarFeed() { var pastDays = 7; - var futureDays = 28; + var futureDays = 28; var start = DateTime.Today.AddDays(-pastDays); var end = DateTime.Today.AddDays(futureDays); var unmonitored = false; + var premiersOnly = false; // TODO: Remove start/end parameters in v3, they don't work well for iCal var queryStart = Request.Query.Start; @@ -34,6 +35,7 @@ namespace NzbDrone.Api.Calendar var queryPastDays = Request.Query.PastDays; var queryFutureDays = Request.Query.FutureDays; var queryUnmonitored = Request.Query.Unmonitored; + var queryPremiersOnly = Request.Query.PremiersOnly; if (queryStart.HasValue) start = DateTime.Parse(queryStart.Value); if (queryEnd.HasValue) end = DateTime.Parse(queryEnd.Value); @@ -55,11 +57,21 @@ namespace NzbDrone.Api.Calendar unmonitored = bool.Parse(queryUnmonitored.Value); } + if (queryPremiersOnly.HasValue) + { + premiersOnly = bool.Parse(queryPremiersOnly.Value); + } + var episodes = _episodeService.EpisodesBetweenDates(start, end, unmonitored); var icalCalendar = new iCalendar(); foreach (var episode in episodes.OrderBy(v => v.AirDateUtc.Value)) { + if (premiersOnly && (episode.SeasonNumber == 0 || episode.EpisodeNumber != 1)) + { + continue; + } + var occurrence = icalCalendar.Create(); occurrence.UID = "NzbDrone_episode_" + episode.Id.ToString(); occurrence.Status = episode.HasFile ? EventStatus.Confirmed : EventStatus.Tentative; diff --git a/src/UI/Calendar/CalendarFeedView.js b/src/UI/Calendar/CalendarFeedView.js index 4ca9f690a..ae076ee7a 100644 --- a/src/UI/Calendar/CalendarFeedView.js +++ b/src/UI/Calendar/CalendarFeedView.js @@ -6,16 +6,40 @@ module.exports = Marionette.Layout.extend({ template : 'Calendar/CalendarFeedViewTemplate', ui : { - icalUrl : '.x-ical-url', - icalCopy : '.x-ical-copy' + includeUnmonitored : '.x-includeUnmonitored', + premiersOnly : '.x-premiersOnly', + icalUrl : '.x-ical-url', + icalCopy : '.x-ical-copy', + icalWebCal : '.x-ical-webcal' }, - templateHelpers : { - icalHttpUrl : window.location.protocol + '//' + window.location.host + StatusModel.get('urlBase') + '/feed/calendar/NzbDrone.ics?apikey=' + window.NzbDrone.ApiKey, - icalWebCalUrl : 'webcal://' + window.location.host + StatusModel.get('urlBase') + '/feed/calendar/NzbDrone.ics?apikey=' + window.NzbDrone.ApiKey + events : { + 'click .x-includeUnmonitored' : '_updateUrl', + 'click .x-premiersOnly' : '_updateUrl' }, onShow : function() { + this._updateUrl(); this.ui.icalCopy.copyToClipboard(this.ui.icalUrl); + }, + + _updateUrl : function() { + var icalUrl = window.location.host + StatusModel.get('urlBase') + '/feed/calendar/NzbDrone.ics?'; + + if (this.ui.includeUnmonitored.prop('checked')) { + icalUrl += 'unmonitored=true&'; + } + + if (this.ui.premiersOnly.prop('checked')) { + icalUrl += 'premiersOnly=true&'; + } + + icalUrl += 'apikey=' + window.NzbDrone.ApiKey; + + var icalHttpUrl = window.location.protocol + '//' + icalUrl; + var icalWebCalUrl = 'webcal://' + icalUrl; + + this.ui.icalUrl.attr('value', icalHttpUrl); + this.ui.icalWebCal.attr('href', icalWebCalUrl); } }); \ No newline at end of file diff --git a/src/UI/Calendar/CalendarFeedViewTemplate.hbs b/src/UI/Calendar/CalendarFeedViewTemplate.hbs index 4e2505ea7..4c40d21b7 100644 --- a/src/UI/Calendar/CalendarFeedViewTemplate.hbs +++ b/src/UI/Calendar/CalendarFeedViewTemplate.hbs @@ -6,16 +6,52 @@