diff --git a/webui-src/app/assets/index.html b/webui-src/app/assets/index.html index cc65f21..f07f98e 100644 --- a/webui-src/app/assets/index.html +++ b/webui-src/app/assets/index.html @@ -12,15 +12,23 @@ This is the node's certificate: + diff --git a/webui-src/app/downloads.js b/webui-src/app/downloads.js new file mode 100644 index 0000000..9af124c --- /dev/null +++ b/webui-src/app/downloads.js @@ -0,0 +1,96 @@ +var m = require("mithril"); +var rs = require("rswebui"); + +function makeFriendlyUnit(bytes) +{ + if(bytes < 1e3) + return bytes.toFixed(1) + "B"; + if(bytes < 1e6) + return (bytes/1e3).toFixed(1) + "kB"; + if(bytes < 1e9) + return (bytes/1e6).toFixed(1) + "MB"; + if(bytes < 1e12) + return (bytes/1e9).toFixed(1) + "GB"; + return (bytes/1e12).toFixed(1) + "TB"; +} + +function progressBar(file){ + return m("div[style=border:5px solid lime;" + + 'border-radius:3mm;' + + 'padding:2mm;' + + 'height:5mm' + + "]", [ + m("div[style=" + + 'background-color:lime;' + + 'height:100%;' + + 'width:' + (file.transferred / file.size * 100)+'%' + + ']' + ,"") + ]); +}; + +//function cntrlBtn(file, act) { +// return( +// m("div.btn",{ +// onclick: function(){ +// rs.request("transfers/control_download",{action: act, hash: file.hash}); +// } +// }, +// act) +// ) +//} + +module.exports = { + view: function(callback){ + rs.requestDownloads(callback); + +// var filestreamer_url = "/fstream/"; +// if (paths === undefined) { +// return m("div", "Downloads ... please wait ..."); +// } +// return m("div", [ +// m("h2","Downloads (" + paths.length +")"), +// m("div.btn2", { +// onclick: function(){ +// m.route("/downloads/add"); +// } +// +// m("hr"), +// m('table', [ +// m("tr",[ +// m("th","name"), +// m("th","size"), +// m("th","progress"), +// m("th","transfer rate"), +// m("th","status"), +// m("th","progress"), +// m("th","action") +// ]), +// paths.map(function (file){ +// var ctrlBtn = m("div",""); +// var progress = file.transferred / file.size * 100; +// return m("tr",[ +// m("td",[ +// m("a.filelink", +// { +// target: "blank", +// href: filestreamer_url + file.hash + "/" + encodeURIComponent(file.name) +// }, +// file.name +// ) +// ]), +// m("td", makeFriendlyUnit(file.size)), +// m("td", progress.toPrecision(3) + "%"), +// m("td", makeFriendlyUnit(file.transfer_rate*1e3)+"/s"), +// m("td", file.download_status), +// m("td", progressBar(file)), +// m("td", [ +// cntrlBtn(file, file.download_status==="paused"?"start":"pause"), +// cntrlBtn(file, "cancel")] +// ) +// ]) +// }) +// ]) +// ]); + } +}; diff --git a/webui-src/app/rswebui.js b/webui-src/app/rswebui.js index 3de72a7..42c1437 100644 --- a/webui-src/app/rswebui.js +++ b/webui-src/app/rswebui.js @@ -29,8 +29,46 @@ module.exports = { var jsonData = JSON.parse(p) callback(jsonData.retval) } - rsJsonApiRequest("/rsPeers/GetRetroshareInvite", "", setNodeCertificate,true) // call is synced because we want to return the result - } + rsJsonApiRequest("/rsPeers/GetRetroshareInvite", "", setNodeCertificate,true) + }, + + requestDownloads:function(callback) { + + var downloads_info = "" + + function displayDLInfo(p) + { + var jsonData = JSON.parse(p) + + if(jsonData.retval === "false") + console.warning("Cannot retrieve info!!"); + + downloads_info += jsonData.info.hash + ": size=" + jsonData.info.size + ": progress=" + jsonData.info.avail + "\n"; + } + function requestDLData(hash) + { + var json_params = { + hash: hash, + hintflags: 16 // = RS_FILE_HINTS_DOWNLOAD + } + console.log("requesting DL data for hash: "+hash) + rsJsonApiRequest("/rsFiles/FileDetails", JSON.stringify(json_params), displayDLInfo,false) + } + + function setDownloads(p) + { + var jsonData = JSON.parse(p) + + // now for each hash, request the current progress + + jsonData.hashs.forEach(requestDLData); + + // and send back the result + + callback(downloads_info); + } + rsJsonApiRequest("/rsFiles/FileDownloads", "", setDownloads,true) + } }; diff --git a/webui.pro b/webui.pro index 13ea789..63090f5 100644 --- a/webui.pro +++ b/webui.pro @@ -42,11 +42,12 @@ linux-* { WEBUI_SRC_JS += webui-src/app/rswebui.js WEBUI_SRC_JS += webui-src/app/mithril.js WEBUI_SRC_JS += webui-src/app/mithril.min.js + WEBUI_SRC_JS += webui-src/app/downloads.js +# WEBUI_SRC_JS += webui-src/app/peers.js # WEBUI_SRC_JS += webui-src/app/main.js # WEBUI_SRC_JS += webui-src/app/menudef.js # WEBUI_SRC_JS += webui-src/app/menu.js -# WEBUI_SRC_JS += webui-src/app/peers.js # WEBUI_SRC_JS += webui-src/app/retroshare.js # WEBUI_SRC_JS += webui-src/app/accountselect.js # WEBUI_SRC_JS += webui-src/app/adddownloads.js @@ -54,7 +55,6 @@ linux-* { # WEBUI_SRC_JS += webui-src/app/addpeer.js # WEBUI_SRC_JS += webui-src/app/chat.js # WEBUI_SRC_JS += webui-src/app/createlogin.js -# WEBUI_SRC_JS += webui-src/app/downloads.js # WEBUI_SRC_JS += webui-src/app/forums.js # WEBUI_SRC_JS += webui-src/app/home.js # WEBUI_SRC_JS += webui-src/app/identities.js