EpisodeFile is downloaded if not available already

This commit is contained in:
Mark McDowall 2013-08-21 20:24:50 -07:00
parent b1899b5f6f
commit ce9166c6a9
8 changed files with 103 additions and 21 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -33,7 +33,7 @@ define(
var self = this;
_.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);
console.debug(episode.title);
});

View File

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