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")
|
: base("/episodefile")
|
||||||
{
|
{
|
||||||
_mediaFileService = mediaFileService;
|
_mediaFileService = mediaFileService;
|
||||||
|
GetResourceAll = GetEpisodeFiles;
|
||||||
UpdateResource = SetQuality;
|
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)
|
private EpisodeFileResource SetQuality(EpisodeFileResource episodeFileResource)
|
||||||
{
|
{
|
||||||
var episodeFile = _mediaFileService.Get(episodeFileResource.Id);
|
var episodeFile = _mediaFileService.Get(episodeFileResource.Id);
|
||||||
|
@ -10,13 +10,11 @@ namespace NzbDrone.Api.Episodes
|
|||||||
public class EpisodeModule : NzbDroneRestModule<EpisodeResource>
|
public class EpisodeModule : NzbDroneRestModule<EpisodeResource>
|
||||||
{
|
{
|
||||||
private readonly IEpisodeService _episodeService;
|
private readonly IEpisodeService _episodeService;
|
||||||
private readonly MediaFileRepository _mediaFileRepository;
|
|
||||||
|
|
||||||
public EpisodeModule(IEpisodeService episodeService, MediaFileRepository mediaFileRepository)
|
public EpisodeModule(IEpisodeService episodeService)
|
||||||
: base("/episodes")
|
: base("/episodes")
|
||||||
{
|
{
|
||||||
_episodeService = episodeService;
|
_episodeService = episodeService;
|
||||||
_mediaFileRepository = mediaFileRepository;
|
|
||||||
|
|
||||||
GetResourceAll = GetEpisodes;
|
GetResourceAll = GetEpisodes;
|
||||||
UpdateResource = SetMonitored;
|
UpdateResource = SetMonitored;
|
||||||
@ -31,10 +29,7 @@ private List<EpisodeResource> GetEpisodes()
|
|||||||
throw new BadRequestException("seriesId is missing");
|
throw new BadRequestException("seriesId is missing");
|
||||||
}
|
}
|
||||||
|
|
||||||
var resource = ToListResource(() => _episodeService.GetEpisodeBySeries(seriesId.Value))
|
return ToListResource(() => _episodeService.GetEpisodeBySeries(seriesId.Value));
|
||||||
.LoadSubtype(e => e.EpisodeFileId, _mediaFileRepository);
|
|
||||||
|
|
||||||
return resource.ToList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private EpisodeResource SetMonitored(EpisodeResource episodeResource)
|
private EpisodeResource SetMonitored(EpisodeResource episodeResource)
|
||||||
|
@ -2,10 +2,11 @@
|
|||||||
|
|
||||||
define(
|
define(
|
||||||
[
|
[
|
||||||
|
'app',
|
||||||
'Cells/NzbDroneCell',
|
'Cells/NzbDroneCell',
|
||||||
'moment',
|
'moment',
|
||||||
'Shared/FormatHelpers'
|
'Shared/FormatHelpers'
|
||||||
], function (NzbDroneCell, Moment, FormatHelpers) {
|
], function (App, NzbDroneCell, Moment, FormatHelpers) {
|
||||||
return NzbDroneCell.extend({
|
return NzbDroneCell.extend({
|
||||||
|
|
||||||
className: 'episode-status-cell',
|
className: 'episode-status-cell',
|
||||||
@ -22,7 +23,10 @@ define(
|
|||||||
var hasFile = this.model.get('hasFile');
|
var hasFile = this.model.get('hasFile');
|
||||||
|
|
||||||
if (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 quality = episodeFile.get('quality');
|
||||||
var size = FormatHelpers.bytes(episodeFile.get('size'));
|
var size = FormatHelpers.bytes(episodeFile.get('size'));
|
||||||
var title = 'Episode downloaded';
|
var title = 'Episode downloaded';
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
define(
|
define(
|
||||||
[
|
[
|
||||||
|
'app',
|
||||||
'marionette',
|
'marionette',
|
||||||
'backgrid',
|
'backgrid',
|
||||||
|
'Series/EpisodeFileCollection',
|
||||||
'Cells/FileSizeCell',
|
'Cells/FileSizeCell',
|
||||||
'Cells/QualityCell',
|
'Cells/QualityCell',
|
||||||
'Episode/Summary/NoFileView'
|
'Episode/Summary/NoFileView'
|
||||||
], function (Marionette, Backgrid, FileSizeCell, QualityCell, NoFileView) {
|
], function (App, Marionette, Backgrid, EpisodeFileCollection, FileSizeCell, QualityCell, NoFileView) {
|
||||||
|
|
||||||
return Marionette.Layout.extend({
|
return Marionette.Layout.extend({
|
||||||
template: 'Episode/Summary/LayoutTemplate',
|
template: 'Episode/Summary/LayoutTemplate',
|
||||||
@ -48,9 +50,11 @@ define(
|
|||||||
},
|
},
|
||||||
|
|
||||||
onShow: function () {
|
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({
|
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,
|
columns : this.columns,
|
||||||
className : 'table table-bordered'
|
className : 'table table-bordered'
|
||||||
}));
|
}));
|
||||||
|
@ -4,6 +4,7 @@ define(
|
|||||||
'app',
|
'app',
|
||||||
'marionette',
|
'marionette',
|
||||||
'Series/EpisodeCollection',
|
'Series/EpisodeCollection',
|
||||||
|
'Series/EpisodeFileCollection',
|
||||||
'Series/SeasonCollection',
|
'Series/SeasonCollection',
|
||||||
'Series/Details/SeasonCollectionView',
|
'Series/Details/SeasonCollectionView',
|
||||||
'Series/Details/SeasonMenu/CollectionView',
|
'Series/Details/SeasonMenu/CollectionView',
|
||||||
@ -12,7 +13,7 @@ define(
|
|||||||
'Shared/Actioneer',
|
'Shared/Actioneer',
|
||||||
'backstrech',
|
'backstrech',
|
||||||
'Mixins/backbone.signalr.mixin'
|
'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({
|
return Marionette.Layout.extend({
|
||||||
|
|
||||||
itemViewContainer: '.x-series-seasons',
|
itemViewContainer: '.x-series-seasons',
|
||||||
@ -85,6 +86,7 @@ define(
|
|||||||
}
|
}
|
||||||
|
|
||||||
$('body').removeClass('backdrop');
|
$('body').removeClass('backdrop');
|
||||||
|
App.reqres.removeHandler(App.Reqres.GetEpisodeFileById);
|
||||||
},
|
},
|
||||||
|
|
||||||
_toggleMonitored: function () {
|
_toggleMonitored: function () {
|
||||||
@ -167,14 +169,19 @@ define(
|
|||||||
|
|
||||||
this.seasonCollection = new SeasonCollection();
|
this.seasonCollection = new SeasonCollection();
|
||||||
this.episodeCollection = new EpisodeCollection({ seriesId: this.model.id });
|
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({
|
var seasonCollectionView = new SeasonCollectionView({
|
||||||
collection : self.seasonCollection,
|
collection : self.seasonCollection,
|
||||||
episodeCollection: self.episodeCollection,
|
episodeCollection: self.episodeCollection,
|
||||||
series : self.model
|
series : self.model
|
||||||
});
|
});
|
||||||
|
|
||||||
|
App.reqres.setHandler(App.Reqres.GetEpisodeFileById, function(episodeFileId){
|
||||||
|
return self.episodeFileCollection.get(episodeFileId);
|
||||||
|
});
|
||||||
|
|
||||||
/* self.episodeCollection.bindSignalR({
|
/* self.episodeCollection.bindSignalR({
|
||||||
onReceived: seasonCollectionView.onEpisodeGrabbed,
|
onReceived: seasonCollectionView.onEpisodeGrabbed,
|
||||||
context : seasonCollectionView
|
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'
|
'backbone'
|
||||||
], function (Backbone) {
|
], function (Backbone) {
|
||||||
return Backbone.Model.extend({
|
return Backbone.Model.extend({
|
||||||
url: window.ApiRoot + '/episodefile'
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -200,6 +200,10 @@ define(
|
|||||||
ShowLogFile : 'showLogFile'
|
ShowLogFile : 'showLogFile'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
app.Reqres = {
|
||||||
|
GetEpisodeFileById: 'GetEpisodeFileById'
|
||||||
|
};
|
||||||
|
|
||||||
app.addInitializer(function () {
|
app.addInitializer(function () {
|
||||||
console.log('starting application');
|
console.log('starting application');
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user