tstor/torrent/assets/js/file_chunks.js
Antonio Navarro Perez ecd524ed3c First functional web interface version.
- Simplify by now all html and javascript.
- Added a simple interface using go templates and plain javascript.
- Improved REST interface for the use case.
- Changed some properties into the config file to make it suitable for
future use cases.

Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>
2020-05-18 19:42:23 +02:00

39 lines
1.3 KiB
JavaScript

function FileChunks() {
this.update = function (chunks, totalPieces, hash) {
var dom = document.getElementById("file-chunks-" + hash);
dom.innerHTML = "";
chunks.forEach(chunk => {
dom.appendChild(getPrintedChunk(chunk.status, chunk.numPieces, totalPieces));
});
};
var pieceStatus = {
"H": { class: "bg-warning", tooltip: "checking pieces" },
"P": { class: "bg-info", tooltip: "" },
"C": { class: "bg-success", tooltip: "downloaded pieces" },
"W": { class: "bg-transparent" },
"?": { class: "bg-danger", tooltip: "erroed pieces" },
};
var getPrintedChunk = function (status, pieces, totalPieces) {
var percentage = totalPieces * pieces / 100;
var pcMeta = pieceStatus[status]
var pieceStatusClass = pcMeta.class;
var pieceStatusTip = pcMeta.tooltip;
var div = document.createElement("div");
div.className = "progress-bar " + pieceStatusClass;
div.setAttribute("role", "progressbar");
if (pieceStatusTip) {
div.setAttribute("data-toggle", "tooltip");
div.setAttribute("data-placement", "top");
div.setAttribute("title", pieceStatusTip);
}
div.style.cssText = "width: " + percentage + "%";
return div;
};
};