From ac3c3386fce14e2e9aa69f644caf4cb23fd87464 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Fri, 26 Aug 2011 17:59:51 -0700 Subject: [PATCH] Added delete and redownload commands to History Grid (redownload will delete the existing item from history and then start an episode search) --- NzbDrone.Core/Providers/HistoryProvider.cs | 5 ++ NzbDrone.Web/Controllers/HistoryController.cs | 29 +++++++++- NzbDrone.Web/Models/HistoryModel.cs | 1 + NzbDrone.Web/Views/History/Index.cshtml | 53 +++++++++++++++++-- 4 files changed, 83 insertions(+), 5 deletions(-) diff --git a/NzbDrone.Core/Providers/HistoryProvider.cs b/NzbDrone.Core/Providers/HistoryProvider.cs index 98a1ab883..14e17231e 100644 --- a/NzbDrone.Core/Providers/HistoryProvider.cs +++ b/NzbDrone.Core/Providers/HistoryProvider.cs @@ -63,5 +63,10 @@ namespace NzbDrone.Core.Providers return history.FirstOrDefault(); } + + public virtual void Delete(int historyId) + { + _database.Delete(historyId); + } } } \ No newline at end of file diff --git a/NzbDrone.Web/Controllers/HistoryController.cs b/NzbDrone.Web/Controllers/HistoryController.cs index 4dd2c3141..a1b7527b2 100644 --- a/NzbDrone.Web/Controllers/HistoryController.cs +++ b/NzbDrone.Web/Controllers/HistoryController.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Web.Mvc; using NzbDrone.Core.Model; using NzbDrone.Core.Providers; +using NzbDrone.Core.Providers.Jobs; using NzbDrone.Web.Models; using Telerik.Web.Mvc; @@ -12,10 +13,12 @@ namespace NzbDrone.Web.Controllers public class HistoryController : Controller { private readonly HistoryProvider _historyProvider; + private readonly JobProvider _jobProvider; - public HistoryController(HistoryProvider historyProvider) + public HistoryController(HistoryProvider historyProvider, JobProvider jobProvider) { _historyProvider = historyProvider; + _jobProvider = jobProvider; } // @@ -38,6 +41,27 @@ namespace NzbDrone.Web.Controllers return Json(new NotificationResult() { Title = "History Cleared" }); } + [HttpPost] + public JsonResult Delete(int historyId) + { + //Delete the existing item from history + _historyProvider.Delete(historyId); + + return Json(new NotificationResult() { Title = "History Item Deleted" }); + } + + [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); + + return Json(new NotificationResult() { Title = "Episode Redownload Started" }); + } + [GridAction] public ActionResult _AjaxBinding() { @@ -53,7 +77,8 @@ namespace NzbDrone.Web.Controllers Quality = h.Quality.ToString(), IsProper = h.IsProper, Date = h.Date, - Indexer = h.Indexer + Indexer = h.Indexer, + EpisodeId = h.EpisodeId }); return View(new GridModel(history)); diff --git a/NzbDrone.Web/Models/HistoryModel.cs b/NzbDrone.Web/Models/HistoryModel.cs index 3a87cb8df..f29a51f6f 100644 --- a/NzbDrone.Web/Models/HistoryModel.cs +++ b/NzbDrone.Web/Models/HistoryModel.cs @@ -16,5 +16,6 @@ namespace NzbDrone.Web.Models public DateTime Date { get; set; } public bool IsProper { get; set; } public string Indexer { get; set; } + public int EpisodeId { get; set; } } } \ No newline at end of file diff --git a/NzbDrone.Web/Views/History/Index.cshtml b/NzbDrone.Web/Views/History/Index.cshtml index d5c124124..392bb0ce0 100644 --- a/NzbDrone.Web/Views/History/Index.cshtml +++ b/NzbDrone.Web/Views/History/Index.cshtml @@ -9,6 +9,25 @@ History
  • @Ajax.ActionLink("Purge History", "Purge", "History", new AjaxOptions { OnSuccess = "reloadHistoryGrid"})
  • } + + + @section MainContent{
    @{Html.Telerik().Grid().Name("history") @@ -25,6 +44,11 @@ History columns.Bound(c => c.EpisodeTitle).Title("Episode Title"); columns.Bound(c => c.Quality).Title("Quality").Width(50); columns.Bound(c => c.Date).Title("Grabbed on"); + columns.Bound(c => c.HistoryId) + .Title("Actions") + .ClientTemplate("\" onclick=\"deleteHistoryRow(<#= HistoryId #>); return false;\">Delete" + + "&episodeId=<#= EpisodeId #>\" onclick=\"redownload(<#= HistoryId #>, <#= EpisodeId #>); return false;\">Redownload") + .Width("40"); }) .DetailView(detailView => detailView.ClientTemplate( "
    " + @@ -43,10 +67,33 @@ History } \ No newline at end of file