mirror of
https://github.com/lidarr/Lidarr
synced 2024-12-24 16:51:58 +00:00
AJax load episode count to keep initial loading time of Series Grid.
This commit is contained in:
parent
681353de3c
commit
467ed51432
2 changed files with 36 additions and 11 deletions
|
@ -133,6 +133,21 @@ public ActionResult _AjaxSeasonGrid(int seasonId)
|
|||
return View(new GridModel(episodes));
|
||||
}
|
||||
|
||||
public JsonResult GetEpisodeCount(int seriesId)
|
||||
{
|
||||
var series = _seriesProvider.GetSeries(seriesId);
|
||||
|
||||
var monitoredSeasons = series.Seasons.Where(e => e.Monitored).Select(e => e.SeasonId);
|
||||
var episodeTotal = series.Episodes.Where(e => monitoredSeasons.Contains(e.SeasonId) && e.AirDate <= DateTime.Today && e.AirDate > new DateTime(1899, 12, 31));
|
||||
var episodes = episodeTotal.Where(e => e.EpisodeFileId > 0);
|
||||
|
||||
return Json(new
|
||||
{
|
||||
Episodes = episodes.Count(),
|
||||
EpisodeTotal = episodeTotal.Count()
|
||||
}, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
//Local Helpers
|
||||
private string GetEpisodePath(EpisodeFile file)
|
||||
{
|
||||
|
@ -237,8 +252,6 @@ private List<SeriesModel> GetSeriesModels(List<Series> seriesInDb)
|
|||
|
||||
foreach (var s in seriesInDb)
|
||||
{
|
||||
var episodesTotal = s.Episodes.Where(e => e.AirDate <= DateTime.Today && e.AirDate > new DateTime(1899, 12, 31));
|
||||
|
||||
series.Add(new SeriesModel
|
||||
{
|
||||
SeriesId = s.SeriesId,
|
||||
|
@ -252,8 +265,8 @@ private List<SeriesModel> GetSeriesModels(List<Series> seriesInDb)
|
|||
SeasonsCount = s.Seasons.Where(x => x.SeasonNumber > 0).Count(),
|
||||
SeasonFolder = s.SeasonFolder,
|
||||
Status = s.Status,
|
||||
Episodes = episodesTotal.Where(e => e.EpisodeFileId != 0).Count(),
|
||||
EpisodeTotal = episodesTotal.Count()
|
||||
Episodes = 0,
|
||||
EpisodeTotal = 0
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -265,7 +278,7 @@ private string GetSeasonString(int seasonNumber)
|
|||
if (seasonNumber == 0)
|
||||
return "Specials";
|
||||
|
||||
return String.Format("Season# {0}", seasonNumber);
|
||||
return String.Format("Season #{0}", seasonNumber);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -151,13 +151,25 @@
|
|||
}
|
||||
|
||||
function grid_rowBound(e) {
|
||||
var data = e.dataItem;
|
||||
var dataItem = e.dataItem;
|
||||
var seriesId = dataItem.SeriesId;
|
||||
var getEpisodeCountUrl = '@Url.Action("GetEpisodeCount", "Series")';
|
||||
|
||||
var seriesId = data.SeriesId;
|
||||
var episodes = data.Episodes;
|
||||
var episodeTotal = data.EpisodeTotal;
|
||||
$("#progressbar_" + seriesId).episodeProgress(0, 0);
|
||||
|
||||
$("#progressbar_" + seriesId).episodeProgress(episodes, episodeTotal);
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: getEpisodeCountUrl,
|
||||
data: jQuery.param({ seriesId: seriesId }),
|
||||
error: function (req, status, error) {
|
||||
alert("Sorry! We could search for " + id + " at this time. " + error);
|
||||
},
|
||||
success: function (data, textStatus, jqXHR) {
|
||||
var episodes = data.Episodes;
|
||||
var episodeTotal = data.EpisodeTotal;
|
||||
$("#progressbar_" + seriesId).episodeProgress(episodes, episodeTotal);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue