diff --git a/src/NzbDrone.Api/History/HistoryModule.cs b/src/NzbDrone.Api/History/HistoryModule.cs index 85b3f6135..405caae93 100644 --- a/src/NzbDrone.Api/History/HistoryModule.cs +++ b/src/NzbDrone.Api/History/HistoryModule.cs @@ -1,7 +1,10 @@ using System; -using System.Collections.Generic; -using NzbDrone.Api.Mapping; +using Nancy; +using Nancy.ModelBinding; +using NzbDrone.Api.Extensions; +using NzbDrone.Common.Serializer; using NzbDrone.Core.Datastore; +using NzbDrone.Core.Download; using NzbDrone.Core.History; namespace NzbDrone.Api.History @@ -9,11 +12,15 @@ namespace NzbDrone.Api.History public class HistoryModule : NzbDroneRestModule { private readonly IHistoryService _historyService; + private readonly IFailedDownloadService _failedDownloadService; - public HistoryModule(IHistoryService historyService) + public HistoryModule(IHistoryService historyService, IFailedDownloadService failedDownloadService) { _historyService = historyService; + _failedDownloadService = failedDownloadService; GetResourcePaged = GetHistory; + + Post["/failed"] = x => MarkAsFailed(); } private PagingResource GetHistory(PagingResource pagingResource) @@ -36,5 +43,12 @@ namespace NzbDrone.Api.History return ApplyToPage(_historyService.Paged, pagingSpec); } + + private Response MarkAsFailed() + { + var id = (int)Request.Form.Id; + _failedDownloadService.MarkAsFailed(id); + return new Object().AsResponse(); + } } } \ No newline at end of file diff --git a/src/NzbDrone.Core/Download/FailedDownloadService.cs b/src/NzbDrone.Core/Download/FailedDownloadService.cs index 59cbb5bd2..40048652a 100644 --- a/src/NzbDrone.Core/Download/FailedDownloadService.cs +++ b/src/NzbDrone.Core/Download/FailedDownloadService.cs @@ -9,7 +9,12 @@ using NzbDrone.Core.Messaging.Events; namespace NzbDrone.Core.Download { - public class FailedDownloadService : IExecute + public interface IFailedDownloadService + { + void MarkAsFailed(int historyId); + } + + public class FailedDownloadService : IFailedDownloadService, IExecute { private readonly IProvideDownloadClient _downloadClientProvider; private readonly IHistoryService _historyService; @@ -37,6 +42,12 @@ namespace NzbDrone.Core.Download _downloadClient = _downloadClientProvider.GetDownloadClient(); } + public void MarkAsFailed(int historyId) + { + var item = _historyService.Get(historyId); + PublishDownloadFailedEvent(new List {item}, "Manually marked as failed"); + } + private void CheckForFailedDownloads() { if (!_configService.EnableFailedDownloadHandling) diff --git a/src/NzbDrone.Core/History/HistoryService.cs b/src/NzbDrone.Core/History/HistoryService.cs index e738393db..7fbb737af 100644 --- a/src/NzbDrone.Core/History/HistoryService.cs +++ b/src/NzbDrone.Core/History/HistoryService.cs @@ -22,6 +22,7 @@ namespace NzbDrone.Core.History List Failed(); List Grabbed(); History MostRecentForEpisode(int episodeId); + History Get(int id); } public class HistoryService : IHistoryService, IHandle, IHandle, IHandle @@ -65,6 +66,11 @@ namespace NzbDrone.Core.History return _historyRepository.MostRecentForEpisode(episodeId); } + public History Get(int id) + { + return _historyRepository.Get(id); + } + public void Purge() { _historyRepository.Purge(); diff --git a/src/UI/History/Details/HistoryDetailsView.js b/src/UI/History/Details/HistoryDetailsView.js index b7c8e1a9d..c1470cb46 100644 --- a/src/UI/History/Details/HistoryDetailsView.js +++ b/src/UI/History/Details/HistoryDetailsView.js @@ -1,10 +1,30 @@ 'use strict'; define( [ - 'marionette' - ], function (Marionette) { + 'vent', + 'marionette', + 'jquery' + ], function (vent, Marionette, $) { return Marionette.ItemView.extend({ - template: 'History/Details/HistoryDetailsViewTemplate' + template: 'History/Details/HistoryDetailsViewTemplate', + + events: { + 'click .x-mark-as-failed': '_markAsFailed' + }, + + _markAsFailed: function () { + var url = window.NzbDrone.ApiRoot + '/history/failed'; + var data = { + id: this.model.get('id') + }; + + $.ajax({ + url: url, + type: 'POST', + data: data + }); + vent.trigger(vent.Commands.CloseModalCommand); + } }); }); diff --git a/src/UI/History/Details/HistoryDetailsViewTemplate.html b/src/UI/History/Details/HistoryDetailsViewTemplate.html index 0dc280370..9e2a1433e 100644 --- a/src/UI/History/Details/HistoryDetailsViewTemplate.html +++ b/src/UI/History/Details/HistoryDetailsViewTemplate.html @@ -63,6 +63,7 @@ {{/if_eq}}