1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-25 01:11:43 +00:00

Fixed seriesGrid query and tests.

Fixed GetEpisodeModels that would fail due to a null AirDate.
This commit is contained in:
Mark McDowall 2011-06-23 11:37:17 -07:00
parent 938fa24a8e
commit 342406784a
5 changed files with 28 additions and 25 deletions

View file

@ -224,7 +224,7 @@ public void Get_Series_With_Count()
//Act
mocker.Resolve<QualityProvider>();
var series = mocker.Resolve<SeriesProvider>().GetAllSeriesWithEpisodeCount(true);
var series = mocker.Resolve<SeriesProvider>().GetAllSeriesWithEpisodeCount();
//Assert
series.Should().HaveCount(1);
@ -249,7 +249,7 @@ public void Get_Series_With_Count_AllIgnored()
//Act
mocker.Resolve<QualityProvider>();
var series = mocker.Resolve<SeriesProvider>().GetAllSeriesWithEpisodeCount(true);
var series = mocker.Resolve<SeriesProvider>().GetAllSeriesWithEpisodeCount();
//Assert
series.Should().HaveCount(1);
@ -274,7 +274,7 @@ public void Get_Series_With_Count_AllDownloaded()
//Act
mocker.Resolve<QualityProvider>();
var series = mocker.Resolve<SeriesProvider>().GetAllSeriesWithEpisodeCount(true);
var series = mocker.Resolve<SeriesProvider>().GetAllSeriesWithEpisodeCount();
//Assert
series.Should().HaveCount(1);
@ -303,7 +303,7 @@ public void Get_Series_With_Count_Half_Ignored()
//Act
mocker.Resolve<QualityProvider>();
var series = mocker.Resolve<SeriesProvider>().GetAllSeriesWithEpisodeCount(true);
var series = mocker.Resolve<SeriesProvider>().GetAllSeriesWithEpisodeCount();
//Assert
series.Should().HaveCount(1);

View file

@ -42,22 +42,21 @@ public virtual IList<Series> GetAllSeries()
return series;
}
public virtual IList<Series> GetAllSeriesWithEpisodeCount(bool ignoreSpecialsInSeasonCount)
public virtual IList<Series> GetAllSeriesWithEpisodeCount()
{
var seasonNumber = 0;
if (!ignoreSpecialsInSeasonCount)
seasonNumber = -1;
var series = _database
.Fetch<Series, QualityProfile>(@"SELECT Series.*, SUM(CASE WHEN Ignored = 0 THEN 1 ELSE 0 END) AS EpisodeCount,
SUM(CASE WHEN Ignored = 0 AND EpisodeFileId > 0 THEN 1 ELSE 0 END) as EpisodeFileCount,
COUNT (DISTINCT(CASE WHEN SeasonNumber = 0 THEN null ELSE SeasonNumber END)) as SeasonCount,
QualityProfiles.*
.Fetch<Series, QualityProfile>(@"SELECT Series.SeriesId, Series.Title, Series.CleanTitle, Series.Status, Series.Overview, Series.AirsDayOfWeek,Series.AirTimes,
Series.Language, Series.Path, Series.Monitored, Series.QualityProfileId, Series.SeasonFolder,
SUM(CASE WHEN Ignored = 0 THEN 1 ELSE 0 END) AS EpisodeCount,
SUM(CASE WHEN Episodes.Ignored = 0 AND Episodes.EpisodeFileId > 0 THEN 1 ELSE 0 END) as EpisodeFileCount,
MAX(Episodes.SeasonNumber) as SeasonCount,
QualityProfiles.QualityProfileId, QualityProfiles.Name, QualityProfiles.Cutoff, QualityProfiles.SonicAllowed
FROM Series
INNER JOIN QualityProfiles ON Series.QualityProfileId = QualityProfiles.QualityProfileId
JOIN Episodes ON Series.SeriesId = Episodes.SeriesId
GROUP BY seriesId");
LEFT JOIN Episodes ON Series.SeriesId = Episodes.SeriesId
GROUP BY Series.SeriesId, Series.Title, Series.CleanTitle, Series.Status, Series.Overview, Series.AirsDayOfWeek,Series.AirTimes,
Series.Language, Series.Path, Series.Monitored, Series.QualityProfileId, Series.SeasonFolder,
QualityProfiles.QualityProfileId, QualityProfiles.Name, QualityProfiles.Cutoff, QualityProfiles.SonicAllowed");
return series;
}

View file

@ -81,7 +81,7 @@ public ActionResult GetSingleSeasonView(SeasonEditModel model)
[GridAction]
public ActionResult _AjaxSeriesGrid()
{
var series = GetSeriesModels(_seriesProvider.GetAllSeriesWithEpisodeCount(true));
var series = GetSeriesModels(_seriesProvider.GetAllSeriesWithEpisodeCount());
return View(new GridModel(series));
}
@ -97,7 +97,7 @@ public ActionResult _SaveAjaxSeriesEditing(int id, string path, bool monitored,
_seriesProvider.UpdateSeries(oldSeries);
var series = GetSeriesModels(_seriesProvider.GetAllSeriesWithEpisodeCount(true));
var series = GetSeriesModels(_seriesProvider.GetAllSeriesWithEpisodeCount());
return View(new GridModel(series));
}
@ -237,6 +237,11 @@ private List<EpisodeModel> GetEpisodeModels(IList<Episode> episodesInDb)
episodeQuality = e.EpisodeFile.Quality.ToString();
}
var airDate = String.Empty;
if (e.AirDate != null)
airDate = e.AirDate.Value.ToShortDateString();
episodes.Add(new EpisodeModel
{
EpisodeId = e.EpisodeId,
@ -244,7 +249,7 @@ private List<EpisodeModel> GetEpisodeModels(IList<Episode> episodesInDb)
SeasonNumber = e.SeasonNumber,
Title = e.Title,
Overview = e.Overview,
AirDate = e.AirDate.Value,
AirDate = airDate,
Path = episodePath,
EpisodeFileId = episodeFileId,
Status = e.Status.ToString(),

View file

@ -13,8 +13,7 @@ public class EpisodeModel
public string Overview { get; set; }
public string Path { get; set; }
public String Status { get; set; }
public DateTime AirDate { get; set; }
public string AirDate { get; set; }
public String Quality { get; set; }
}
}

View file

@ -61,7 +61,7 @@
columns.Bound(c => c.EpisodeNumber).Width(0).Title("Episode");
columns.Bound(c => c.Title).Title("Title");
columns.Bound(c => c.AirDate).Format("{0:d}").Width(0);
columns.Bound(c => c.AirDate).Width(0);
columns.Bound(c => c.Quality).Width(0);
columns.Bound(c => c.Status).Width(0);
columns.Bound(o => o.EpisodeId).Title("")
@ -111,7 +111,7 @@
columns.Bound(c => c.EpisodeNumber).Width(10).Title("Episode");
columns.Bound(c => c.Title).Title("Title").Width(10000);
columns.Bound(c => c.AirDate).Format("{0:d}").Width(10);
columns.Bound(c => c.AirDate).Width(10);
columns.Bound(c => c.Quality).Width(10);
columns.Bound(c => c.Status).Width(10);
})