From ce9166c6a91655e515c77d55fc2128edbdfd62c0 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Wed, 21 Aug 2013 20:24:50 -0700 Subject: [PATCH] EpisodeFile is downloaded if not available already --- .../EpisodeFiles/EpisodeFileModule.cs | 6 ++ UI/Cells/Edit/QualityCellEditor.js | 5 +- UI/Episode/Layout.js | 2 +- UI/Episode/Summary/EpisodeSummaryLayout.js | 88 +++++++++++++++++++ ...html => EpisodeSummaryLayoutTemplate.html} | 0 UI/Episode/Summary/Layout.js | 5 +- UI/Series/Details/SeasonCollectionView.js | 2 +- UI/Series/EpisodeModel.js | 16 +--- 8 files changed, 103 insertions(+), 21 deletions(-) create mode 100644 UI/Episode/Summary/EpisodeSummaryLayout.js rename UI/Episode/Summary/{LayoutTemplate.html => EpisodeSummaryLayoutTemplate.html} (100%) diff --git a/NzbDrone.Api/EpisodeFiles/EpisodeFileModule.cs b/NzbDrone.Api/EpisodeFiles/EpisodeFileModule.cs index 136bf9e6f..cfb062866 100644 --- a/NzbDrone.Api/EpisodeFiles/EpisodeFileModule.cs +++ b/NzbDrone.Api/EpisodeFiles/EpisodeFileModule.cs @@ -16,10 +16,16 @@ public EpisodeModule(IMediaFileService mediaFileService) : base("/episodefile") { _mediaFileService = mediaFileService; + GetResourceById = GetEpisodeFile; GetResourceAll = GetEpisodeFiles; UpdateResource = SetQuality; } + private EpisodeFileResource GetEpisodeFile(int id) + { + return ToResource(() => _mediaFileService.Get(id)); + } + private List GetEpisodeFiles() { var seriesId = (int?)Request.Query.SeriesId; diff --git a/UI/Cells/Edit/QualityCellEditor.js b/UI/Cells/Edit/QualityCellEditor.js index 9dfe2201b..711bbed99 100644 --- a/UI/Cells/Edit/QualityCellEditor.js +++ b/UI/Cells/Edit/QualityCellEditor.js @@ -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', diff --git a/UI/Episode/Layout.js b/UI/Episode/Layout.js index 54dfbd231..a785aaad4 100644 --- a/UI/Episode/Layout.js +++ b/UI/Episode/Layout.js @@ -2,7 +2,7 @@ define( [ 'marionette', - 'Episode/Summary/Layout', + 'Episode/Summary/EpisodeSummaryLayout', 'Episode/Search/Layout', 'Series/SeriesCollection' ], function (Marionette, SummaryLayout, SearchLayout, SeriesCollection) { diff --git a/UI/Episode/Summary/EpisodeSummaryLayout.js b/UI/Episode/Summary/EpisodeSummaryLayout.js new file mode 100644 index 000000000..3861179f1 --- /dev/null +++ b/UI/Episode/Summary/EpisodeSummaryLayout.js @@ -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' + })); + } + }); + }); diff --git a/UI/Episode/Summary/LayoutTemplate.html b/UI/Episode/Summary/EpisodeSummaryLayoutTemplate.html similarity index 100% rename from UI/Episode/Summary/LayoutTemplate.html rename to UI/Episode/Summary/EpisodeSummaryLayoutTemplate.html diff --git a/UI/Episode/Summary/Layout.js b/UI/Episode/Summary/Layout.js index 1e552da7b..9a92affe2 100644 --- a/UI/Episode/Summary/Layout.js +++ b/UI/Episode/Summary/Layout.js @@ -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' })); diff --git a/UI/Series/Details/SeasonCollectionView.js b/UI/Series/Details/SeasonCollectionView.js index 49e333c8a..52a549df3 100644 --- a/UI/Series/Details/SeasonCollectionView.js +++ b/UI/Series/Details/SeasonCollectionView.js @@ -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); }); diff --git a/UI/Series/EpisodeModel.js b/UI/Series/EpisodeModel.js index d5f4a19d7..624019b50 100644 --- a/UI/Series/EpisodeModel.js +++ b/UI/Series/EpisodeModel.js @@ -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