Added delete and redownload commands to History Grid (redownload will delete the existing item from history and then start an episode search)

pull/7/merge
Mark McDowall 13 years ago
parent 1d983801e8
commit ac3c3386fc

@ -63,5 +63,10 @@ namespace NzbDrone.Core.Providers
return history.FirstOrDefault();
}
public virtual void Delete(int historyId)
{
_database.Delete<History>(historyId);
}
}
}

@ -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));

@ -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; }
}
}

@ -9,6 +9,25 @@ History
<li>@Ajax.ActionLink("Purge History", "Purge", "History", new AjaxOptions { OnSuccess = "reloadHistoryGrid"})</li>
</ul>
}
<style>
.searchImage
{
width: 18px;
height: 18px;
padding: 1px;
margin: 2px;
@*border-width: 1px;
border-style: dashed;
border-color: lightgray;*@
}
.searchImage:hover
{
background-color: #065EFE;
}
</style>
@section MainContent{
<div class="grid-container">
@{Html.Telerik().Grid<HistoryModel>().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("<a href=\"../History/Delete?historyId=<#= HistoryId #>\" onclick=\"deleteHistoryRow(<#= HistoryId #>); return false;\"><img src='../../Content/Images/X.png' alt='Delete' title='Delete from History' class='searchImage' /></a>" +
"<a href=\"../History/Redownload?historyId=<#= HistoryId #>&episodeId=<#= EpisodeId #>\" onclick=\"redownload(<#= HistoryId #>, <#= EpisodeId #>); return false;\"><img src='../../Content/Images/Downloading.png' alt='Redownload' title='Redownload Episode' class='searchImage' /></a>")
.Width("40");
})
.DetailView(detailView => detailView.ClientTemplate(
"<fieldset>" +
@ -43,10 +67,33 @@ History
}
<script type="text/javascript">
deleteHistoryRowUrl = '../History/Delete';
redownloadUrl = '../History/Redownload';
function reloadHistoryGrid() {
var grid = $('#history').data('tGrid');
grid.rebind();
}
var grid = $('#history').data('tGrid');
grid.rebind();
}
function deleteHistoryRow(historyId) {
$.ajax({
type: "POST",
url: deleteHistoryRowUrl,
data: jQuery.param({ historyId: historyId }),
success: function () {
reloadHistoryGrid();
}
});
}
function redownload(historyId, episodeId) {
$.ajax({
type: "POST",
url: redownloadUrl,
data: jQuery.param({ historyId: historyId, episodeId: episodeId }),
success: function () {
reloadHistoryGrid();
}
});
}
</script>
Loading…
Cancel
Save