From f63fadfe3524b9b25bb52f8971c9aa100b7ee57f Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Fri, 27 Jan 2012 22:28:24 -0800 Subject: [PATCH] New: Blacklisting can now be toggled in History, preventing that Nzb from being downloaded again. --- .../ProviderTests/HistoryProviderTest.cs | 38 ++++++++++++++ NzbDrone.Core/Providers/HistoryProvider.cs | 5 ++ .../Content/Images/blacklist_false.png | Bin 0 -> 737 bytes .../Content/Images/blacklist_true.png | Bin 0 -> 977 bytes NzbDrone.Web/Controllers/HistoryController.cs | 13 ++++- NzbDrone.Web/Models/HistoryModel.cs | 1 + NzbDrone.Web/NzbDrone.Web.csproj | 2 + NzbDrone.Web/Views/History/Index.cshtml | 49 +++++++++++++++++- 8 files changed, 105 insertions(+), 3 deletions(-) create mode 100644 NzbDrone.Web/Content/Images/blacklist_false.png create mode 100644 NzbDrone.Web/Content/Images/blacklist_true.png diff --git a/NzbDrone.Core.Test/ProviderTests/HistoryProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/HistoryProviderTest.cs index 777f425b0..54633acc4 100644 --- a/NzbDrone.Core.Test/ProviderTests/HistoryProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/HistoryProviderTest.cs @@ -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.CreateNew() + .With(h => h.Blacklisted = false) + .Build(); + + Db.Insert(history); + + //Act + Mocker.Resolve().SetBlacklist(history.HistoryId, true); + + //Assert + var result = Db.Single(history.HistoryId); + result.Blacklisted.Should().BeTrue(); + } + + [Test] + public void SetBlacklist_should_set_to_false_when_false_is_passed_in() + { + WithRealDb(); + + var history = Builder.CreateNew() + .With(h => h.Blacklisted = true) + .Build(); + + Db.Insert(history); + + //Act + Mocker.Resolve().SetBlacklist(history.HistoryId, false); + + //Assert + var result = Db.Single(history.HistoryId); + result.Blacklisted.Should().BeFalse(); + } } } \ No newline at end of file diff --git a/NzbDrone.Core/Providers/HistoryProvider.cs b/NzbDrone.Core/Providers/HistoryProvider.cs index 667ad35ac..b8663b70e 100644 --- a/NzbDrone.Core/Providers/HistoryProvider.cs +++ b/NzbDrone.Core/Providers/HistoryProvider.cs @@ -78,5 +78,10 @@ namespace NzbDrone.Core.Providers { return _database.Exists("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); + } } } \ No newline at end of file diff --git a/NzbDrone.Web/Content/Images/blacklist_false.png b/NzbDrone.Web/Content/Images/blacklist_false.png new file mode 100644 index 0000000000000000000000000000000000000000..39a1bfeceeafdcfdb8849bbb20cf7f84ffec8278 GIT binary patch literal 737 zcmV<70v`Q|P)P`FnKYjV=ce{A-WL^DU7` zfWzScMNwd}Sip9>WtZD#GdP`2u-R;|TrQzdD8OJah@cZ+_0+(5Fc?(9kH=$mCN`T5 zkh82BjYs3s_=JP-+@`axA`W}KUYO74OlN(c(fEXe@DMJ&4oDQb)oNu3rXd_wtI9WS z-7It$N+XyS4(lNu<#IVDfGPUPWb(Lm;MB9Pcl?7QkV>WaS&4bsBR$={5HAsUx(@8K zd_K>NM&t4LGpEsg9nkL7XbuP#5)O!k>^Y@Su~=jS3SVBL(WpqFd%wkEF}@cv!9s$C zL<(^pfl{e-)L@ZFgzpr3j6M%~BMXPaqKJh9Vj+8EYcv|rZny905+rgQUBoOlaIIDg z(&@A+G5u|%)?~BUnc*Wqx)?>k?fzHGsMTt8_-yD1s6~l0Pm0W)CPy}zOrTz`)9IyN z2S$pbNVl>MQzJ#xVzHsugT8o1mgVnyLudlDas_r)@q2l8sR^|!5<=2agi;X=z zJPaZtA{uV2b@0EkV7ItJ!-gsaTid%Y54ZDIo9Ep*@!|7xf3~o&Fg89uJ~lPAUrTq? z|Nm$B=f}t9hu`1d=Xvwy4NqNN9ZyqJQ=W19xjVgU_!Jrnc4~Y+)XJT3{PV|;jm}Lo zXG+Q#e>tS^+u>W&8}^;dPvkO++!z@cTTU~tdw+j_`hzD=mSnF;)=h2r)_jMti2p?F zi%%fg(mxAUBqt|Ji>UIRkgfmshtaU|!czvO4%X>v5g~kR4d-Qnq2bi!xNzaZl0pNG zZ{|5S9HvA8y{vfrI&5}@PV9VtZ;AUXTII+DIL>^~wVBoFf zXJ8TVoM~ZTFd^^gi)p&i9YNdz4$k`|SUD6X*)U|y(;G~SBy%&0>jYg#w8PtCyvHO8!Rma9z1=T z8W0}NZn*lwRc01}bv}OtO^iLyd)i8{-TeLief$P?V0w|*v15nCnX_jd|J(tlwY_fT z8V(E(KOL}RWMtgcZl`krnBtByY20mo*3oEqfu-b+NKO?46UTJ+W!hR=O}tCg1%!l> zDt>>{wRqCn+A6tb%^HaxKYzY%>|1|)DZ4_$hjUk$yVt$iUH;yv=Fg9b53jF}FVS>z zoGCsfXUUQ!4z8I>7d~=NxC&0L1yu|z4f6_;9M(*ouprnahV{`_hdYcVf67ZdOTGic h@NqzV9zApUz~{dF9Bvh22WQ%mvv4FO#n~Ff!Y87 literal 0 HcmV?d00001 diff --git a/NzbDrone.Web/Controllers/HistoryController.cs b/NzbDrone.Web/Controllers/HistoryController.cs index f742f4804..ee0ea089a 100644 --- a/NzbDrone.Web/Controllers/HistoryController.cs +++ b/NzbDrone.Web/Controllers/HistoryController.cs @@ -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" }; + } } } \ No newline at end of file diff --git a/NzbDrone.Web/Models/HistoryModel.cs b/NzbDrone.Web/Models/HistoryModel.cs index 1bb6cbd25..e95452388 100644 --- a/NzbDrone.Web/Models/HistoryModel.cs +++ b/NzbDrone.Web/Models/HistoryModel.cs @@ -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; } } } \ No newline at end of file diff --git a/NzbDrone.Web/NzbDrone.Web.csproj b/NzbDrone.Web/NzbDrone.Web.csproj index cecff258d..f13ce7724 100644 --- a/NzbDrone.Web/NzbDrone.Web.csproj +++ b/NzbDrone.Web/NzbDrone.Web.csproj @@ -141,6 +141,8 @@ + + diff --git a/NzbDrone.Web/Views/History/Index.cshtml b/NzbDrone.Web/Views/History/Index.cshtml index 497acf2de..fb5162c4f 100644 --- a/NzbDrone.Web/Views/History/Index.cshtml +++ b/NzbDrone.Web/Views/History/Index.cshtml @@ -11,6 +11,20 @@ @section HeaderContent { @Html.IncludeCss("Grid.css") + + }
@{Html.Telerik().Grid().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("" + + 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 @@