From 0399b18357795a89efcfd13cecc08fbdc917ad4e Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Mon, 25 Feb 2013 19:30:24 -0800 Subject: [PATCH] Calendar uses start and end date --- NzbDrone.Api/Calendar/CalendarModule.cs | 16 +++++----- .../Calendar/CalendarCollectionTemplate.html | 2 +- .../Calendar/CalendarCollectionView.js | 30 ++++++++++++++----- NzbDrone.Core/Tv/EpisodeService.cs | 9 ++---- 4 files changed, 33 insertions(+), 24 deletions(-) diff --git a/NzbDrone.Api/Calendar/CalendarModule.cs b/NzbDrone.Api/Calendar/CalendarModule.cs index 649b67f8c..4c8141b54 100644 --- a/NzbDrone.Api/Calendar/CalendarModule.cs +++ b/NzbDrone.Api/Calendar/CalendarModule.cs @@ -22,19 +22,17 @@ namespace NzbDrone.Api.Calendar private Response Calendar() { - var year = DateTime.Now.Year; - //Todo: This is just for testing - //var month = DateTime.Now.Month; - var month = 1; + var start = DateTime.Today; + var end = DateTime.Today.AddDays(7); - var yearQuery = Request.Query.Year; - var monthQuery = Request.Query.Month; + var queryStart = Request.Query.Start; + var queryEnd = Request.Query.End; - if (yearQuery.HasValue) year = Convert.ToInt32(yearQuery.Value); + if (queryStart.HasValue) start = DateTime.Parse(queryStart.Value); - if(monthQuery.HasValue) month = Convert.ToInt32(monthQuery.Value); + if(queryEnd.HasValue) end = DateTime.Parse(queryEnd.Value); - var episodes = _episodeService.GetEpisodesAiredInMonth(year, month); + var episodes = _episodeService.EpisodesBetweenDates(start, end); return Mapper.Map, List>(episodes).AsResponse(); } } diff --git a/NzbDrone.Backbone/Calendar/CalendarCollectionTemplate.html b/NzbDrone.Backbone/Calendar/CalendarCollectionTemplate.html index 2eab9aca0..7633f71a6 100644 --- a/NzbDrone.Backbone/Calendar/CalendarCollectionTemplate.html +++ b/NzbDrone.Backbone/Calendar/CalendarCollectionTemplate.html @@ -1,3 +1,3 @@ 
-
\ No newline at end of file +
\ No newline at end of file diff --git a/NzbDrone.Backbone/Calendar/CalendarCollectionView.js b/NzbDrone.Backbone/Calendar/CalendarCollectionView.js index 431b28f19..16062b9b0 100644 --- a/NzbDrone.Backbone/Calendar/CalendarCollectionView.js +++ b/NzbDrone.Backbone/Calendar/CalendarCollectionView.js @@ -3,7 +3,7 @@ define(['app', 'Calendar/CalendarItemView'], function (app) { NzbDrone.Calendar.CalendarCollectionView = Backbone.Marionette.CompositeView.extend({ itemView: NzbDrone.Calendar.CalendarItemView, - itemViewContainer: '#fakeContainer', + itemViewContainer: '#upcomingContainer', template: 'Calendar/CalendarCollectionTemplate', ui: { @@ -12,25 +12,39 @@ define(['app', 'Calendar/CalendarItemView'], function (app) { initialize: function (context, collection) { this.collection = collection; + this.calendar = new NzbDrone.Calendar.CalendarCollection(); }, - onRender: function() { + onCompositeCollectionRendered: function() { $(this.ui.calendar).fullCalendar({ + allDayDefault: false, + //ignoreTimezone: false, + weekMode: 'variable', header: { left: 'prev,next today', center: 'title', - right: 'month,basicWeek', - ignoreTimezone: false + right: 'month,basicWeek' }, buttonText: { prev: '', next: '' - } + }, + events: this.getEvents }); - $(this.ui.calendar).fullCalendar('addEventSource', this.collection.toJSON()); + NzbDrone.Calendar.CalendarCollectionView.Instance = this; + $(this.ui.calendar).fullCalendar('addEventSource', this.calendar.toJSON()); }, - addAll: function(){ - $(this.ui.calendar).fullCalendar('addEventSource', this.collection.toJSON()); + getEvents: function(start, end, callback){ + var bbView = NzbDrone.Calendar.CalendarCollectionView.Instance; + + + + bbView.calendar.fetch({ + data:{ start: Date.create(start).format(Date.ISO8601_DATETIME), end: Date.create(end).format(Date.ISO8601_DATETIME) }, + success:function (calendarCollection) { + callback(calendarCollection.toJSON()); + } + }); } }); }); \ No newline at end of file diff --git a/NzbDrone.Core/Tv/EpisodeService.cs b/NzbDrone.Core/Tv/EpisodeService.cs index 2c3958d6b..7a837265c 100644 --- a/NzbDrone.Core/Tv/EpisodeService.cs +++ b/NzbDrone.Core/Tv/EpisodeService.cs @@ -31,7 +31,7 @@ namespace NzbDrone.Core.Tv void SetPostDownloadStatus(List episodeIds, PostDownloadStatusType postDownloadStatus); void UpdateEpisodes(List episodes); Episode GetEpisodeBySceneNumbering(int seriesId, int seasonNumber, int episodeNumber); - List GetEpisodesAiredInMonth(int year, int month); + List EpisodesBetweenDates(DateTime start, DateTime end); } public class EpisodeService : IEpisodeService, IHandle @@ -337,12 +337,9 @@ namespace NzbDrone.Core.Tv return _episodeRepository.GetEpisodeBySceneNumbering(seriesId, seasonNumber, episodeNumber); } - public List GetEpisodesAiredInMonth(int year, int month) + public List EpisodesBetweenDates(DateTime start, DateTime end) { - var firstDay = new DateTime(year, month, 1); - var lastDay = firstDay.AddMonths(1).AddDays(-1); - - return _episodeRepository.EpisodesBetweenDates(firstDay, lastDay); + return _episodeRepository.EpisodesBetweenDates(start.ToUniversalTime(), end.ToUniversalTime()); } public void Handle(EpisodeGrabbedEvent message)