mirror of
https://github.com/transmission/transmission.git
synced 2025-12-24 12:28:52 +00:00
(trunk web) #4312 "Add sorting by ratio" -- implemented.
This commit is contained in:
@@ -525,6 +525,7 @@
|
|||||||
<li id="sort_by_age">Age</li>
|
<li id="sort_by_age">Age</li>
|
||||||
<li id="sort_by_name">Name</li>
|
<li id="sort_by_name">Name</li>
|
||||||
<li id="sort_by_percent_completed">Progress</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_queue_order">Queue Order</li>
|
||||||
<li id="sort_by_state">State</li>
|
<li id="sort_by_state">State</li>
|
||||||
<li class="separator"></li>
|
<li class="separator"></li>
|
||||||
|
|||||||
@@ -235,6 +235,7 @@ Prefs._SortByActivity = 'activity';
|
|||||||
Prefs._SortByQueue = 'queue_order';
|
Prefs._SortByQueue = 'queue_order';
|
||||||
Prefs._SortByName = 'name';
|
Prefs._SortByName = 'name';
|
||||||
Prefs._SortByProgress = 'percent_completed';
|
Prefs._SortByProgress = 'percent_completed';
|
||||||
|
Prefs._SortByRatio = 'ratio';
|
||||||
Prefs._SortByState = 'state';
|
Prefs._SortByState = 'state';
|
||||||
Prefs._SortByTracker = 'tracker';
|
Prefs._SortByTracker = 'tracker';
|
||||||
|
|
||||||
|
|||||||
@@ -760,14 +760,19 @@ Torrent.compareByActivity = function( a, b ) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/** Helper function for sortTorrents(). */
|
/** Helper function for sortTorrents(). */
|
||||||
Torrent.compareByProgress = function( a, b ) {
|
Torrent.compareByRatio = function( a, b ) {
|
||||||
if( a.getPercentDone() !== b.getPercentDone() )
|
|
||||||
return a.getPercentDone() - b.getPercentDone();
|
|
||||||
var a_ratio = Math.ratio( a._upload_total, a._download_total );
|
var a_ratio = Math.ratio( a._upload_total, a._download_total );
|
||||||
var b_ratio = Math.ratio( b._upload_total, b._download_total );
|
var b_ratio = Math.ratio( b._upload_total, b._download_total );
|
||||||
return a_ratio - b_ratio;
|
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 torrents an array of Torrent objects
|
||||||
* @param sortMethod one of Prefs._SortBy*
|
* @param sortMethod one of Prefs._SortBy*
|
||||||
@@ -795,6 +800,9 @@ Torrent.sortTorrents = function( torrents, sortMethod, sortDirection )
|
|||||||
case Prefs._SortByName:
|
case Prefs._SortByName:
|
||||||
torrents.sort( this.compareByName );
|
torrents.sort( this.compareByName );
|
||||||
break;
|
break;
|
||||||
|
case Prefs._SortByRatio:
|
||||||
|
torrents.sort( this.compareByRatio );
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
console.warn( "unknown sort method: " + sortMethod );
|
console.warn( "unknown sort method: " + sortMethod );
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user