From 90a6bcaa47275ad1c52e63ba76ca81d5d9b9670f Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Mon, 24 Feb 2014 18:50:09 -0800 Subject: [PATCH] New: Filter history by event (all/grabbed/imported/failed) --- src/NzbDrone.Api/History/HistoryModule.cs | 5 ++ src/UI/History/HistoryCollection.js | 13 +++- src/UI/History/Table/HistoryTableLayout.js | 70 +++++++++++++++++-- .../Table/HistoryTableLayoutTemplate.html | 4 +- src/UI/Wanted/Missing/MissingCollection.js | 5 +- src/UI/Wanted/Missing/MissingLayout.js | 2 +- 6 files changed, 86 insertions(+), 13 deletions(-) diff --git a/src/NzbDrone.Api/History/HistoryModule.cs b/src/NzbDrone.Api/History/HistoryModule.cs index 080e74a46..69ed1dc15 100644 --- a/src/NzbDrone.Api/History/HistoryModule.cs +++ b/src/NzbDrone.Api/History/HistoryModule.cs @@ -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) { diff --git a/src/UI/History/HistoryCollection.js b/src/UI/History/HistoryCollection.js index 89abc33a8..623e38cee 100644 --- a/src/UI/History/HistoryCollection.js +++ b/src/UI/History/HistoryCollection.js @@ -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); }); diff --git a/src/UI/History/Table/HistoryTableLayout.js b/src/UI/History/Table/HistoryTableLayout.js index f4a9dcd04..9ae911de0 100644 --- a/src/UI/History/Table/HistoryTableLayout.js +++ b/src/UI/History/Table/HistoryTableLayout.js @@ -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); } }); }); diff --git a/src/UI/History/Table/HistoryTableLayoutTemplate.html b/src/UI/History/Table/HistoryTableLayoutTemplate.html index ae43e6692..753b8b049 100644 --- a/src/UI/History/Table/HistoryTableLayoutTemplate.html +++ b/src/UI/History/Table/HistoryTableLayoutTemplate.html @@ -1,4 +1,4 @@ -
+
@@ -6,6 +6,6 @@
-
+
diff --git a/src/UI/Wanted/Missing/MissingCollection.js b/src/UI/Wanted/Missing/MissingCollection.js index 61564359f..17a79995f 100644 --- a/src/UI/Wanted/Missing/MissingCollection.js +++ b/src/UI/Wanted/Missing/MissingCollection.js @@ -29,11 +29,10 @@ define( '1' : 'desc' } }, - - // Filter Modes + filterModes: { 'monitored' : ['monitored', 'true'], - 'unmonitored' : ['monitored', 'false'], + 'unmonitored' : ['monitored', 'false'] }, parseState: function (resp) { diff --git a/src/UI/Wanted/Missing/MissingLayout.js b/src/UI/Wanted/Missing/MissingLayout.js index bd8f20843..5b52251a1 100644 --- a/src/UI/Wanted/Missing/MissingLayout.js +++ b/src/UI/Wanted/Missing/MissingLayout.js @@ -149,7 +149,7 @@ define( tooltip : 'Unmonitored Only', icon : 'icon-nd-unmonitored', callback : this._setFilter - }, + } ] };