From 97d80b72aa9617949a63dd7afb683eac99963ddf Mon Sep 17 00:00:00 2001 From: Jordan Lee Date: Fri, 10 Jun 2011 14:04:32 +0000 Subject: [PATCH] (trunk web) #4312 "Add sorting by ratio" -- implemented. --- web/index.html | 1 + web/javascript/common.js | 1 + web/javascript/torrent.js | 14 +++++++++++--- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/web/index.html b/web/index.html index 45f82bbd6..7252a17c0 100755 --- a/web/index.html +++ b/web/index.html @@ -525,6 +525,7 @@
  • Age
  • Name
  • Progress
  • +
  • Ratio
  • Queue Order
  • State
  • diff --git a/web/javascript/common.js b/web/javascript/common.js index 1626ab778..66a342268 100644 --- a/web/javascript/common.js +++ b/web/javascript/common.js @@ -235,6 +235,7 @@ Prefs._SortByActivity = 'activity'; Prefs._SortByQueue = 'queue_order'; Prefs._SortByName = 'name'; Prefs._SortByProgress = 'percent_completed'; +Prefs._SortByRatio = 'ratio'; Prefs._SortByState = 'state'; Prefs._SortByTracker = 'tracker'; diff --git a/web/javascript/torrent.js b/web/javascript/torrent.js index 965231ede..95df0142f 100644 --- a/web/javascript/torrent.js +++ b/web/javascript/torrent.js @@ -760,14 +760,19 @@ Torrent.compareByActivity = function( a, b ) { }; /** Helper function for sortTorrents(). */ -Torrent.compareByProgress = function( a, b ) { - if( a.getPercentDone() !== b.getPercentDone() ) - return a.getPercentDone() - b.getPercentDone(); +Torrent.compareByRatio = function( a, b ) { var a_ratio = Math.ratio( a._upload_total, a._download_total ); var b_ratio = Math.ratio( b._upload_total, b._download_total ); return a_ratio - b_ratio; }; +/** Helper function for sortTorrents(). */ +Torrent.compareByProgress = function( a, b ) { + if( a.getPercentDone() !== b.getPercentDone() ) + return a.getPercentDone() - b.getPercentDone(); + return this.compareByRatio( a, b ); +}; + /** * @param torrents an array of Torrent objects * @param sortMethod one of Prefs._SortBy* @@ -795,6 +800,9 @@ Torrent.sortTorrents = function( torrents, sortMethod, sortDirection ) case Prefs._SortByName: torrents.sort( this.compareByName ); break; + case Prefs._SortByRatio: + torrents.sort( this.compareByRatio ); + break; default: console.warn( "unknown sort method: " + sortMethod ); break;