Browse Source

Update torrent list after operations with torrents.

Immediately update torrent list after some operations with torrents.
Such as changing priority, adding torrent, pause/resume, etc.
adaptive-webui-19844
buinsky 10 years ago
parent
commit
b4f39add08
  1. 226
      src/webui/www/public/scripts/client.js
  2. 7
      src/webui/www/public/scripts/mocha-init.js

226
src/webui/www/public/scripts/client.js

@ -24,6 +24,119 @@ @@ -24,6 +24,119 @@
myTable = new dynamicTable();
var stateToImg = function (state) {
if (state == "pausedUP" || state == "pausedDL") {
state = "paused";
} else {
if (state == "queuedUP" || state == "queuedDL") {
state = "queued";
} else {
if (state == "checkingUP" || state == "checkingDL") {
state = "checking";
}
}
}
return 'images/skin/' + state + '.png';
};
var loadTorrentsInfoTimer;
var loadTorrentsInfo = function () {
var queueing_enabled = false;
var url = new URI('json/torrents');
url.setData('filter', filter);
url.setData('sort', myTable.table.sortedColumn);
url.setData('reverse', myTable.table.reverseSort);
var request = new Request.JSON({
url : url,
noCache : true,
method : 'get',
onFailure : function () {
$('error_div').set('html', '_(qBittorrent client is not reachable)');
loadTorrentsInfoTimer = loadTorrentsInfo.delay(2000);
},
onSuccess : function (events) {
$('error_div').set('html', '');
if (events) {
// Add new torrents or update them
torrent_hashes = myTable.getRowIds();
events_hashes = new Array();
pos = 0;
events.each(function (event) {
events_hashes[events_hashes.length] = event.hash;
var row = new Array();
var data = new Array();
row.length = 10;
row[0] = stateToImg(event.state);
row[1] = event.name;
row[2] = event.priority > -1 ? event.priority : null;
data[2] = event.priority;
row[3] = friendlyUnit(event.size, false);
data[3] = event.size;
row[4] = (event.progress * 100).round(1);
if (row[4] == 100.0 && event.progress != 1.0)
row[4] = 99.9;
data[4] = event.progress;
row[5] = event.num_seeds;
if (event.num_complete != -1)
row[5] += " (" + event.num_complete + ")";
data[5] = event.num_seeds;
row[6] = event.num_leechs;
if (event.num_incomplete != -1)
row[6] += " (" + event.num_incomplete + ")";
data[6] = event.num_leechs;
row[7] = friendlyUnit(event.dlspeed, true);
data[7] = event.dlspeed;
row[8] = friendlyUnit(event.upspeed, true);
data[8] = event.upspeed;
row[9] = friendlyDuration(event.eta);
data[9] = event.eta;
if (event.ratio == -1)
row[10] = "∞";
else
row[10] = (Math.floor(100 * event.ratio) / 100).toFixed(2); //Don't round up
data[10] = event.ratio;
if (row[2] != null)
queueing_enabled = true;
if (!torrent_hashes.contains(event.hash)) {
// New unfinished torrent
torrent_hashes[torrent_hashes.length] = event.hash;
//alert("Inserting row");
myTable.insertRow(event.hash, row, data, event.state, pos);
} else {
// Update torrent data
myTable.updateRow(event.hash, row, data, event.state, pos);
}
pos++;
});
// Remove deleted torrents
torrent_hashes.each(function (hash) {
if (!events_hashes.contains(hash)) {
myTable.removeRow(hash);
}
});
if (queueing_enabled) {
$('queueingButtons').removeClass('invisible');
$('queueingMenuItems').removeClass('invisible');
myTable.showPriority();
} else {
$('queueingButtons').addClass('invisible');
$('queueingMenuItems').addClass('invisible');
myTable.hidePriority();
}
myTable.altRow();
}
loadTorrentsInfoTimer = loadTorrentsInfo.delay(1500);
}
}).send();
};
var updateTransferList = function() {
clearTimeout(loadTorrentsInfoTimer);
loadTorrentsInfoTimer = loadTorrentsInfo();
}
window.addEvent('load', function () {
var saveColumnSizes = function () {
@ -80,21 +193,6 @@ window.addEvent('load', function () { @@ -80,21 +193,6 @@ window.addEvent('load', function () {
if (!speedInTitle)
$('speedInBrowserTitleBarLink').firstChild.style.opacity = '0';
var stateToImg = function (state) {
if (state == "pausedUP" || state == "pausedDL") {
state = "paused";
} else {
if (state == "queuedUP" || state == "queuedDL") {
state = "queued";
} else {
if (state == "checkingUP" || state == "checkingDL") {
state = "checking";
}
}
}
return 'images/skin/' + state + '.png';
};
var loadTransferInfoTimer;
var loadTransferInfo = function () {
var url = 'json/transferInfo';
@ -135,104 +233,6 @@ window.addEvent('load', function () { @@ -135,104 +233,6 @@ window.addEvent('load', function () {
$('DlInfos').addEvent('click', globalDownloadLimitFN);
$('UpInfos').addEvent('click', globalUploadLimitFN);
var ajaxfnTimer;
var ajaxfn = function () {
var queueing_enabled = false;
var url = new URI('json/torrents');
url.setData('filter', filter);
url.setData('sort', myTable.table.sortedColumn);
url.setData('reverse', myTable.table.reverseSort);
var request = new Request.JSON({
url : url,
noCache : true,
method : 'get',
onFailure : function () {
$('error_div').set('html', '_(qBittorrent client is not reachable)');
ajaxfnTimer = ajaxfn.delay(2000);
},
onSuccess : function (events) {
$('error_div').set('html', '');
if (events) {
// Add new torrents or update them
torrent_hashes = myTable.getRowIds();
events_hashes = new Array();
pos = 0;
events.each(function (event) {
events_hashes[events_hashes.length] = event.hash;
var row = new Array();
var data = new Array();
row.length = 10;
row[0] = stateToImg(event.state);
row[1] = event.name;
row[2] = event.priority > -1 ? event.priority : null;
data[2] = event.priority;
row[3] = friendlyUnit(event.size, false);
data[3] = event.size;
row[4] = (event.progress * 100).round(1);
if (row[4] == 100.0 && event.progress != 1.0)
row[4] = 99.9;
data[4] = event.progress;
row[5] = event.num_seeds;
if (event.num_complete != -1)
row[5] += " (" + event.num_complete + ")";
data[5] = event.num_seeds;
row[6] = event.num_leechs;
if (event.num_incomplete != -1)
row[6] += " (" + event.num_incomplete + ")";
data[6] = event.num_leechs;
row[7] = friendlyUnit(event.dlspeed, true);
data[7] = event.dlspeed;
row[8] = friendlyUnit(event.upspeed, true);
data[8] = event.upspeed;
row[9] = friendlyDuration(event.eta);
data[9] = event.eta;
if (event.ratio == -1)
row[10] = "∞";
else
row[10] = (Math.floor(100 * event.ratio) / 100).toFixed(2); //Don't round up
data[10] = event.ratio;
if (row[2] != null)
queueing_enabled = true;
if (!torrent_hashes.contains(event.hash)) {
// New unfinished torrent
torrent_hashes[torrent_hashes.length] = event.hash;
//alert("Inserting row");
myTable.insertRow(event.hash, row, data, event.state, pos);
} else {
// Update torrent data
myTable.updateRow(event.hash, row, data, event.state, pos);
}
pos++;
});
// Remove deleted torrents
torrent_hashes.each(function (hash) {
if (!events_hashes.contains(hash)) {
myTable.removeRow(hash);
}
});
if (queueing_enabled) {
$('queueingButtons').removeClass('invisible');
$('queueingMenuItems').removeClass('invisible');
myTable.showPriority();
} else {
$('queueingButtons').addClass('invisible');
$('queueingMenuItems').addClass('invisible');
myTable.hidePriority();
}
myTable.altRow();
}
ajaxfnTimer = ajaxfn.delay(1500);
}
}).send();
};
var updateTransferList = function() {
clearTimeout(ajaxfnTimer);
ajaxfnTimer = ajaxfn();
}
setSortedColumn = function (column) {
myTable.setSortedColumn(column);
updateTransferList();

7
src/webui/www/public/scripts/mocha-init.js

@ -48,6 +48,7 @@ initializeWindows = function() { @@ -48,6 +48,7 @@ initializeWindows = function() {
width: 500,
height: 300
});
updateTransferList();
});
addClickEvent('preferences', function(e) {
@ -87,6 +88,7 @@ initializeWindows = function() { @@ -87,6 +88,7 @@ initializeWindows = function() {
width: 600,
height: 130
});
updateTransferList();
});
globalUploadLimitFN = function() {
@ -181,6 +183,7 @@ initializeWindows = function() { @@ -181,6 +183,7 @@ initializeWindows = function() {
width: 424,
height: 140
});
updateTransferList();
}
};
@ -201,6 +204,7 @@ initializeWindows = function() { @@ -201,6 +204,7 @@ initializeWindows = function() {
}
}).send();
});
updateTransferList();
}
};
@ -216,6 +220,7 @@ initializeWindows = function() { @@ -216,6 +220,7 @@ initializeWindows = function() {
}
}).send();
});
updateTransferList();
}
};
@ -248,6 +253,7 @@ initializeWindows = function() { @@ -248,6 +253,7 @@ initializeWindows = function() {
}
}).send();
});
updateTransferList();
}
});
@ -276,6 +282,7 @@ initializeWindows = function() { @@ -276,6 +282,7 @@ initializeWindows = function() {
hashes: h.join("|")
}
}).send();
updateTransferList();
}
}

Loading…
Cancel
Save