mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-16 11:37:58 +02:00
Option to prevent backbone from adding new models to a collection (update only)
Prevents upcoming/calendar from blowing up when
This commit is contained in:
parent
517b318b75
commit
9142d1b188
@ -16,7 +16,7 @@ define(
|
||||
|
||||
return Marionette.ItemView.extend({
|
||||
initialize: function () {
|
||||
this.collection = new CalendarCollection().bindSignalR();
|
||||
this.collection = new CalendarCollection().bindSignalR({ updateOnly: true });
|
||||
this.listenTo(this.collection, 'change', this._reloadCalendarEvents);
|
||||
},
|
||||
render : function () {
|
||||
|
@ -11,14 +11,8 @@ define(
|
||||
itemView: UpcomingItemView,
|
||||
|
||||
initialize: function () {
|
||||
this.collection = new UpcomingCollection().bindSignalR();
|
||||
this.collection = new UpcomingCollection().bindSignalR({ updateOnly: true });
|
||||
this.collection.fetch();
|
||||
|
||||
this.listenTo(this.collection, 'change', this._refresh);
|
||||
},
|
||||
|
||||
_refresh: function () {
|
||||
this.render();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -22,6 +22,8 @@ define(
|
||||
this.model.set({
|
||||
end: end.toISOString()
|
||||
});
|
||||
|
||||
this.listenTo(this.model, 'change', this.render);
|
||||
},
|
||||
|
||||
_showEpisodeDetails: function () {
|
||||
|
@ -8,9 +8,10 @@ define(
|
||||
], function (vent, _, Backbone) {
|
||||
|
||||
_.extend(Backbone.Collection.prototype, {
|
||||
bindSignalR: function () {
|
||||
bindSignalR: function (bindOptions) {
|
||||
|
||||
var collection = this;
|
||||
bindOptions = bindOptions || {};
|
||||
|
||||
var processMessage = function (options) {
|
||||
|
||||
@ -22,6 +23,12 @@ define(
|
||||
}
|
||||
|
||||
var model = new collection.model(options.resource, {parse: true});
|
||||
|
||||
//updateOnly will prevent the collection from adding a new item
|
||||
if (bindOptions.updateOnly && !collection.get(model.get('id'))) {
|
||||
return;
|
||||
}
|
||||
|
||||
collection.add(model, {merge: true});
|
||||
console.log(options.action + ': {0}}'.format(options.resource));
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user