diff --git a/NzbDrone.Api/Calendar/CalendarModule.cs b/NzbDrone.Api/Calendar/CalendarModule.cs index e4ed0f560..a03026cde 100644 --- a/NzbDrone.Api/Calendar/CalendarModule.cs +++ b/NzbDrone.Api/Calendar/CalendarModule.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; +using System.Linq; using NzbDrone.Api.Episodes; using NzbDrone.Api.Mapping; +using NzbDrone.Common; using NzbDrone.Core.Tv; namespace NzbDrone.Api.Calendar @@ -9,11 +11,13 @@ namespace NzbDrone.Api.Calendar public class CalendarModule : NzbDroneRestModule { private readonly IEpisodeService _episodeService; + private readonly SeriesService _seriesService; - public CalendarModule(IEpisodeService episodeService) + public CalendarModule(IEpisodeService episodeService, SeriesService seriesService) : base("/calendar") { _episodeService = episodeService; + _seriesService = seriesService; GetResourceAll = GetPaged; } @@ -27,12 +31,15 @@ private List GetPaged() var queryEnd = Request.Query.End; if (queryStart.HasValue) start = DateTime.Parse(queryStart.Value); - if (queryEnd.HasValue) end = DateTime.Parse(queryEnd.Value); var episodes = _episodeService.EpisodesBetweenDates(start, end); + var episodeResources = ToListResource(() => episodes); - return ToListResource(() => episodes); + var series = _seriesService.GetSeriesInList(episodeResources.SelectDistinct(e => e.SeriesId)); + episodeResources.Join(series, episode => episode.SeriesId, s => s.Id, episode => episode.Series); + + return episodeResources; } } } diff --git a/NzbDrone.Api/Missing/MissingModule.cs b/NzbDrone.Api/Missing/MissingModule.cs index 8527284c5..57402e547 100644 --- a/NzbDrone.Api/Missing/MissingModule.cs +++ b/NzbDrone.Api/Missing/MissingModule.cs @@ -1,4 +1,6 @@ -using NzbDrone.Api.Episodes; +using System.Linq; +using NzbDrone.Api.Episodes; +using NzbDrone.Common; using NzbDrone.Core.Datastore; using NzbDrone.Core.Tv; @@ -7,11 +9,13 @@ namespace NzbDrone.Api.Missing public class MissingModule : NzbDroneRestModule { private readonly IEpisodeService _episodeService; + private readonly SeriesService _seriesService; - public MissingModule(IEpisodeService episodeService) + public MissingModule(IEpisodeService episodeService, SeriesService seriesService) :base("missing") { _episodeService = episodeService; + _seriesService = seriesService; GetResourcePaged = GetMissingEpisodes; } @@ -25,7 +29,12 @@ private PagingResource GetMissingEpisodes(PagingResource e.SeriesId)); + episodeResources.Records.Join(series, episode => episode.SeriesId, s => s.Id, episode => episode.Series); + + return episodeResources; } } } \ No newline at end of file diff --git a/NzbDrone.Common/EnumerableExtensions.cs b/NzbDrone.Common/EnumerableExtensions.cs new file mode 100644 index 000000000..2f084fffc --- /dev/null +++ b/NzbDrone.Common/EnumerableExtensions.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; + +namespace NzbDrone.Common +{ + public static class EnumerableExtensions + { + public static IEnumerable SelectDistinct(this IEnumerable outer, Func outerKeySelector) + { + return outer.Select(outerKeySelector).Distinct(); + } + + public static IEnumerable Join(this IEnumerable outer, IEnumerable inner, Func outerKeySelector, Func innerKeySelector, Expression> outerProperty) + { + var outerList = outer.ToList(); + var innerList = inner.ToList(); + + foreach (var outerElement in outerList) + { + var outerKey = outerKeySelector(outerElement); + + foreach (var innerElement in innerList) + { + var innerKey = innerKeySelector(innerElement); + + if (innerKey.Equals(outerKey)) + { + var prop = (PropertyInfo)((MemberExpression)outerProperty.Body).Member; + prop.SetValue(outerElement, innerElement, null); + } + } + } + + return outerList; + } + } +} \ No newline at end of file diff --git a/NzbDrone.Common/NzbDrone.Common.csproj b/NzbDrone.Common/NzbDrone.Common.csproj index 7410fc382..e7c49248c 100644 --- a/NzbDrone.Common/NzbDrone.Common.csproj +++ b/NzbDrone.Common/NzbDrone.Common.csproj @@ -84,6 +84,7 @@ + diff --git a/UI/Missing/MissingLayout.js b/UI/Missing/MissingLayout.js index 1f58b22f4..a955a0e06 100644 --- a/UI/Missing/MissingLayout.js +++ b/UI/Missing/MissingLayout.js @@ -20,6 +20,7 @@ define([ { name : 'series.Title', label : 'Series Title', + sortable : false, cell : Backgrid.TemplateBackedCell.extend({ template: 'Missing/SeriesTitleTemplate' }) }, {