Series detials fixes

Fixed: Adding a new series and going to series details will show data after information is fetched
Fixed: Series details won't reload view after update
This commit is contained in:
Mark McDowall 2014-11-06 07:34:15 -08:00
parent 48ec113598
commit b6fc490b89
6 changed files with 87 additions and 34 deletions

View File

@ -24,7 +24,8 @@ namespace NzbDrone.Api.Series
IHandle<EpisodeFileDeletedEvent>,
IHandle<SeriesUpdatedEvent>,
IHandle<SeriesEditedEvent>,
IHandle<SeriesDeletedEvent>
IHandle<SeriesDeletedEvent>,
IHandle<SeriesRenamedEvent>
{
private readonly ISeriesService _seriesService;
@ -207,5 +208,10 @@ namespace NzbDrone.Api.Series
{
BroadcastResourceChange(ModelAction.Deleted, message.Series.InjectTo<SeriesResource>());
}
public void Handle(SeriesRenamedEvent message)
{
BroadcastResourceChange(ModelAction.Updated, message.Series.Id);
}
}
}

View File

@ -35,7 +35,7 @@ define(
return;
}
collection.add(model, {merge: true});
collection.add(model, {merge: true, changeSource: 'signalr'});
console.log(options.action + ': {0}}'.format(options.resource));
};

View File

@ -19,6 +19,27 @@ define(
this.series = options.series;
},
appendHtml: function(collectionView, itemView, index) {
var childrenContainer = collectionView.itemViewContainer ? collectionView.$(collectionView.itemViewContainer) : collectionView.$el;
var collection = collectionView.collection;
// If the index of the model is at the end of the collection append, else insert at proper index
if (index >= collection.size() - 1) {
childrenContainer.append(itemView.el);
} else {
var previousModel = collection.at(index + 1);
var previousView = this.children.findByModel(previousModel);
if (previousView) {
previousView.$el.before(itemView.$el);
}
else {
childrenContainer.append(itemView.el);
}
}
},
itemViewOptions: function () {
return {
episodeCollection: this.episodeCollection,

View File

@ -105,20 +105,17 @@ define(
throw 'episodeCollection is needed';
}
this.episodeCollection = options.episodeCollection.bySeason(this.model.get('seasonNumber'));
var self = this;
this.episodeCollection.each(function (model) {
model.episodeCollection = self.episodeCollection;
});
this.series = options.series;
this.fullEpisodeCollection = options.episodeCollection;
this.episodeCollection = this.fullEpisodeCollection.bySeason(this.model.get('seasonNumber'));
this._updateEpisodeCollection();
this.showingEpisodes = this._shouldShowEpisodes();
this.listenTo(this.model, 'sync', this._afterSeasonMonitored);
this.listenTo(this.episodeCollection, 'sync', this.render);
this.listenTo(this.fullEpisodeCollection, 'sync', this._updateEpisodeCollection);
},
onRender: function () {
@ -293,6 +290,16 @@ define(
var range = _.range(low + 1, high);
this.episodeCollection.lastToggled = model;
},
_updateEpisodeCollection: function () {
var self = this;
this.episodeCollection.add(this.fullEpisodeCollection.bySeason(this.model.get('seasonNumber')).models, { merge: true });
this.episodeCollection.each(function (model) {
model.episodeCollection = self.episodeCollection;
});
}
});
});

View File

@ -7,6 +7,7 @@ define(
'reqres',
'marionette',
'backbone',
'Series/SeriesCollection',
'Series/EpisodeCollection',
'Series/EpisodeFileCollection',
'Series/SeasonCollection',
@ -22,6 +23,7 @@ define(
reqres,
Marionette,
Backbone,
SeriesCollection,
EpisodeCollection,
EpisodeFileCollection,
SeasonCollection,
@ -57,9 +59,18 @@ define(
},
initialize: function () {
this.seriesCollection = SeriesCollection.clone();
this.seriesCollection.shadowCollection.bindSignalR();
this.listenTo(this.model, 'change:monitored', this._setMonitoredState);
this.listenTo(vent, vent.Events.SeriesDeleted, this._onSeriesDeleted);
this.listenTo(this.model, 'remove', this._seriesRemoved);
this.listenTo(vent, vent.Events.CommandComplete, this._commandComplete);
this.listenTo(this.model, 'change', function (model, options) {
if (options && options.changeSource === 'signalr') {
this._refresh();
}
});
},
onShow: function () {
@ -103,16 +114,6 @@ define(
});
},
_getFanArt: function () {
var fanArt = _.where(this.model.get('images'), {coverType: 'fanart'});
if (fanArt && fanArt[0]) {
return fanArt[0].url;
}
return undefined;
},
onClose: function () {
if (this._backstrech) {
@ -124,6 +125,16 @@ define(
reqres.removeHandler(reqres.Requests.GetEpisodeFileById);
},
_getFanArt: function () {
var fanArt = _.where(this.model.get('images'), {coverType: 'fanart'});
if (fanArt && fanArt[0]) {
return fanArt[0].url;
}
return undefined;
},
_toggleMonitored: function () {
var savePromise = this.model.save('monitored', !this.model.get('monitored'), {
wait: true
@ -160,11 +171,8 @@ define(
});
},
_onSeriesDeleted: function (event) {
if (this.model.get('id') === event.series.get('id')) {
_seriesRemoved: function () {
Backbone.history.navigate('/', { trigger: true });
}
},
_renameSeries: function () {
@ -215,13 +223,20 @@ define(
},
_commandComplete: function (options) {
if (options.command.get('name') === 'refreshseries' || options.command.get('name') === 'renamefiles') {
if (options.command.get('name') === 'renamefiles') {
if (options.command.get('seriesId') === this.model.get('id')) {
this._showSeasons();
this._refresh();
}
}
},
_refresh: function () {
this.seasonCollection.add(this.model.get('seasons'), { merge: true });
this.episodeCollection.fetch();
this.episodeFileCollection.fetch();
this._setMonitoredState();
this._showInfo();
}
}
}
});
});

View File

@ -7,6 +7,10 @@ define(
defaults: {
seasonNumber: 0
},
initialize: function () {
this.set('id', this.get('seasonNumber'));
}
});
});