From a3d649452f0eacddf7c9c9294c0fa84ae6f7ddbd Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sun, 22 Feb 2015 12:40:25 -0800 Subject: [PATCH] Fixed sorting in episode file editor --- .../Editor/EpisodeFileEditorLayout.js | 35 +++++++++++++------ src/UI/Series/EpisodeCollection.js | 10 ++++-- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/UI/EpisodeFile/Editor/EpisodeFileEditorLayout.js b/src/UI/EpisodeFile/Editor/EpisodeFileEditorLayout.js index d3f5e99e2..a5d6f0906 100644 --- a/src/UI/EpisodeFile/Editor/EpisodeFileEditorLayout.js +++ b/src/UI/EpisodeFile/Editor/EpisodeFileEditorLayout.js @@ -2,6 +2,7 @@ var _ = require('underscore'); var reqres = require('../../reqres'); var Marionette = require('marionette'); var Backgrid = require('backgrid'); +var FormatHelpers = require('../../Shared/FormatHelpers'); var SelectAllCell = require('../../Cells/SelectAllCell'); var EpisodeNumberCell = require('../../Series/Details/EpisodeNumberCell'); var SeasonEpisodeNumberCell = require('../../Cells/EpisodeNumberCell'); @@ -63,15 +64,17 @@ module.exports = Marionette.Layout.extend({ var episodeCell = {}; if (this.model) { - episodeCell.name = 'episodeNumber'; + episodeCell.name = 'episodeNumber';s episodeCell.label = '#'; episodeCell.cell = EpisodeNumberCell; } else { - episodeCell.name = 'this'; + episodeCell.name = 'seasonEpisode'; + episodeCell.cellValue = 'this'; episodeCell.label = 'Episode'; episodeCell.cell = SeasonEpisodeNumberCell; + episodeCell.sortValue = this._seasonEpisodeSorter; } this.columns = [ @@ -83,9 +86,10 @@ module.exports = Marionette.Layout.extend({ }, episodeCell, { - name : 'episodeNumber', - label : 'Relative Path', - cell : EpisodeFilePathCell + name : 'episodeNumber', + label : 'Relative Path', + cell : EpisodeFilePathCell, + sortable : false }, { name : 'airDateUtc', @@ -99,11 +103,6 @@ module.exports = Marionette.Layout.extend({ sortable : false } ]; - - if (!this.model) { - this.columns[1].name = 'this'; - this.columns[1].cell = SeasonEpisodeNumberCell; - } }, _showEpisodes : function() { @@ -112,6 +111,8 @@ module.exports = Marionette.Layout.extend({ return; } + this._setInitialSort(); + this.episodeGridView = new Backgrid.Grid({ columns : this.columns, collection : this.filteredEpisodes, @@ -121,6 +122,13 @@ module.exports = Marionette.Layout.extend({ this.episodeGrid.show(this.episodeGridView); }, + _setInitialSort : function () { + if (!this.model) { + this.filteredEpisodes.setSorting('seasonEpisode', 1, { sortValue: this._seasonEpisodeSorter }); + this.filteredEpisodes.fullCollection.sort(); + } + }, + _getQualities : function() { var self = this; @@ -181,5 +189,12 @@ module.exports = Marionette.Layout.extend({ return _.uniq(_.map(this.episodeGridView.getSelectedModels(), function (episode) { return episode.get('episodeFileId'); })); + }, + + _seasonEpisodeSorter : function (model, attr) { + var seasonNumber = FormatHelpers.pad(model.get('seasonNumber'), 4, 0); + var episodeNumber = FormatHelpers.pad(model.get('episodeNumber'), 4, 0); + + return seasonNumber + episodeNumber; } }); \ No newline at end of file diff --git a/src/UI/Series/EpisodeCollection.js b/src/UI/Series/EpisodeCollection.js index eeae5c04b..a6794394b 100644 --- a/src/UI/Series/EpisodeCollection.js +++ b/src/UI/Series/EpisodeCollection.js @@ -1,16 +1,20 @@ var Backbone = require('backbone'); +var PageableCollection = require('backbone.pageable'); var EpisodeModel = require('./EpisodeModel'); require('./EpisodeCollection'); -module.exports = Backbone.Collection.extend({ +module.exports = PageableCollection.extend({ url : window.NzbDrone.ApiRoot + '/episode', model : EpisodeModel, state : { - sortKey : 'episodeNumber', - order : 1 + sortKey : 'episodeNumber', + order : 1, + pageSize : 100000 }, + mode : 'client', + originalFetch : Backbone.Collection.prototype.fetch, initialize : function(options) {