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. 171
      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 @@
'limit': limit 'limit': limit
}, },
onComplete: function() { onComplete: function() {
window.parent.updateTransferInfo(); window.parent.updateMainData();
window.parent.closeWindows(); window.parent.closeWindows();
} }
}).send(); }).send();

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

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

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

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

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

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

Loading…
Cancel
Save