From 46405194388757422dc636ba117e31d83f9e533a Mon Sep 17 00:00:00 2001 From: Leonardo Galli Date: Mon, 6 Mar 2017 22:02:25 +0100 Subject: [PATCH] Fix most paging issues on first load. --- src/UI/Movies/Index/MoviesIndexLayout.js | 14 +++- src/UI/Movies/MoviesCollection.js | 88 ++++++++++++++---------- 2 files changed, 61 insertions(+), 41 deletions(-) diff --git a/src/UI/Movies/Index/MoviesIndexLayout.js b/src/UI/Movies/Index/MoviesIndexLayout.js index 87faa6db4..e014e7060 100644 --- a/src/UI/Movies/Index/MoviesIndexLayout.js +++ b/src/UI/Movies/Index/MoviesIndexLayout.js @@ -61,7 +61,7 @@ module.exports = Marionette.Layout.extend({ name : 'added', label : 'Date Added', cell : RelativeDateCell - }, + }, { name : "downloadedQuality", label : "Downloaded", @@ -139,6 +139,7 @@ module.exports = Marionette.Layout.extend({ initialize : function() { //this variable prevents us from showing the list before seriesCollection has been fetched the first time this.seriesCollection = MoviesCollection.clone(); + //debugger; this.seriesCollection.bindSignalR(); var pageSize = parseInt(Config.getValue("pageSize")) || 10; // this.seriesCollection.setPageSize(pageSize); @@ -191,7 +192,7 @@ module.exports = Marionette.Layout.extend({ } }); - this.seriesCollection.setPageSize(pageSize); + //this.seriesCollection.setPageSize(pageSize); this.sortingOptions = { @@ -303,6 +304,12 @@ module.exports = Marionette.Layout.extend({ } ] }; + + //this._showToolbar(); + //debugger; + self = this; + setTimeout(function(){self._showToolbar();}, 0);//wtf??? + //this._renderView(); }, onShow : function() { @@ -375,6 +382,7 @@ module.exports = Marionette.Layout.extend({ }, _showToolbar : function() { + //debugger; if (this.toolbar.currentView) { return; } @@ -416,7 +424,7 @@ module.exports = Marionette.Layout.extend({ var movies = FullMovieCollection.models.length; //instead of all the counters could do something like this with different query in the where... //var releasedMovies = FullMovieCollection.where({ 'released' : this.model.get('released') }); - // releasedMovies.length + // releasedMovies.length var announced = 0; var incinemas = 0; diff --git a/src/UI/Movies/MoviesCollection.js b/src/UI/Movies/MoviesCollection.js index 4ce33bac9..e42a8d0f9 100644 --- a/src/UI/Movies/MoviesCollection.js +++ b/src/UI/Movies/MoviesCollection.js @@ -13,6 +13,44 @@ var Config = require('../Config'); var pageSize = parseInt(Config.getValue("pageSize")) || 1000; +var filterModes = { + 'all' : [ + null, + null + ], + 'continuing' : [ + 'status', + 'continuing' + ], + 'ended' : [ + 'status', + 'ended' + ], + 'monitored' : [ + 'monitored', + true + ], + 'missing' : [ + 'downloaded', + false + ], + 'released' : [ + "status", + "released", + //function(model) { return model.getStatus() == "released"; } + ], + 'announced' : [ + "status", + "announced", + //function(model) { return model.getStatus() == "announced"; } + ], + 'cinemas' : [ + "status", + "inCinemas", + //function(model) { return model.getStatus() == "inCinemas"; } + ] +}//Hacky, I know + var Collection = PageableCollection.extend({ url : window.NzbDrone.ApiRoot + '/movie', @@ -122,43 +160,7 @@ var Collection = PageableCollection.extend({ return proxy.save(); }, - filterModes : { - 'all' : [ - null, - null - ], - 'continuing' : [ - 'status', - 'continuing' - ], - 'ended' : [ - 'status', - 'ended' - ], - 'monitored' : [ - 'monitored', - true - ], - 'missing' : [ - 'downloaded', - false - ], - 'released' : [ - "status", - "released", - //function(model) { return model.getStatus() == "released"; } - ], - 'announced' : [ - "status", - "announced", - //function(model) { return model.getStatus() == "announced"; } - ], - 'cinemas' : [ - "status", - "inCinemas", - //function(model) { return model.getStatus() == "inCinemas"; } - ] - }, + filterModes : filterModes, sortMappings : { title : { @@ -263,6 +265,16 @@ Collection = AsFilteredCollection.call(Collection); Collection = AsSortedCollection.call(Collection); Collection = AsPersistedStateCollection.call(Collection); -var data = ApiData.get('movie?page=1&pageSize='+pageSize+'&sortKey=sortTitle&sortDir=asc'); +var filterMode = Config.getValue("series.filterMode", "all"); +var sortKey = Config.getValue("movie.sortKey", "sortTitle"); +var sortDir = Config.getValue("movie.sortDirection", -1); +var sortD = "asc"; +if (sortDir == 1) { + sortD = "desc"; +} + +var values = filterModes[filterMode]; + +var data = ApiData.get("movie?page=1&pageSize={0}&sortKey={3}&sortDir={4}&filterKey={1}&filterValue={2}".format(pageSize, values[0], values[1], sortKey, sortD)); module.exports = new Collection(data.records, { full : false, state : { totalRecords : data.totalRecords} }).bindSignalR();