mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
webui: add / remove peers
This commit is contained in:
parent
5f77719f9c
commit
2e41c373b5
@ -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")
|
||||
|
||||
])
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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,
|
||||
]),
|
||||
]);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user