mirror of
https://github.com/transmission/transmission
synced 2024-12-23 16:24:02 +00:00
(trunk web) #4312 "Add sorting by ratio" -- implemented.
This commit is contained in:
parent
f6d68844bd
commit
97d80b72aa
3 changed files with 13 additions and 3 deletions
|
@ -525,6 +525,7 @@
|
|||
<li id="sort_by_age">Age</li>
|
||||
<li id="sort_by_name">Name</li>
|
||||
<li id="sort_by_percent_completed">Progress</li>
|
||||
<li id="sort_by_ratio">Ratio</li>
|
||||
<li id="sort_by_queue_order">Queue Order</li>
|
||||
<li id="sort_by_state">State</li>
|
||||
<li class="separator"></li>
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue