EpisodeFile is downloaded if not available already

pull/3113/head
Mark McDowall 11 years ago
parent b1899b5f6f
commit ce9166c6a9

@ -16,10 +16,16 @@ namespace NzbDrone.Api.EpisodeFiles
: base("/episodefile") : base("/episodefile")
{ {
_mediaFileService = mediaFileService; _mediaFileService = mediaFileService;
GetResourceById = GetEpisodeFile;
GetResourceAll = GetEpisodeFiles; GetResourceAll = GetEpisodeFiles;
UpdateResource = SetQuality; UpdateResource = SetQuality;
} }
private EpisodeFileResource GetEpisodeFile(int id)
{
return ToResource(() => _mediaFileService.Get(id));
}
private List<EpisodeFileResource> GetEpisodeFiles() private List<EpisodeFileResource> GetEpisodeFiles()
{ {
var seriesId = (int?)Request.Query.SeriesId; var seriesId = (int?)Request.Query.SeriesId;

@ -2,8 +2,9 @@
define( define(
[ [
'backgrid', 'backgrid',
'Settings/Quality/Profile/QualityProfileSchemaCollection' 'Settings/Quality/Profile/QualityProfileSchemaCollection',
], function (Backgrid, QualityProfileSchemaCollection) { 'Series/EpisodeFileModel'
], function (Backgrid, QualityProfileSchemaCollection, EpisodeFileModel) {
return Backgrid.CellEditor.extend({ return Backgrid.CellEditor.extend({
className: 'quality-cell-editor', className: 'quality-cell-editor',

@ -2,7 +2,7 @@
define( define(
[ [
'marionette', 'marionette',
'Episode/Summary/Layout', 'Episode/Summary/EpisodeSummaryLayout',
'Episode/Search/Layout', 'Episode/Search/Layout',
'Series/SeriesCollection' 'Series/SeriesCollection'
], function (Marionette, SummaryLayout, SearchLayout, SeriesCollection) { ], function (Marionette, SummaryLayout, SearchLayout, SeriesCollection) {

@ -0,0 +1,88 @@
'use strict';
define(
[
'app',
'marionette',
'backgrid',
'Series/EpisodeFileModel',
'Series/EpisodeFileCollection',
'Cells/FileSizeCell',
'Cells/QualityCell',
'Episode/Summary/NoFileView'
], function (App, Marionette, Backgrid, EpisodeFileModel, EpisodeFileCollection, FileSizeCell, QualityCell, NoFileView) {
return Marionette.Layout.extend({
template: 'Episode/Summary/EpisodeSummaryLayoutTemplate',
regions: {
overview: '.episode-overview',
activity: '.episode-file-info'
},
columns:
[
{
name : 'path',
label : 'Path',
cell : 'string',
sortable: false
},
{
name : 'size',
label : 'Size',
cell : FileSizeCell,
sortable: false
},
{
name : 'quality',
label : 'Quality',
cell : QualityCell,
sortable: false,
editable: true
}
],
templateHelpers: {},
initialize: function (options) {
if (!this.model.series) {
this.templateHelpers.series = options.series.toJSON();
}
},
onShow: function () {
if (this.model.get('hasFile')) {
var episodeFileId = this.model.get('episodeFileId');
if (App.reqres.hasHandler(App.Reqres.GetEpisodeFileById)) {
var episodeFile = App.request(App.Reqres.GetEpisodeFileById, episodeFileId);
var episodeFileCollection = new EpisodeFileCollection(episodeFile, { seriesId: this.model.get('seriesId') });
this._showTable(episodeFileCollection)
}
else {
var self = this;
var newEpisodeFile = new EpisodeFileModel({ id: episodeFileId });
var newEpisodeFileCollection = new EpisodeFileCollection(newEpisodeFile, { seriesId: this.model.get('seriesId') });
var promise = newEpisodeFile.fetch();
promise.done(function () {
self._showTable(newEpisodeFileCollection);
});
}
}
else {
this.activity.show(new NoFileView());
}
},
_showTable: function (episodeFileCollection) {
this.activity.show(new Backgrid.Grid({
collection: episodeFileCollection,
columns : this.columns,
className : 'table table-bordered'
}));
}
});
});

@ -4,11 +4,10 @@ define(
'app', 'app',
'marionette', 'marionette',
'backgrid', 'backgrid',
'Series/EpisodeFileCollection',
'Cells/FileSizeCell', 'Cells/FileSizeCell',
'Cells/QualityCell', 'Cells/QualityCell',
'Episode/Summary/NoFileView' 'Episode/Summary/NoFileView'
], function (App, Marionette, Backgrid, EpisodeFileCollection, FileSizeCell, QualityCell, NoFileView) { ], function (App, Marionette, Backgrid, FileSizeCell, QualityCell, NoFileView) {
return Marionette.Layout.extend({ return Marionette.Layout.extend({
template: 'Episode/Summary/LayoutTemplate', template: 'Episode/Summary/LayoutTemplate',
@ -54,7 +53,7 @@ define(
var episodeFile = App.request(App.Reqres.GetEpisodeFileById, this.model.get('episodeFileId')); var episodeFile = App.request(App.Reqres.GetEpisodeFileById, this.model.get('episodeFileId'));
this.activity.show(new Backgrid.Grid({ this.activity.show(new Backgrid.Grid({
collection: new EpisodeFileCollection(episodeFile, { seriesId: this.model.get('seriesId') }), collection: new Backbone.Collection(episodeFile),
columns : this.columns, columns : this.columns,
className : 'table table-bordered' className : 'table table-bordered'
})); }));

@ -33,7 +33,7 @@ define(
var self = this; var self = this;
_.each(message.episode.episodes, function (episode){ _.each(message.episode.episodes, function (episode){
var ep = self.episodeCollection.find({ id: episode.id }); var ep = self.episodeCollection.get(episode.id);
ep.set('downloading', true); ep.set('downloading', true);
console.debug(episode.title); console.debug(episode.title);
}); });

@ -1,22 +1,10 @@
'use strict'; 'use strict';
define( define(
[ [
'backbone', 'backbone'
'moment', ], function (Backbone) {
'Series/SeriesModel',
'Series/EpisodeFileModel'
], function (Backbone, Moment, SeriesModel, EpisodeFileModel) {
return Backbone.Model.extend({ return Backbone.Model.extend({
parse: function (model) {
if (model.episodeFile) {
model.episodeFile = new EpisodeFileModel(model.episodeFile);
}
return model;
},
defaults: { defaults: {
seasonNumber: 0, seasonNumber: 0,
status : 0 status : 0

Loading…
Cancel
Save