WebUI: Add pieces progress bar to General tab

Closes #15292.
PR #15418.
This commit is contained in:
Jesse Smick
2021-09-11 21:55:41 -07:00
committed by GitHub
parent dabba89682
commit 6229b81730
3 changed files with 87 additions and 0 deletions

View File

@@ -65,6 +65,9 @@ window.qBittorrent.PropGeneral = (function() {
$('torrent_hash_v2').set('html', '');
$('save_path').set('html', '');
$('comment').set('html', '');
const canvas = $('progress').getFirst('canvas');
canvas.getContext('2d').clearRect(0, 0, canvas.width, canvas.height);
};
let loadTorrentDataTimer;
@@ -213,6 +216,66 @@ window.qBittorrent.PropGeneral = (function() {
loadTorrentDataTimer = loadTorrentData.delay(5000);
}
}).send();
const piecesUrl = new URI('api/v2/torrents/pieceStates?hash=' + current_id);
new Request.JSON({
url: piecesUrl,
noCache: true,
method: 'get',
onFailure: function() {
$('error_div').set('html', 'QBT_TR(qBittorrent client is not reachable)QBT_TR[CONTEXT=HttpServer]');
clearTimeout(loadTorrentDataTimer);
loadTorrentDataTimer = loadTorrentData.delay(10000);
},
onSuccess: function(data) {
$('error_div').set('html', '');
if (data) {
const canvas = $('progress').getFirst('canvas');
canvas.width = data.length;
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Group contiguous colors together and draw as a single rectangle
let color = '';
let rectWidth = 1;
for (let i = 0; i < data.length; ++i) {
const status = data[i];
let newColor = '';
if (status === 1)
newColor = 'green';
else if (status === 2)
newColor = 'blue';
if (newColor === color) {
++rectWidth;
continue;
}
if (color !== '') {
ctx.fillStyle = color;
ctx.fillRect((i - rectWidth), 0, rectWidth, canvas.height);
}
rectWidth = 1;
color = newColor;
}
// Fill a rect at the end of the canvas if one is needed
if (color !== '') {
ctx.fillStyle = color;
ctx.fillRect((data.length - rectWidth), 0, rectWidth, canvas.height);
}
}
else {
clearData();
}
clearTimeout(loadTorrentDataTimer);
loadTorrentDataTimer = loadTorrentData.delay(5000);
}
}).send();
};
const updateData = function() {