AJax load episode count to keep initial loading time of Series Grid.

pull/2/head
Mark McDowall 14 years ago
parent 681353de3c
commit 467ed51432

@ -133,6 +133,21 @@ namespace NzbDrone.Web.Controllers
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 @@ namespace NzbDrone.Web.Controllers
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 @@ namespace NzbDrone.Web.Controllers
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 @@ namespace NzbDrone.Web.Controllers
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 seriesId = data.SeriesId;
var episodes = data.Episodes;
var episodeTotal = data.EpisodeTotal;
$("#progressbar_" + seriesId).episodeProgress(episodes, episodeTotal);
var dataItem = e.dataItem;
var seriesId = dataItem.SeriesId;
var getEpisodeCountUrl = '@Url.Action("GetEpisodeCount", "Series")';
$("#progressbar_" + seriesId).episodeProgress(0, 0);
$.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…
Cancel
Save