New: Blacklisting can now be toggled in History, preventing that Nzb from being downloaded again.

This commit is contained in:
Mark McDowall 2012-01-27 22:28:24 -08:00
parent 51bec56741
commit f63fadfe35
8 changed files with 105 additions and 3 deletions

View File

@ -299,5 +299,43 @@ namespace NzbDrone.Core.Test.ProviderTests
//Assert
result.Should().BeTrue();
}
[Test]
public void SetBlacklist_should_set_to_true_when_true_is_passed_in()
{
WithRealDb();
var history = Builder<History>.CreateNew()
.With(h => h.Blacklisted = false)
.Build();
Db.Insert(history);
//Act
Mocker.Resolve<HistoryProvider>().SetBlacklist(history.HistoryId, true);
//Assert
var result = Db.Single<History>(history.HistoryId);
result.Blacklisted.Should().BeTrue();
}
[Test]
public void SetBlacklist_should_set_to_false_when_false_is_passed_in()
{
WithRealDb();
var history = Builder<History>.CreateNew()
.With(h => h.Blacklisted = true)
.Build();
Db.Insert(history);
//Act
Mocker.Resolve<HistoryProvider>().SetBlacklist(history.HistoryId, false);
//Assert
var result = Db.Single<History>(history.HistoryId);
result.Blacklisted.Should().BeFalse();
}
}
}

View File

@ -78,5 +78,10 @@ namespace NzbDrone.Core.Providers
{
return _database.Exists<History>("WHERE Blacklisted = 1 AND NewzbinId = @0", newzbinId);
}
public virtual void SetBlacklist(int historyId, bool toggle)
{
_database.Execute("UPDATE History SET Blacklisted = @0 WHERE HistoryId = @1", toggle, historyId);
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 737 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 977 B

View File

@ -1,4 +1,5 @@
using System.Linq;
using System;
using System.Linq;
using System.Web.Mvc;
using NzbDrone.Core.Jobs;
using NzbDrone.Core.Providers;
@ -73,10 +74,18 @@ namespace NzbDrone.Web.Controllers
IsProper = h.IsProper,
Date = h.Date,
Indexer = h.Indexer,
EpisodeId = h.EpisodeId
EpisodeId = h.EpisodeId,
Blacklisted = h.Blacklisted
});
return View(new GridModel(history));
}
[HttpPost]
public JsonResult ToggleBlacklist(int historyId, bool toggle)
{
_historyProvider.SetBlacklist(historyId, toggle);
return new JsonResult { Data = "Success" };
}
}
}

View File

@ -18,5 +18,6 @@ namespace NzbDrone.Web.Models
public bool IsProper { get; set; }
public string Indexer { get; set; }
public int EpisodeId { get; set; }
public bool Blacklisted { get; set; }
}
}

View File

@ -141,6 +141,8 @@
<Content Include="Content\2011.3.1115\telerik.metro.min.css" />
<Content Include="Content\2011.3.1115\telerik.sitefinity.min.css" />
<Content Include="Content\Images\background.jpg" />
<Content Include="Content\Images\blacklist_false.png" />
<Content Include="Content\Images\blacklist_true.png" />
<Content Include="Content\Images\blue.png" />
<Content Include="Content\Images\Gear.png" />
<Content Include="Content\Images\green.png" />

View File

@ -11,6 +11,20 @@
@section HeaderContent
{
@Html.IncludeCss("Grid.css")
<style>
.blacklist
{
width: 18px;
height: 18px;
padding: 1px;
margin: 2px;
}
.blacklist:hover
{
}
</style>
}
<div class="grid-container">
@{Html.Telerik().Grid<HistoryModel>().Name("history")
@ -33,7 +47,8 @@
columns.Bound(c => c.Date).Title("Grabbed on");
columns.Bound(c => c.HistoryId)
.Title("Actions")
.ClientTemplate(Ajax.ImageActionLink("../../Content/Images/X.png", new { Alt = "Delete", Title = "Delete from history", @class = "searchImage" }, "Delete", "History", new { HistoryId = "<#= HistoryId #>" }, new AjaxOptions { OnSuccess = "reloadHistoryGrid" }, null).ToString() +
.ClientTemplate("<img src='../../Content/Images/blacklist_<#= Blacklisted #>.png' class='blacklist blacklist_<#= Blacklisted #>' id='<#= HistoryId #>' title='Click to toggle blacklisting status' />" +
Ajax.ImageActionLink("../../Content/Images/X.png", new { Alt = "Delete", Title = "Delete from history", @class = "searchImage" }, "Delete", "History", new { HistoryId = "<#= HistoryId #>" }, new AjaxOptions { OnSuccess = "reloadHistoryGrid" }, null).ToString() +
Ajax.ImageActionLink("../../Content/Images/Downloading.png", new { Alt = "Redownload", Title = "Redownlod Episode", @class = "searchImage" }, "Redownload", "History", new { HistoryId = "<#= HistoryId #>", EpisodeId = "<#= EpisodeId #>" }, new AjaxOptions { OnSuccess = "reloadHistoryGrid" }, null).ToString())
.Width("40");
})
@ -54,9 +69,41 @@
<script type="text/javascript">
deleteHistoryRowUrl = '../History/Delete';
redownloadUrl = '../History/Redownload';
var toggleBlacklistUrl = '../History/ToggleBlacklist';
var blacklistedTrueImage = '../../Content/Images/blacklist_true.png';
var blacklistedFalseImage = '../../Content/Images/blacklist_false.png';
function reloadHistoryGrid() {
var grid = $('#history').data('tGrid');
grid.ajaxRequest();
}
$(".blacklist").live("click", function () {
var toggle = $(this);
var result = toggle.hasClass('blacklist_true');
var id = toggle.attr('id');
toggle.toggleClass('blacklist_true blacklist_false');
if (result) {
toggle.attr('src', blacklistedFalseImage);
toggleBlacklist(id, false);
}
else {
toggle.attr('src', blacklistedTrueImage);
toggleBlacklist(id, true);
}
});
function toggleBlacklist(historyId, toggle) {
$.ajax({
type: "POST",
url: toggleBlacklistUrl,
data: jQuery.param({ historyId: historyId, toggle: toggle }),
error: function (req, status, error) {
alert("Sorry! We could not toggle blacklist for History: " + historyId + " " + error);
}
});
}
</script>