mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-03 22:22:33 -06:00
WebUI: make API locale independet
Sizes are now given in bytes. Dates are Unix timestamps and converted to ISO 8601 in the web UI. Numbers are not converted to strings. -1 is returned for undefined values. Some keys have been splitted: Torrent list (json/torrents) * num_seeds: Torrent seeds connected to * num_complete: Torrent seeds in the swarm * num_leechs: Torrent leechers connected to * num_incomplete: Torrent leechers in the swarm Torrent generic properties (propertiesGeneral/hash) * total_uploaded: Total data uploaded * total_uploaded_session: Total data uploaded this session * total_downloaded: Total data dowloaded * total_downloaded_session: Total data downloaded this session * time_elapsed: Torrent elapsed time * seeding_time: Torrent elapsed time while complete * nb_connections: Torrent connection count * nb_connections_limit: Torrent connection count limit Global transfer info (json/transferInfo) * dl_info_speed: Global downalod rate * dl_info_data: Data downloaded this session * up_info_speed: Global upload rate * up_info_data: Data uploaded this session Closes #1524.
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
<![endif]-->
|
||||
<script type="text/javascript" src="scripts/mocha-yc.js"></script>
|
||||
<script type="text/javascript" src="scripts/mocha-init.js"></script>
|
||||
<script type="text/javascript" src="scripts/misc.js"></script>
|
||||
<script type="text/javascript" src="scripts/progressbar.js"></script>
|
||||
<script type="text/javascript" src="scripts/dynamicTable.js" charset="utf-8"></script>
|
||||
<script type="text/javascript" src="scripts/client.js" charset="utf-8"></script>
|
||||
|
||||
@@ -303,7 +303,7 @@ var createPriorityCombo = function(id, selected_prio) {
|
||||
row.length = 4;
|
||||
row[0] = file.priority;
|
||||
row[1] = file.name;
|
||||
row[2] = file.size;
|
||||
row[2] = friendlyUnit(file.size, false);
|
||||
row[3] = (file.progress*100).round(1);
|
||||
if(row[3] == 100.0 && file.progress < 1.0)
|
||||
row[3] = 99.9
|
||||
|
||||
@@ -80,19 +80,34 @@ dynamic information: total_downloaded, total_uploaded, total_wasted, up_limit, d
|
||||
onSuccess: function(data) {
|
||||
$('error_div').set('html', '');
|
||||
if(data){
|
||||
var temp;
|
||||
// Update Torrent data
|
||||
$('save_path').set('html', data.save_path);
|
||||
$('creation_date').set('html', data.creation_date);
|
||||
$('piece_size').set('html', data.piece_size);
|
||||
temp = data.creation_date;
|
||||
var timestamp = "_(Unknown)";
|
||||
if (temp != -1)
|
||||
timestamp = new Date(data.creation_date*1000).toISOString();
|
||||
$('creation_date').set('html', timestamp);
|
||||
$('piece_size').set('html', friendlyUnit(data.piece_size));
|
||||
$('comment').set('html', data.comment);
|
||||
$('total_uploaded').set('html', data.total_uploaded);
|
||||
$('total_downloaded').set('html', data.total_downloaded);
|
||||
$('total_uploaded').set('html', friendlyUnit(data.total_uploaded) +
|
||||
" (" + friendlyUnit(data.total_uploaded_session) +
|
||||
" (" + "_(this session)" + ")");
|
||||
$('total_downloaded').set('html', friendlyUnit(data.total_downloaded) +
|
||||
" (" + friendlyUnit(data.total_downloaded_session) +
|
||||
" (" + "_(this session)" + ")");
|
||||
$('total_wasted').set('html', data.total_wasted);
|
||||
$('up_limit').set('html', data.up_limit);
|
||||
$('dl_limit').set('html', data.dl_limit);
|
||||
$('time_elapsed').set('html', data.time_elapsed);
|
||||
$('nb_connections').set('html', data.nb_connections);
|
||||
$('share_ratio').set('html', data.share_ratio);
|
||||
temp = data.up_limit;
|
||||
$('up_limit').set('html', temp == -1 ? "∞" : temp);
|
||||
temp = data.dl_limit;
|
||||
$('dl_limit').set('html', temp == -1 ? "∞" : temp);
|
||||
temp = friendlyDuration(status.active_time);
|
||||
if (status.is_seed)
|
||||
temp += " (" + "_(Seeded for %1)".replace("%1", status.seeding_time) + ")";
|
||||
$('time_elapsed').set('html', temp);
|
||||
temp = data.nb_connections + " (" + "_(%1 max)".replace("%1", status.nb_connections_limit) + ")";
|
||||
$('nb_connections').set('html', temp);
|
||||
$('share_ratio').set('html', data.share_ratio.toFixed(2));
|
||||
} else {
|
||||
clearData();
|
||||
}
|
||||
|
||||
@@ -108,8 +108,10 @@ window.addEvent('load', function(){
|
||||
},
|
||||
onSuccess: function(info) {
|
||||
if(info) {
|
||||
$("DlInfos").set('html', info.dl_info);
|
||||
$("UpInfos").set('html', info.up_info);
|
||||
$("DlInfos").set('html', "_(D: %1 - T: %2)".replace("%1", friendlyUnit(info.dl_info_speed, true))
|
||||
.replace("%2", friendlyUnit(info.dl_info_data, false)));
|
||||
$("UpInfos").set('html', "_(U: %1 - T: %2)".replace("%1", friendlyUnit(info.up_info_speed, true))
|
||||
.replace("%2", friendlyUnit(info.up_info_data, false)));
|
||||
waitingTrInfo=false;
|
||||
loadTransferInfo.delay(3000);
|
||||
}
|
||||
@@ -146,18 +148,25 @@ window.addEvent('load', function(){
|
||||
row.length = 10;
|
||||
row[0] = stateToImg(event.state);
|
||||
row[1] = event.name;
|
||||
row[2] = event.priority
|
||||
row[3] = event.size;
|
||||
row[2] = event.priority > -1 ? event.priority : null;
|
||||
row[3] = friendlyUnit(event.size, false);
|
||||
row[4] = (event.progress*100).round(1);
|
||||
if(row[4] == 100.0 && event.progress != 1.0)
|
||||
row[4] = 99.9;
|
||||
row[5] = event.num_seeds;
|
||||
row[6] = event.num_leechs;
|
||||
row[7] = event.dlspeed;
|
||||
row[8] = event.upspeed;
|
||||
row[9] = event.eta;
|
||||
row[10] = event.ratio;
|
||||
if(row[2] != "*")
|
||||
row[5] = event.num_seeds;
|
||||
if (event.num_complete != -1)
|
||||
row[5] += " (" + event.num_complete + ")";
|
||||
row[6] = event.num_leechs;
|
||||
if (event.num_incomplete != -1)
|
||||
row[6] += " (" + event.num_incomplete + ")";
|
||||
row[7] = friendlyUnit(event.dlspeed, true);
|
||||
row[8] = friendlyUnit(event.upspeed, true);
|
||||
row[9] = friendlyDuration(event.eta);
|
||||
if(event.ratio == -1)
|
||||
row[10] = "∞";
|
||||
else
|
||||
row[10] = (Math.floor(100 * event.ratio) / 100).toFixed(2); //Don't round up
|
||||
if(row[2] != null)
|
||||
queueing_enabled = true;
|
||||
if(!torrent_hashes.contains(event.hash)) {
|
||||
// New unfinished torrent
|
||||
|
||||
78
src/webui/www/public/scripts/misc.js
Normal file
78
src/webui/www/public/scripts/misc.js
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* JS counterpart of the function in src/misc.cpp
|
||||
*/
|
||||
function friendlyUnit(value, isSpeed) {
|
||||
units = [
|
||||
"_(B)",
|
||||
"_(KiB)",
|
||||
"_(MiB)",
|
||||
"_(GiB)",
|
||||
"_(TiB)",
|
||||
];
|
||||
|
||||
if (value < 0)
|
||||
return "_(Unknown)";
|
||||
var i = 0;
|
||||
while (value >= 1024. && i++ < 6)
|
||||
value /= 1024.;
|
||||
var ret;
|
||||
if (i == 0)
|
||||
ret = value.toFixed(2) + " " + units[0];
|
||||
else
|
||||
ret = value.toFixed(2) + " " + units[i];
|
||||
if (isSpeed)
|
||||
ret += "_(/s)";
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* JS counterpart of the function in src/misc.cpp
|
||||
*/
|
||||
function friendlyDuration(seconds) {
|
||||
var MAX_ETA = 8640000;
|
||||
if (seconds < 0 || seconds >= MAX_ETA)
|
||||
return "∞";
|
||||
if (seconds == 0)
|
||||
return "0";
|
||||
if (seconds < 60)
|
||||
return "< " + "_(%1m)".replace("%1", "1"); //translation of "< 1m" not working
|
||||
var minutes = seconds / 60;
|
||||
if (minutes < 60)
|
||||
return "_(%1m)".replace("%1", parseInt(minutes));
|
||||
var hours = minutes / 60;
|
||||
minutes = minutes - hours*60;
|
||||
if (hours < 24)
|
||||
return "_(%1h %2m)".replace("%1", parseInt(hours)).replace("%2", parseInt(minutes))
|
||||
var days = hours / 24;
|
||||
hours = hours - days * 24;
|
||||
if (days < 100)
|
||||
return "_(%1d %2h)".replace("%1", parseInt(days)).replace("%2", parseInt(hours))
|
||||
return "∞";
|
||||
}
|
||||
|
||||
/*
|
||||
* From: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
|
||||
*/
|
||||
if (!Date.prototype.toISOString) {
|
||||
(function() {
|
||||
|
||||
function pad(number) {
|
||||
if (number < 10) {
|
||||
return '0' + number;
|
||||
}
|
||||
return number;
|
||||
}
|
||||
|
||||
Date.prototype.toISOString = function() {
|
||||
return this.getUTCFullYear() +
|
||||
'-' + pad(this.getUTCMonth() + 1) +
|
||||
'-' + pad(this.getUTCDate()) +
|
||||
'T' + pad(this.getUTCHours()) +
|
||||
':' + pad(this.getUTCMinutes()) +
|
||||
':' + pad(this.getUTCSeconds()) +
|
||||
'.' + (this.getUTCMilliseconds() / 1000).toFixed(3).slice(2, 5) +
|
||||
'Z';
|
||||
};
|
||||
|
||||
}());
|
||||
}
|
||||
Reference in New Issue
Block a user