New: Series lists will auto update when files are imported/deleted

This commit is contained in:
Mark McDowall 2014-02-05 16:30:14 -08:00
commit e47b4c7686
10 changed files with 131 additions and 27 deletions

View file

@ -1,9 +1,9 @@
'use strict';
define(
[
'backgrid'
], function (Backgrid) {
return Backgrid.Cell.extend({
'Cells/NzbDroneCell'
], function (NzbDroneCell) {
return NzbDroneCell.extend({
className: 'series-status-cell',
render: function () {
@ -13,20 +13,24 @@ define(
if (status === 'ended') {
this.$el.html('<i class="icon-stop grid-icon" title="Ended"></i>');
this.model.set('statusWeight', 3);
this._setStatusWeight(3);
}
else if (!monitored) {
this.$el.html('<i class="icon-pause grid-icon" title="Not Monitored"></i>');
this.model.set('statusWeight', 2);
this._setStatusWeight(2);
}
else {
this.$el.html('<i class="icon-play grid-icon" title="Continuing"></i>');
this.model.set('statusWeight', 1);
this._setStatusWeight(1);
}
return this;
},
_setStatusWeight: function (weight) {
this.model.set('statusWeight', weight, {silent: true});
}
});
});

View file

@ -32,7 +32,7 @@ define(
this.prototype._makeFullCollection = function (models, options) {
var self = this;
self.shadowCollection = originalMakeFullCollection.apply(this, [models, options]);
self.shadowCollection = originalMakeFullCollection.call(this, models, options);
var filterModel = function(model) {
if (!self.state.filterKey || !self.state.filterValue)
@ -46,12 +46,10 @@ define(
};
var filteredModels = self.shadowCollection.filtered();
var fullCollection = originalMakeFullCollection.apply(this, [filteredModels, options]);
var fullCollection = originalMakeFullCollection.call(this, filteredModels, options);
fullCollection.resetFiltered = function(options) {
Backbone.Collection.prototype.reset.apply(this, [self.shadowCollection.filtered(), options]);
Backbone.Collection.prototype.reset.call(this, self.shadowCollection.filtered(), options);
};
fullCollection.reset = function (models, options) {

View file

@ -22,6 +22,12 @@ define(
return;
}
if (options.action === 'deleted') {
collection.remove(new collection.model(options.resource, {parse: true}));
return;
}
var model = new collection.model(options.resource, {parse: true});
//updateOnly will prevent the collection from adding a new item

View file

@ -1,6 +1,7 @@
'use strict';
define(
[
'underscore',
'marionette',
'backgrid',
'Series/Index/Posters/SeriesPostersCollectionView',
@ -16,9 +17,9 @@ define(
'Cells/SeriesStatusCell',
'Series/Index/FooterView',
'Series/Index/FooterModel',
'Shared/Toolbar/ToolbarLayout',
'underscore'
], function (Marionette,
'Shared/Toolbar/ToolbarLayout'
], function (_,
Marionette,
Backgrid,
PosterCollectionView,
ListCollectionView,
@ -33,8 +34,7 @@ define(
SeriesStatusCell,
FooterView,
FooterModel,
ToolbarLayout,
_) {
ToolbarLayout) {
return Marionette.Layout.extend({
template: 'Series/Index/SeriesIndexLayoutTemplate',
@ -131,8 +131,25 @@ define(
initialize: function () {
this.seriesCollection = SeriesCollection.clone();
this.listenTo(SeriesCollection, 'sync', this._renderView);
this.listenTo(SeriesCollection, 'remove', this._renderView);
this.listenTo(SeriesCollection, 'sync', function (model, collection, options) {
this.seriesCollection.shadowCollection.add(model, options);
this.seriesCollection.fullCollection.resetFiltered();
this._renderView();
});
this.listenTo(SeriesCollection, 'add', function (model, collection, options) {
this.seriesCollection.shadowCollection.add(model, options);
this.seriesCollection.fullCollection.resetFiltered();
this._renderView();
});
this.listenTo(SeriesCollection, 'remove', function (model, collection, options) {
this.seriesCollection.shadowCollection.remove(model, options);
this.seriesCollection.fullCollection.resetFiltered();
this._renderView();
});
this.sortingOptions = {
type : 'sorting',
@ -255,7 +272,7 @@ define(
},
_showList: function () {
this.currentView = new ListCollectionView({
this.currentView = new ListCollectionView({
collection: this.seriesCollection
});
@ -269,7 +286,7 @@ define(
this._renderView();
},
_renderView: function () {
if (SeriesCollection.length === 0) {
@ -278,6 +295,8 @@ define(
this.toolbar2.close();
}
else {
this._resetFilter();
this.seriesRegion.show(this.currentView);
this._showToolbar();
@ -295,6 +314,18 @@ define(
this.seriesCollection.setFilterMode(mode);
},
_resetFilter: function () {
var key = this.seriesCollection.state.filterKey;
var value = this.seriesCollection.state.filterValue;
this.seriesCollection.setFilter([ null, null ]);
this.seriesCollection.setFilter([ key, value ]);
},
_shadowTest: function () {
window.alert('added to shadow');
},
_showToolbar: function () {
if (this.toolbar.currentView) {

View file

@ -8,7 +8,8 @@ define(
'api!series',
'Mixins/AsFilteredCollection',
'Mixins/AsPersistedStateCollection',
'moment'
'moment',
'Mixins/backbone.signalr.mixin'
], function (_, Backbone, PageableCollection, SeriesModel, SeriesData, AsFilteredCollection, AsPersistedStateCollection, Moment) {
var Collection = PageableCollection.extend({
url : window.NzbDrone.ApiRoot + '/series',
@ -72,5 +73,5 @@ define(
var MixedIn = AsPersistedStateCollection.call(FilteredCollection);
var collection = new MixedIn(SeriesData, { full: true });
return collection;
return collection.bindSignalR();
});

View file

@ -50,7 +50,6 @@ define(
throw 'ownerContext must be set.';
}
var callback = this.model.get('callback');
if (callback) {
callback.call(this.model.ownerContext, this);