New: Filter history by event (all/grabbed/imported/failed)

This commit is contained in:
Mark McDowall 2014-02-24 18:50:09 -08:00
parent ccedf07d54
commit 90a6bcaa47
6 changed files with 86 additions and 13 deletions

View File

@ -39,6 +39,11 @@ namespace NzbDrone.Api.History
pagingSpec.SortKey = "series.title"; pagingSpec.SortKey = "series.title";
} }
if (pagingResource.FilterKey == "eventType")
{
var filterValue = (HistoryEventType)Convert.ToInt32(pagingResource.FilterValue);
pagingSpec.FilterExpression = v => v.EventType == filterValue;
}
if (episodeId.HasValue) if (episodeId.HasValue)
{ {

View File

@ -3,8 +3,9 @@ define(
[ [
'History/HistoryModel', 'History/HistoryModel',
'backbone.pageable', 'backbone.pageable',
'Mixins/AsFilteredCollection',
'Mixins/AsPersistedStateCollection' 'Mixins/AsPersistedStateCollection'
], function (HistoryModel, PageableCollection, AsPersistedStateCollection) { ], function (HistoryModel, PageableCollection, AsFilteredCollection, AsPersistedStateCollection) {
var collection = PageableCollection.extend({ var collection = PageableCollection.extend({
url : window.NzbDrone.ApiRoot + '/history', url : window.NzbDrone.ApiRoot + '/history',
model: HistoryModel, model: HistoryModel,
@ -27,6 +28,13 @@ define(
} }
}, },
filterModes: {
'all' : [null, null],
'grabbed' : ['eventType', '1'],
'imported' : ['eventType', '3'],
'failed' : ['eventType', '4']
},
initialize: function (options) { initialize: function (options) {
delete this.queryParams.episodeId; delete this.queryParams.episodeId;
@ -50,5 +58,6 @@ define(
} }
}); });
return AsPersistedStateCollection.apply(collection); collection = AsFilteredCollection.call(collection);
return AsPersistedStateCollection.call(collection);
}); });

View File

@ -12,6 +12,7 @@ define(
'Cells/RelativeDateCell', 'Cells/RelativeDateCell',
'History/Table/HistoryDetailsCell', 'History/Table/HistoryDetailsCell',
'Shared/Grid/Pager', 'Shared/Grid/Pager',
'Shared/Toolbar/ToolbarLayout',
'Shared/LoadingView' 'Shared/LoadingView'
], function (Marionette, ], function (Marionette,
Backgrid, Backgrid,
@ -24,14 +25,15 @@ define(
RelativeDateCell, RelativeDateCell,
HistoryDetailsCell, HistoryDetailsCell,
GridPager, GridPager,
ToolbarLayout,
LoadingView) { LoadingView) {
return Marionette.Layout.extend({ return Marionette.Layout.extend({
template: 'History/Table/HistoryTableLayoutTemplate', template: 'History/Table/HistoryTableLayoutTemplate',
regions: { regions: {
history: '#x-history', history: '#x-history',
toolbar: '#x-toolbar', toolbar: '#x-history-toolbar',
pager : '#x-pager' pager : '#x-history-pager'
}, },
columns: columns:
@ -84,6 +86,11 @@ define(
this.listenTo(this.collection, 'sync', this._showTable); this.listenTo(this.collection, 'sync', this._showTable);
}, },
onShow: function () {
this.history.show(new LoadingView());
this.collection.fetch();
this._showToolbar();
},
_showTable: function (collection) { _showTable: function (collection) {
@ -99,9 +106,62 @@ define(
})); }));
}, },
onShow: function () { _showToolbar: function () {
this.history.show(new LoadingView()); var filterOptions = {
this.collection.fetch(); type : 'radio',
storeState : false,
menuKey : 'history.filterMode',
defaultAction : 'all',
items :
[
{
key : 'all',
title : '',
tooltip : 'All',
icon : 'icon-circle-blank',
callback : this._setFilter
},
{
key : 'grabbed',
title : '',
tooltip : 'Grabbed',
icon : 'icon-nd-downloading',
callback : this._setFilter
},
{
key : 'imported',
title : '',
tooltip : 'Imported',
icon : 'icon-nd-imported',
callback : this._setFilter
},
{
key : 'failed',
title : '',
tooltip : 'Failed',
icon : 'icon-nd-download-failed',
callback : this._setFilter
}
]
};
this.toolbar.show(new ToolbarLayout({
right :
[
filterOptions
],
context: this
}));
},
_setFilter: function(buttonContext) {
var mode = buttonContext.model.get('key');
this.collection.state.currentPage = 1;
var promise = this.collection.setFilterMode(mode);
if (buttonContext)
buttonContext.ui.icon.spinForPromise(promise);
} }
}); });
}); });

View File

@ -1,4 +1,4 @@
<div id="x-toolbar"/> <div id="x-history-toolbar"/>
<div class="row"> <div class="row">
<div class="span12"> <div class="span12">
<div id="x-history"/> <div id="x-history"/>
@ -6,6 +6,6 @@
</div> </div>
<div class="row"> <div class="row">
<div class="span12"> <div class="span12">
<div id="x-pager"/> <div id="x-history-pager"/>
</div> </div>
</div> </div>

View File

@ -30,10 +30,9 @@ define(
} }
}, },
// Filter Modes
filterModes: { filterModes: {
'monitored' : ['monitored', 'true'], 'monitored' : ['monitored', 'true'],
'unmonitored' : ['monitored', 'false'], 'unmonitored' : ['monitored', 'false']
}, },
parseState: function (resp) { parseState: function (resp) {

View File

@ -149,7 +149,7 @@ define(
tooltip : 'Unmonitored Only', tooltip : 'Unmonitored Only',
icon : 'icon-nd-unmonitored', icon : 'icon-nd-unmonitored',
callback : this._setFilter callback : this._setFilter
}, }
] ]
}; };