New: Series Overview sorted by Next Airing now sorts all remaining items by their Last Aired date.

pull/3113/head
Taloth Saldono 11 years ago
parent 221a457f3a
commit c2b06d957d

@ -177,6 +177,7 @@ namespace NzbDrone.Api.Series
resource.EpisodeCount = seriesStatistics.EpisodeCount;
resource.EpisodeFileCount = seriesStatistics.EpisodeFileCount;
resource.NextAiring = seriesStatistics.NextAiring;
resource.PreviousAiring = seriesStatistics.PreviousAiring;
}
public void Handle(EpisodeImportedEvent message)

@ -34,6 +34,7 @@ namespace NzbDrone.Api.Series
public String QualityProfileName { get; set; }
public String Overview { get; set; }
public DateTime? NextAiring { get; set; }
public DateTime? PreviousAiring { get; set; }
public String Network { get; set; }
public String AirTime { get; set; }
public List<MediaCover> Images { get; set; }

@ -39,6 +39,11 @@ namespace NzbDrone.Core.Test.SeriesStatsTests
_episode.EpisodeFileId = 1;
}
private void GivenOldEpisode()
{
_episode.AirDateUtc = DateTime.Now.AddSeconds(-10);
}
private void GivenMonitoredEpisode()
{
_episode.Monitored = true;
@ -59,6 +64,7 @@ namespace NzbDrone.Core.Test.SeriesStatsTests
stats.Should().HaveCount(1);
stats.First().NextAiring.Should().Be(_episode.AirDateUtc);
stats.First().PreviousAiring.Should().NotHaveValue();
}
[Test]
@ -73,6 +79,47 @@ namespace NzbDrone.Core.Test.SeriesStatsTests
stats.First().NextAiring.Should().NotHaveValue();
}
[Test]
public void should_have_previous_airing_for_old_episode_with_file()
{
GivenEpisodeWithFile();
GivenOldEpisode();
GivenFile();
var stats = Subject.SeriesStatistics();
stats.Should().HaveCount(1);
stats.First().NextAiring.Should().NotHaveValue();
stats.First().PreviousAiring.Should().Be(_episode.AirDateUtc);
}
[Test]
public void should_have_previous_airing_for_old_episode_without_file_monitored()
{
GivenMonitoredEpisode();
GivenOldEpisode();
GivenFile();
var stats = Subject.SeriesStatistics();
stats.Should().HaveCount(1);
stats.First().NextAiring.Should().NotHaveValue();
stats.First().PreviousAiring.Should().Be(_episode.AirDateUtc);
}
[Test]
public void should_not_have_previous_airing_for_old_episode_without_file_unmonitored()
{
GivenOldEpisode();
GivenFile();
var stats = Subject.SeriesStatistics();
stats.Should().HaveCount(1);
stats.First().NextAiring.Should().NotHaveValue();
stats.First().PreviousAiring.Should().NotHaveValue();
}
[Test]
public void should_not_include_unmonitored_episode_in_episode_count()
{

@ -7,6 +7,7 @@ namespace NzbDrone.Core.SeriesStats
{
public int SeriesId { get; set; }
public string NextAiringString { get; set; }
public string PreviousAiringString { get; set; }
public int EpisodeFileCount { get; set; }
public int EpisodeCount { get; set; }
@ -21,5 +22,17 @@ namespace NzbDrone.Core.SeriesStats
return nextAiring;
}
}
public DateTime? PreviousAiring
{
get
{
DateTime previousAiring;
if (!DateTime.TryParse(PreviousAiringString, out previousAiring)) return null;
return previousAiring;
}
}
}
}

@ -56,7 +56,8 @@ namespace NzbDrone.Core.SeriesStats
SeriesId,
SUM(CASE WHEN (Monitored = 1 AND AirdateUtc <= @currentDate) OR EpisodeFileId > 0 THEN 1 ELSE 0 END) AS EpisodeCount,
SUM(CASE WHEN EpisodeFileId > 0 THEN 1 ELSE 0 END) AS EpisodeFileCount,
MIN(CASE WHEN AirDateUtc < @currentDate OR EpisodeFileId > 0 OR Monitored = 0 THEN NULL ELSE AirDateUtc END) AS NextAiringString
MIN(CASE WHEN AirDateUtc < @currentDate OR EpisodeFileId > 0 OR Monitored = 0 THEN NULL ELSE AirDateUtc END) AS NextAiringString,
MAX(CASE WHEN AirDateUtc >= @currentDate OR EpisodeFileId = 0 AND Monitored = 0 THEN NULL ELSE AirDateUtc END) AS PreviousAiringString
FROM Episodes";
}

@ -59,12 +59,18 @@ define(
//Sorters
nextAiring: function (model, attr) {
var nextAiring = model.get(attr);
if (!nextAiring) {
return Number.MAX_VALUE;
if (nextAiring) {
return Moment(nextAiring).unix();
}
var previousAiring = model.get(attr.replace('nextAiring', 'previousAiring'));
if (previousAiring) {
return 10000000000 - Moment(previousAiring).unix();
}
return Moment(nextAiring).unix();
return Number.MAX_VALUE;
}
});

Loading…
Cancel
Save