Fixed: Cutoff Unmet not loading
Fixed injection of lazy loaded models to resources
This commit is contained in:
parent
64ecaf5f6e
commit
9f3bdaa1ce
|
@ -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;
|
||||
|
|
|
@ -58,7 +58,6 @@ namespace NzbDrone.Api.Episodes
|
|||
{
|
||||
if (episode.EpisodeFile.IsLoaded && episode.EpisodeFile.Value != null)
|
||||
{
|
||||
resource.EpisodeFile = episode.EpisodeFile.Value.InjectTo<EpisodeFileResource>();
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -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<CloneInjection>(sourceItem);
|
||||
addMethod.Invoke(result, new[] {e });
|
||||
var e = Activator.CreateInstance(targetType).InjectFrom<CloneInjection>(sourceItem);
|
||||
addMethod.Invoke(result, new[] { e });
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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'));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue