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 @@ @@ -24,6 +24,8 @@
myTable = new dynamicTable();
var updatePropertiesPanel = function(){};
var stateToImg = function (state) {
if (state == "pausedUP" || state == "pausedDL") {
state = "paused";
@ -320,22 +322,34 @@ window.addEvent('load', function () { @@ -320,22 +322,34 @@ window.addEvent('load', function () {
tabsOnload : function() {
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){
$('prop_general').removeClass("invisible");
$('prop_trackers').addClass("invisible");
$('prop_files').addClass("invisible");
updatePropertiesPanel();
});
$('PropTrackersLink').addEvent('click', function(e){
$('prop_trackers').removeClass("invisible");
$('prop_general').addClass("invisible");
$('prop_files').addClass("invisible");
updatePropertiesPanel();
});
$('PropFilesLink').addEvent('click', function(e){
$('prop_files').removeClass("invisible");
$('prop_general').addClass("invisible");
$('prop_trackers').addClass("invisible");
updatePropertiesPanel();
});
},
column : 'mainColumn',

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

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

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

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

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

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

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

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

Loading…
Cancel
Save