Deleting episode files from episode details is a go

New: Delete episode file from episode details
pull/6/head
Mark McDowall 11 years ago
parent 133ee1a0b3
commit ce6a299c98

@ -1,4 +1,5 @@
using System.Collections.Generic;
using NLog;
using NzbDrone.Api.REST;
using NzbDrone.Core.Datastore.Events;
using NzbDrone.Core.MediaFiles;
@ -13,14 +14,22 @@ namespace NzbDrone.Api.EpisodeFiles
IHandle<EpisodeFileAddedEvent>
{
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)
{
_mediaFileService = mediaFileService;
_recycleBinProvider = recycleBinProvider;
_logger = logger;
GetResourceById = GetEpisodeFile;
GetResourceAll = GetEpisodeFiles;
UpdateResource = SetQuality;
DeleteResource = DeleteEpisodeFile;
}
private EpisodeFileResource GetEpisodeFile(int id)
@ -47,6 +56,15 @@ namespace NzbDrone.Api.EpisodeFiles
_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)
{
BroadcastResourceChange(ModelAction.Updated, message.EpisodeFile.Id);

@ -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 });
});
}
}
});
});

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

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

@ -8,9 +8,19 @@ define(
'Series/EpisodeFileCollection',
'Cells/FileSizeCell',
'Cells/QualityCell',
'Cells/DeleteEpisodeFileCell',
'Episode/Summary/NoFileView',
'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({
template: 'Episode/Summary/EpisodeSummaryLayoutTemplate',
@ -40,6 +50,12 @@ define(
cell : QualityCell,
sortable: false,
editable: true
},
{
name : 'this',
label : '',
cell : DeleteEpisodeFileCell,
sortable: false
}
],
@ -57,8 +73,10 @@ define(
if (reqres.hasHandler(reqres.Requests.GetEpisodeFileById)) {
var episodeFile = reqres.request(reqres.Requests.GetEpisodeFileById, episodeFileId);
var episodeFileCollection = new EpisodeFileCollection(episodeFile, { seriesId: this.model.get('seriesId') });
this._showTable(episodeFileCollection);
this.episodeFileCollection = new EpisodeFileCollection(episodeFile, { seriesId: this.model.get('seriesId') });
this.listenTo(episodeFile, 'destroy', this._episodeFileDeleted);
this._showTable();
}
else {
@ -66,26 +84,51 @@ define(
var self = this;
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();
this.listenTo(newEpisodeFile, 'destroy', this._episodeFileDeleted);
promise.done(function () {
self._showTable(newEpisodeFileCollection);
self._showTable();
});
}
this.listenTo(this.episodeFileCollection, 'all', this._collectionChanged);
}
else {
this.activity.show(new NoFileView());
this._showNoFileView();
}
},
_showTable: function (episodeFileCollection) {
_showTable: function () {
this.activity.show(new Backgrid.Grid({
collection: episodeFileCollection,
collection: this.episodeFileCollection,
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
});
}
});
});

@ -11,7 +11,8 @@ define(
SeriesAdded : 'series:added',
SeriesDeleted : 'series:deleted',
CommandComplete : 'command:complete',
ServerUpdated : 'server:updated'
ServerUpdated : 'server:updated',
EpisodeFileDeleted: 'episodefile:deleted'
};
vent.Commands = {

Loading…
Cancel
Save