From c55099ce5a09dac868d8235214e5871359d6f4ff Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sat, 16 Feb 2013 17:16:37 -0800 Subject: [PATCH] Added custom sorting to table sorter --- NzbDrone.Web/NzbDrone.Web.csproj | 1 + NzbDrone.Web/Views/V2/Index.cshtml | 2 + .../Mixins/tablesorter.extensions.js | 49 +++++++++++++++++++ .../Series/SeriesCollectionView.js | 36 ++++++++++++-- NzbDrone/NzbDrone.Console.csproj | 5 +- NzbDrone/NzbDrone.csproj | 5 +- 6 files changed, 91 insertions(+), 7 deletions(-) create mode 100644 NzbDrone.Web/_backboneApp/Mixins/tablesorter.extensions.js diff --git a/NzbDrone.Web/NzbDrone.Web.csproj b/NzbDrone.Web/NzbDrone.Web.csproj index 2fed4a6cc..deb611854 100644 --- a/NzbDrone.Web/NzbDrone.Web.csproj +++ b/NzbDrone.Web/NzbDrone.Web.csproj @@ -213,6 +213,7 @@ + diff --git a/NzbDrone.Web/Views/V2/Index.cshtml b/NzbDrone.Web/Views/V2/Index.cshtml index e37caf806..8c555d5a2 100644 --- a/NzbDrone.Web/Views/V2/Index.cshtml +++ b/NzbDrone.Web/Views/V2/Index.cshtml @@ -75,6 +75,7 @@ + @* *@ @@ -82,6 +83,7 @@ + diff --git a/NzbDrone.Web/_backboneApp/Mixins/tablesorter.extensions.js b/NzbDrone.Web/_backboneApp/Mixins/tablesorter.extensions.js new file mode 100644 index 000000000..91c593f51 --- /dev/null +++ b/NzbDrone.Web/_backboneApp/Mixins/tablesorter.extensions.js @@ -0,0 +1,49 @@ +$.tablesorter.addParser({ + // set a unique id + id: 'title', + is: function (s) { + // return false so this parser is not auto detected + return false; + }, + format: function (s) { + // format your data for normalization + return s.match(/title="(.*?)"/)[1].toLowerCase(); + }, + // set type, either numeric or text + type: 'text' +}); + +$.tablesorter.addParser({ + // set a unique id + id: 'date', + is: function (s) { + // return false so this parser is not auto detected + return false; + }, + format: function (s) { + // format your data for normalization + var match = s.match(/data-date="(.*?)"/)[1]; + + if (match === '') + return Date.create().addYears(100).format(Date.ISO8601_DATETIME); + + return match; + }, + // set type, either numeric or text + type: 'text' +}); + +$.tablesorter.addParser({ + // set a unique id + id: 'innerHtml', + is: function (s) { + // return false so this parser is not auto detected + return false; + }, + format: function (s) { + // format your data for normalization + return $(s).get(0).innerHTML; + }, + // set type, either numeric or text + type: 'text' +}); \ No newline at end of file diff --git a/NzbDrone.Web/_backboneApp/Series/SeriesCollectionView.js b/NzbDrone.Web/_backboneApp/Series/SeriesCollectionView.js index e39ddfc5c..dab677063 100644 --- a/NzbDrone.Web/_backboneApp/Series/SeriesCollectionView.js +++ b/NzbDrone.Web/_backboneApp/Series/SeriesCollectionView.js @@ -31,14 +31,44 @@ define(['app', 'Quality/QualityProfileCollection', 'Series/SeriesItemView'], fun if(!this.tableSorter && this.collection.length > 0) { + this.tableSorter = this.ui.table.tablesorter({ + textExtraction: function (node) { + return node.innerHTML; + }, + sortList: [[1,0]], + headers: { + 0: { + sorter: 'title' + }, + 1: { + sorter: 'innerHtml' + }, + 5: { + sorter: 'date' + }, + 6: { + sorter: false + }, + 7: { + sorter: false + } + } + }); - this.tableSorter = this.ui.table.tablesorter(); + this.ui.table.find('th.header').each(function(){ + $(this).append(''); + }); - this.ui.table.bind("sortEnd",function() { + this.ui.table.bind("sortEnd", function() { $(this).find('th.header i').each(function(){ $(this).remove(); }); + $(this).find('th.header').each(function () { + if (!$(this).hasClass('headerSortDown') && !$(this).hasClass('headerSortUp')) + $(this).append(''); + }); + $(this).find('th.headerSortDown').each(function(){ $(this).append(''); }); @@ -47,7 +77,7 @@ define(['app', 'Quality/QualityProfileCollection', 'Series/SeriesItemView'], fun $(this).append(''); }); }); - } + } else { this.ui.table.trigger('update'); diff --git a/NzbDrone/NzbDrone.Console.csproj b/NzbDrone/NzbDrone.Console.csproj index b5174a0e6..b7de7c5e7 100644 --- a/NzbDrone/NzbDrone.Console.csproj +++ b/NzbDrone/NzbDrone.Console.csproj @@ -42,7 +42,7 @@ 4 true BasicCorrectnessRules.ruleset - C:\Users\Mark.McDowall\AppData\Local\Temp\vs83FB.tmp\x86\Debug\ + C:\Users\Mark\AppData\Local\Temp\vs1A55.tmp\x86\Debug\ x86 @@ -52,7 +52,7 @@ TRACE prompt 4 - C:\Users\Mark.McDowall\AppData\Local\Temp\vs83FB.tmp\x86\Release\ + C:\Users\Mark\AppData\Local\Temp\vs1A55.tmp\x86\Release\ NzbDrone.ico @@ -71,6 +71,7 @@ x86 prompt MinimumRecommendedRules.ruleset + C:\Users\Mark\AppData\Local\Temp\vs1A55.tmp\x86\Mono\ diff --git a/NzbDrone/NzbDrone.csproj b/NzbDrone/NzbDrone.csproj index 6d9ff5f0f..a02315ef8 100644 --- a/NzbDrone/NzbDrone.csproj +++ b/NzbDrone/NzbDrone.csproj @@ -42,7 +42,7 @@ 4 true BasicCorrectnessRules.ruleset - C:\Users\Mark.McDowall\AppData\Local\Temp\vs8003.tmp\x86\Debug\ + C:\Users\Mark\AppData\Local\Temp\vs167E.tmp\x86\Debug\ x86 @@ -52,7 +52,7 @@ TRACE prompt 4 - C:\Users\Mark.McDowall\AppData\Local\Temp\vs8003.tmp\x86\Release\ + C:\Users\Mark\AppData\Local\Temp\vs167E.tmp\x86\Release\ NzbDrone.ico @@ -71,6 +71,7 @@ x86 prompt MinimumRecommendedRules.ruleset + C:\Users\Mark\AppData\Local\Temp\vs167E.tmp\x86\Mono\