Deleting episode files from episode details is a go

New: Delete episode file from episode details
This commit is contained in:
Mark McDowall 2013-11-28 22:31:46 -08:00
parent 133ee1a0b3
commit ce6a299c98
6 changed files with 122 additions and 15 deletions

View File

@ -1,4 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using NLog;
using NzbDrone.Api.REST; using NzbDrone.Api.REST;
using NzbDrone.Core.Datastore.Events; using NzbDrone.Core.Datastore.Events;
using NzbDrone.Core.MediaFiles; using NzbDrone.Core.MediaFiles;
@ -13,14 +14,22 @@ namespace NzbDrone.Api.EpisodeFiles
IHandle<EpisodeFileAddedEvent> IHandle<EpisodeFileAddedEvent>
{ {
private readonly IMediaFileService _mediaFileService; private readonly IMediaFileService _mediaFileService;
private readonly IRecycleBinProvider _recycleBinProvider;
private readonly Logger _logger;
public EpisodeModule(ICommandExecutor commandExecutor, IMediaFileService mediaFileService) public EpisodeModule(ICommandExecutor commandExecutor,
IMediaFileService mediaFileService,
IRecycleBinProvider recycleBinProvider,
Logger logger)
: base(commandExecutor) : base(commandExecutor)
{ {
_mediaFileService = mediaFileService; _mediaFileService = mediaFileService;
_recycleBinProvider = recycleBinProvider;
_logger = logger;
GetResourceById = GetEpisodeFile; GetResourceById = GetEpisodeFile;
GetResourceAll = GetEpisodeFiles; GetResourceAll = GetEpisodeFiles;
UpdateResource = SetQuality; UpdateResource = SetQuality;
DeleteResource = DeleteEpisodeFile;
} }
private EpisodeFileResource GetEpisodeFile(int id) private EpisodeFileResource GetEpisodeFile(int id)
@ -47,6 +56,15 @@ namespace NzbDrone.Api.EpisodeFiles
_mediaFileService.Update(episodeFile); _mediaFileService.Update(episodeFile);
} }
private void DeleteEpisodeFile(int id)
{
var episodeFile = _mediaFileService.Get(id);
_logger.Info("Deleting episode file: {0}", episodeFile.Path);
_recycleBinProvider.DeleteFile(episodeFile.Path);
_mediaFileService.Delete(episodeFile);
}
public void Handle(EpisodeFileAddedEvent message) public void Handle(EpisodeFileAddedEvent message)
{ {
BroadcastResourceChange(ModelAction.Updated, message.EpisodeFile.Id); BroadcastResourceChange(ModelAction.Updated, message.EpisodeFile.Id);

View File

@ -0,0 +1,33 @@
'use strict';
define(
[
'vent',
'backgrid'
], function (vent, Backgrid) {
return Backgrid.Cell.extend({
className : 'delete-episode-file-cell',
events: {
'click': '_onClick'
},
render: function () {
this.$el.empty();
this.$el.html('<i class="icon-nd-delete"></i>');
return this;
},
_onClick: function () {
var self = this;
if (window.confirm('Are you sure you want to delete \'{0}\' form disk?'.format(this.model.get('path')))) {
this.model.destroy()
.done(function () {
vent.trigger(vent.Events.EpisodeFileDeleted, { episodeFile: self.model });
});
}
}
});
});

View File

@ -5,7 +5,7 @@ define(
], function (Backgrid) { ], function (Backgrid) {
return Backgrid.Cell.extend({ return Backgrid.Cell.extend({
class : 'indexer-cell', className : 'indexer-cell',
render: function () { render: function () {
var indexer = this.model.get(this.column.get('name')); var indexer = this.model.get(this.column.get('name'));

View File

@ -105,4 +105,16 @@ td.episode-status-cell, td.quality-cell {
.download-log-cell { .download-log-cell {
width: 80px; width: 80px;
}
td.delete-episode-file-cell {
.clickable();
text-align: center;
width: 20px;
font-size: 20px;
i {
.clickable();
}
} }

View File

@ -8,9 +8,19 @@ define(
'Series/EpisodeFileCollection', 'Series/EpisodeFileCollection',
'Cells/FileSizeCell', 'Cells/FileSizeCell',
'Cells/QualityCell', 'Cells/QualityCell',
'Cells/DeleteEpisodeFileCell',
'Episode/Summary/NoFileView', 'Episode/Summary/NoFileView',
'Shared/LoadingView' 'Shared/LoadingView'
], function (reqres, Marionette, Backgrid, EpisodeFileModel, EpisodeFileCollection, FileSizeCell, QualityCell, NoFileView, LoadingView) { ], function (reqres,
Marionette,
Backgrid,
EpisodeFileModel,
EpisodeFileCollection,
FileSizeCell,
QualityCell,
DeleteEpisodeFileCell,
NoFileView,
LoadingView) {
return Marionette.Layout.extend({ return Marionette.Layout.extend({
template: 'Episode/Summary/EpisodeSummaryLayoutTemplate', template: 'Episode/Summary/EpisodeSummaryLayoutTemplate',
@ -40,6 +50,12 @@ define(
cell : QualityCell, cell : QualityCell,
sortable: false, sortable: false,
editable: true editable: true
},
{
name : 'this',
label : '',
cell : DeleteEpisodeFileCell,
sortable: false
} }
], ],
@ -57,8 +73,10 @@ define(
if (reqres.hasHandler(reqres.Requests.GetEpisodeFileById)) { if (reqres.hasHandler(reqres.Requests.GetEpisodeFileById)) {
var episodeFile = reqres.request(reqres.Requests.GetEpisodeFileById, episodeFileId); var episodeFile = reqres.request(reqres.Requests.GetEpisodeFileById, episodeFileId);
var episodeFileCollection = new EpisodeFileCollection(episodeFile, { seriesId: this.model.get('seriesId') }); this.episodeFileCollection = new EpisodeFileCollection(episodeFile, { seriesId: this.model.get('seriesId') });
this._showTable(episodeFileCollection); this.listenTo(episodeFile, 'destroy', this._episodeFileDeleted);
this._showTable();
} }
else { else {
@ -66,26 +84,51 @@ define(
var self = this; var self = this;
var newEpisodeFile = new EpisodeFileModel({ id: episodeFileId }); var newEpisodeFile = new EpisodeFileModel({ id: episodeFileId });
var newEpisodeFileCollection = new EpisodeFileCollection(newEpisodeFile, { seriesId: this.model.get('seriesId') }); this.episodeFileCollection = new EpisodeFileCollection(newEpisodeFile, { seriesId: this.model.get('seriesId') });
var promise = newEpisodeFile.fetch(); var promise = newEpisodeFile.fetch();
this.listenTo(newEpisodeFile, 'destroy', this._episodeFileDeleted);
promise.done(function () { promise.done(function () {
self._showTable(newEpisodeFileCollection); self._showTable();
}); });
} }
this.listenTo(this.episodeFileCollection, 'all', this._collectionChanged);
} }
else { else {
this.activity.show(new NoFileView()); this._showNoFileView();
} }
}, },
_showTable: function (episodeFileCollection) { _showTable: function () {
this.activity.show(new Backgrid.Grid({ this.activity.show(new Backgrid.Grid({
collection: episodeFileCollection, collection: this.episodeFileCollection,
columns : this.columns, columns : this.columns,
className : 'table table-bordered' className : 'table table-bordered',
emptyText : 'Nothing to see here!'
})); }));
},
_showNoFileView: function () {
this.activity.show(new NoFileView());
},
_collectionChanged: function () {
if (!this.episodeFileCollection.any()) {
this._showNoFileView();
}
else {
this._showTable();
}
},
_episodeFileDeleted: function () {
this.model.set({
episodeFileId: 0,
hasFile : false
});
} }
}); });
}); });

View File

@ -8,10 +8,11 @@ define(
var vent = new Backbone.Wreqr.EventAggregator(); var vent = new Backbone.Wreqr.EventAggregator();
vent.Events = { vent.Events = {
SeriesAdded : 'series:added', SeriesAdded : 'series:added',
SeriesDeleted : 'series:deleted', SeriesDeleted : 'series:deleted',
CommandComplete: 'command:complete', CommandComplete : 'command:complete',
ServerUpdated : 'server:updated' ServerUpdated : 'server:updated',
EpisodeFileDeleted: 'episodefile:deleted'
}; };
vent.Commands = { vent.Commands = {