Merge branch 'wanted' into develop
This commit is contained in:
commit
860db98294
|
@ -160,6 +160,14 @@ namespace Marr.Data
|
|||
get { return _children; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds an Child in the graph for LazyLoaded property.
|
||||
/// </summary>
|
||||
public void AddLazyRelationship(Relationship childRelationship)
|
||||
{
|
||||
_children.Add(new EntityGraph(childRelationship.RelationshipInfo.EntityType.GetGenericArguments()[0], this, childRelationship));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds an entity to the appropriate place in the object graph.
|
||||
/// </summary>
|
||||
|
@ -182,7 +190,10 @@ namespace Marr.Data
|
|||
}
|
||||
else // RelationTypes.One
|
||||
{
|
||||
_relationship.Setter(_parent._entity, entityInstance);
|
||||
if (_relationship.IsLazyLoaded)
|
||||
_relationship.Setter(_parent._entity, Activator.CreateInstance(_relationship.MemberType, entityInstance));
|
||||
else
|
||||
_relationship.Setter(_parent._entity, entityInstance);
|
||||
}
|
||||
|
||||
EntityReference entityRef = new EntityReference(entityInstance);
|
||||
|
|
|
@ -551,6 +551,23 @@ namespace Marr.Data.QGen
|
|||
return Join(joinType, rightMember, filterExpression);
|
||||
}
|
||||
|
||||
public virtual QueryBuilder<T> Join<TLeft, TRight>(JoinType joinType, Expression<Func<TLeft, LazyLoaded<TRight>>> rightEntity, Expression<Func<TLeft, TRight, bool>> filterExpression)
|
||||
{
|
||||
_isJoin = true;
|
||||
MemberInfo rightMember = (rightEntity.Body as MemberExpression).Member;
|
||||
|
||||
foreach (var item in EntGraph)
|
||||
{
|
||||
if (item.EntityType == typeof(TLeft))
|
||||
{
|
||||
var relationship = item.Relationships.Single(v => v.Member == rightMember);
|
||||
item.AddLazyRelationship(relationship);
|
||||
}
|
||||
}
|
||||
|
||||
return Join(joinType, rightMember, filterExpression);
|
||||
}
|
||||
|
||||
public virtual QueryBuilder<T> Join<TLeft, TRight>(JoinType joinType, MemberInfo rightMember, Expression<Func<TLeft, TRight, bool>> filterExpression)
|
||||
{
|
||||
_isJoin = true;
|
||||
|
|
|
@ -150,7 +150,9 @@
|
|||
<Compile Include="Mapping\MappingValidation.cs" />
|
||||
<Compile Include="Mapping\ResourceMappingException.cs" />
|
||||
<Compile Include="Mapping\ValueInjectorExtensions.cs" />
|
||||
<Compile Include="Missing\MissingModule.cs" />
|
||||
<Compile Include="Wanted\CutoffModule.cs" />
|
||||
<Compile Include="Wanted\LegacyMissingModule.cs" />
|
||||
<Compile Include="Wanted\MissingModule.cs" />
|
||||
<Compile Include="Config\NamingSampleResource.cs" />
|
||||
<Compile Include="NzbDroneRestModuleWithSignalR.cs" />
|
||||
<Compile Include="Qualities\QualityProfileValidation.cs" />
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
using System.Linq;
|
||||
using NzbDrone.Api.Episodes;
|
||||
using NzbDrone.Api.Extensions;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Api.Wanted
|
||||
{
|
||||
public class CutoffModule : NzbDroneRestModule<EpisodeResource>
|
||||
{
|
||||
private readonly IEpisodeCutoffService _episodeCutoffService;
|
||||
private readonly SeriesRepository _seriesRepository;
|
||||
|
||||
public CutoffModule(IEpisodeCutoffService episodeCutoffService, SeriesRepository seriesRepository)
|
||||
:base("wanted/cutoff")
|
||||
{
|
||||
_episodeCutoffService = episodeCutoffService;
|
||||
_seriesRepository = seriesRepository;
|
||||
GetResourcePaged = GetCutoffUnmetEpisodes;
|
||||
}
|
||||
|
||||
private PagingResource<EpisodeResource> GetCutoffUnmetEpisodes(PagingResource<EpisodeResource> pagingResource)
|
||||
{
|
||||
var pagingSpec = new PagingSpec<Episode>
|
||||
{
|
||||
Page = pagingResource.Page,
|
||||
PageSize = pagingResource.PageSize,
|
||||
SortKey = pagingResource.SortKey,
|
||||
SortDirection = pagingResource.SortDirection
|
||||
};
|
||||
|
||||
if (pagingResource.FilterKey == "monitored" && pagingResource.FilterValue == "false")
|
||||
{
|
||||
pagingSpec.FilterExpression = v => v.Monitored == false || v.Series.Monitored == false;
|
||||
}
|
||||
else
|
||||
{
|
||||
pagingSpec.FilterExpression = v => v.Monitored == true && v.Series.Monitored == true;
|
||||
}
|
||||
|
||||
PagingResource<EpisodeResource> resource = ApplyToPage(_episodeCutoffService.EpisodesWhereCutoffUnmet, pagingSpec);
|
||||
|
||||
resource.Records = resource.Records.LoadSubtype(e => e.SeriesId, _seriesRepository).ToList();
|
||||
|
||||
return resource;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
using System;
|
||||
using System.Text;
|
||||
using Nancy;
|
||||
|
||||
namespace NzbDrone.Api.Wanted
|
||||
{
|
||||
class LegacyMissingModule : NzbDroneApiModule
|
||||
{
|
||||
public LegacyMissingModule() : base("missing")
|
||||
{
|
||||
Get["/"] = x =>
|
||||
{
|
||||
string queryString = ConvertQueryParams(Request.Query);
|
||||
var url = String.Format("/api/wanted/missing?{0}", queryString);
|
||||
|
||||
return Response.AsRedirect(url);
|
||||
};
|
||||
}
|
||||
|
||||
private string ConvertQueryParams(DynamicDictionary query)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
|
||||
foreach (var key in query)
|
||||
{
|
||||
var value = query[key];
|
||||
|
||||
sb.AppendFormat("&{0}={1}", key, value);
|
||||
}
|
||||
|
||||
return sb.ToString().Trim('&');
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@ using NzbDrone.Api.Extensions;
|
|||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Api.Missing
|
||||
namespace NzbDrone.Api.Wanted
|
||||
{
|
||||
public class MissingModule : NzbDroneRestModule<EpisodeResource>
|
||||
{
|
||||
|
@ -12,7 +12,7 @@ namespace NzbDrone.Api.Missing
|
|||
private readonly SeriesRepository _seriesRepository;
|
||||
|
||||
public MissingModule(IEpisodeService episodeService, SeriesRepository seriesRepository)
|
||||
:base("missing")
|
||||
:base("wanted/missing")
|
||||
{
|
||||
_episodeService = episodeService;
|
||||
_seriesRepository = seriesRepository;
|
||||
|
@ -29,7 +29,17 @@ namespace NzbDrone.Api.Missing
|
|||
SortDirection = pagingResource.SortDirection
|
||||
};
|
||||
|
||||
var resource = ApplyToPage(_episodeService.EpisodesWithoutFiles, pagingSpec);
|
||||
if (pagingResource.FilterKey == "monitored" && pagingResource.FilterValue == "false")
|
||||
{
|
||||
pagingSpec.FilterExpression = v => v.Monitored == false || v.Series.Monitored == false;
|
||||
}
|
||||
else
|
||||
{
|
||||
pagingSpec.FilterExpression = v => v.Monitored == true && v.Series.Monitored == true;
|
||||
}
|
||||
|
||||
PagingResource<EpisodeResource> resource = ApplyToPage(v => _episodeService.EpisodesWithoutFiles(v), pagingSpec);
|
||||
|
||||
resource.Records = resource.Records.LoadSubtype(e => e.SeriesId, _seriesRepository).ToList();
|
||||
|
||||
return resource;
|
|
@ -45,12 +45,12 @@ namespace NzbDrone.Automation.Test
|
|||
}
|
||||
|
||||
[Test]
|
||||
public void missing_page()
|
||||
public void wanted_page()
|
||||
{
|
||||
page.MissingNavIcon.Click();
|
||||
page.WantedNavIcon.Click();
|
||||
page.WaitForNoSpinner();
|
||||
|
||||
page.FindByClass("iv-missing-missinglayout").Should().NotBeNull();
|
||||
page.FindByClass("iv-wanted-missing-missinglayout").Should().NotBeNull();
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
|
|
@ -72,11 +72,11 @@ namespace NzbDrone.Automation.Test.PageModel
|
|||
}
|
||||
}
|
||||
|
||||
public IWebElement MissingNavIcon
|
||||
public IWebElement WantedNavIcon
|
||||
{
|
||||
get
|
||||
{
|
||||
return Find(By.LinkText("Missing"));
|
||||
return Find(By.LinkText("Wanted"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,105 @@
|
|||
using FizzWare.NBuilder;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
|
||||
namespace NzbDrone.Core.Test.Datastore
|
||||
{
|
||||
|
||||
[TestFixture]
|
||||
public class MarrDataLazyLoadingFixture : DbTest
|
||||
{
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
var qualityProfile = new NzbDrone.Core.Qualities.QualityProfile
|
||||
{
|
||||
Name = "Test",
|
||||
Cutoff = Quality.WEBDL720p,
|
||||
Items = NzbDrone.Core.Test.Qualities.QualityFixture.GetDefaultQualities()
|
||||
};
|
||||
|
||||
|
||||
qualityProfile = Db.Insert(qualityProfile);
|
||||
|
||||
var series = Builder<Series>.CreateListOfSize(1)
|
||||
.All()
|
||||
.With(v => v.QualityProfileId = qualityProfile.Id)
|
||||
.BuildListOfNew();
|
||||
|
||||
Db.InsertMany(series);
|
||||
|
||||
var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(1)
|
||||
.All()
|
||||
.With(v => v.SeriesId = series[0].Id)
|
||||
.BuildListOfNew();
|
||||
|
||||
Db.InsertMany(episodeFiles);
|
||||
|
||||
var episodes = Builder<Episode>.CreateListOfSize(10)
|
||||
.All()
|
||||
.With(v => v.Monitored = true)
|
||||
.With(v => v.EpisodeFileId = episodeFiles[0].Id)
|
||||
.With(v => v.SeriesId = series[0].Id)
|
||||
.BuildListOfNew();
|
||||
|
||||
Db.InsertMany(episodes);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_lazy_load_qualityprofile_if_not_joined()
|
||||
{
|
||||
var db = Mocker.Resolve<IDatabase>();
|
||||
var DataMapper = db.GetDataMapper();
|
||||
|
||||
var episodes = DataMapper.Query<Episode>()
|
||||
.Join<Episode, Series>(Marr.Data.QGen.JoinType.Inner, v => v.Series, (l, r) => l.SeriesId == r.Id)
|
||||
.ToList();
|
||||
|
||||
foreach (var episode in episodes)
|
||||
{
|
||||
Assert.IsNotNull(episode.Series);
|
||||
Assert.IsFalse(episode.Series.QualityProfile.IsLoaded);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_explicit_load_episodefile_if_joined()
|
||||
{
|
||||
var db = Mocker.Resolve<IDatabase>();
|
||||
var DataMapper = db.GetDataMapper();
|
||||
|
||||
var episodes = DataMapper.Query<Episode>()
|
||||
.Join<Episode, EpisodeFile>(Marr.Data.QGen.JoinType.Inner, v => v.EpisodeFile, (l, r) => l.EpisodeFileId == r.Id)
|
||||
.ToList();
|
||||
|
||||
foreach (var episode in episodes)
|
||||
{
|
||||
Assert.IsNull(episode.Series);
|
||||
Assert.IsTrue(episode.EpisodeFile.IsLoaded);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_explicit_load_qualityprofile_if_joined()
|
||||
{
|
||||
var db = Mocker.Resolve<IDatabase>();
|
||||
var DataMapper = db.GetDataMapper();
|
||||
|
||||
var episodes = DataMapper.Query<Episode>()
|
||||
.Join<Episode, Series>(Marr.Data.QGen.JoinType.Inner, v => v.Series, (l, r) => l.SeriesId == r.Id)
|
||||
.Join<Series, QualityProfile>(Marr.Data.QGen.JoinType.Inner, v => v.QualityProfile, (l, r) => l.QualityProfileId == r.Id)
|
||||
.ToList();
|
||||
|
||||
foreach (var episode in episodes)
|
||||
{
|
||||
Assert.IsNotNull(episode.Series);
|
||||
Assert.IsTrue(episode.Series.QualityProfile.IsLoaded);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -104,6 +104,7 @@
|
|||
<Compile Include="Blacklisting\BlacklistRepositoryFixture.cs" />
|
||||
<Compile Include="DataAugmentationFixture\Scene\SceneMappingProxyFixture.cs" />
|
||||
<Compile Include="DataAugmentationFixture\Scene\SceneMappingServiceFixture.cs" />
|
||||
<Compile Include="Datastore\MarrDataLazyLoadingFixture.cs" />
|
||||
<Compile Include="Datastore\BasicRepositoryFixture.cs" />
|
||||
<Compile Include="Datastore\Converters\ProviderSettingConverterFixture.cs" />
|
||||
<Compile Include="Datastore\DatabaseRelationshipFixture.cs" />
|
||||
|
@ -211,6 +212,7 @@
|
|||
<Compile Include="Housekeeping\Housekeepers\CleanupOrphanedEpisodesFixture.cs" />
|
||||
<Compile Include="ThingiProviderTests\NullConfigFixture.cs" />
|
||||
<Compile Include="ThingiProvider\ProviderBaseFixture.cs" />
|
||||
<Compile Include="TvTests\EpisodeRepositoryTests\EpisodesWhereCutoffUnmetFixture.cs" />
|
||||
<Compile Include="TvTests\RefreshEpisodeServiceFixture.cs" />
|
||||
<Compile Include="TvTests\EpisodeProviderTests\HandleEpisodeFileDeletedFixture.cs" />
|
||||
<Compile Include="TvTests\EpisodeRepositoryTests\FindEpisodeFixture.cs" />
|
||||
|
|
|
@ -0,0 +1,167 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
|
||||
namespace NzbDrone.Core.Test.TvTests.EpisodeRepositoryTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class EpisodesWhereCutoffUnmetFixture : DbTest<EpisodeRepository, Episode>
|
||||
{
|
||||
private Series _monitoredSeries;
|
||||
private Series _unmonitoredSeries;
|
||||
private PagingSpec<Episode> _pagingSpec;
|
||||
private List<QualitiesBelowCutoff> _qualitiesBelowCutoff;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
var qualityProfile = new QualityProfile
|
||||
{
|
||||
Id = 1,
|
||||
Cutoff = Quality.WEBDL480p,
|
||||
Items = new List<QualityProfileItem>
|
||||
{
|
||||
new QualityProfileItem { Allowed = true, Quality = Quality.SDTV },
|
||||
new QualityProfileItem { Allowed = true, Quality = Quality.WEBDL480p },
|
||||
new QualityProfileItem { Allowed = true, Quality = Quality.RAWHD }
|
||||
}
|
||||
};
|
||||
|
||||
_monitoredSeries = Builder<Series>.CreateNew()
|
||||
.With(s => s.TvRageId = RandomNumber)
|
||||
.With(s => s.Runtime = 30)
|
||||
.With(s => s.Monitored = true)
|
||||
.With(s => s.TitleSlug = "Title3")
|
||||
.With(s => s.Id = qualityProfile.Id)
|
||||
.BuildNew();
|
||||
|
||||
_unmonitoredSeries = Builder<Series>.CreateNew()
|
||||
.With(s => s.TvdbId = RandomNumber)
|
||||
.With(s => s.Runtime = 30)
|
||||
.With(s => s.Monitored = false)
|
||||
.With(s => s.TitleSlug = "Title2")
|
||||
.With(s => s.Id = qualityProfile.Id)
|
||||
.BuildNew();
|
||||
|
||||
_monitoredSeries.Id = Db.Insert(_monitoredSeries).Id;
|
||||
_unmonitoredSeries.Id = Db.Insert(_unmonitoredSeries).Id;
|
||||
|
||||
_pagingSpec = new PagingSpec<Episode>
|
||||
{
|
||||
Page = 1,
|
||||
PageSize = 10,
|
||||
SortKey = "AirDate",
|
||||
SortDirection = SortDirection.Ascending
|
||||
};
|
||||
|
||||
_qualitiesBelowCutoff = new List<QualitiesBelowCutoff>
|
||||
{
|
||||
new QualitiesBelowCutoff(qualityProfile.Id, new[] {Quality.SDTV.Id})
|
||||
};
|
||||
|
||||
var qualityMet = new EpisodeFile { Path = "a", Quality = new QualityModel { Quality = Quality.WEBDL480p } };
|
||||
var qualityUnmet = new EpisodeFile { Path = "b", Quality = new QualityModel { Quality = Quality.SDTV } };
|
||||
var qualityRawHD = new EpisodeFile { Path = "c", Quality = new QualityModel { Quality = Quality.RAWHD } };
|
||||
|
||||
MediaFileRepository fileRepository = Mocker.Resolve<MediaFileRepository>();
|
||||
|
||||
qualityMet = fileRepository.Insert(qualityMet);
|
||||
qualityUnmet = fileRepository.Insert(qualityUnmet);
|
||||
qualityRawHD = fileRepository.Insert(qualityRawHD);
|
||||
|
||||
var monitoredSeriesEpisodes = Builder<Episode>.CreateListOfSize(4)
|
||||
.All()
|
||||
.With(e => e.Id = 0)
|
||||
.With(e => e.SeriesId = _monitoredSeries.Id)
|
||||
.With(e => e.AirDateUtc = DateTime.Now.AddDays(-5))
|
||||
.With(e => e.Monitored = true)
|
||||
.With(e => e.EpisodeFileId = qualityUnmet.Id)
|
||||
.TheFirst(1)
|
||||
.With(e => e.Monitored = false)
|
||||
.With(e => e.EpisodeFileId = qualityMet.Id)
|
||||
.TheNext(1)
|
||||
.With(e => e.EpisodeFileId = qualityRawHD.Id)
|
||||
.TheLast(1)
|
||||
.With(e => e.SeasonNumber = 0)
|
||||
.Build();
|
||||
|
||||
var unmonitoredSeriesEpisodes = Builder<Episode>.CreateListOfSize(3)
|
||||
.All()
|
||||
.With(e => e.Id = 0)
|
||||
.With(e => e.SeriesId = _unmonitoredSeries.Id)
|
||||
.With(e => e.AirDateUtc = DateTime.Now.AddDays(-5))
|
||||
.With(e => e.Monitored = true)
|
||||
.With(e => e.EpisodeFileId = qualityUnmet.Id)
|
||||
.TheFirst(1)
|
||||
.With(e => e.Monitored = false)
|
||||
.With(e => e.EpisodeFileId = qualityMet.Id)
|
||||
.TheLast(1)
|
||||
.With(e => e.SeasonNumber = 0)
|
||||
.Build();
|
||||
|
||||
|
||||
var unairedEpisodes = Builder<Episode>.CreateListOfSize(1)
|
||||
.All()
|
||||
.With(e => e.Id = 0)
|
||||
.With(e => e.SeriesId = _monitoredSeries.Id)
|
||||
.With(e => e.AirDateUtc = DateTime.Now.AddDays(5))
|
||||
.With(e => e.Monitored = true)
|
||||
.With(e => e.EpisodeFileId = qualityUnmet.Id)
|
||||
.Build();
|
||||
|
||||
Db.InsertMany(monitoredSeriesEpisodes);
|
||||
Db.InsertMany(unmonitoredSeriesEpisodes);
|
||||
Db.InsertMany(unairedEpisodes);
|
||||
}
|
||||
|
||||
private void GivenMonitoredFilterExpression()
|
||||
{
|
||||
_pagingSpec.FilterExpression = e => e.Monitored == true && e.Series.Monitored == true;
|
||||
}
|
||||
|
||||
private void GivenUnmonitoredFilterExpression()
|
||||
{
|
||||
_pagingSpec.FilterExpression = e => e.Monitored == false || e.Series.Monitored == false;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_include_episodes_where_cutoff_has_not_be_met()
|
||||
{
|
||||
GivenMonitoredFilterExpression();
|
||||
|
||||
var spec = Subject.EpisodesWhereCutoffUnmet(_pagingSpec, _qualitiesBelowCutoff, false);
|
||||
|
||||
spec.Records.Should().HaveCount(1);
|
||||
spec.Records.Should().OnlyContain(e => e.EpisodeFile.Value.Quality.Quality == Quality.SDTV);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_only_contain_monitored_episodes()
|
||||
{
|
||||
GivenMonitoredFilterExpression();
|
||||
|
||||
var spec = Subject.EpisodesWhereCutoffUnmet(_pagingSpec, _qualitiesBelowCutoff, false);
|
||||
|
||||
spec.Records.Should().HaveCount(1);
|
||||
spec.Records.Should().OnlyContain(e => e.Monitored);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_only_contain_episode_with_monitored_series()
|
||||
{
|
||||
GivenMonitoredFilterExpression();
|
||||
|
||||
var spec = Subject.EpisodesWhereCutoffUnmet(_pagingSpec, _qualitiesBelowCutoff, false);
|
||||
|
||||
spec.Records.Should().HaveCount(1);
|
||||
spec.Records.Should().OnlyContain(e => e.Series.Monitored);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -72,13 +72,36 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeRepositoryTests
|
|||
.Build();
|
||||
|
||||
|
||||
var unairedEpisodes = Builder<Episode>.CreateListOfSize(1)
|
||||
.All()
|
||||
.With(e => e.Id = 0)
|
||||
.With(e => e.SeriesId = _monitoredSeries.Id)
|
||||
.With(e => e.EpisodeFileId = 0)
|
||||
.With(e => e.AirDateUtc = DateTime.Now.AddDays(5))
|
||||
.With(e => e.Monitored = true)
|
||||
.Build();
|
||||
|
||||
|
||||
Db.InsertMany(monitoredSeriesEpisodes);
|
||||
Db.InsertMany(unmonitoredSeriesEpisodes);
|
||||
Db.InsertMany(unairedEpisodes);
|
||||
}
|
||||
|
||||
private void GivenMonitoredFilterExpression()
|
||||
{
|
||||
_pagingSpec.FilterExpression = e => e.Monitored == true && e.Series.Monitored == true;
|
||||
}
|
||||
|
||||
private void GivenUnmonitoredFilterExpression()
|
||||
{
|
||||
_pagingSpec.FilterExpression = e => e.Monitored == false || e.Series.Monitored == false;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_get_monitored_episodes()
|
||||
{
|
||||
GivenMonitoredFilterExpression();
|
||||
|
||||
var episodes = Subject.EpisodesWithoutFiles(_pagingSpec, false);
|
||||
|
||||
episodes.Records.Should().HaveCount(1);
|
||||
|
@ -96,6 +119,8 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeRepositoryTests
|
|||
[Test]
|
||||
public void should_not_include_unmonitored_episodes()
|
||||
{
|
||||
GivenMonitoredFilterExpression();
|
||||
|
||||
var episodes = Subject.EpisodesWithoutFiles(_pagingSpec, false);
|
||||
|
||||
episodes.Records.Should().NotContain(e => e.Monitored == false);
|
||||
|
@ -104,17 +129,19 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeRepositoryTests
|
|||
[Test]
|
||||
public void should_not_contain_unmonitored_series()
|
||||
{
|
||||
GivenMonitoredFilterExpression();
|
||||
|
||||
var episodes = Subject.EpisodesWithoutFiles(_pagingSpec, false);
|
||||
|
||||
episodes.Records.Should().NotContain(e => e.SeriesId == _unmonitoredSeries.Id);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_have_count_of_one()
|
||||
public void should_not_return_unaired()
|
||||
{
|
||||
var episodes = Subject.EpisodesWithoutFiles(_pagingSpec, false);
|
||||
|
||||
episodes.TotalRecords.Should().Be(1);
|
||||
episodes.TotalRecords.Should().Be(4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -512,6 +512,7 @@
|
|||
<Compile Include="Parser\Parser.cs" />
|
||||
<Compile Include="Parser\ParsingService.cs" />
|
||||
<Compile Include="Parser\QualityParser.cs" />
|
||||
<Compile Include="Qualities\QualitiesBelowCutoff.cs" />
|
||||
<Compile Include="Qualities\QualityModelComparer.cs" />
|
||||
<Compile Include="Qualities\QualityProfileItem.cs" />
|
||||
<Compile Include="Rest\JsonNetSerializer.cs" />
|
||||
|
@ -536,6 +537,7 @@
|
|||
<Compile Include="ThingiProvider\ProviderRepository.cs" />
|
||||
<Compile Include="ThingiProvider\ProviderFactory.cs" />
|
||||
<Compile Include="Tv\Actor.cs" />
|
||||
<Compile Include="Tv\EpisodeCutoffService.cs" />
|
||||
<Compile Include="Tv\EpisodeService.cs" />
|
||||
<Compile Include="Tv\Events\SeriesEditedEvent.cs" />
|
||||
<Compile Include="Tv\Events\SeriesRefreshStartingEvent.cs" />
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NzbDrone.Core.Qualities
|
||||
{
|
||||
public class QualitiesBelowCutoff
|
||||
{
|
||||
public Int32 ProfileId { get; set; }
|
||||
public IEnumerable<Int32> QualityIds { get; set; }
|
||||
|
||||
public QualitiesBelowCutoff(int profileId, IEnumerable<int> qualityIds)
|
||||
{
|
||||
ProfileId = profileId;
|
||||
QualityIds = qualityIds;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Qualities;
|
||||
|
||||
namespace NzbDrone.Core.Tv
|
||||
{
|
||||
public interface IEpisodeCutoffService
|
||||
{
|
||||
PagingSpec<Episode> EpisodesWhereCutoffUnmet(PagingSpec<Episode> pagingSpec);
|
||||
}
|
||||
|
||||
public class EpisodeCutoffService : IEpisodeCutoffService
|
||||
{
|
||||
private readonly IEpisodeRepository _episodeRepository;
|
||||
private readonly IQualityProfileService _qualityProfileService;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public EpisodeCutoffService(IEpisodeRepository episodeRepository, IQualityProfileService qualityProfileService, Logger logger)
|
||||
{
|
||||
_episodeRepository = episodeRepository;
|
||||
_qualityProfileService = qualityProfileService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public PagingSpec<Episode> EpisodesWhereCutoffUnmet(PagingSpec<Episode> pagingSpec)
|
||||
{
|
||||
var qualitiesBelowCutoff = new List<QualitiesBelowCutoff>();
|
||||
var qualityProfiles = _qualityProfileService.All();
|
||||
|
||||
//Get all items less than the cutoff
|
||||
foreach (var qualityProfile in qualityProfiles)
|
||||
{
|
||||
var cutoffIndex = qualityProfile.Items.FindIndex(v => v.Quality == qualityProfile.Cutoff);
|
||||
var belowCutoff = qualityProfile.Items.Take(cutoffIndex).ToList();
|
||||
|
||||
if (belowCutoff.Any())
|
||||
{
|
||||
qualitiesBelowCutoff.Add(new QualitiesBelowCutoff(qualityProfile.Id, belowCutoff.Select(i => i.Quality.Id)));
|
||||
}
|
||||
}
|
||||
|
||||
return _episodeRepository.EpisodesWhereCutoffUnmet(pagingSpec, qualitiesBelowCutoff, false);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,7 +4,8 @@ using System.Linq;
|
|||
using Marr.Data.QGen;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Qualities;
|
||||
|
||||
namespace NzbDrone.Core.Tv
|
||||
{
|
||||
|
@ -18,6 +19,7 @@ namespace NzbDrone.Core.Tv
|
|||
List<Episode> GetEpisodes(int seriesId, int seasonNumber);
|
||||
List<Episode> GetEpisodeByFileId(int fileId);
|
||||
PagingSpec<Episode> EpisodesWithoutFiles(PagingSpec<Episode> pagingSpec, bool includeSpecials);
|
||||
PagingSpec<Episode> EpisodesWhereCutoffUnmet(PagingSpec<Episode> pagingSpec, List<QualitiesBelowCutoff> qualitiesBelowCutoff, bool includeSpecials);
|
||||
Episode FindEpisodeBySceneNumbering(int seriesId, int seasonNumber, int episodeNumber);
|
||||
List<Episode> EpisodesBetweenDates(DateTime startDate, DateTime endDate);
|
||||
void SetMonitoredFlat(Episode episode, bool monitored);
|
||||
|
@ -91,8 +93,24 @@ namespace NzbDrone.Core.Tv
|
|||
startingSeasonNumber = 0;
|
||||
}
|
||||
|
||||
pagingSpec.Records = GetEpisodesWithoutFilesQuery(pagingSpec, currentTime, startingSeasonNumber).ToList();
|
||||
pagingSpec.TotalRecords = GetEpisodesWithoutFilesQuery(pagingSpec, currentTime, startingSeasonNumber).GetRowCount();
|
||||
pagingSpec.TotalRecords = GetMissingEpisodesQuery(pagingSpec, currentTime, startingSeasonNumber).GetRowCount();
|
||||
pagingSpec.Records = GetMissingEpisodesQuery(pagingSpec, currentTime, startingSeasonNumber).ToList();
|
||||
|
||||
return pagingSpec;
|
||||
}
|
||||
|
||||
public PagingSpec<Episode> EpisodesWhereCutoffUnmet(PagingSpec<Episode> pagingSpec, List<QualitiesBelowCutoff> qualitiesBelowCutoff, bool includeSpecials)
|
||||
{
|
||||
var currentTime = DateTime.UtcNow;
|
||||
var startingSeasonNumber = 1;
|
||||
|
||||
if (includeSpecials)
|
||||
{
|
||||
startingSeasonNumber = 0;
|
||||
}
|
||||
|
||||
pagingSpec.TotalRecords = EpisodesWhereCutoffUnmetQuery(pagingSpec, currentTime, qualitiesBelowCutoff, startingSeasonNumber).GetRowCount();
|
||||
pagingSpec.Records = EpisodesWhereCutoffUnmetQuery(pagingSpec, currentTime, qualitiesBelowCutoff, startingSeasonNumber).ToList();
|
||||
|
||||
return pagingSpec;
|
||||
}
|
||||
|
@ -142,17 +160,45 @@ namespace NzbDrone.Core.Tv
|
|||
SetFields(new Episode { Id = episodeId, EpisodeFileId = fileId }, episode => episode.EpisodeFileId);
|
||||
}
|
||||
|
||||
private SortBuilder<Episode> GetEpisodesWithoutFilesQuery(PagingSpec<Episode> pagingSpec, DateTime currentTime, int startingSeasonNumber)
|
||||
private SortBuilder<Episode> GetMissingEpisodesQuery(PagingSpec<Episode> pagingSpec, DateTime currentTime, int startingSeasonNumber)
|
||||
{
|
||||
return Query.Join<Episode, Series>(JoinType.Inner, e => e.Series, (e, s) => e.SeriesId == s.Id)
|
||||
.Where(e => e.EpisodeFileId == 0)
|
||||
.AndWhere(e => e.SeasonNumber >= startingSeasonNumber)
|
||||
.AndWhere(e => e.AirDateUtc <= currentTime)
|
||||
.AndWhere(e => e.Monitored)
|
||||
.AndWhere(e => e.Series.Monitored)
|
||||
.OrderBy(pagingSpec.OrderByClause(), pagingSpec.ToSortDirection())
|
||||
.Skip(pagingSpec.PagingOffset())
|
||||
.Take(pagingSpec.PageSize);
|
||||
.Where(pagingSpec.FilterExpression)
|
||||
.AndWhere(e => e.EpisodeFileId == 0)
|
||||
.AndWhere(e => e.SeasonNumber >= startingSeasonNumber)
|
||||
.AndWhere(e => e.AirDateUtc <= currentTime)
|
||||
.OrderBy(pagingSpec.OrderByClause(), pagingSpec.ToSortDirection())
|
||||
.Skip(pagingSpec.PagingOffset())
|
||||
.Take(pagingSpec.PageSize);
|
||||
}
|
||||
|
||||
private SortBuilder<Episode> EpisodesWhereCutoffUnmetQuery(PagingSpec<Episode> pagingSpec, DateTime currentTime, List<QualitiesBelowCutoff> qualitiesBelowCutoff, int startingSeasonNumber)
|
||||
{
|
||||
return Query.Join<Episode, Series>(JoinType.Inner, e => e.Series, (e, s) => e.SeriesId == s.Id)
|
||||
.Join<Episode, EpisodeFile>(JoinType.Left, e => e.EpisodeFile, (e, s) => e.EpisodeFileId == s.Id)
|
||||
.Where(pagingSpec.FilterExpression)
|
||||
.AndWhere(e => e.EpisodeFileId != 0)
|
||||
.AndWhere(e => e.SeasonNumber >= startingSeasonNumber)
|
||||
.AndWhere(e => e.AirDateUtc <= currentTime)
|
||||
.AndWhere(BuildQualityCutoffWhereClause(qualitiesBelowCutoff))
|
||||
.OrderBy(pagingSpec.OrderByClause(), pagingSpec.ToSortDirection())
|
||||
.Skip(pagingSpec.PagingOffset())
|
||||
.Take(pagingSpec.PageSize);
|
||||
}
|
||||
|
||||
private string BuildQualityCutoffWhereClause(List<QualitiesBelowCutoff> qualitiesBelowCutoff)
|
||||
{
|
||||
var clauses = new List<String>();
|
||||
|
||||
foreach (var profile in qualitiesBelowCutoff)
|
||||
{
|
||||
foreach (var belowCutoff in profile.QualityIds)
|
||||
{
|
||||
clauses.Add(String.Format("([t1].[QualityProfileId] = {0} AND [t2].[Quality] LIKE '%_quality_: {1},%')", profile.ProfileId, belowCutoff));
|
||||
}
|
||||
}
|
||||
|
||||
return String.Format("({0})", String.Join(" OR ", clauses));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ using NzbDrone.Core.Datastore;
|
|||
using NzbDrone.Core.MediaFiles.Events;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Tv.Events;
|
||||
using NzbDrone.Core.Qualities;
|
||||
|
||||
namespace NzbDrone.Core.Tv
|
||||
{
|
||||
|
@ -40,12 +41,14 @@ namespace NzbDrone.Core.Tv
|
|||
{
|
||||
|
||||
private readonly IEpisodeRepository _episodeRepository;
|
||||
private readonly IQualityProfileRepository _qualityProfileRepository;
|
||||
private readonly IConfigService _configService;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public EpisodeService(IEpisodeRepository episodeRepository, IConfigService configService, Logger logger)
|
||||
public EpisodeService(IEpisodeRepository episodeRepository, IQualityProfileRepository qualityProfileRepository, IConfigService configService, Logger logger)
|
||||
{
|
||||
_episodeRepository = episodeRepository;
|
||||
_qualityProfileRepository = qualityProfileRepository;
|
||||
_configService = configService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
@ -88,7 +91,7 @@ namespace NzbDrone.Core.Tv
|
|||
{
|
||||
return _episodeRepository.GetEpisodes(seriesId, seasonNumber);
|
||||
}
|
||||
|
||||
|
||||
public Episode FindEpisodeByName(int seriesId, int seasonNumber, string episodeTitle)
|
||||
{
|
||||
// TODO: can replace this search mechanism with something smarter/faster/better
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<mapping url="http://localhost:8989/Upcoming" local-file="$PROJECT_DIR$/Upcoming" />
|
||||
<mapping url="http://localhost:8989/app.js" local-file="$PROJECT_DIR$/app.js" />
|
||||
<mapping url="http://localhost:8989/Mixins" local-file="$PROJECT_DIR$/Mixins" />
|
||||
<mapping url="http://localhost:8989/Missing" local-file="$PROJECT_DIR$/Missing" />
|
||||
<mapping url="http://localhost:8989/Wanted" local-file="$PROJECT_DIR$/Wanted" />
|
||||
<mapping url="http://localhost:8989/Quality" local-file="$PROJECT_DIR$/Quality" />
|
||||
<mapping url="http://localhost:8989/Config.js" local-file="$PROJECT_DIR$/Config.js" />
|
||||
<mapping url="http://localhost:8989/Shared" local-file="$PROJECT_DIR$/Shared" />
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<mapping url="http://localhost:8989/Upcoming" local-file="$PROJECT_DIR$/Upcoming" />
|
||||
<mapping url="http://localhost:8989/app.js" local-file="$PROJECT_DIR$/app.js" />
|
||||
<mapping url="http://localhost:8989/Mixins" local-file="$PROJECT_DIR$/Mixins" />
|
||||
<mapping url="http://localhost:8989/Missing" local-file="$PROJECT_DIR$/Missing" />
|
||||
<mapping url="http://localhost:8989/Wanted" local-file="$PROJECT_DIR$/Wanted" />
|
||||
<mapping url="http://localhost:8989/Config.js" local-file="$PROJECT_DIR$/Config.js" />
|
||||
<mapping url="http://localhost:8989/Quality" local-file="$PROJECT_DIR$/Quality" />
|
||||
<mapping url="http://localhost:8989/AddSeries" local-file="$PROJECT_DIR$/AddSeries" />
|
||||
|
|
|
@ -3,11 +3,12 @@
|
|||
define(
|
||||
[
|
||||
'reqres',
|
||||
'backbone',
|
||||
'Cells/NzbDroneCell',
|
||||
'History/Queue/QueueCollection',
|
||||
'moment',
|
||||
'Shared/FormatHelpers'
|
||||
], function (reqres, NzbDroneCell, QueueCollection, Moment, FormatHelpers) {
|
||||
], function (reqres, Backbone, NzbDroneCell, QueueCollection, Moment, FormatHelpers) {
|
||||
return NzbDroneCell.extend({
|
||||
|
||||
className: 'episode-status-cell',
|
||||
|
@ -31,8 +32,16 @@ define(
|
|||
var hasAired = Moment(this.model.get('airDateUtc')).isBefore(Moment());
|
||||
var hasFile = this.model.get('hasFile');
|
||||
|
||||
if (hasFile && reqres.hasHandler(reqres.Requests.GetEpisodeFileById)) {
|
||||
var episodeFile = reqres.request(reqres.Requests.GetEpisodeFileById, this.model.get('episodeFileId'));
|
||||
if (hasFile) {
|
||||
var episodeFile;
|
||||
|
||||
if (reqres.hasHandler(reqres.Requests.GetEpisodeFileById)) {
|
||||
episodeFile = reqres.request(reqres.Requests.GetEpisodeFileById, this.model.get('episodeFileId'));
|
||||
}
|
||||
|
||||
else {
|
||||
episodeFile = new Backbone.Model(this.model.get('episodeFile'));
|
||||
}
|
||||
|
||||
this.listenTo(episodeFile, 'change', this._refresh);
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ define(
|
|||
'History/HistoryLayout',
|
||||
'Settings/SettingsLayout',
|
||||
'AddSeries/AddSeriesLayout',
|
||||
'Missing/MissingLayout',
|
||||
'Wanted/WantedLayout',
|
||||
'Calendar/CalendarLayout',
|
||||
'Release/ReleaseLayout',
|
||||
'System/SystemLayout',
|
||||
|
@ -20,7 +20,7 @@ define(
|
|||
HistoryLayout,
|
||||
SettingsLayout,
|
||||
AddSeriesLayout,
|
||||
MissingLayout,
|
||||
WantedLayout,
|
||||
CalendarLayout,
|
||||
ReleaseLayout,
|
||||
SystemLayout,
|
||||
|
@ -44,10 +44,10 @@ define(
|
|||
this.showMainRegion(new SettingsLayout({ action: action }));
|
||||
},
|
||||
|
||||
missing: function () {
|
||||
this.setTitle('Missing');
|
||||
wanted: function (action) {
|
||||
this.setTitle('Wanted');
|
||||
|
||||
this.showMainRegion(new MissingLayout());
|
||||
this.showMainRegion(new WantedLayout({ action: action }));
|
||||
},
|
||||
|
||||
history: function (action) {
|
||||
|
|
|
@ -24,7 +24,7 @@ define(
|
|||
};
|
||||
|
||||
this.prototype.setFilterMode = function(mode, options) {
|
||||
this.setFilter(this.filterModes[mode], options);
|
||||
return this.setFilter(this.filterModes[mode], options);
|
||||
};
|
||||
|
||||
var originalMakeFullCollection = this.prototype._makeFullCollection;
|
||||
|
|
|
@ -29,10 +29,10 @@
|
|||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{{UrlBase}}/missing">
|
||||
<a href="{{UrlBase}}/wanted">
|
||||
<i class="icon-warning-sign"></i>
|
||||
<br>
|
||||
Missing
|
||||
Wanted
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
|
|
|
@ -14,7 +14,8 @@ define(
|
|||
'calendar' : 'calendar',
|
||||
'settings' : 'settings',
|
||||
'settings/:action(/:query)' : 'settings',
|
||||
'missing' : 'missing',
|
||||
'wanted' : 'wanted',
|
||||
'wanted/:action' : 'wanted',
|
||||
'history' : 'history',
|
||||
'history/:action' : 'history',
|
||||
'rss' : 'rss',
|
||||
|
|
|
@ -16,13 +16,18 @@ define(
|
|||
initialize: function (options) {
|
||||
this.menu = options.menu;
|
||||
|
||||
if (this.menu.storeState) {
|
||||
this.setActive();
|
||||
}
|
||||
this.setActive();
|
||||
},
|
||||
|
||||
setActive: function () {
|
||||
var storedKey = Config.getValue(this.menu.menuKey, this.menu.defaultAction);
|
||||
var storedKey = this.menu.defaultAction;
|
||||
|
||||
if (this.menu.storeState) {
|
||||
storedKey = Config.getValue(this.menu.menuKey, storedKey);
|
||||
}
|
||||
|
||||
if (!storedKey)
|
||||
return;
|
||||
|
||||
this.collection.each(function (model) {
|
||||
if (model.get('key').toLocaleLowerCase() === storedKey.toLowerCase()) {
|
||||
|
|
|
@ -1,19 +1,21 @@
|
|||
'use strict';
|
||||
define(
|
||||
[
|
||||
'underscore',
|
||||
'Series/EpisodeModel',
|
||||
'backbone.pageable',
|
||||
'Mixins/AsFilteredCollection',
|
||||
'Mixins/AsPersistedStateCollection'
|
||||
], function (EpisodeModel, PagableCollection, AsPersistedStateCollection) {
|
||||
], function (_, EpisodeModel, PagableCollection, AsFilteredCollection, AsPersistedStateCollection) {
|
||||
var collection = PagableCollection.extend({
|
||||
url : window.NzbDrone.ApiRoot + '/missing',
|
||||
url : window.NzbDrone.ApiRoot + '/wanted/cutoff',
|
||||
model: EpisodeModel,
|
||||
tableName: 'missing',
|
||||
tableName: 'wanted.cutoff',
|
||||
|
||||
state: {
|
||||
pageSize: 15,
|
||||
sortKey : 'airDateUtc',
|
||||
order : 1
|
||||
pageSize : 15,
|
||||
sortKey : 'airDateUtc',
|
||||
order : 1
|
||||
},
|
||||
|
||||
queryParams: {
|
||||
|
@ -27,6 +29,12 @@ define(
|
|||
'1' : 'desc'
|
||||
}
|
||||
},
|
||||
|
||||
// Filter Modes
|
||||
filterModes: {
|
||||
'monitored' : ['monitored', 'true'],
|
||||
'unmonitored' : ['monitored', 'false'],
|
||||
},
|
||||
|
||||
parseState: function (resp) {
|
||||
return {totalRecords: resp.totalRecords};
|
||||
|
@ -41,5 +49,6 @@ define(
|
|||
}
|
||||
});
|
||||
|
||||
collection = AsFilteredCollection.call(collection);
|
||||
return AsPersistedStateCollection.call(collection);
|
||||
});
|
|
@ -0,0 +1,206 @@
|
|||
'use strict';
|
||||
define(
|
||||
[
|
||||
'underscore',
|
||||
'marionette',
|
||||
'backgrid',
|
||||
'Wanted/Cutoff/CutoffUnmetCollection',
|
||||
'Cells/SeriesTitleCell',
|
||||
'Cells/EpisodeNumberCell',
|
||||
'Cells/EpisodeTitleCell',
|
||||
'Cells/RelativeDateCell',
|
||||
'Cells/EpisodeStatusCell',
|
||||
'Shared/Grid/Pager',
|
||||
'Shared/Toolbar/ToolbarLayout',
|
||||
'Shared/LoadingView',
|
||||
'Shared/Messenger',
|
||||
'Commands/CommandController',
|
||||
'backgrid.selectall'
|
||||
], function (_,
|
||||
Marionette,
|
||||
Backgrid,
|
||||
CutoffUnmetCollection,
|
||||
SeriesTitleCell,
|
||||
EpisodeNumberCell,
|
||||
EpisodeTitleCell,
|
||||
RelativeDateCell,
|
||||
EpisodeStatusCell,
|
||||
GridPager,
|
||||
ToolbarLayout,
|
||||
LoadingView,
|
||||
Messenger,
|
||||
CommandController) {
|
||||
return Marionette.Layout.extend({
|
||||
template: 'Wanted/Cutoff/CutoffUnmetLayoutTemplate',
|
||||
|
||||
regions: {
|
||||
missing: '#x-missing',
|
||||
toolbar: '#x-toolbar',
|
||||
pager : '#x-pager'
|
||||
},
|
||||
|
||||
ui: {
|
||||
searchSelectedButton: '.btn i.icon-search'
|
||||
},
|
||||
|
||||
columns:
|
||||
[
|
||||
{
|
||||
name : '',
|
||||
cell : 'select-row',
|
||||
headerCell: 'select-all',
|
||||
sortable : false
|
||||
},
|
||||
{
|
||||
name : 'series',
|
||||
label : 'Series Title',
|
||||
sortable : false,
|
||||
cell : SeriesTitleCell
|
||||
},
|
||||
{
|
||||
name : 'this',
|
||||
label : 'Episode',
|
||||
sortable : false,
|
||||
cell : EpisodeNumberCell
|
||||
},
|
||||
{
|
||||
name : 'this',
|
||||
label : 'Episode Title',
|
||||
sortable : false,
|
||||
cell : EpisodeTitleCell,
|
||||
},
|
||||
{
|
||||
name : 'airDateUtc',
|
||||
label : 'Air Date',
|
||||
cell : RelativeDateCell
|
||||
},
|
||||
{
|
||||
name : 'status',
|
||||
label : 'Status',
|
||||
cell : EpisodeStatusCell,
|
||||
sortable: false
|
||||
}
|
||||
],
|
||||
|
||||
initialize: function () {
|
||||
this.collection = new CutoffUnmetCollection();
|
||||
|
||||
this.listenTo(this.collection, 'sync', this._showTable);
|
||||
},
|
||||
|
||||
onShow: function () {
|
||||
this.missing.show(new LoadingView());
|
||||
this._showToolbar();
|
||||
this.collection.fetch();
|
||||
},
|
||||
|
||||
_showTable: function () {
|
||||
this.missingGrid = new Backgrid.Grid({
|
||||
columns : this.columns,
|
||||
collection: this.collection,
|
||||
className : 'table table-hover'
|
||||
});
|
||||
|
||||
this.missing.show(this.missingGrid);
|
||||
|
||||
this.pager.show(new GridPager({
|
||||
columns : this.columns,
|
||||
collection: this.collection
|
||||
}));
|
||||
},
|
||||
|
||||
_showToolbar: function () {
|
||||
var leftSideButtons = {
|
||||
type : 'default',
|
||||
storeState: false,
|
||||
items :
|
||||
[
|
||||
{
|
||||
title: 'Search Selected',
|
||||
icon : 'icon-search',
|
||||
callback: this._searchSelected,
|
||||
ownerContext: this
|
||||
},
|
||||
{
|
||||
title: 'Season Pass',
|
||||
icon : 'icon-bookmark',
|
||||
route: 'seasonpass'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
var filterOptions = {
|
||||
type : 'radio',
|
||||
storeState : false,
|
||||
menuKey : 'wanted.filterMode',
|
||||
defaultAction : 'monitored',
|
||||
items :
|
||||
[
|
||||
{
|
||||
key : 'monitored',
|
||||
title : '',
|
||||
tooltip : 'Monitored Only',
|
||||
icon : 'icon-nd-monitored',
|
||||
callback : this._setFilter
|
||||
},
|
||||
{
|
||||
key : 'unmonitored',
|
||||
title : '',
|
||||
tooltip : 'Unmonitored Only',
|
||||
icon : 'icon-nd-unmonitored',
|
||||
callback : this._setFilter
|
||||
},
|
||||
]
|
||||
};
|
||||
|
||||
this.toolbar.show(new ToolbarLayout({
|
||||
left :
|
||||
[
|
||||
leftSideButtons
|
||||
],
|
||||
right :
|
||||
[
|
||||
filterOptions
|
||||
],
|
||||
context: this
|
||||
}));
|
||||
|
||||
CommandController.bindToCommand({
|
||||
element: this.$('.x-toolbar-left-1 .btn i.icon-search'),
|
||||
command: {
|
||||
name: 'episodeSearch'
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
_setFilter: function(buttonContext) {
|
||||
var mode = buttonContext.model.get('key');
|
||||
|
||||
this.collection.state.currentPage = 1;
|
||||
var promise = this.collection.setFilterMode(mode);
|
||||
|
||||
if (buttonContext)
|
||||
buttonContext.ui.icon.spinForPromise(promise);
|
||||
},
|
||||
|
||||
_searchSelected: function () {
|
||||
var selected = this.missingGrid.getSelectedModels();
|
||||
|
||||
if (selected.length === 0) {
|
||||
Messenger.show({
|
||||
type: 'error',
|
||||
message: 'No episodes selected'
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var ids = _.pluck(selected, 'id');
|
||||
|
||||
CommandController.Execute('episodeSearch', {
|
||||
name : 'episodeSearch',
|
||||
episodeIds: ids
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
|
@ -0,0 +1,54 @@
|
|||
'use strict';
|
||||
define(
|
||||
[
|
||||
'underscore',
|
||||
'Series/EpisodeModel',
|
||||
'backbone.pageable',
|
||||
'Mixins/AsFilteredCollection',
|
||||
'Mixins/AsPersistedStateCollection'
|
||||
], function (_, EpisodeModel, PagableCollection, AsFilteredCollection, AsPersistedStateCollection) {
|
||||
var collection = PagableCollection.extend({
|
||||
url : window.NzbDrone.ApiRoot + '/wanted/missing',
|
||||
model: EpisodeModel,
|
||||
tableName: 'wanted.missing',
|
||||
|
||||
state: {
|
||||
pageSize : 15,
|
||||
sortKey : 'airDateUtc',
|
||||
order : 1
|
||||
},
|
||||
|
||||
queryParams: {
|
||||
totalPages : null,
|
||||
totalRecords: null,
|
||||
pageSize : 'pageSize',
|
||||
sortKey : 'sortKey',
|
||||
order : 'sortDir',
|
||||
directions : {
|
||||
'-1': 'asc',
|
||||
'1' : 'desc'
|
||||
}
|
||||
},
|
||||
|
||||
// Filter Modes
|
||||
filterModes: {
|
||||
'monitored' : ['monitored', 'true'],
|
||||
'unmonitored' : ['monitored', 'false'],
|
||||
},
|
||||
|
||||
parseState: function (resp) {
|
||||
return {totalRecords: resp.totalRecords};
|
||||
},
|
||||
|
||||
parseRecords: function (resp) {
|
||||
if (resp) {
|
||||
return resp.records;
|
||||
}
|
||||
|
||||
return resp;
|
||||
}
|
||||
});
|
||||
|
||||
collection = AsFilteredCollection.call(collection);
|
||||
return AsPersistedStateCollection.call(collection);
|
||||
});
|
|
@ -4,11 +4,12 @@ define(
|
|||
'underscore',
|
||||
'marionette',
|
||||
'backgrid',
|
||||
'Missing/MissingCollection',
|
||||
'Wanted/Missing/MissingCollection',
|
||||
'Cells/SeriesTitleCell',
|
||||
'Cells/EpisodeNumberCell',
|
||||
'Cells/EpisodeTitleCell',
|
||||
'Cells/RelativeDateCell',
|
||||
'Cells/EpisodeStatusCell',
|
||||
'Shared/Grid/Pager',
|
||||
'Shared/Toolbar/ToolbarLayout',
|
||||
'Shared/LoadingView',
|
||||
|
@ -23,13 +24,14 @@ define(
|
|||
EpisodeNumberCell,
|
||||
EpisodeTitleCell,
|
||||
RelativeDateCell,
|
||||
EpisodeStatusCell,
|
||||
GridPager,
|
||||
ToolbarLayout,
|
||||
LoadingView,
|
||||
Messenger,
|
||||
CommandController) {
|
||||
return Marionette.Layout.extend({
|
||||
template: 'Missing/MissingLayoutTemplate',
|
||||
template: 'Wanted/Missing/MissingLayoutTemplate',
|
||||
|
||||
regions: {
|
||||
missing: '#x-missing',
|
||||
|
@ -52,25 +54,31 @@ define(
|
|||
{
|
||||
name : 'series',
|
||||
label : 'Series Title',
|
||||
sortable: false,
|
||||
sortable : false,
|
||||
cell : SeriesTitleCell
|
||||
},
|
||||
{
|
||||
name : 'this',
|
||||
label : 'Episode',
|
||||
sortable: false,
|
||||
sortable : false,
|
||||
cell : EpisodeNumberCell
|
||||
},
|
||||
{
|
||||
name : 'this',
|
||||
label : 'Episode Title',
|
||||
sortable: false,
|
||||
cell : EpisodeTitleCell
|
||||
sortable : false,
|
||||
cell : EpisodeTitleCell,
|
||||
},
|
||||
{
|
||||
name : 'airDateUtc',
|
||||
label: 'Air Date',
|
||||
cell : RelativeDateCell
|
||||
name : 'airDateUtc',
|
||||
label : 'Air Date',
|
||||
cell : RelativeDateCell
|
||||
},
|
||||
{
|
||||
name : 'status',
|
||||
label : 'Status',
|
||||
cell : EpisodeStatusCell,
|
||||
sortable: false
|
||||
}
|
||||
],
|
||||
|
||||
|
@ -82,8 +90,8 @@ define(
|
|||
|
||||
onShow: function () {
|
||||
this.missing.show(new LoadingView());
|
||||
this.collection.fetch();
|
||||
this._showToolbar();
|
||||
this.collection.fetch();
|
||||
},
|
||||
|
||||
_showTable: function () {
|
||||
|
@ -120,12 +128,40 @@ define(
|
|||
}
|
||||
]
|
||||
};
|
||||
|
||||
var filterOptions = {
|
||||
type : 'radio',
|
||||
storeState : false,
|
||||
menuKey : 'wanted.filterMode',
|
||||
defaultAction : 'monitored',
|
||||
items :
|
||||
[
|
||||
{
|
||||
key : 'monitored',
|
||||
title : '',
|
||||
tooltip : 'Monitored Only',
|
||||
icon : 'icon-nd-monitored',
|
||||
callback : this._setFilter
|
||||
},
|
||||
{
|
||||
key : 'unmonitored',
|
||||
title : '',
|
||||
tooltip : 'Unmonitored Only',
|
||||
icon : 'icon-nd-unmonitored',
|
||||
callback : this._setFilter
|
||||
},
|
||||
]
|
||||
};
|
||||
|
||||
this.toolbar.show(new ToolbarLayout({
|
||||
left :
|
||||
[
|
||||
leftSideButtons
|
||||
],
|
||||
right :
|
||||
[
|
||||
filterOptions
|
||||
],
|
||||
context: this
|
||||
}));
|
||||
|
||||
|
@ -136,6 +172,16 @@ define(
|
|||
}
|
||||
});
|
||||
},
|
||||
|
||||
_setFilter: function(buttonContext) {
|
||||
var mode = buttonContext.model.get('key');
|
||||
|
||||
this.collection.state.currentPage = 1;
|
||||
var promise = this.collection.setFilterMode(mode);
|
||||
|
||||
if (buttonContext)
|
||||
buttonContext.ui.icon.spinForPromise(promise);
|
||||
},
|
||||
|
||||
_searchSelected: function () {
|
||||
var selected = this.missingGrid.getSelectedModels();
|
|
@ -0,0 +1,11 @@
|
|||
<div id="x-toolbar"/>
|
||||
<div class="row">
|
||||
<div class="span12">
|
||||
<div id="x-missing"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="span12">
|
||||
<div id="x-pager"/>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,69 @@
|
|||
'use strict';
|
||||
define(
|
||||
[
|
||||
'marionette',
|
||||
'backbone',
|
||||
'backgrid',
|
||||
'Wanted/Missing/MissingLayout',
|
||||
'Wanted/Cutoff/CutoffUnmetLayout'
|
||||
], function (Marionette, Backbone, Backgrid, MissingLayout, CutoffUnmetLayout) {
|
||||
return Marionette.Layout.extend({
|
||||
template: 'Wanted/WantedLayoutTemplate',
|
||||
|
||||
regions: {
|
||||
content : '#content'
|
||||
//missing : '#missing',
|
||||
//cutoff : '#cutoff'
|
||||
},
|
||||
|
||||
ui: {
|
||||
missingTab : '.x-missing-tab',
|
||||
cutoffTab : '.x-cutoff-tab'
|
||||
},
|
||||
|
||||
events: {
|
||||
'click .x-missing-tab' : '_showMissing',
|
||||
'click .x-cutoff-tab' : '_showCutoffUnmet'
|
||||
},
|
||||
|
||||
initialize: function (options) {
|
||||
if (options.action) {
|
||||
this.action = options.action.toLowerCase();
|
||||
}
|
||||
},
|
||||
|
||||
onShow: function () {
|
||||
switch (this.action) {
|
||||
case 'cutoff':
|
||||
this._showCutoffUnmet();
|
||||
break;
|
||||
default:
|
||||
this._showMissing();
|
||||
}
|
||||
},
|
||||
|
||||
_navigate: function (route) {
|
||||
Backbone.history.navigate(route);
|
||||
},
|
||||
|
||||
_showMissing: function (e) {
|
||||
if (e) {
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
this.content.show(new MissingLayout());
|
||||
this.ui.missingTab.tab('show');
|
||||
this._navigate('/wanted/missing');
|
||||
},
|
||||
|
||||
_showCutoffUnmet: function (e) {
|
||||
if (e) {
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
this.content.show(new CutoffUnmetLayout());
|
||||
this.ui.cutoffTab.tab('show');
|
||||
this._navigate('/wanted/cutoff');
|
||||
}
|
||||
});
|
||||
});
|
|
@ -0,0 +1,10 @@
|
|||
<ul class="nav nav-tabs">
|
||||
<li><a href="#missing" class="x-missing-tab no-router">Missing</a></li>
|
||||
<li><a href="#cutoff" class="x-cutoff-tab no-router">Cutoff Unmet</a></li>
|
||||
</ul>
|
||||
|
||||
<div class="tab-pane" id="content"></div>
|
||||
<!--<div class="tab-content">
|
||||
<div class="tab-pane" id="missing"></div>
|
||||
<div class="tab-pane" id="cutoff"></div>
|
||||
</div>-->
|
Loading…
Reference in New Issue