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";
}
if (pagingResource.FilterKey == "eventType")
{
var filterValue = (HistoryEventType)Convert.ToInt32(pagingResource.FilterValue);
pagingSpec.FilterExpression = v => v.EventType == filterValue;
}
if (episodeId.HasValue)
{

View File

@ -3,8 +3,9 @@ define(
[
'History/HistoryModel',
'backbone.pageable',
'Mixins/AsFilteredCollection',
'Mixins/AsPersistedStateCollection'
], function (HistoryModel, PageableCollection, AsPersistedStateCollection) {
], function (HistoryModel, PageableCollection, AsFilteredCollection, AsPersistedStateCollection) {
var collection = PageableCollection.extend({
url : window.NzbDrone.ApiRoot + '/history',
model: HistoryModel,
@ -27,6 +28,13 @@ define(
}
},
filterModes: {
'all' : [null, null],
'grabbed' : ['eventType', '1'],
'imported' : ['eventType', '3'],
'failed' : ['eventType', '4']
},
initialize: function (options) {
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',
'History/Table/HistoryDetailsCell',
'Shared/Grid/Pager',
'Shared/Toolbar/ToolbarLayout',
'Shared/LoadingView'
], function (Marionette,
Backgrid,
@ -24,14 +25,15 @@ define(
RelativeDateCell,
HistoryDetailsCell,
GridPager,
ToolbarLayout,
LoadingView) {
return Marionette.Layout.extend({
template: 'History/Table/HistoryTableLayoutTemplate',
regions: {
history: '#x-history',
toolbar: '#x-toolbar',
pager : '#x-pager'
toolbar: '#x-history-toolbar',
pager : '#x-history-pager'
},
columns:
@ -84,6 +86,11 @@ define(
this.listenTo(this.collection, 'sync', this._showTable);
},
onShow: function () {
this.history.show(new LoadingView());
this.collection.fetch();
this._showToolbar();
},
_showTable: function (collection) {
@ -99,9 +106,62 @@ define(
}));
},
onShow: function () {
this.history.show(new LoadingView());
this.collection.fetch();
_showToolbar: function () {
var filterOptions = {
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="span12">
<div id="x-history"/>
@ -6,6 +6,6 @@
</div>
<div class="row">
<div class="span12">
<div id="x-pager"/>
<div id="x-history-pager"/>
</div>
</div>

View File

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

View File

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