From b430cba806a292c5d6dc87b98f5f7901bdf4d727 Mon Sep 17 00:00:00 2001 From: zeners Date: Thu, 7 Jan 2016 21:00:57 +0100 Subject: [PATCH] webui: download prototype --- libresapi/src/webui-src/app/downloads.js | 83 ++++++++++++++++++++++++ libresapi/src/webui-src/app/main.js | 4 +- libresapi/src/webui-src/app/menudef.js | 4 ++ 3 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 libresapi/src/webui-src/app/downloads.js diff --git a/libresapi/src/webui-src/app/downloads.js b/libresapi/src/webui-src/app/downloads.js new file mode 100644 index 000000000..6ea65f2f0 --- /dev/null +++ b/libresapi/src/webui-src/app/downloads.js @@ -0,0 +1,83 @@ +var m = require("mithril"); +var rs = require("retroshare"); + +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.transfered / file.size * 100)+'%' + + ']' + ,"") + ]); +}; + +function cntrlBtn(file, act) { + return( + m("button",{ + onclick: function(){ + rs.request("transfers/control_download",{action: act, id: file.id}); + } + }, + act) + ) +} + + +module.exports = { + view: function(){ + var paths = rs("transfers/downloads"); + if (paths === undefined) { + return m("div", "Downloads ... please wait ..."); + } + return m("div", [ + m("div","Downloads (" + paths.length +")"), + m("hr[style=color:silver]"), + m('table[cellspacing=2][style=padding:2px !important;margin:2px !important;border-spacing: 2px]', [ + m("tr[style=font-weight:bold]",[ + m("th[style=padding:2px]","name"), + m("th[style=padding:2px]","size"), + m("th[style=padding:2px]","progress"), + m("th[style=padding:2px]","transfer rate"), + m("th[style=padding:2px]","status"), + m("th[style=padding:2px]","progress"), + m("th[style=padding:2px]","action") + ]), + paths.map(function (file){ + var ctrlBtn = m("div",""); + var progress = file.transfered / file.size * 100; + return m("tr",[ + m("td[style=padding:2px;style=padding: 0.3em;border-style: solid;border-width: 0.1em;border-color: #0F0]", file.name), + m("td[style=padding:2px;style=padding: 0.3em;border-style: solid;border-width: 0.1em;border-color: #0F0]", makeFriendlyUnit(file.size)), + m("td[style=text-align:right;padding:2px;style=padding: 0.3em;border-style: solid;border-width: 0.1em;border-color: #0F0]", progress.toPrecision(3) + "%"), + m("td[style=text-align:right;padding:2px;style=padding: 0.3em;border-style: solid;border-width: 0.1em;border-color: #0F0]", makeFriendlyUnit(file.transfer_rate*1e3)+"/s"), + m("td[style=padding:2px;style=padding: 0.3em;border-style: solid;border-width: 0.1em;border-color: #0F0]", file.download_status), + m("td[style=padding:2px;style=padding: 0.3em;border-style: solid;border-width: 0.1em;border-color: #0F0]", progressBar(file)), + m("td[style=padding:2px;style=padding: 0.3em;border-style: solid;border-width: 0.1em;border-color: #0F0]", [ + cntrlBtn(file, file.download_status==="paused"?"start":"pause"), + m("span"," "), + cntrlBtn(file, "cancel")] + ) + ]) + }) + ]) + ]); + } +}; diff --git a/libresapi/src/webui-src/app/main.js b/libresapi/src/webui-src/app/main.js index ff58a7699..39273fba5 100644 --- a/libresapi/src/webui-src/app/main.js +++ b/libresapi/src/webui-src/app/main.js @@ -21,7 +21,7 @@ function Page(content, runst){ this.view = function(){ var runstate = rs("control/runstate"); var needpasswd = rs("control/password"); - console.log("runstate: " + (runstate === undefined ? runstate : runstate.runstate)); + //console.log("runstate: " + (runstate === undefined ? runstate : runstate.runstate)); if(runstate === undefined){ return m("div", "waiting_server ... "); } else if (runstate.runstate == null){ @@ -78,7 +78,7 @@ me.init = function(main){ } }); m.route.mode = "hash"; - m.route(main,"/chat",maps); + m.route(main,"/",maps); console.log("init done."); }; diff --git a/libresapi/src/webui-src/app/menudef.js b/libresapi/src/webui-src/app/menudef.js index 57fd13cae..f03ac9db8 100644 --- a/libresapi/src/webui-src/app/menudef.js +++ b/libresapi/src/webui-src/app/menudef.js @@ -12,6 +12,10 @@ module.exports = { nodes: [ name: "peers", runstate: "running_ok.*", }, + { + name: "downloads", + runstate: "running_ok.*", + }, { name: "chat", runstate: "running_ok.*",