From 59c033dd6890983038dd64c6234531a4d24d4d40 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sun, 18 Aug 2013 16:32:27 -0700 Subject: [PATCH] Allow series grid sorting by episodes (percent downloaded) --- UI/Cells/EpisodeProgressCell.js | 33 +++++++++++++++++++ .../EpisodeProgressCellTemplate.html} | 0 UI/Series/Index/SeriesIndexLayout.js | 18 ++++------ 3 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 UI/Cells/EpisodeProgressCell.js rename UI/{Series/EpisodeProgressTemplate.html => Cells/EpisodeProgressCellTemplate.html} (100%) diff --git a/UI/Cells/EpisodeProgressCell.js b/UI/Cells/EpisodeProgressCell.js new file mode 100644 index 000000000..9d9e1370f --- /dev/null +++ b/UI/Cells/EpisodeProgressCell.js @@ -0,0 +1,33 @@ +'use strict'; + +define( + [ + 'marionette', + 'Cells/NzbDroneCell' + ], function (Marionette, NzbDroneCell) { + return NzbDroneCell.extend({ + className: 'episode-progress-cell', + template : 'Cells/EpisodeProgressCellTemplate', + + render: function () { + + var episodeCount = this.model.get('episodeCount'); + var episodeFileCount = this.model.get('episodeFileCount'); + + var percent = 100; + + if (episodeCount > 0) { + percent = episodeFileCount / episodeCount * 100; + } + + this.model.set('percentOfEpisodes', percent); + + this.templateFunction = Marionette.TemplateCache.get(this.template); + var data = this.model.toJSON(); + var html = this.templateFunction(data); + this.$el.html(html); + + return this; + } + }); + }); diff --git a/UI/Series/EpisodeProgressTemplate.html b/UI/Cells/EpisodeProgressCellTemplate.html similarity index 100% rename from UI/Series/EpisodeProgressTemplate.html rename to UI/Cells/EpisodeProgressCellTemplate.html diff --git a/UI/Series/Index/SeriesIndexLayout.js b/UI/Series/Index/SeriesIndexLayout.js index 99ba4ae1e..b35234589 100644 --- a/UI/Series/Index/SeriesIndexLayout.js +++ b/UI/Series/Index/SeriesIndexLayout.js @@ -10,14 +10,13 @@ define( 'Cells/SeriesTitleCell', 'Cells/TemplatedCell', 'Cells/QualityProfileCell', + 'Cells/EpisodeProgressCell', 'Shared/Grid/DateHeaderCell', 'Series/Index/Table/SeriesStatusCell', - 'Series/Index/Table/SeriesStatusHeaderCell', 'Series/Index/Table/Row', 'Series/Index/FooterView', 'Series/Index/FooterModel', - 'Shared/Toolbar/ToolbarLayout', - 'Shared/LoadingView' + 'Shared/Toolbar/ToolbarLayout' ], function (Marionette, PosterCollectionView, ListCollectionView, @@ -27,14 +26,13 @@ define( SeriesTitleCell, TemplatedCell, QualityProfileCell, + EpisodeProgressCell, DateHeaderCell, SeriesStatusCell, - SeriesStatusHeaderCell, SeriesIndexRow, FooterView, FooterModel, - ToolbarLayout, - LoadingView) { + ToolbarLayout) { return Marionette.Layout.extend({ template: 'Series/Index/SeriesIndexLayoutTemplate', @@ -79,11 +77,9 @@ define( headerCell: DateHeaderCell }, { - name : 'this', - label : 'Episodes', - sortable: false, - template: 'Series/EpisodeProgressTemplate', - cell : TemplatedCell, + name : 'percentOfEpisodes', + label : 'Episodes', + cell : EpisodeProgressCell, className: 'episode-progress-cell' }, {