diff --git a/src/NzbDrone.Api/History/HistoryModule.cs b/src/NzbDrone.Api/History/HistoryModule.cs index 7b0aa3c7e..bae183df6 100644 --- a/src/NzbDrone.Api/History/HistoryModule.cs +++ b/src/NzbDrone.Api/History/HistoryModule.cs @@ -39,6 +39,11 @@ namespace NzbDrone.Api.History pagingSpec.FilterExpression = h => h.EpisodeId == i; } + if (pagingSpec.SortKey.Equals("series", StringComparison.InvariantCultureIgnoreCase)) + { + pagingSpec.SortKey = "series.title"; + } + return ApplyToPage(_historyService.Paged, pagingSpec); } diff --git a/src/UI/Episode/Activity/EpisodeActivityLayout.js b/src/UI/Episode/Activity/EpisodeActivityLayout.js index f1ed7cbbb..53de87fdc 100644 --- a/src/UI/Episode/Activity/EpisodeActivityLayout.js +++ b/src/UI/Episode/Activity/EpisodeActivityLayout.js @@ -47,7 +47,7 @@ define( this.model = options.model; this.series = options.series; - this.collection = new HistoryCollection({ episodeId: this.model.id }); + this.collection = new HistoryCollection({ episodeId: this.model.id, tableName: 'episodeActivity' }); this.collection.fetch(); this.listenTo(this.collection, 'sync', this._showTable); }, diff --git a/src/UI/History/HistoryCollection.js b/src/UI/History/HistoryCollection.js index 5341c6507..89abc33a8 100644 --- a/src/UI/History/HistoryCollection.js +++ b/src/UI/History/HistoryCollection.js @@ -2,9 +2,10 @@ define( [ 'History/HistoryModel', - 'backbone.pageable' - ], function (HistoryModel, PageableCollection) { - return PageableCollection.extend({ + 'backbone.pageable', + 'Mixins/AsPersistedStateCollection' + ], function (HistoryModel, PageableCollection, AsPersistedStateCollection) { + var collection = PageableCollection.extend({ url : window.NzbDrone.ApiRoot + '/history', model: HistoryModel, @@ -48,4 +49,6 @@ define( return resp; } }); + + return AsPersistedStateCollection.apply(collection); }); diff --git a/src/UI/History/Table/HistoryTableLayout.js b/src/UI/History/Table/HistoryTableLayout.js index 9e3263c71..25dff7526 100644 --- a/src/UI/History/Table/HistoryTableLayout.js +++ b/src/UI/History/Table/HistoryTableLayout.js @@ -80,7 +80,7 @@ define( initialize: function () { - this.collection = new HistoryCollection(); + this.collection = new HistoryCollection({ tableName: 'history' }); this.listenTo(this.collection, 'sync', this._showTable); }, diff --git a/src/UI/Mixins/AsPersistedStateCollection.js b/src/UI/Mixins/AsPersistedStateCollection.js index de663b794..518209fe7 100644 --- a/src/UI/Mixins/AsPersistedStateCollection.js +++ b/src/UI/Mixins/AsPersistedStateCollection.js @@ -8,9 +8,15 @@ define( var originalInit = this.prototype.initialize; - this.prototype.initialize = function () { + this.prototype.initialize = function (options) { - if (!this.tableName) { + options = options || {}; + + if (options.tableName) { + this.tableName = options.tableName; + } + + if (!this.tableName && !options.tableName) { throw 'tableName is required'; } @@ -19,7 +25,7 @@ define( this.on('backgrid:sort', _storeState, this); if (originalInit) { - originalInit.call(this); + originalInit.call(this, options); } };