diff --git a/src/NzbDrone.Api/Episodes/EpisodeModule.cs b/src/NzbDrone.Api/Episodes/EpisodeModule.cs index ee56fb00b..15b77749d 100644 --- a/src/NzbDrone.Api/Episodes/EpisodeModule.cs +++ b/src/NzbDrone.Api/Episodes/EpisodeModule.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using NzbDrone.Api.REST; -using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Tv; using NzbDrone.Api.Mapping; using NzbDrone.Core.DecisionEngine; diff --git a/src/NzbDrone.Api/Episodes/EpisodeModuleWithSignalR.cs b/src/NzbDrone.Api/Episodes/EpisodeModuleWithSignalR.cs index 6f3b7c7fc..642874fd3 100644 --- a/src/NzbDrone.Api/Episodes/EpisodeModuleWithSignalR.cs +++ b/src/NzbDrone.Api/Episodes/EpisodeModuleWithSignalR.cs @@ -58,7 +58,6 @@ namespace NzbDrone.Api.Episodes { if (episode.EpisodeFile.IsLoaded && episode.EpisodeFile.Value != null) { - resource.EpisodeFile = episode.EpisodeFile.Value.InjectTo(); resource.EpisodeFile.Path = Path.Combine(episode.Series.Path, episode.EpisodeFile.Value.RelativePath); resource.EpisodeFile.QualityCutoffNotMet = _qualityUpgradableSpecification.CutoffNotMet(episode.Series.Profile.Value, episode.EpisodeFile.Value.Quality); } diff --git a/src/NzbDrone.Api/Episodes/EpisodeResource.cs b/src/NzbDrone.Api/Episodes/EpisodeResource.cs index 50d274143..3e97e50b0 100644 --- a/src/NzbDrone.Api/Episodes/EpisodeResource.cs +++ b/src/NzbDrone.Api/Episodes/EpisodeResource.cs @@ -2,7 +2,6 @@ using Newtonsoft.Json; using NzbDrone.Api.EpisodeFiles; using NzbDrone.Api.REST; -using NzbDrone.Core.MediaFiles; namespace NzbDrone.Api.Episodes { @@ -27,9 +26,11 @@ namespace NzbDrone.Api.Episodes public Int32? AbsoluteEpisodeNumber { get; set; } public DateTime? EndTime { get; set; } public DateTime? GrabDate { get; set; } - public Core.Tv.Series Series { get; set; } public String SeriesTitle { get; set; } + //I'd like to replace this with SeriesResource, but LoadSubType would need to be reworked to support that + public Core.Tv.Series Series { get; set; } + //Hiding this so people don't think its usable (only used to set the initial state) [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public Boolean Grabbed { get; set; } diff --git a/src/NzbDrone.Api/Mapping/CloneInjection.cs b/src/NzbDrone.Api/Mapping/CloneInjection.cs index 1266ebd0b..5a1afa067 100644 --- a/src/NzbDrone.Api/Mapping/CloneInjection.cs +++ b/src/NzbDrone.Api/Mapping/CloneInjection.cs @@ -62,14 +62,33 @@ namespace NzbDrone.Api.Mapping private static object MapLazy(ConventionInfo conventionInfo) { - - var genericArgument = conventionInfo.SourceProp.Type.GetGenericArguments()[0]; + var sourceArgument = conventionInfo.SourceProp.Type.GetGenericArguments()[0]; dynamic lazy = conventionInfo.SourceProp.Value; - if (lazy.IsLoaded && conventionInfo.TargetProp.Type.IsAssignableFrom(genericArgument)) + if (lazy.IsLoaded) { - return lazy.Value; + if (conventionInfo.TargetProp.Type.IsAssignableFrom(sourceArgument)) + { + return lazy.Value; + } + + var genericArgument = conventionInfo.TargetProp.Type; + + if (genericArgument.IsValueType || genericArgument == typeof(string)) + { + return lazy.Value; + } + + if (genericArgument.IsGenericType) + { + if (conventionInfo.SourceProp.Type.GetGenericTypeDefinition().GetInterfaces().Any(d => d == typeof(IEnumerable))) + { + return MapLists(genericArgument, lazy.Value); + } + } + + return Activator.CreateInstance(genericArgument).InjectFrom((object)lazy.Value); } return null; @@ -78,25 +97,29 @@ namespace NzbDrone.Api.Mapping private static object MapLists(ConventionInfo conventionInfo) { var genericArgument = conventionInfo.TargetProp.Type.GetGenericArguments()[0]; - if (genericArgument.IsValueType || genericArgument == typeof(string)) + + return MapLists(genericArgument, conventionInfo.SourceProp.Value); + } + + private static object MapLists(Type targetType, object sourceValue) + { + if (targetType.IsValueType || targetType == typeof(string)) { - return conventionInfo.SourceProp.Value; + return sourceValue; } - - var listType = typeof(List<>).MakeGenericType(genericArgument); + var listType = typeof(List<>).MakeGenericType(targetType); var addMethod = listType.GetMethod("Add"); var result = Activator.CreateInstance(listType); - foreach (var sourceItem in (IEnumerable)conventionInfo.SourceProp.Value) + foreach (var sourceItem in (IEnumerable)sourceValue) { - var e = Activator.CreateInstance(genericArgument).InjectFrom(sourceItem); - addMethod.Invoke(result, new[] {e }); + var e = Activator.CreateInstance(targetType).InjectFrom(sourceItem); + addMethod.Invoke(result, new[] { e }); } return result; - } } -} \ No newline at end of file +} diff --git a/src/UI/Cells/EpisodeStatusCell.js b/src/UI/Cells/EpisodeStatusCell.js index 84272bfc1..a7ed8a694 100644 --- a/src/UI/Cells/EpisodeStatusCell.js +++ b/src/UI/Cells/EpisodeStatusCell.js @@ -116,7 +116,7 @@ define( episodeFile = reqres.request(reqres.Requests.GetEpisodeFileById, this.model.get('episodeFileId')); } - else { + else if (this.model.has('episodeFile')) { episodeFile = new Backbone.Model(this.model.get('episodeFile')); }