2012-07-28 06:37:47 +00:00
|
|
|
|
using System;
|
2012-12-06 01:54:09 +00:00
|
|
|
|
using System.Globalization;
|
2012-07-28 06:37:47 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Linq.Dynamic;
|
2011-03-23 05:19:23 +00:00
|
|
|
|
using System.Web.Mvc;
|
2012-02-09 00:26:34 +00:00
|
|
|
|
using System.Web.Script.Serialization;
|
2012-07-28 06:37:47 +00:00
|
|
|
|
using DataTables.Mvc.Core.Models;
|
2012-02-27 04:47:49 +00:00
|
|
|
|
using NzbDrone.Core.Helpers;
|
2011-12-02 01:33:17 +00:00
|
|
|
|
using NzbDrone.Core.Jobs;
|
2011-03-23 05:19:23 +00:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2012-12-21 05:36:48 +00:00
|
|
|
|
using NzbDrone.Core.Providers.Core;
|
2011-03-23 05:19:23 +00:00
|
|
|
|
using NzbDrone.Web.Models;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Web.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class HistoryController : Controller
|
|
|
|
|
{
|
2011-04-10 02:44:01 +00:00
|
|
|
|
private readonly HistoryProvider _historyProvider;
|
2011-08-27 00:59:51 +00:00
|
|
|
|
private readonly JobProvider _jobProvider;
|
2012-12-21 05:36:48 +00:00
|
|
|
|
private readonly ConfigProvider _configProvider;
|
2011-03-23 05:19:23 +00:00
|
|
|
|
|
2012-12-21 05:36:48 +00:00
|
|
|
|
public HistoryController(HistoryProvider historyProvider, JobProvider jobProvider,
|
|
|
|
|
ConfigProvider configProvider)
|
2011-03-23 05:19:23 +00:00
|
|
|
|
{
|
|
|
|
|
_historyProvider = historyProvider;
|
2011-08-27 00:59:51 +00:00
|
|
|
|
_jobProvider = jobProvider;
|
2012-12-21 05:36:48 +00:00
|
|
|
|
_configProvider = configProvider;
|
2011-03-23 05:19:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult Index()
|
2012-02-11 05:00:22 +00:00
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-28 06:37:47 +00:00
|
|
|
|
public ActionResult AjaxBinding(DataTablesPageRequest pageRequest)
|
2011-03-23 05:19:23 +00:00
|
|
|
|
{
|
2012-07-28 06:37:47 +00:00
|
|
|
|
var pageResult = _historyProvider.GetPagedItems(pageRequest);
|
|
|
|
|
var totalItems = _historyProvider.Count();
|
2012-12-21 05:36:48 +00:00
|
|
|
|
var ignoreArticles = _configProvider.IgnoreArticlesWhenSortingSeries;
|
2012-07-28 06:37:47 +00:00
|
|
|
|
|
|
|
|
|
var items = pageResult.Items.Select(h => new HistoryModel
|
2012-02-08 08:17:40 +00:00
|
|
|
|
{
|
|
|
|
|
HistoryId = h.HistoryId,
|
|
|
|
|
SeriesId = h.SeriesId,
|
2012-07-28 06:37:47 +00:00
|
|
|
|
EpisodeNumbering = string.Format("{0}x{1:00}", h.SeasonNumber, h.EpisodeNumber),
|
|
|
|
|
EpisodeTitle = h.EpisodeTitle,
|
|
|
|
|
EpisodeOverview = h.EpisodeOverview,
|
2012-02-08 08:17:40 +00:00
|
|
|
|
SeriesTitle = h.SeriesTitle,
|
2012-12-21 05:36:48 +00:00
|
|
|
|
SeriesTitleSorter = ignoreArticles ? h.SeriesTitle.IgnoreArticles() : h.SeriesTitle,
|
2012-02-08 08:17:40 +00:00
|
|
|
|
NzbTitle = h.NzbTitle,
|
|
|
|
|
Quality = h.Quality.ToString(),
|
|
|
|
|
IsProper = h.IsProper,
|
2012-02-09 00:26:34 +00:00
|
|
|
|
Date = h.Date.ToString(),
|
2012-12-06 01:54:09 +00:00
|
|
|
|
DateSorter = h.Date.ToString("o", CultureInfo.InvariantCulture),
|
2012-02-08 08:17:40 +00:00
|
|
|
|
Indexer = h.Indexer,
|
2012-05-02 22:42:21 +00:00
|
|
|
|
EpisodeId = h.EpisodeId,
|
2012-08-07 23:46:23 +00:00
|
|
|
|
NzbInfoUrl = h.NzbInfoUrl,
|
|
|
|
|
ReleaseGroup = h.ReleaseGroup
|
2012-07-28 06:37:47 +00:00
|
|
|
|
});
|
2012-02-08 08:17:40 +00:00
|
|
|
|
|
2012-02-11 05:00:22 +00:00
|
|
|
|
return Json(new
|
|
|
|
|
{
|
2012-07-28 06:37:47 +00:00
|
|
|
|
sEcho = pageRequest.Echo,
|
|
|
|
|
iTotalRecords = totalItems,
|
|
|
|
|
iTotalDisplayRecords = pageResult.TotalItems,
|
|
|
|
|
aaData = items
|
2012-02-11 05:00:22 +00:00
|
|
|
|
},
|
|
|
|
|
JsonRequestBehavior.AllowGet);
|
2011-03-23 05:19:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-06 02:04:35 +00:00
|
|
|
|
public JsonResult Trim()
|
2011-03-23 05:19:23 +00:00
|
|
|
|
{
|
|
|
|
|
_historyProvider.Trim();
|
2012-01-19 05:01:47 +00:00
|
|
|
|
return JsonNotificationResult.Info("Trimmed History");
|
2011-03-23 05:19:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-06 02:04:35 +00:00
|
|
|
|
public JsonResult Purge()
|
2011-03-23 05:19:23 +00:00
|
|
|
|
{
|
|
|
|
|
_historyProvider.Purge();
|
2012-01-19 05:01:47 +00:00
|
|
|
|
return JsonNotificationResult.Info("History Cleared");
|
2011-03-23 05:19:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-27 00:59:51 +00:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public JsonResult Delete(int historyId)
|
|
|
|
|
{
|
|
|
|
|
//Delete the existing item from history
|
|
|
|
|
_historyProvider.Delete(historyId);
|
|
|
|
|
|
2012-01-19 05:01:47 +00:00
|
|
|
|
return JsonNotificationResult.Info("History Item Deleted");
|
2011-08-27 00:59:51 +00: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
|
2012-10-20 04:36:47 +00:00
|
|
|
|
_jobProvider.QueueJob(typeof(EpisodeSearchJob), new { EpisodeId = episodeId });
|
2011-08-27 00:59:51 +00:00
|
|
|
|
|
2012-02-26 21:47:04 +00:00
|
|
|
|
return JsonNotificationResult.Queued("Episode search");
|
2011-08-27 00:59:51 +00:00
|
|
|
|
}
|
2011-03-23 05:19:23 +00:00
|
|
|
|
}
|
2011-04-10 02:44:01 +00:00
|
|
|
|
}
|