tracker stats table periodically
This commit is contained in:
parent
79616c5ed5
commit
bfb968fc4f
|
@ -12,6 +12,12 @@ async def active_torrents(ws, data):
|
||||||
res = {'event': 'active_torrents', 'data': data}
|
res = {'event': 'active_torrents', 'data': data}
|
||||||
await ws.send_json(res)
|
await ws.send_json(res)
|
||||||
|
|
||||||
|
async def tracker_stats(ws, data):
|
||||||
|
"""Returns tracker stats."""
|
||||||
|
data = rtorrent.get_stats()
|
||||||
|
res = {'event': 'tracker_stats', 'data': data}
|
||||||
|
await ws.send_json(res)
|
||||||
|
|
||||||
events = {}
|
events = {}
|
||||||
for obj in dir():
|
for obj in dir():
|
||||||
if type(locals()[obj]) == types.FunctionType:
|
if type(locals()[obj]) == types.FunctionType:
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
function load() {
|
function load() {
|
||||||
//let intervalID = window.setInterval(get_active_torrents_ajax, 20000);
|
//let intervalID = window.setInterval(get_active_torrents_ajax, 20000);
|
||||||
let intervalID = window.setInterval(get_active_torrents, 5000);
|
let intervalID = window.setInterval(update, 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_active_torrents_ajax() {
|
function get_active_torrents_ajax() {
|
||||||
|
@ -65,7 +65,19 @@ socket.events['active_torrents'] = function(data) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
socket.events['tracker_stats'] = function(data) {
|
socket.events['tracker_stats'] = function(data) {
|
||||||
console.log(data);
|
let table = document.querySelector('#tracker_stats tbody');
|
||||||
|
while (table.firstChild) {
|
||||||
|
table.removeChild(table.firstChild);
|
||||||
|
}
|
||||||
|
for (let [tracker, values] of Object.entries(data)) {
|
||||||
|
let template = document.querySelector('#tracker_template');
|
||||||
|
let node = document.importNode(template.content, true);
|
||||||
|
node.children[0].children[0].textContent = tracker;
|
||||||
|
for (let i = 0; i < values.length; i++) {
|
||||||
|
node.children[0].children[i+1].textContent = values[i];
|
||||||
|
}
|
||||||
|
table.appendChild(node);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Websocket send */
|
/* Websocket send */
|
||||||
|
@ -75,3 +87,9 @@ function get_active_torrents() {
|
||||||
function get_tracker_stats() {
|
function get_tracker_stats() {
|
||||||
socket.send('tracker_stats', {});
|
socket.send('tracker_stats', {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Helper */
|
||||||
|
function update() {
|
||||||
|
get_active_torrents();
|
||||||
|
get_tracker_stats();
|
||||||
|
}
|
||||||
|
|
|
@ -75,5 +75,13 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<template id="tracker_template">
|
||||||
|
<tr>
|
||||||
|
<td class="tracker_stat"></td>
|
||||||
|
<td class="hashing"></td>
|
||||||
|
<td class="error"></td>
|
||||||
|
<td class="total"></td>
|
||||||
|
</tr>
|
||||||
|
</template>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user