Browse Source

Use sync/maindata request in WebUI

adaptive-webui-19844
buinsky 10 years ago
parent
commit
574c57ee18
  1. 2
      src/webui/www/public/downloadlimit.html
  2. 131
      src/webui/www/public/scripts/client.js
  3. 18
      src/webui/www/public/scripts/mocha-init.js
  4. 2
      src/webui/www/public/uploadlimit.html

2
src/webui/www/public/downloadlimit.html

@ -31,7 +31,7 @@ @@ -31,7 +31,7 @@
'limit': limit
},
onComplete: function() {
window.parent.updateTransferInfo();
window.parent.updateMainData();
window.parent.closeWindows();
}
}).send();

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

@ -25,8 +25,7 @@ @@ -25,8 +25,7 @@
myTable = new dynamicTable();
var updatePropertiesPanel = function(){};
var updateTransferInfo = function(){};
var updateTransferList = function(){};
var updateMainData = function(){};
var alternativeSpeedLimits = false;
selected_filter = getLocalStorageItem('selected_filter', 'all');
@ -49,7 +48,6 @@ var saveSelectedLabel = function () { @@ -49,7 +48,6 @@ var saveSelectedLabel = function () {
}
}
window.addEvent('load', function () {
var saveColumnSizes = function () {
@ -104,7 +102,7 @@ window.addEvent('load', function () { @@ -104,7 +102,7 @@ window.addEvent('load', function () {
localStorage.setItem('selected_filter', f);
// Reload torrents
if (typeof myTable.table != 'undefined')
updateTransferList();
updateMainData();
}
new MochaUI.Panel({
@ -131,36 +129,32 @@ window.addEvent('load', function () { @@ -131,36 +129,32 @@ window.addEvent('load', function () {
if (!speedInTitle)
$('speedInBrowserTitleBarLink').firstChild.style.opacity = '0';
var loadTorrentsInfoTimer;
var loadTorrentsInfo = function () {
var url = new URI('json/torrents');
var syncMainDataLastResponseId = 0;
var serverState = {};
var syncMainDataTimer;
var syncMainData = function () {
var url = new URI('sync/maindata');
url.setData('rid', syncMainDataLastResponseId);
var request = new Request.JSON({
url : url,
noCache : true,
method : 'get',
onFailure : function () {
$('error_div').set('html', 'QBT_TR(qBittorrent client is not reachable)QBT_TR');
clearTimeout(loadTorrentsInfoTimer);
loadTorrentsInfoTimer = loadTorrentsInfo.delay(2000);
clearTimeout(syncMainDataTimer);
syncMainDataTimer = syncMainData.delay(2000);
},
onSuccess : function (response) {
$('error_div').set('html', '');
if (response) {
var queueing_enabled = false;
var torrents_hashes = new Array();
for (var i = 0; i < response.length; i++) {
torrents_hashes.push(response[i].hash);
if (response[i].priority > -1)
queueing_enabled = true;
myTable.updateRowData(response[i])
}
var keys = myTable.rows.getKeys();
for (var i = 0; i < keys.length; i++) {
if (!torrents_hashes.contains(keys[i]))
myTable.rows.erase(keys[i]);
}
var full_update = (response['full_update'] == true);
if (full_update)
myTable.rows.erase();
if (response['rid'])
syncMainDataLastResponseId = response['rid'];
if ('queueing' in response) {
var queueing_enabled = response['queueing'];
myTable.columns['priority'].force_hide = !queueing_enabled;
myTable.updateColumn('priority');
if (queueing_enabled) {
@ -171,74 +165,63 @@ window.addEvent('load', function () { @@ -171,74 +165,63 @@ window.addEvent('load', function () {
$('queueingButtons').addClass('invisible');
$('queueingMenuItems').addClass('invisible');
}
myTable.updateTable(true);
}
if (response['torrents'])
for (var key in response['torrents']) {
response['torrents'][key]['hash'] = key;
myTable.updateRowData(response['torrents'][key]);
}
myTable.updateTable(full_update);
if (response['torrents_removed'])
response['torrents_removed'].each(function (hash) {
myTable.removeRow(hash);
});
myTable.altRow();
if (response['server_state']) {
var tmp = response['server_state'];
for(var key in tmp)
serverState[key] = tmp[key];
processServerState();
}
}
clearTimeout(loadTorrentsInfoTimer);
loadTorrentsInfoTimer = loadTorrentsInfo.delay(1500);
clearTimeout(syncMainDataTimer);
syncMainDataTimer = syncMainData.delay(1500);
}
}).send();
};
updateTransferList = function() {
updateMainData = function() {
myTable.updateTable();
clearTimeout(loadTorrentsInfoTimer);
loadTorrentsInfoTimer = loadTorrentsInfo.delay(30);
clearTimeout(syncMainDataTimer);
syncMainDataTimer = syncMainData.delay(100);
}
var loadTransferInfoTimer;
var loadTransferInfo = function () {
var url = 'json/transferInfo';
var request = new Request.JSON({
url : url,
noCache : true,
method : 'get',
onFailure : function () {
$('error_div').set('html', 'QBT_TR(qBittorrent client is not reachable)QBT_TR');
clearTimeout(loadTransferInfoTimer);
loadTransferInfoTimer = loadTransferInfo.delay(4000);
},
onSuccess : function (info) {
if (info) {
var processServerState = function () {
var transfer_info = "";
if (info.dl_rate_limit != undefined)
transfer_info += "[" + friendlyUnit(info.dl_rate_limit, true) + "] ";
transfer_info += friendlyUnit(info.dl_info_speed, true);
transfer_info += " (" + friendlyUnit(info.dl_info_data, false) + ")"
if (serverState.dl_rate_limit > 0)
transfer_info += "[" + friendlyUnit(serverState.dl_rate_limit, true) + "] ";
transfer_info += friendlyUnit(serverState.dl_info_speed, true);
transfer_info += " (" + friendlyUnit(serverState.dl_info_data, false) + ")"
$("DlInfos").set('html', transfer_info);
transfer_info = "";
if (info.up_rate_limit != undefined)
transfer_info += "[" + friendlyUnit(info.up_rate_limit, true) + "] ";
transfer_info += friendlyUnit(info.up_info_speed, true)
transfer_info += " (" + friendlyUnit(info.up_info_data, false) + ")"
if (serverState.up_rate_limit > 0)
transfer_info += "[" + friendlyUnit(serverState.up_rate_limit, true) + "] ";
transfer_info += friendlyUnit(serverState.up_info_speed, true)
transfer_info += " (" + friendlyUnit(serverState.up_info_data, false) + ")"
$("UpInfos").set('html', transfer_info);
if (speedInTitle)
document.title = "QBT_TR(D:%1 U:%2)QBT_TR".replace("%1", friendlyUnit(info.dl_info_speed, true)).replace("%2", friendlyUnit(info.up_info_speed, true));
document.title = "QBT_TR(D:%1 U:%2)QBT_TR".replace("%1", friendlyUnit(serverState.dl_info_speed, true)).replace("%2", friendlyUnit(serverState.up_info_speed, true));
else
document.title = "QBT_TR(qBittorrent web User Interface)QBT_TR";
$('DHTNodes').set('html', 'QBT_TR(DHT: %1 nodes)QBT_TR'.replace("%1", info.dht_nodes));
if (info.connection_status == "connected")
$('DHTNodes').set('html', 'QBT_TR(DHT: %1 nodes)QBT_TR'.replace("%1", serverState.dht_nodes));
if (serverState.connection_status == "connected")
$('connectionStatus').src = 'images/skin/connected.png';
else if (info.connection_status == "firewalled")
else if (serverState.connection_status == "firewalled")
$('connectionStatus').src = 'images/skin/firewalled.png';
else
$('connectionStatus').src = 'images/skin/disconnected.png';
clearTimeout(loadTransferInfoTimer);
loadTransferInfoTimer = loadTransferInfo.delay(3000);
}
}
}).send();
};
updateTransferInfo = function() {
clearTimeout(loadTransferInfoTimer);
loadTransferInfo();
}
// Start fetching data now
loadTransferInfo();
var updateAltSpeedIcon = function(enabled) {
if (enabled)
$('alternativeSpeedLimits').src = "images/slow.png";
@ -264,7 +247,7 @@ window.addEvent('load', function () { @@ -264,7 +247,7 @@ window.addEvent('load', function () {
method: 'post',
onComplete: function() {
alternativeSpeedLimits = !alternativeSpeedLimits;
updateTransferInfo();
updateMainData();
},
onFailure: function() {
// Restore icon in case of failure
@ -278,7 +261,7 @@ window.addEvent('load', function () { @@ -278,7 +261,7 @@ window.addEvent('load', function () {
setSortedColumn = function (column) {
myTable.setSortedColumn(column);
updateTransferList();
updateMainData();
};
$('speedInBrowserTitleBarLink').addEvent('click', function(e) {
@ -288,7 +271,7 @@ window.addEvent('load', function () { @@ -288,7 +271,7 @@ window.addEvent('load', function () {
$('speedInBrowserTitleBarLink').firstChild.style.opacity = '1';
else
$('speedInBrowserTitleBarLink').firstChild.style.opacity = '0';
updateTransferInfo();
updateMainData();
});
new MochaUI.Panel({
@ -304,7 +287,7 @@ window.addEvent('load', function () { @@ -304,7 +287,7 @@ window.addEvent('load', function () {
loadMethod : 'xhr',
contentURL : 'transferlist.html',
onContentLoaded : function () {
updateTransferList();
updateMainData();
},
column : 'mainColumn',
onResize : saveColumnSizes,

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

@ -55,7 +55,7 @@ initializeWindows = function() { @@ -55,7 +55,7 @@ initializeWindows = function() {
width: 500,
height: 300
});
updateTransferList();
updateMainData();
});
addClickEvent('preferences', function(e) {
@ -95,7 +95,7 @@ initializeWindows = function() { @@ -95,7 +95,7 @@ initializeWindows = function() {
width: 600,
height: 130
});
updateTransferList();
updateMainData();
});
globalUploadLimitFN = function() {
@ -144,7 +144,7 @@ initializeWindows = function() { @@ -144,7 +144,7 @@ initializeWindows = function() {
hashes: h.join("|")
}
}).send();
updateTransferList();
updateMainData();
}
};
@ -158,7 +158,7 @@ initializeWindows = function() { @@ -158,7 +158,7 @@ initializeWindows = function() {
hashes: h.join("|")
}
}).send();
updateTransferList();
updateMainData();
}
};
@ -218,7 +218,7 @@ initializeWindows = function() { @@ -218,7 +218,7 @@ initializeWindows = function() {
width: 424,
height: 140
});
updateTransferList();
updateMainData();
}
};
@ -239,7 +239,7 @@ initializeWindows = function() { @@ -239,7 +239,7 @@ initializeWindows = function() {
}
}).send();
});
updateTransferList();
updateMainData();
}
};
@ -255,7 +255,7 @@ initializeWindows = function() { @@ -255,7 +255,7 @@ initializeWindows = function() {
}
}).send();
});
updateTransferList();
updateMainData();
}
};
@ -288,7 +288,7 @@ initializeWindows = function() { @@ -288,7 +288,7 @@ initializeWindows = function() {
}
}).send();
});
updateTransferList();
updateMainData();
}
});
@ -317,7 +317,7 @@ initializeWindows = function() { @@ -317,7 +317,7 @@ initializeWindows = function() {
hashes: h.join("|")
}
}).send();
updateTransferList();
updateMainData();
}
}

2
src/webui/www/public/uploadlimit.html

@ -31,7 +31,7 @@ @@ -31,7 +31,7 @@
'limit': limit
},
onComplete: function() {
window.parent.updateTransferInfo();
window.parent.updateMainData();
window.parent.closeWindows();
}
}).send();

Loading…
Cancel
Save