diff --git a/libresapi/src/webui-src/app/addpeer.js b/libresapi/src/webui-src/app/addpeer.js index 5d6ba7992..5f8806ccf 100644 --- a/libresapi/src/webui-src/app/addpeer.js +++ b/libresapi/src/webui-src/app/addpeer.js @@ -3,12 +3,92 @@ var m = require("mithril"); var rs = require("retroshare"); +var newkey = ""; +var remote = ""; module.exports = { view: function(){ - return m("h2","add new friend"); + var key = m.route.param("radix"); + var pgp = m.route.param("pgp_id"); + var peer_id =m.route.param("peer_id"); + + if (key===undefined && pgp === undefined) { + + var owncert = rs("peers/self/certificate"); + if (owncert === undefined ) { + owncert = {cert_string:"< waiting for server ... >"} + } + return m("div", [ + m("h2","add new friend (Step 1/3)"), + m("p","Your own key, give it to your friends"), + m("pre", owncert.cert_string), + m("p","paste your friends key below"), + m("textarea", { + ref:"cert", + cols:"70", + rows:"16", + onchange: m.withAttr("value", function(value){newkey=value;}) + }), + m("br"), + m("input.btn2",{ + type:"button", + value:"read", + onclick: function (){ + m.route("/addpeer",{radix:newkey}) + }, + }) + ]); + } else if (pgp === undefined) { + rs.request("peers/examine_cert",{cert_string:key}, + function(data,responsetoken){ + data.radix=key; + m.route("/addpeer", data); + } + ); + return m("div", [ + m("h2","add new friend (Step 2/3)"), + m("div", "analyse cert, please wait for server ...") + // { data: null, debug_msg: "failed to load certificate ", returncode: "fail" } + ]); + } else { + var result = { + cert_string:key , + flags:{ + allow_direct_download:false, + allow_push:false, + // set to false, until the webinterface supports managment of the blacklist/whitelist + require_whitelist: false, + } + }; + return m("div",[ + m("h2","add new friend (Step 2/3)"), + m("p","Do you want to add " + + m.route.param("name") + + " (" + m.route.param("location") + ")" + + " to your friendslist?"), + m("input.checkbox[type=checkbox]", { + onchange: m.withAttr("checked", function(checked){ + result.flags.allow_direct_download=checked; + }) + }), "Allow direct downloads from this node", + m("br"), + m("input.checkbox[type=checkbox]", { + onchange: m.withAttr("checked", function(checked){ + result.flags.allow_push=checked; + }) + }), "Auto download recommended files from this node", + m("div.btn2",{ + onclick: function(){ + rs.request("peers",result,function(data, responsetoken){ + m.route("/peers"); + }) + } + },"add to friendslist") + + ]) + } } -} +}; /* diff --git a/libresapi/src/webui-src/app/main.js b/libresapi/src/webui-src/app/main.js index a7f687ee3..32ea255a0 100644 --- a/libresapi/src/webui-src/app/main.js +++ b/libresapi/src/webui-src/app/main.js @@ -37,7 +37,7 @@ function Page(content, runst){ } else { if ("waiting_init|waiting_startup".match(runstate.runstate)) { return m("h2","server starting ...") - } else if("waiting_account_select|running_ok*".match(runstate.runstate)) { + } else if("waiting_account_select|running_ok.*".match(runstate.runstate)) { if (runst === undefined || runst.match(runstate.runstate)) { return m("div", [ m("div", menu.view()), @@ -61,26 +61,24 @@ function Page(content, runst){ }; -var me ={}; +module.exports = { + init:function(main){ + console.log("start init ..."); + var menudef = require("menudef"); + var maps = {}; + var m = require("mithril"); -me.init = function(main){ - console.log("start init ..."); - var menudef = require("menudef"); - var maps = {}; - var m = require("mithril"); - - menudef.nodes.map(function(menu){ - if (menu.action === undefined) { - var path = menu.path != undefined ? menu.path : ("/" + menu.name); - var module = menu.module != undefined ? menu.module : menu.name - console.log("adding route " + menu.name + " for " + path + " with module " + module); - maps[path] = new Page(require(module), menu.runstate); - } - }); - m.route.mode = "hash"; - m.route(main,"/",maps); - console.log("init done."); + menudef.nodes.map(function(menu){ + if (menu.action === undefined) { + var path = menu.path != undefined ? menu.path : ("/" + menu.name); + var module = menu.module != undefined ? menu.module : menu.name + console.log("adding route " + menu.name + " for " + path + " with module " + module); + maps[path] = new Page(require(module), menu.runstate); + } + }); + m.route.mode = "hash"; + m.route(main,"/",maps); + console.log("init done."); + } }; -module.exports = me; - diff --git a/libresapi/src/webui-src/app/peers.js b/libresapi/src/webui-src/app/peers.js index 45a235f79..763a3ca10 100644 --- a/libresapi/src/webui-src/app/peers.js +++ b/libresapi/src/webui-src/app/peers.js @@ -6,34 +6,78 @@ var rs = require("retroshare"); module.exports = {view: function(){ var peers = rs("peers"); console.log("peers:" + peers); + + //waiting for peerlist ... if(peers === undefined){ return m("div",[ m("h2","peers"), m("h3","waiting_server"), ]); }; + + //building peerlist (prebuild for counting) var online = 0; var peerlist = peers.map(function(peer){ var isonline = false; + var avatar_address =""; + + //building location list (prebuild for state + icon) var loclist = peer.locations.map(function(location){ if (location.is_online && ! isonline){ online +=1; isonline = true; } - return m("li", - {style:"color:" + (location.is_online ? "lime": "grey")}, - location.location); + if (location.avatar_address != "" && avatar_address =="") { + avatar_address=location.avatar_address; + } + return m("div",{ + style:"color:" + (location.is_online ? "lime": "grey") + + ";cursor:pointer", + + },location.location); }); - return [ - m("h2", {style:"color:" + (isonline ? "lime": "grey")} ,peer.name), - m("ul", loclist ), - ]; + + //return friend (peer + locations) + return m("div.flexbox[style=color:lime]",[ + // avatar-icon + m("div", [ + avatar_address == "" ? "" : ( + m("img",{ + src: rs.apiurl("peers" + avatar_address), + style:"border-radius:3mm;margin:2mm;", + }) + ) + ]), + //peername + locations + m("div.flexwidemember",[ + m("h1[style=margin-bottom:1mm;]", + {style:"color:" + (isonline ? "lime": "grey")} , + peer.name + ), + m("div", loclist ), + ]), + //remove-button + m("div", { + style: "color:red;" + + "font-size:1.5em;" + + "padding:0.2em;" + + "cursor:pointer", + onclick: function (){ + var yes = window.confirm( + "Remove " + peer.name + " from friendslist?"); + if(yes){ + rs.request("peers/" + peer.pgp_id +"/delete"); + } + } + }, "X") + ]); }); + // return add-peer-button + peerlist return m("div",[ m("div.btn2",{onclick: function(){m.route("/addpeer")}},"add new friend"), - m("h2","peers ( online: " + online +" / " + peers.length + "):"), - m("table", [ + m("h2","peers (online: " + online +" / " + peers.length + "):"), + m("div", [ peerlist, ]), ]); diff --git a/libresapi/src/webui-src/app/retroshare.js b/libresapi/src/webui-src/app/retroshare.js index e7e2521a3..4bedf306d 100644 --- a/libresapi/src/webui-src/app/retroshare.js +++ b/libresapi/src/webui-src/app/retroshare.js @@ -215,3 +215,14 @@ rs.forceUpdate = function(path){ cache[path].requested=false; } +//return api-path +rs.apiurl = function(path) { + if (path === undefined) { + path=""; + } + if (path.length > 0 && "^\\\\|\\/".match(path)) { + path=path.substr(1); + } + return api_url + path; +} +