2012-01-19 08:01:47 +03:00
|
|
|
using System.Linq;
|
2011-03-23 07:19:23 +02:00
|
|
|
using System.Web.Mvc;
|
2012-02-09 03:26:34 +03:00
|
|
|
using System.Web.Script.Serialization;
|
2011-12-02 04:33:17 +03:00
|
|
|
using NzbDrone.Core.Jobs;
|
2011-03-23 07:19:23 +02:00
|
|
|
using NzbDrone.Core.Providers;
|
|
|
|
using NzbDrone.Web.Models;
|
|
|
|
|
|
|
|
namespace NzbDrone.Web.Controllers
|
|
|
|
{
|
|
|
|
public class HistoryController : Controller
|
|
|
|
{
|
2011-04-10 05:44:01 +03:00
|
|
|
private readonly HistoryProvider _historyProvider;
|
2011-08-27 03:59:51 +03:00
|
|
|
private readonly JobProvider _jobProvider;
|
2011-03-23 07:19:23 +02:00
|
|
|
|
2011-08-27 03:59:51 +03:00
|
|
|
public HistoryController(HistoryProvider historyProvider, JobProvider jobProvider)
|
2011-03-23 07:19:23 +02:00
|
|
|
{
|
|
|
|
_historyProvider = historyProvider;
|
2011-08-27 03:59:51 +03:00
|
|
|
_jobProvider = jobProvider;
|
2011-03-23 07:19:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public ActionResult Index()
|
2012-02-11 08:00:22 +03:00
|
|
|
{
|
|
|
|
return View();
|
|
|
|
}
|
|
|
|
|
|
|
|
public JsonResult AjaxBinding()
|
2011-03-23 07:19:23 +02:00
|
|
|
{
|
2012-02-08 11:17:40 +03:00
|
|
|
var history = _historyProvider.AllItemsWithRelationships().Select(h => new HistoryModel
|
|
|
|
{
|
|
|
|
HistoryId = h.HistoryId,
|
|
|
|
SeriesId = h.SeriesId,
|
2012-02-09 03:26:34 +03:00
|
|
|
EpisodeNumbering = string.Format("{0}x{1:00}", h.Episode.SeasonNumber, h.Episode.EpisodeNumber),
|
2012-02-08 11:17:40 +03:00
|
|
|
EpisodeTitle = h.Episode.Title,
|
|
|
|
EpisodeOverview = h.Episode.Overview,
|
|
|
|
SeriesTitle = h.SeriesTitle,
|
|
|
|
NzbTitle = h.NzbTitle,
|
|
|
|
Quality = h.Quality.ToString(),
|
|
|
|
IsProper = h.IsProper,
|
2012-02-09 03:26:34 +03:00
|
|
|
Date = h.Date.ToString(),
|
2012-02-14 21:48:13 +03:00
|
|
|
DateSorter = h.Date.ToString("MM/dd/yyyy h:mm:ss tt"),
|
2012-02-08 11:17:40 +03:00
|
|
|
Indexer = h.Indexer,
|
|
|
|
EpisodeId = h.EpisodeId
|
2012-02-09 03:26:34 +03:00
|
|
|
}).OrderByDescending(h => h.Date).ToList();
|
2012-02-08 11:17:40 +03:00
|
|
|
|
2012-02-11 08:00:22 +03:00
|
|
|
return Json(new
|
|
|
|
{
|
|
|
|
aaData = history
|
|
|
|
},
|
|
|
|
JsonRequestBehavior.AllowGet);
|
2011-03-23 07:19:23 +02:00
|
|
|
}
|
|
|
|
|
2011-08-06 05:04:35 +03:00
|
|
|
public JsonResult Trim()
|
2011-03-23 07:19:23 +02:00
|
|
|
{
|
|
|
|
_historyProvider.Trim();
|
2012-01-19 08:01:47 +03:00
|
|
|
return JsonNotificationResult.Info("Trimmed History");
|
2011-03-23 07:19:23 +02:00
|
|
|
}
|
|
|
|
|
2011-08-06 05:04:35 +03:00
|
|
|
public JsonResult Purge()
|
2011-03-23 07:19:23 +02:00
|
|
|
{
|
|
|
|
_historyProvider.Purge();
|
2012-01-19 08:01:47 +03:00
|
|
|
return JsonNotificationResult.Info("History Cleared");
|
2011-03-23 07:19:23 +02:00
|
|
|
}
|
|
|
|
|
2011-08-27 03:59:51 +03:00
|
|
|
[HttpPost]
|
|
|
|
public JsonResult Delete(int historyId)
|
|
|
|
{
|
|
|
|
//Delete the existing item from history
|
|
|
|
_historyProvider.Delete(historyId);
|
|
|
|
|
2012-01-19 08:01:47 +03:00
|
|
|
return JsonNotificationResult.Info("History Item Deleted");
|
2011-08-27 03:59:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
public JsonResult Redownload(int historyId, int episodeId)
|
|
|
|
{
|
|
|
|
//Delete the existing item from history
|
|
|
|
_historyProvider.Delete(historyId);
|
|
|
|
|
|
|
|
//Queue a job to download the replacement episode
|
|
|
|
_jobProvider.QueueJob(typeof(EpisodeSearchJob), episodeId);
|
|
|
|
|
2012-01-19 08:01:47 +03:00
|
|
|
return JsonNotificationResult.Info("Episode Redownload Started");
|
2011-08-27 03:59:51 +03:00
|
|
|
}
|
2011-03-23 07:19:23 +02:00
|
|
|
}
|
2011-04-10 05:44:01 +03:00
|
|
|
}
|