mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-11 07:18:08 +00:00
Use raw data to sort columns
Store the raw data retrieved in a new data-raw attribute and use these to sort the columns. In addition, make the ETA column sortable.
This commit is contained in:
parent
ec592f8175
commit
ed83070517
@ -145,37 +145,47 @@ window.addEvent('load', function(){
|
|||||||
events.each(function(event){
|
events.each(function(event){
|
||||||
events_hashes[events_hashes.length] = event.hash;
|
events_hashes[events_hashes.length] = event.hash;
|
||||||
var row = new Array();
|
var row = new Array();
|
||||||
|
var data = new Array();
|
||||||
row.length = 10;
|
row.length = 10;
|
||||||
row[0] = stateToImg(event.state);
|
row[0] = stateToImg(event.state);
|
||||||
row[1] = event.name;
|
row[1] = event.name;
|
||||||
row[2] = event.priority > -1 ? event.priority : null;
|
row[2] = event.priority > -1 ? event.priority : null;
|
||||||
|
data[2] = event.priority;
|
||||||
row[3] = friendlyUnit(event.size, false);
|
row[3] = friendlyUnit(event.size, false);
|
||||||
|
data[3] = event.size;
|
||||||
row[4] = (event.progress*100).round(1);
|
row[4] = (event.progress*100).round(1);
|
||||||
if(row[4] == 100.0 && event.progress != 1.0)
|
if(row[4] == 100.0 && event.progress != 1.0)
|
||||||
row[4] = 99.9;
|
row[4] = 99.9;
|
||||||
|
data[4] = event.progress;
|
||||||
row[5] = event.num_seeds;
|
row[5] = event.num_seeds;
|
||||||
if (event.num_complete != -1)
|
if (event.num_complete != -1)
|
||||||
row[5] += " (" + event.num_complete + ")";
|
row[5] += " (" + event.num_complete + ")";
|
||||||
|
data[5] = event.num_seeds;
|
||||||
row[6] = event.num_leechs;
|
row[6] = event.num_leechs;
|
||||||
if (event.num_incomplete != -1)
|
if (event.num_incomplete != -1)
|
||||||
row[6] += " (" + event.num_incomplete + ")";
|
row[6] += " (" + event.num_incomplete + ")";
|
||||||
|
data[6] = event.num_leechs;
|
||||||
row[7] = friendlyUnit(event.dlspeed, true);
|
row[7] = friendlyUnit(event.dlspeed, true);
|
||||||
|
data[7] = event.dlspeed;
|
||||||
row[8] = friendlyUnit(event.upspeed, true);
|
row[8] = friendlyUnit(event.upspeed, true);
|
||||||
|
data[8] = event.upspeed;
|
||||||
row[9] = friendlyDuration(event.eta);
|
row[9] = friendlyDuration(event.eta);
|
||||||
|
data[9] = event.eta
|
||||||
if(event.ratio == -1)
|
if(event.ratio == -1)
|
||||||
row[10] = "∞";
|
row[10] = "∞";
|
||||||
else
|
else
|
||||||
row[10] = (Math.floor(100 * event.ratio) / 100).toFixed(2); //Don't round up
|
row[10] = (Math.floor(100 * event.ratio) / 100).toFixed(2); //Don't round up
|
||||||
|
data[10] = event.ratio;
|
||||||
if(row[2] != null)
|
if(row[2] != null)
|
||||||
queueing_enabled = true;
|
queueing_enabled = true;
|
||||||
if(!torrent_hashes.contains(event.hash)) {
|
if(!torrent_hashes.contains(event.hash)) {
|
||||||
// New unfinished torrent
|
// New unfinished torrent
|
||||||
torrent_hashes[torrent_hashes.length] = event.hash;
|
torrent_hashes[torrent_hashes.length] = event.hash;
|
||||||
//alert("Inserting row");
|
//alert("Inserting row");
|
||||||
myTable.insertRow(event.hash, row, event.state);
|
myTable.insertRow(event.hash, row, data, event.state);
|
||||||
} else {
|
} else {
|
||||||
// Update torrent data
|
// Update torrent data
|
||||||
myTable.updateRow(event.hash, row, event.state);
|
myTable.updateRow(event.hash, row, data, event.state);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// Remove deleted torrents
|
// Remove deleted torrents
|
||||||
|
@ -66,60 +66,18 @@ var dynamicTable = new Class ({
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
case 2: // Prio
|
case 2: // Prio
|
||||||
var prio1 = tr1.getElements('td')[i].get('html');
|
|
||||||
if(prio1 == '*') prio1 = '-1';
|
|
||||||
var prio2 = tr2.getElements('td')[i].get('html');
|
|
||||||
if(prio2 == '*') prio2 = '-1';
|
|
||||||
if(!reverseSort)
|
|
||||||
return (prio1.toInt() - prio2.toInt());
|
|
||||||
else
|
|
||||||
return (prio2.toInt() - prio1.toInt());
|
|
||||||
case 3: // Size
|
case 3: // Size
|
||||||
case 7: // Up Speed
|
|
||||||
case 8: // Down Speed
|
|
||||||
var sizeStrToFloat = function(mystr) {
|
|
||||||
var val1 = mystr.split(' ');
|
|
||||||
var val1num = val1[0].toFloat()
|
|
||||||
var unit = val1[1];
|
|
||||||
switch(unit) {
|
|
||||||
case '_(TiB)':
|
|
||||||
return val1num*1099511627776;
|
|
||||||
case '_(GiB)':
|
|
||||||
return val1num*1073741824;
|
|
||||||
case '_(MiB)':
|
|
||||||
return val1num*1048576;
|
|
||||||
case '_(KiB)':
|
|
||||||
return val1num*1024;
|
|
||||||
default:
|
|
||||||
return val1num;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if(!reverseSort)
|
|
||||||
return (sizeStrToFloat(tr1.getElements('td')[i].get('html')) - sizeStrToFloat(tr2.getElements('td')[i].get('html')));
|
|
||||||
else
|
|
||||||
return (sizeStrToFloat(tr2.getElements('td')[i].get('html')) - sizeStrToFloat(tr1.getElements('td')[i].get('html')));
|
|
||||||
case 4: // Progress
|
case 4: // Progress
|
||||||
if(!reverseSort)
|
|
||||||
return (tr1.getElements('td')[i].getChildren()[0].getValue() - tr2.getElements('td')[i].getChildren()[0].getValue());
|
|
||||||
else
|
|
||||||
return (tr2.getElements('td')[i].getChildren()[0].getValue() - tr1.getElements('td')[i].getChildren()[0].getValue());
|
|
||||||
case 5: // Seeds
|
case 5: // Seeds
|
||||||
case 6: // Peers
|
case 6: // Peers
|
||||||
if(!reverseSort)
|
case 7: // Up Speed
|
||||||
return (tr1.getElements('td')[i].get('html').split(' ')[0].toInt() - tr2.getElements('td')[i].get('html').split(' ')[0].toInt());
|
case 8: // Down Speed
|
||||||
else
|
case 9: // ETA
|
||||||
return (tr2.getElements('td')[i].get('html').split(' ')[0].toInt() - tr1.getElements('td')[i].get('html').split(' ')[0].toInt());
|
|
||||||
default: // Ratio
|
default: // Ratio
|
||||||
var ratio1 = tr1.getElements('td')[i].get('html');
|
|
||||||
if(ratio1 == '∞')
|
|
||||||
ratio1 = '101.0';
|
|
||||||
var ratio2 = tr2.getElements('td')[i].get('html');
|
|
||||||
if(ratio2 == '∞')
|
|
||||||
ratio2 = '101.0';
|
|
||||||
if(!reverseSort)
|
if(!reverseSort)
|
||||||
return (ratio1.toFloat() - ratio2.toFloat());
|
return (tr1.getElements('td')[i].get('data-raw') - tr2.getElements('td')[i].get('data-raw'));
|
||||||
else
|
else
|
||||||
return (ratio2.toFloat() - ratio1.toFloat());
|
return (tr2.getElements('td')[i].get('data-raw') - tr1.getElements('td')[i].get('data-raw'));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -229,7 +187,7 @@ var dynamicTable = new Class ({
|
|||||||
return !tr.hasClass('invisible');
|
return !tr.hasClass('invisible');
|
||||||
},
|
},
|
||||||
|
|
||||||
insertRow: function(id, row, status){
|
insertRow: function(id, row, data, status){
|
||||||
if(this.rows.has(id)) {
|
if(this.rows.has(id)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -241,6 +199,8 @@ var dynamicTable = new Class ({
|
|||||||
var td = new Element('td');
|
var td = new Element('td');
|
||||||
if(i==this.progressIndex) {
|
if(i==this.progressIndex) {
|
||||||
td.adopt(new ProgressBar(row[i].toFloat(), {'id': 'pb_'+id, 'width':80}));
|
td.adopt(new ProgressBar(row[i].toFloat(), {'id': 'pb_'+id, 'width':80}));
|
||||||
|
if (typeof data[i] != 'undefined')
|
||||||
|
td.set('data-raw', data[i])
|
||||||
} else {
|
} else {
|
||||||
if(i==0) {
|
if(i==0) {
|
||||||
td.adopt(new Element('img', {'src':row[i], 'class': 'statusIcon'}));
|
td.adopt(new Element('img', {'src':row[i], 'class': 'statusIcon'}));
|
||||||
@ -251,6 +211,8 @@ var dynamicTable = new Class ({
|
|||||||
td.addClass('invisible');
|
td.addClass('invisible');
|
||||||
}
|
}
|
||||||
td.set('html', row[i]);
|
td.set('html', row[i]);
|
||||||
|
if (typeof data[i] != 'undefined')
|
||||||
|
td.set('data-raw', data[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
td.injectInside(tr);
|
td.injectInside(tr);
|
||||||
@ -370,7 +332,7 @@ var dynamicTable = new Class ({
|
|||||||
}, this);
|
}, this);
|
||||||
},
|
},
|
||||||
|
|
||||||
updateRow: function(id, row, status){
|
updateRow: function(id, row, data, status){
|
||||||
if(!this.rows.has(id)) {
|
if(!this.rows.has(id)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -389,6 +351,8 @@ var dynamicTable = new Class ({
|
|||||||
tds[i].set('html', row[i]);
|
tds[i].set('html', row[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (typeof data[i] != 'undefined')
|
||||||
|
tds[i].set('data-raw', data[i])
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
// Row was hidden, check if it was selected
|
// Row was hidden, check if it was selected
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
<th onClick="setSortedColumn(6);" style="cursor: pointer;">_(Peers)</th>
|
<th onClick="setSortedColumn(6);" style="cursor: pointer;">_(Peers)</th>
|
||||||
<th onClick="setSortedColumn(7);" style="cursor: pointer;">_(Down Speed)</th>
|
<th onClick="setSortedColumn(7);" style="cursor: pointer;">_(Down Speed)</th>
|
||||||
<th onClick="setSortedColumn(8);" style="cursor: pointer;">_(Up Speed)</th>
|
<th onClick="setSortedColumn(8);" style="cursor: pointer;">_(Up Speed)</th>
|
||||||
<th>_(ETA)</th>
|
<th onClick="setSortedColumn(9);" style="cursor: pointer;">_(ETA)</th>
|
||||||
<th onClick="setSortedColumn(10);" style="cursor: pointer;">_(Ratio)</th>
|
<th onClick="setSortedColumn(10);" style="cursor: pointer;">_(Ratio)</th>
|
||||||
|
|
||||||
</tr>
|
</tr>
|
||||||
|
Loading…
Reference in New Issue
Block a user