Series Index can now be filtered and no longer fetches twice when starting.

This commit is contained in:
Taloth Saldono
2014-02-01 23:09:19 +01:00
parent 953e59d7e3
commit af4c351428
7 changed files with 183 additions and 45 deletions

View File

@@ -167,6 +167,44 @@ define(
this.listenTo(SeriesCollection, 'sync', this._renderView);
this.listenTo(SeriesCollection, 'remove', this._renderView);
this.filteringOptions = {
type : 'radio',
storeState : true,
menuKey : 'series.filterMode',
defaultAction: 'all',
items :
[
{
key : 'all',
title : '',
tooltip : 'All',
icon : 'icon-circle-blank',
callback: this._setFilter
},
{
key : 'monitored',
title : '',
tooltip : 'Monitored Only',
icon : 'icon-nd-monitored',
callback: this._setFilter
},
{
key : 'continuing',
title : '',
tooltip : 'Continuing Only',
icon : 'icon-play',
callback: this._setFilter
},
{
key : 'ended',
title : '',
tooltip : 'Ended Only',
icon : 'icon-stop',
callback: this._setFilter
}
]
};
this.viewButtons = {
type : 'radio',
storeState : true,
@@ -201,26 +239,30 @@ define(
_showTable: function () {
this.currentView = new Backgrid.Grid({
collection: SeriesCollection,
collection: this.seriesCollection,
columns : this.columns,
className : 'table table-hover'
});
this._fetchCollection();
this._renderView();
},
_showList: function () {
this.currentView = new ListCollectionView({ collection: SeriesCollection });
this.currentView = new ListCollectionView({
collection: this.seriesCollection
});
this._fetchCollection();
this._renderView();
},
_showPosters: function () {
this.currentView = new PosterCollectionView({ collection: SeriesCollection });
this.currentView = new PosterCollectionView({
collection: this.seriesCollection
});
this._fetchCollection();
this._renderView();
},
_renderView: function () {
if (SeriesCollection.length === 0) {
@@ -238,10 +280,17 @@ define(
onShow: function () {
this._showToolbar();
this._renderView();
this._fetchCollection();
},
_fetchCollection: function () {
SeriesCollection.fetch();
this.seriesCollection.fetch();
},
_setFilter: function(buttonContext) {
var mode = buttonContext.model.get('key');
this.seriesCollection.setFilterMode(mode);
},
_showToolbar: function () {
@@ -251,11 +300,11 @@ define(
}
var rightButtons = [
this.sortingOptions,
this.filteringOptions,
this.viewButtons
];
rightButtons.splice(0, 0, this.sortingOptions);
this.toolbar.show(new ToolbarLayout({
right : rightButtons,
left :

View File

@@ -6,9 +6,10 @@ define(
'backbone.pageable',
'Series/SeriesModel',
'api!series',
'Mixins/AsFilteredCollection',
'Mixins/AsPersistedStateCollection',
'moment'
], function (_, Backbone, PageableCollection, SeriesModel, SeriesData, AsPersistedStateCollection, Moment) {
], function (_, Backbone, PageableCollection, SeriesModel, SeriesData, AsFilteredCollection, AsPersistedStateCollection, Moment) {
var Collection = PageableCollection.extend({
url : window.NzbDrone.ApiRoot + '/series',
model: SeriesModel,
@@ -47,6 +48,14 @@ define(
return proxy.save();
},
// Filter Modes
filterModes: {
'all' : [null, null],
'continuing' : ['status', 'continuing'],
'ended' : ['status', 'ended'],
'monitored' : ['monitored', true]
},
//Sorters
nextAiring: function (model, attr) {
var nextAiring = model.get(attr);
@@ -59,9 +68,9 @@ define(
}
});
var MixedIn = AsPersistedStateCollection.call(Collection);
var collection = new MixedIn(SeriesData);
collection.initialSort();
var FilteredCollection = AsFilteredCollection.call(Collection);
var MixedIn = AsPersistedStateCollection.call(FilteredCollection);
var collection = new MixedIn(SeriesData, { full: true });
return collection;
});