Manually mark a release as failed to start failed download process (history details)

pull/4/head
Mark McDowall 11 years ago
parent 70127125c2
commit da0f04d4c8

@ -1,7 +1,10 @@
using System; using System;
using System.Collections.Generic; using Nancy;
using NzbDrone.Api.Mapping; using Nancy.ModelBinding;
using NzbDrone.Api.Extensions;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore;
using NzbDrone.Core.Download;
using NzbDrone.Core.History; using NzbDrone.Core.History;
namespace NzbDrone.Api.History namespace NzbDrone.Api.History
@ -9,11 +12,15 @@ namespace NzbDrone.Api.History
public class HistoryModule : NzbDroneRestModule<HistoryResource> public class HistoryModule : NzbDroneRestModule<HistoryResource>
{ {
private readonly IHistoryService _historyService; private readonly IHistoryService _historyService;
private readonly IFailedDownloadService _failedDownloadService;
public HistoryModule(IHistoryService historyService) public HistoryModule(IHistoryService historyService, IFailedDownloadService failedDownloadService)
{ {
_historyService = historyService; _historyService = historyService;
_failedDownloadService = failedDownloadService;
GetResourcePaged = GetHistory; GetResourcePaged = GetHistory;
Post["/failed"] = x => MarkAsFailed();
} }
private PagingResource<HistoryResource> GetHistory(PagingResource<HistoryResource> pagingResource) private PagingResource<HistoryResource> GetHistory(PagingResource<HistoryResource> pagingResource)
@ -36,5 +43,12 @@ namespace NzbDrone.Api.History
return ApplyToPage(_historyService.Paged, pagingSpec); return ApplyToPage(_historyService.Paged, pagingSpec);
} }
private Response MarkAsFailed()
{
var id = (int)Request.Form.Id;
_failedDownloadService.MarkAsFailed(id);
return new Object().AsResponse();
}
} }
} }

@ -9,7 +9,12 @@ using NzbDrone.Core.Messaging.Events;
namespace NzbDrone.Core.Download namespace NzbDrone.Core.Download
{ {
public class FailedDownloadService : IExecute<FailedDownloadCommand> public interface IFailedDownloadService
{
void MarkAsFailed(int historyId);
}
public class FailedDownloadService : IFailedDownloadService, IExecute<FailedDownloadCommand>
{ {
private readonly IProvideDownloadClient _downloadClientProvider; private readonly IProvideDownloadClient _downloadClientProvider;
private readonly IHistoryService _historyService; private readonly IHistoryService _historyService;
@ -37,6 +42,12 @@ namespace NzbDrone.Core.Download
_downloadClient = _downloadClientProvider.GetDownloadClient(); _downloadClient = _downloadClientProvider.GetDownloadClient();
} }
public void MarkAsFailed(int historyId)
{
var item = _historyService.Get(historyId);
PublishDownloadFailedEvent(new List<History.History> {item}, "Manually marked as failed");
}
private void CheckForFailedDownloads() private void CheckForFailedDownloads()
{ {
if (!_configService.EnableFailedDownloadHandling) if (!_configService.EnableFailedDownloadHandling)

@ -22,6 +22,7 @@ namespace NzbDrone.Core.History
List<History> Failed(); List<History> Failed();
List<History> Grabbed(); List<History> Grabbed();
History MostRecentForEpisode(int episodeId); History MostRecentForEpisode(int episodeId);
History Get(int id);
} }
public class HistoryService : IHistoryService, IHandle<EpisodeGrabbedEvent>, IHandle<EpisodeImportedEvent>, IHandle<DownloadFailedEvent> public class HistoryService : IHistoryService, IHandle<EpisodeGrabbedEvent>, IHandle<EpisodeImportedEvent>, IHandle<DownloadFailedEvent>
@ -65,6 +66,11 @@ namespace NzbDrone.Core.History
return _historyRepository.MostRecentForEpisode(episodeId); return _historyRepository.MostRecentForEpisode(episodeId);
} }
public History Get(int id)
{
return _historyRepository.Get(id);
}
public void Purge() public void Purge()
{ {
_historyRepository.Purge(); _historyRepository.Purge();

@ -1,10 +1,30 @@
'use strict'; 'use strict';
define( define(
[ [
'marionette' 'vent',
], function (Marionette) { 'marionette',
'jquery'
], function (vent, Marionette, $) {
return Marionette.ItemView.extend({ 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);
}
}); });
}); });

@ -63,6 +63,7 @@
{{/if_eq}} {{/if_eq}}
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
{{#if_eq eventType compare="grabbed"}}<button class="btn btn-danger x-mark-as-failed">mark as failed</button>{{/if_eq}}
<button class="btn" data-dismiss="modal">close</button> <button class="btn" data-dismiss="modal">close</button>
</div> </div>
</div> </div>

Loading…
Cancel
Save