mirror of
https://github.com/zoriya/flood.git
synced 2026-06-03 11:16:36 +00:00
Add sort by eta
This commit is contained in:
+10
-4
@@ -170,27 +170,33 @@ client.prototype.getTorrentList = function(callback) {
|
||||
var hours = Math.floor((((seconds % 31536000) % 604800) % 86400) / 3600);
|
||||
var minutes = Math.floor(((((seconds % 31536000) % 604800) % 86400) % 3600) / 60);
|
||||
var wholeSeconds = Math.floor((((((seconds % 31536000) % 604800) % 86400) % 3600) % 60) / 60);
|
||||
|
||||
var timeRemaining = {};
|
||||
seconds = Math.floor(seconds);
|
||||
|
||||
if (years > 0) {
|
||||
timeRemaining = {
|
||||
years: years,
|
||||
weeks: weeks
|
||||
weeks: weeks,
|
||||
seconds: seconds
|
||||
}
|
||||
} else if (weeks > 0) {
|
||||
timeRemaining = {
|
||||
weeks: weeks,
|
||||
days: days
|
||||
days: days,
|
||||
seconds: seconds
|
||||
}
|
||||
} else if (days > 0) {
|
||||
timeRemaining = {
|
||||
days: days,
|
||||
hours: hours
|
||||
hours: hours,
|
||||
seconds: seconds
|
||||
}
|
||||
} else if (hours > 0) {
|
||||
timeRemaining = {
|
||||
hours: hours,
|
||||
minutes: minutes
|
||||
minutes: minutes,
|
||||
seconds: seconds
|
||||
}
|
||||
} else if (minutes > 0) {
|
||||
timeRemaining = {
|
||||
|
||||
@@ -52,7 +52,7 @@ var TorrentListHeader = React.createClass({
|
||||
<div className="torrent__detail--secondary">
|
||||
<HeaderItem label="Up" slug="speed" propertyVar="uploadRate" sortCriteria={this.props.sortCriteria} />
|
||||
<HeaderItem label="Down" slug="speed" propertyVar="downloadRate" sortCriteria={this.props.sortCriteria} />
|
||||
<HeaderItem label="ETA" slug="eta" propertyVar="name" sortCriteria={this.props.sortCriteria} />
|
||||
<HeaderItem label="ETA" slug="eta" propertyVar="eta" sortCriteria={this.props.sortCriteria} />
|
||||
<HeaderItem label="Completed" slug="completed" propertyVar="percentComplete" sortCriteria={this.props.sortCriteria} />
|
||||
<HeaderItem label="Size" slug="size" propertyVar="sizeBytes" sortCriteria={this.props.sortCriteria} />
|
||||
<HeaderItem label="Ratio" slug="ratio" propertyVar="ratio" sortCriteria={this.props.sortCriteria} />
|
||||
|
||||
@@ -124,34 +124,54 @@ var sortTorrentList = function() {
|
||||
|
||||
var sortedList = _torrents.sort(function(a, b) {
|
||||
|
||||
var propA = a[property];
|
||||
var propB = b[property];
|
||||
var valA = a[property];
|
||||
var valB = b[property];
|
||||
|
||||
if (property === 'name') {
|
||||
propA = propA.toLowerCase();
|
||||
propB = propB.toLowerCase();
|
||||
if (property === 'eta') {
|
||||
|
||||
// keep infinity at bottom of array when sorting by eta
|
||||
if (valA === 'Infinity' && valB !== 'Infinity') {
|
||||
return 1;
|
||||
} else if (valA !== 'Infinity' && valB === 'Infinity') {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// if it's not infinity, compare the second as numbers
|
||||
if (valA !== 'Infinity') {
|
||||
valA = Number(valA.seconds);
|
||||
}
|
||||
|
||||
if (valB !== 'Infinity') {
|
||||
valB = Number(valB.seconds);
|
||||
}
|
||||
|
||||
} else if (property === 'name') {
|
||||
|
||||
valA = valA.toLowerCase();
|
||||
valB = valB.toLowerCase();
|
||||
} else {
|
||||
propA = Number(propA);
|
||||
propB = Number(propB);
|
||||
|
||||
valA = Number(valA);
|
||||
valB = Number(valB);
|
||||
}
|
||||
|
||||
if (direction === 'asc') {
|
||||
|
||||
if (propA > propB) {
|
||||
if (valA > valB) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (propA < propB) {
|
||||
if (valA < valB) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if (propA > propB) {
|
||||
if (valA > valB) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (propA < propB) {
|
||||
if (valA < valB) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user