Browse Source

WebUI: Update torrent properties immediately

Don't wait for new data to be fetched, request them as soon as
they are required, i.e. when a property tab is loaded or when a
different torrent is selected.
adaptive-webui-19844
Gabriele 10 years ago
parent
commit
408cc7101e
  1. 14
      src/webui/www/public/scripts/client.js
  2. 2
      src/webui/www/public/scripts/dynamicTable.js
  3. 18
      src/webui/www/public/scripts/prop-files.js
  4. 21
      src/webui/www/public/scripts/prop-general.js
  5. 18
      src/webui/www/public/scripts/prop-trackers.js

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

@ -24,6 +24,8 @@
myTable = new dynamicTable(); myTable = new dynamicTable();
var updatePropertiesPanel = function(){};
var stateToImg = function (state) { var stateToImg = function (state) {
if (state == "pausedUP" || state == "pausedDL") { if (state == "pausedUP" || state == "pausedDL") {
state = "paused"; state = "paused";
@ -320,22 +322,34 @@ window.addEvent('load', function () {
tabsOnload : function() { tabsOnload : function() {
MochaUI.initializeTabs('propertiesTabs'); MochaUI.initializeTabs('propertiesTabs');
updatePropertiesPanel = function() {
if (!$('prop_general').hasClass('invisible'))
updateTorrentData();
else if (!$('prop_trackers').hasClass('invisible'))
updateTrackersData();
else if (!$('prop_files').hasClass('invisible'))
updateTorrentFilesData();
}
$('PropGeneralLink').addEvent('click', function(e){ $('PropGeneralLink').addEvent('click', function(e){
$('prop_general').removeClass("invisible"); $('prop_general').removeClass("invisible");
$('prop_trackers').addClass("invisible"); $('prop_trackers').addClass("invisible");
$('prop_files').addClass("invisible"); $('prop_files').addClass("invisible");
updatePropertiesPanel();
}); });
$('PropTrackersLink').addEvent('click', function(e){ $('PropTrackersLink').addEvent('click', function(e){
$('prop_trackers').removeClass("invisible"); $('prop_trackers').removeClass("invisible");
$('prop_general').addClass("invisible"); $('prop_general').addClass("invisible");
$('prop_files').addClass("invisible"); $('prop_files').addClass("invisible");
updatePropertiesPanel();
}); });
$('PropFilesLink').addEvent('click', function(e){ $('PropFilesLink').addEvent('click', function(e){
$('prop_files').removeClass("invisible"); $('prop_files').removeClass("invisible");
$('prop_general').addClass("invisible"); $('prop_general').addClass("invisible");
$('prop_trackers').addClass("invisible"); $('prop_trackers').addClass("invisible");
updatePropertiesPanel();
}); });
}, },
column : 'mainColumn', column : 'mainColumn',

2
src/webui/www/public/scripts/dynamicTable.js

@ -220,7 +220,7 @@ var dynamicTable = new Class({
temptr.addClass('selected'); temptr.addClass('selected');
} }
this.cur[0] = id; this.cur[0] = id;
// TODO: Warn Properties panel updatePropertiesPanel();
} }
} }
return false; return false;

18
src/webui/www/public/scripts/prop-files.js

@ -1,4 +1,3 @@
var waitingTorrentFiles = false;
var is_seed = true; var is_seed = true;
var current_hash = ""; var current_hash = "";
@ -273,6 +272,7 @@ var filesDynTable = new Class({
}, },
}); });
var loadTorrentFilesDataTimer;
var loadTorrentFilesData = function() { var loadTorrentFilesData = function() {
if ($('prop_files').hasClass('invisible')) { if ($('prop_files').hasClass('invisible')) {
// Tab changed, don't do anything // Tab changed, don't do anything
@ -281,7 +281,7 @@ var loadTorrentFilesData = function() {
var new_hash = myTable.getCurrentTorrentHash(); var new_hash = myTable.getCurrentTorrentHash();
if (new_hash == "") { if (new_hash == "") {
fTable.removeAllRows(); fTable.removeAllRows();
loadTorrentFilesData.delay(1500); loadTorrentFilesDataTimer = loadTorrentFilesData.delay(1500);
return; return;
} }
if (new_hash != current_hash) { if (new_hash != current_hash) {
@ -289,16 +289,13 @@ var loadTorrentFilesData = function() {
current_hash = new_hash; current_hash = new_hash;
} }
var url = 'json/propertiesFiles/' + current_hash; var url = 'json/propertiesFiles/' + current_hash;
if (!waitingTorrentFiles) {
waitingTorrentFiles = true;
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', '_(qBittorrent client is not reachable)'); $('error_div').set('html', '_(qBittorrent client is not reachable)');
waitingTorrentFiles = false; loadTorrentFilesDataTimer = loadTorrentFilesData.delay(2000);
loadTorrentFilesData.delay(2000);
}, },
onSuccess: function(files) { onSuccess: function(files) {
$('error_div').set('html', ''); $('error_div').set('html', '');
@ -337,12 +334,15 @@ var loadTorrentFilesData = function() {
else { else {
fTable.removeAllRows(); fTable.removeAllRows();
} }
waitingTorrentFiles = false; loadTorrentFilesDataTimer = loadTorrentFilesData.delay(1500);
loadTorrentFilesData.delay(1500);
} }
}).send(); }).send();
} }
var updateTorrentFilesData = function() {
clearTimeout(loadTorrentFilesDataTimer);
loadTorrentFilesData();
} }
fTable = new filesDynTable(); fTable = new filesDynTable();
fTable.setup($('filesTable')); fTable.setup($('filesTable'));

21
src/webui/www/public/scripts/prop-general.js

@ -1,5 +1,3 @@
var waiting = false;
var clearData = function() { var clearData = function() {
$('torrent_hash').set('html', ''); $('torrent_hash').set('html', '');
$('save_path').set('html', ''); $('save_path').set('html', '');
@ -16,7 +14,8 @@ var clearData = function() {
$('share_ratio').set('html', ''); $('share_ratio').set('html', '');
} }
var loadData = function() { var loadTorrentDataTimer;
var loadTorrentData = function() {
if ($('prop_general').hasClass('invisible')) { if ($('prop_general').hasClass('invisible')) {
// Tab changed, don't do anything // Tab changed, don't do anything
return; return;
@ -24,22 +23,19 @@ var loadData = function() {
var current_hash = myTable.getCurrentTorrentHash(); var current_hash = myTable.getCurrentTorrentHash();
if (current_hash == "") { if (current_hash == "") {
clearData(); clearData();
loadData.delay(1500); loadTorrentDataTimer = loadTorrentData.delay(1500);
return; return;
} }
// Display hash // Display hash
$('torrent_hash').set('html', current_hash); $('torrent_hash').set('html', current_hash);
var url = 'json/propertiesGeneral/' + current_hash; var url = 'json/propertiesGeneral/' + current_hash;
if (!waiting) {
waiting = true;
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', '_(qBittorrent client is not reachable)'); $('error_div').set('html', '_(qBittorrent client is not reachable)');
waiting = false; loadTorrentDataTimer = loadTorrentData.delay(2000);
loadData.delay(2000);
}, },
onSuccess: function(data) { onSuccess: function(data) {
$('error_div').set('html', ''); $('error_div').set('html', '');
@ -76,9 +72,12 @@ var loadData = function() {
else { else {
clearData(); clearData();
} }
waiting = false; loadTorrentDataTimer = loadTorrentData.delay(1500);
loadData.delay(1500);
} }
}).send(); }).send();
} }
var updateTorrentData = function() {
clearTimeout(loadTorrentDataTimer);
loadTorrentData();
} }

18
src/webui/www/public/scripts/prop-trackers.js

@ -50,9 +50,9 @@ var trackersDynTable = new Class({
}, },
}); });
var waitingTrackers = false;
var current_hash = ""; var current_hash = "";
var loadTrackersDataTimer;
var loadTrackersData = function() { var loadTrackersData = function() {
if ($('prop_trackers').hasClass('invisible')) { if ($('prop_trackers').hasClass('invisible')) {
// Tab changed, don't do anything // Tab changed, don't do anything
@ -61,7 +61,7 @@ var loadTrackersData = function() {
var new_hash = myTable.getCurrentTorrentHash(); var new_hash = myTable.getCurrentTorrentHash();
if (new_hash == "") { if (new_hash == "") {
tTable.removeAllRows(); tTable.removeAllRows();
loadTrackersData.delay(1500); loadTrackersDataTimer = loadTrackersData.delay(1500);
return; return;
} }
if (new_hash != current_hash) { if (new_hash != current_hash) {
@ -69,16 +69,13 @@ var loadTrackersData = function() {
current_hash = new_hash; current_hash = new_hash;
} }
var url = 'json/propertiesTrackers/' + current_hash; var url = 'json/propertiesTrackers/' + current_hash;
if (!waitingTrackers) {
waitingTrackers = true;
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', '_(qBittorrent client is not reachable)'); $('error_div').set('html', '_(qBittorrent client is not reachable)');
waitingTrackers = false; loadTrackersDataTimer = loadTrackersData.delay(2000);
loadTrackersData.delay(2000);
}, },
onSuccess: function(trackers) { onSuccess: function(trackers) {
$('error_div').set('html', ''); $('error_div').set('html', '');
@ -97,13 +94,16 @@ var loadTrackersData = function() {
else { else {
tTable.removeAllRows(); tTable.removeAllRows();
} }
waitingTrackers = false; loadTrackersDataTimer = loadTrackersData.delay(1500);
loadTrackersData.delay(1500);
} }
}).send(); }).send();
} }
var updateTrackersData = function() {
clearTimeout(loadTrackersDataTimer);
loadTrackersData();
} }
tTable = new trackersDynTable(); tTable = new trackersDynTable();
tTable.setup($('trackersTable')); tTable.setup($('trackersTable'));

Loading…
Cancel
Save