webui: adding counting feature for menu

This commit is contained in:
zeners 2016-01-16 17:25:12 +01:00
parent 2e41c373b5
commit b6bb69df7a
3 changed files with 30 additions and 3 deletions

View File

@ -16,6 +16,13 @@ function buildmenu(menu, tagname, runstate, ignore){
&& (menu.path === undefined || !menu.path.contains(":")) && (menu.path === undefined || !menu.path.contains(":"))
&& (menu.show === undefined || menu.show) && (menu.show === undefined || menu.show)
) { ) {
var name = menu.name;
if (menu.counter != undefined && menu.counterfnkt != undefined) {
var data=rs(menu.counter);
if (data != undefined) {
name += " (" + menu.counterfnkt(data) + ")";
}
}
if (menu.action === undefined) { if (menu.action === undefined) {
return m(tagname , { return m(tagname , {
onclick: function(){ onclick: function(){
@ -23,9 +30,9 @@ function buildmenu(menu, tagname, runstate, ignore){
menu.path != undefined ? menu.path : "/" + menu.name menu.path != undefined ? menu.path : "/" + menu.name
) )
} }
}, menu.name); }, name);
} else { } else {
return m(tagname, {onclick: function(){menu.action(rs,m)}}, menu.name); return m(tagname, {onclick: function(){menu.action(rs,m)}}, name);
} }
} }
} }

View File

@ -11,6 +11,22 @@ module.exports = { nodes: [
{ {
name: "peers", name: "peers",
runstate: "running_ok.*", runstate: "running_ok.*",
counter: "peers",
counterfnkt: function(data){
var onlinecount = 0;
data.map(function(peer) {
var is_online = false;
peer.locations.map(function (location){
if (location.is_online) {
is_online=true;
}
});
if (is_online) {
onlinecount +=1;
}
});
return onlinecount + "/" + data.length;
}
}, },
{ {
name: "addpeer", name: "addpeer",
@ -29,6 +45,10 @@ module.exports = { nodes: [
{ {
name: "downloads", name: "downloads",
runstate: "running_ok.*", runstate: "running_ok.*",
counter: "transfers/downloads",
counterfnkt: function(data){
return data.length;
}
}, },
{ {
name: "chat", name: "chat",

View File

@ -5,7 +5,7 @@ var rs = require("retroshare");
module.exports = {view: function(){ module.exports = {view: function(){
var peers = rs("peers"); var peers = rs("peers");
console.log("peers:" + peers); //console.log("peers:" + peers);
//waiting for peerlist ... //waiting for peerlist ...
if(peers === undefined){ if(peers === undefined){