From 794c09c17ac8b17c1f1900be86134e8a98232036 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Fri, 14 Mar 2014 21:30:49 +0100 Subject: [PATCH] New: iCal calendar feed. --- .../Calendar/CalendarFeedModule.cs | 37 +++++++++---------- src/UI/Calendar/CalendarFeedView.js | 25 +++++++++---- src/UI/Calendar/CalendarFeedViewTemplate.html | 17 +++++---- src/UI/Calendar/CalendarLayoutTemplate.html | 4 +- src/UI/Calendar/calendar.less | 12 ++++-- src/UI/index.html | 2 +- src/UI/jQuery/RouteBinder.js | 8 +++- 7 files changed, 61 insertions(+), 44 deletions(-) diff --git a/src/NzbDrone.Api/Calendar/CalendarFeedModule.cs b/src/NzbDrone.Api/Calendar/CalendarFeedModule.cs index 9bdf4ec25..3f05eb36c 100644 --- a/src/NzbDrone.Api/Calendar/CalendarFeedModule.cs +++ b/src/NzbDrone.Api/Calendar/CalendarFeedModule.cs @@ -23,7 +23,7 @@ namespace NzbDrone.Api.Calendar private Response GetCalendarFeed() { - var start = DateTime.Today.Subtract(TimeSpan.FromDays(7)); + var start = DateTime.Today.AddDays(-7); var end = DateTime.Today.AddDays(28); var queryStart = Request.Query.Start; @@ -35,28 +35,25 @@ namespace NzbDrone.Api.Calendar var episodes = _episodeService.EpisodesBetweenDates(start, end); var icalCalendar = new iCalendar(); - foreach (var series in episodes.GroupBy(v => v.Series)) + foreach (var episode in episodes.OrderBy(v => v.AirDateUtc.Value)) { - foreach (var episode in series) - { - var occurrence = icalCalendar.Create(); - occurrence.UID = "NzbDrone_episode_" + episode.Id.ToString(); - occurrence.Status = episode.HasFile ? EventStatus.Confirmed : EventStatus.Tentative; - occurrence.Start = new iCalDateTime(episode.AirDateUtc.Value); - occurrence.End = new iCalDateTime(episode.AirDateUtc.Value.AddMinutes(episode.Series.Runtime)); - occurrence.Description = episode.Overview; - occurrence.Categories = new List() { episode.Series.Network }; + var occurrence = icalCalendar.Create(); + occurrence.UID = "NzbDrone_episode_" + episode.Id.ToString(); + occurrence.Status = episode.HasFile ? EventStatus.Confirmed : EventStatus.Tentative; + occurrence.Start = new iCalDateTime(episode.AirDateUtc.Value); + occurrence.End = new iCalDateTime(episode.AirDateUtc.Value.AddMinutes(episode.Series.Runtime)); + occurrence.Description = episode.Overview; + occurrence.Categories = new List() { episode.Series.Network }; - switch (episode.Series.SeriesType) - { - case SeriesTypes.Daily: - occurrence.Summary = string.Format("{0} - {1}", episode.Series.Title, episode.Title); - break; + switch (episode.Series.SeriesType) + { + case SeriesTypes.Daily: + occurrence.Summary = string.Format("{0} - {1}", episode.Series.Title, episode.Title); + break; - default: - occurrence.Summary = string.Format("{0} - {1}x{2:00} - {3}", episode.Series.Title, episode.SeasonNumber, episode.EpisodeNumber, episode.Title); - break; - } + default: + occurrence.Summary = string.Format("{0} - {1}x{2:00} - {3}", episode.Series.Title, episode.SeasonNumber, episode.EpisodeNumber, episode.Title); + break; } } diff --git a/src/UI/Calendar/CalendarFeedView.js b/src/UI/Calendar/CalendarFeedView.js index 1ceb86c01..e69895af9 100644 --- a/src/UI/Calendar/CalendarFeedView.js +++ b/src/UI/Calendar/CalendarFeedView.js @@ -2,15 +2,24 @@ define( [ 'marionette', - ], function (Marionette) { + 'System/StatusModel', + 'Mixins/CopyToClipboard' + ], function (Marionette, StatusModel) { return Marionette.Layout.extend({ template: 'Calendar/CalendarFeedViewTemplate', - - onRender: function() { - // hackish way to determine the correct url, as using urlBase seems to only work for reverse proxies or so - var ics = '//' + window.location.host + '/feed/calendar/NzbDrone.ics'; - this.$('#ical-url').val(window.location.protocol + ics); - this.$('#ical-subscribe-button').attr('href', 'webcal:' + ics); - } + + ui: { + icalUrl : '.x-ical-url', + icalCopy : '.x-ical-copy' + }, + + templateHelpers: { + icalHttpUrl : window.location.protocol + '//' + window.location.host + StatusModel.get('urlBase') + '/feed/calendar/NzbDrone.ics', + icalWebCalUrl : 'webcal://' + window.location.host + StatusModel.get('urlBase') + '/feed/calendar/NzbDrone.ics' + }, + + onShow: function () { + this.ui.icalCopy.copyToClipboard(this.ui.icalUrl); + } }); }); diff --git a/src/UI/Calendar/CalendarFeedViewTemplate.html b/src/UI/Calendar/CalendarFeedViewTemplate.html index 366ec21af..4c4d8c0d9 100644 --- a/src/UI/Calendar/CalendarFeedViewTemplate.html +++ b/src/UI/Calendar/CalendarFeedViewTemplate.html @@ -7,14 +7,17 @@
- + -
- - - - - or subscribe now! +
+
+ + + +
+ + +
diff --git a/src/UI/Calendar/CalendarLayoutTemplate.html b/src/UI/Calendar/CalendarLayoutTemplate.html index a6bdc92d1..0df20bd10 100644 --- a/src/UI/Calendar/CalendarLayoutTemplate.html +++ b/src/UI/Calendar/CalendarLayoutTemplate.html @@ -5,9 +5,9 @@

- +

-
+
diff --git a/src/UI/Calendar/calendar.less b/src/UI/Calendar/calendar.less index 8ca64ee2e..430de3e0a 100644 --- a/src/UI/Calendar/calendar.less +++ b/src/UI/Calendar/calendar.less @@ -162,9 +162,13 @@ .ical { color: @btnInverseBackground; + cursor: pointer; } -#ical-url -{ - width: 370px; -} \ No newline at end of file +.ical-url { + + input { + width : 440px; + cursor : text; + } +} diff --git a/src/UI/index.html b/src/UI/index.html index 14e06ebaf..7fe301c61 100644 --- a/src/UI/index.html +++ b/src/UI/index.html @@ -24,7 +24,7 @@ - + diff --git a/src/UI/jQuery/RouteBinder.js b/src/UI/jQuery/RouteBinder.js index a67077a07..f4b541102 100644 --- a/src/UI/jQuery/RouteBinder.js +++ b/src/UI/jQuery/RouteBinder.js @@ -29,17 +29,21 @@ define( return; } - event.preventDefault(); - var href = event.target.getAttribute('href'); if (!href && $target.closest('a') && $target.closest('a')[0]) { var linkElement = $target.closest('a')[0]; + if ($(linkElement).hasClass('no-router')) { + return; + } + href = linkElement.getAttribute('href'); } + event.preventDefault(); + if (!href) { throw 'couldn\'t find route target'; }