mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-14 01:03:08 -07:00
Move WebUI Peers code to separate file
This commit is contained in:
parent
a5266c7018
commit
26a9af850b
4 changed files with 108 additions and 81 deletions
|
@ -154,7 +154,6 @@
|
||||||
<script>
|
<script>
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
torrentPeersTable.setup('torrentPeersTableDiv', 'torrentPeersTableFixedHeaderDiv', null);
|
|
||||||
var selectedTab = $(getLocalStorageItem('selected_tab', 'PropGeneralLink'));
|
var selectedTab = $(getLocalStorageItem('selected_tab', 'PropGeneralLink'));
|
||||||
if (selectedTab)
|
if (selectedTab)
|
||||||
selectedTab.click();
|
selectedTab.click();
|
||||||
|
|
|
@ -700,7 +700,7 @@ window.addEvent('load', function() {
|
||||||
contentURL: 'properties_content.html',
|
contentURL: 'properties_content.html',
|
||||||
require: {
|
require: {
|
||||||
css: ['css/Tabs.css', 'css/dynamicTable.css'],
|
css: ['css/Tabs.css', 'css/dynamicTable.css'],
|
||||||
js: ['scripts/prop-general.js', 'scripts/prop-trackers.js', 'scripts/prop-webseeds.js', 'scripts/prop-files.js'],
|
js: ['scripts/prop-general.js', 'scripts/prop-trackers.js', 'scripts/prop-peers.js', 'scripts/prop-webseeds.js', 'scripts/prop-files.js'],
|
||||||
},
|
},
|
||||||
tabsURL: 'properties.html',
|
tabsURL: 'properties.html',
|
||||||
tabsOnload: function() {
|
tabsOnload: function() {
|
||||||
|
@ -838,82 +838,3 @@ var keyboardEvents = new Keyboard({
|
||||||
});
|
});
|
||||||
|
|
||||||
keyboardEvents.activate();
|
keyboardEvents.activate();
|
||||||
|
|
||||||
var loadTorrentPeersTimer;
|
|
||||||
var syncTorrentPeersLastResponseId = 0;
|
|
||||||
var show_flags = true;
|
|
||||||
var loadTorrentPeersData = function() {
|
|
||||||
if ($('prop_peers').hasClass('invisible')
|
|
||||||
|| $('propertiesPanel_collapseToggle').hasClass('panel-expand')) {
|
|
||||||
syncTorrentPeersLastResponseId = 0;
|
|
||||||
torrentPeersTable.clear();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var current_hash = torrentsTable.getCurrentTorrentHash();
|
|
||||||
if (current_hash === "") {
|
|
||||||
syncTorrentPeersLastResponseId = 0;
|
|
||||||
torrentPeersTable.clear();
|
|
||||||
clearTimeout(loadTorrentPeersTimer);
|
|
||||||
loadTorrentPeersTimer = loadTorrentPeersData.delay(getSyncMainDataInterval());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var url = new URI('api/v2/sync/torrentPeers');
|
|
||||||
url.setData('rid', syncTorrentPeersLastResponseId);
|
|
||||||
url.setData('hash', current_hash);
|
|
||||||
new Request.JSON({
|
|
||||||
url: url,
|
|
||||||
noCache: true,
|
|
||||||
method: 'get',
|
|
||||||
onFailure: function() {
|
|
||||||
$('error_div').set('html', 'QBT_TR(qBittorrent client is not reachable)QBT_TR[CONTEXT=HttpServer]');
|
|
||||||
clearTimeout(loadTorrentPeersTimer);
|
|
||||||
loadTorrentPeersTimer = loadTorrentPeersData.delay(5000);
|
|
||||||
},
|
|
||||||
onSuccess: function(response) {
|
|
||||||
$('error_div').set('html', '');
|
|
||||||
if (response) {
|
|
||||||
var full_update = (response['full_update'] === true);
|
|
||||||
if (full_update) {
|
|
||||||
torrentPeersTable.clear();
|
|
||||||
}
|
|
||||||
if (response['rid']) {
|
|
||||||
syncTorrentPeersLastResponseId = response['rid'];
|
|
||||||
}
|
|
||||||
if (response['peers']) {
|
|
||||||
for (var key in response['peers']) {
|
|
||||||
response['peers'][key]['rowId'] = key;
|
|
||||||
|
|
||||||
if (response['peers'][key]['client'])
|
|
||||||
response['peers'][key]['client'] = escapeHtml(response['peers'][key]['client']);
|
|
||||||
|
|
||||||
torrentPeersTable.updateRowData(response['peers'][key]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (response['peers_removed'])
|
|
||||||
response['peers_removed'].each(function(hash) {
|
|
||||||
torrentPeersTable.removeRow(hash);
|
|
||||||
});
|
|
||||||
torrentPeersTable.updateTable(full_update);
|
|
||||||
torrentPeersTable.altRow();
|
|
||||||
|
|
||||||
if (response['show_flags']) {
|
|
||||||
if (show_flags != response['show_flags']) {
|
|
||||||
show_flags = response['show_flags'];
|
|
||||||
torrentPeersTable.columns['country'].force_hide = !show_flags;
|
|
||||||
torrentPeersTable.updateColumn('country');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
torrentPeersTable.clear();
|
|
||||||
}
|
|
||||||
clearTimeout(loadTorrentPeersTimer);
|
|
||||||
loadTorrentPeersTimer = loadTorrentPeersData.delay(getSyncMainDataInterval());
|
|
||||||
}
|
|
||||||
}).send();
|
|
||||||
};
|
|
||||||
|
|
||||||
updateTorrentPeersData = function() {
|
|
||||||
clearTimeout(loadTorrentPeersTimer);
|
|
||||||
loadTorrentPeersData();
|
|
||||||
};
|
|
||||||
|
|
106
src/webui/www/private/scripts/prop-peers.js
Normal file
106
src/webui/www/private/scripts/prop-peers.js
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
/*
|
||||||
|
* Bittorrent Client using Qt and libtorrent.
|
||||||
|
* Copyright (C) 2018 Thomas Piccirello <thomas.piccirello@gmail.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
* In addition, as a special exception, the copyright holders give permission to
|
||||||
|
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
||||||
|
* modified versions of it that use the same license as the "OpenSSL" library),
|
||||||
|
* and distribute the linked executables. You must obey the GNU General Public
|
||||||
|
* License in all respects for all of the code used other than "OpenSSL". If you
|
||||||
|
* modify file(s), you may extend this exception to your version of the file(s),
|
||||||
|
* but you are not obligated to do so. If you do not wish to do so, delete this
|
||||||
|
* exception statement from your version.
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var loadTorrentPeersTimer;
|
||||||
|
var syncTorrentPeersLastResponseId = 0;
|
||||||
|
var show_flags = true;
|
||||||
|
var loadTorrentPeersData = function() {
|
||||||
|
if ($('prop_peers').hasClass('invisible')
|
||||||
|
|| $('propertiesPanel_collapseToggle').hasClass('panel-expand')) {
|
||||||
|
syncTorrentPeersLastResponseId = 0;
|
||||||
|
torrentPeersTable.clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var current_hash = torrentsTable.getCurrentTorrentHash();
|
||||||
|
if (current_hash === "") {
|
||||||
|
syncTorrentPeersLastResponseId = 0;
|
||||||
|
torrentPeersTable.clear();
|
||||||
|
clearTimeout(loadTorrentPeersTimer);
|
||||||
|
loadTorrentPeersTimer = loadTorrentPeersData.delay(getSyncMainDataInterval());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var url = new URI('api/v2/sync/torrentPeers');
|
||||||
|
url.setData('rid', syncTorrentPeersLastResponseId);
|
||||||
|
url.setData('hash', current_hash);
|
||||||
|
new Request.JSON({
|
||||||
|
url: url,
|
||||||
|
noCache: true,
|
||||||
|
method: 'get',
|
||||||
|
onComplete: function() {
|
||||||
|
clearTimeout(loadTorrentPeersTimer);
|
||||||
|
loadTorrentPeersTimer = loadTorrentPeersData.delay(getSyncMainDataInterval());
|
||||||
|
},
|
||||||
|
onSuccess: function(response) {
|
||||||
|
$('error_div').set('html', '');
|
||||||
|
if (response) {
|
||||||
|
var full_update = (response['full_update'] === true);
|
||||||
|
if (full_update)
|
||||||
|
torrentPeersTable.clear();
|
||||||
|
if (response['rid'])
|
||||||
|
syncTorrentPeersLastResponseId = response['rid'];
|
||||||
|
if (response['peers']) {
|
||||||
|
for (var key in response['peers']) {
|
||||||
|
response['peers'][key]['rowId'] = key;
|
||||||
|
|
||||||
|
if (response['peers'][key]['client'])
|
||||||
|
response['peers'][key]['client'] = escapeHtml(response['peers'][key]['client']);
|
||||||
|
|
||||||
|
torrentPeersTable.updateRowData(response['peers'][key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (response['peers_removed']) {
|
||||||
|
response['peers_removed'].each(function(hash) {
|
||||||
|
torrentPeersTable.removeRow(hash);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
torrentPeersTable.updateTable(full_update);
|
||||||
|
torrentPeersTable.altRow();
|
||||||
|
|
||||||
|
if (response['show_flags']) {
|
||||||
|
if (show_flags != response['show_flags']) {
|
||||||
|
show_flags = response['show_flags'];
|
||||||
|
torrentPeersTable.columns['country'].force_hide = !show_flags;
|
||||||
|
torrentPeersTable.updateColumn('country');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
torrentPeersTable.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).send();
|
||||||
|
};
|
||||||
|
|
||||||
|
updateTorrentPeersData = function() {
|
||||||
|
clearTimeout(loadTorrentPeersTimer);
|
||||||
|
loadTorrentPeersData();
|
||||||
|
};
|
||||||
|
|
||||||
|
torrentPeersTable.setup('torrentPeersTableDiv', 'torrentPeersTableFixedHeaderDiv', null);
|
|
@ -38,6 +38,7 @@
|
||||||
<file>private/scripts/progressbar.js</file>
|
<file>private/scripts/progressbar.js</file>
|
||||||
<file>private/scripts/prop-files.js</file>
|
<file>private/scripts/prop-files.js</file>
|
||||||
<file>private/scripts/prop-general.js</file>
|
<file>private/scripts/prop-general.js</file>
|
||||||
|
<file>private/scripts/prop-peers.js</file>
|
||||||
<file>private/scripts/prop-trackers.js</file>
|
<file>private/scripts/prop-trackers.js</file>
|
||||||
<file>private/scripts/prop-webseeds.js</file>
|
<file>private/scripts/prop-webseeds.js</file>
|
||||||
<file>private/setlocation.html</file>
|
<file>private/setlocation.html</file>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue