mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-16 11:37:58 +02:00
Using reqres to map episode to episode file
This commit is contained in:
parent
8737cb0145
commit
b1899b5f6f
@ -16,10 +16,22 @@ public EpisodeModule(IMediaFileService mediaFileService)
|
||||
: base("/episodefile")
|
||||
{
|
||||
_mediaFileService = mediaFileService;
|
||||
|
||||
GetResourceAll = GetEpisodeFiles;
|
||||
UpdateResource = SetQuality;
|
||||
}
|
||||
|
||||
private List<EpisodeFileResource> GetEpisodeFiles()
|
||||
{
|
||||
var seriesId = (int?)Request.Query.SeriesId;
|
||||
|
||||
if (seriesId == null)
|
||||
{
|
||||
throw new BadRequestException("seriesId is missing");
|
||||
}
|
||||
|
||||
return ToListResource(() => _mediaFileService.GetFilesBySeries(seriesId.Value));
|
||||
}
|
||||
|
||||
private EpisodeFileResource SetQuality(EpisodeFileResource episodeFileResource)
|
||||
{
|
||||
var episodeFile = _mediaFileService.Get(episodeFileResource.Id);
|
||||
|
@ -10,13 +10,11 @@ namespace NzbDrone.Api.Episodes
|
||||
public class EpisodeModule : NzbDroneRestModule<EpisodeResource>
|
||||
{
|
||||
private readonly IEpisodeService _episodeService;
|
||||
private readonly MediaFileRepository _mediaFileRepository;
|
||||
|
||||
public EpisodeModule(IEpisodeService episodeService, MediaFileRepository mediaFileRepository)
|
||||
public EpisodeModule(IEpisodeService episodeService)
|
||||
: base("/episodes")
|
||||
{
|
||||
_episodeService = episodeService;
|
||||
_mediaFileRepository = mediaFileRepository;
|
||||
|
||||
GetResourceAll = GetEpisodes;
|
||||
UpdateResource = SetMonitored;
|
||||
@ -31,10 +29,7 @@ private List<EpisodeResource> GetEpisodes()
|
||||
throw new BadRequestException("seriesId is missing");
|
||||
}
|
||||
|
||||
var resource = ToListResource(() => _episodeService.GetEpisodeBySeries(seriesId.Value))
|
||||
.LoadSubtype(e => e.EpisodeFileId, _mediaFileRepository);
|
||||
|
||||
return resource.ToList();
|
||||
return ToListResource(() => _episodeService.GetEpisodeBySeries(seriesId.Value));
|
||||
}
|
||||
|
||||
private EpisodeResource SetMonitored(EpisodeResource episodeResource)
|
||||
|
@ -2,10 +2,11 @@
|
||||
|
||||
define(
|
||||
[
|
||||
'app',
|
||||
'Cells/NzbDroneCell',
|
||||
'moment',
|
||||
'Shared/FormatHelpers'
|
||||
], function (NzbDroneCell, Moment, FormatHelpers) {
|
||||
], function (App, NzbDroneCell, Moment, FormatHelpers) {
|
||||
return NzbDroneCell.extend({
|
||||
|
||||
className: 'episode-status-cell',
|
||||
@ -22,7 +23,10 @@ define(
|
||||
var hasFile = this.model.get('hasFile');
|
||||
|
||||
if (hasFile) {
|
||||
var episodeFile = this.model.get('episodeFile');
|
||||
var episodeFile = App.request(App.Reqres.GetEpisodeFileById, this.model.get('episodeFileId'));
|
||||
|
||||
this.listenTo(episodeFile, 'change', this._refresh);
|
||||
|
||||
var quality = episodeFile.get('quality');
|
||||
var size = FormatHelpers.bytes(episodeFile.get('size'));
|
||||
var title = 'Episode downloaded';
|
||||
|
@ -1,12 +1,14 @@
|
||||
'use strict';
|
||||
define(
|
||||
[
|
||||
'app',
|
||||
'marionette',
|
||||
'backgrid',
|
||||
'Series/EpisodeFileCollection',
|
||||
'Cells/FileSizeCell',
|
||||
'Cells/QualityCell',
|
||||
'Episode/Summary/NoFileView'
|
||||
], function (Marionette, Backgrid, FileSizeCell, QualityCell, NoFileView) {
|
||||
], function (App, Marionette, Backgrid, EpisodeFileCollection, FileSizeCell, QualityCell, NoFileView) {
|
||||
|
||||
return Marionette.Layout.extend({
|
||||
template: 'Episode/Summary/LayoutTemplate',
|
||||
@ -48,9 +50,11 @@ define(
|
||||
},
|
||||
|
||||
onShow: function () {
|
||||
if (this.model.get('episodeFile')) {
|
||||
if (this.model.get('hasFile')) {
|
||||
var episodeFile = App.request(App.Reqres.GetEpisodeFileById, this.model.get('episodeFileId'));
|
||||
|
||||
this.activity.show(new Backgrid.Grid({
|
||||
collection: new Backbone.Collection(this.model.get('episodeFile')),
|
||||
collection: new EpisodeFileCollection(episodeFile, { seriesId: this.model.get('seriesId') }),
|
||||
columns : this.columns,
|
||||
className : 'table table-bordered'
|
||||
}));
|
||||
|
@ -4,6 +4,7 @@ define(
|
||||
'app',
|
||||
'marionette',
|
||||
'Series/EpisodeCollection',
|
||||
'Series/EpisodeFileCollection',
|
||||
'Series/SeasonCollection',
|
||||
'Series/Details/SeasonCollectionView',
|
||||
'Series/Details/SeasonMenu/CollectionView',
|
||||
@ -12,7 +13,7 @@ define(
|
||||
'Shared/Actioneer',
|
||||
'backstrech',
|
||||
'Mixins/backbone.signalr.mixin'
|
||||
], function (App, Marionette, EpisodeCollection, SeasonCollection, SeasonCollectionView, SeasonMenuCollectionView, InfoView, LoadingView, Actioneer) {
|
||||
], function (App, Marionette, EpisodeCollection, EpisodeFileCollection, SeasonCollection, SeasonCollectionView, SeasonMenuCollectionView, InfoView, LoadingView, Actioneer) {
|
||||
return Marionette.Layout.extend({
|
||||
|
||||
itemViewContainer: '.x-series-seasons',
|
||||
@ -85,6 +86,7 @@ define(
|
||||
}
|
||||
|
||||
$('body').removeClass('backdrop');
|
||||
App.reqres.removeHandler(App.Reqres.GetEpisodeFileById);
|
||||
},
|
||||
|
||||
_toggleMonitored: function () {
|
||||
@ -167,14 +169,19 @@ define(
|
||||
|
||||
this.seasonCollection = new SeasonCollection();
|
||||
this.episodeCollection = new EpisodeCollection({ seriesId: this.model.id });
|
||||
this.episodeFileCollection = new EpisodeFileCollection({ seriesId: this.model.id });
|
||||
|
||||
$.when(this.episodeCollection.fetch(), this.seasonCollection.fetch({data: { seriesId: this.model.id }})).done(function () {
|
||||
$.when(this.episodeCollection.fetch(), this.episodeFileCollection.fetch(), this.seasonCollection.fetch({data: { seriesId: this.model.id }})).done(function () {
|
||||
var seasonCollectionView = new SeasonCollectionView({
|
||||
collection : self.seasonCollection,
|
||||
episodeCollection: self.episodeCollection,
|
||||
series : self.model
|
||||
});
|
||||
|
||||
App.reqres.setHandler(App.Reqres.GetEpisodeFileById, function(episodeFileId){
|
||||
return self.episodeFileCollection.get(episodeFileId);
|
||||
});
|
||||
|
||||
/* self.episodeCollection.bindSignalR({
|
||||
onReceived: seasonCollectionView.onEpisodeGrabbed,
|
||||
context : seasonCollectionView
|
||||
|
31
UI/Series/EpisodeFileCollection.js
Normal file
31
UI/Series/EpisodeFileCollection.js
Normal file
@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
define(
|
||||
[
|
||||
'backbone',
|
||||
'Series/EpisodeFileModel'
|
||||
], function (Backbone, EpisodeFileModel) {
|
||||
return Backbone.Collection.extend({
|
||||
url : window.ApiRoot + '/episodefile',
|
||||
model: EpisodeFileModel,
|
||||
|
||||
originalFetch: Backbone.Collection.prototype.fetch,
|
||||
|
||||
initialize: function (options) {
|
||||
this.seriesId = options.seriesId;
|
||||
},
|
||||
|
||||
fetch: function (options) {
|
||||
if (!this.seriesId) {
|
||||
throw 'seriesId is required';
|
||||
}
|
||||
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
|
||||
options['data'] = { seriesId: this.seriesId };
|
||||
|
||||
return this.originalFetch.call(this, options);
|
||||
}
|
||||
});
|
||||
});
|
@ -4,6 +4,6 @@ define(
|
||||
'backbone'
|
||||
], function (Backbone) {
|
||||
return Backbone.Model.extend({
|
||||
url: window.ApiRoot + '/episodefile'
|
||||
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user