webui: reorganize counterfnkt

This commit is contained in:
zeners 2016-01-31 15:58:20 +01:00
parent 22afc8e67b
commit 284e5a9ed0
3 changed files with 19 additions and 13 deletions

View File

@ -17,11 +17,8 @@ function buildmenu(menu, tagname, runstate, ignore){
&& (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.counter != undefined) {
name += menu.counter();
}
if (menu.action === undefined) {
return m(tagname , {
@ -32,7 +29,7 @@ function buildmenu(menu, tagname, runstate, ignore){
}
}, name);
} else {
return m(tagname, {onclick: function(){menu.action(rs,m)}}, name);
return m(tagname, {onclick: function(){menu.action(m)}}, name);
}
}
}

View File

@ -1,3 +1,4 @@
rs=require("retroshare");
module.exports = { nodes: [
{
name: "home",
@ -17,8 +18,7 @@ module.exports = { nodes: [
{
name: "peers",
runstate: "running_ok.*",
counter: "peers",
counterfnkt: function(data){
counter: rs.counting("peers", function(data){
var onlinecount = 0;
data.map(function(peer) {
var is_online = false;
@ -32,7 +32,7 @@ module.exports = { nodes: [
}
});
return onlinecount + "/" + data.length;
}
})
},
{
name: "addpeer",
@ -51,10 +51,9 @@ module.exports = { nodes: [
{
name: "downloads",
runstate: "running_ok.*",
counter: "transfers/downloads",
counterfnkt: function(data){
counter: rs.counting("transfers/downloads", function(data) {
return data.length;
}
})
},
{
name: "chat",
@ -63,7 +62,7 @@ module.exports = { nodes: [
{
name: "shutdown",
runstate: "running_ok|waiting_account_select",
action: function(rs, m){
action: function(m){
rs.request("control/shutdown",null,function(){
rs("control/runstate").runstate=null;
rs.forceUpdate("control/runstate");

View File

@ -241,3 +241,13 @@ rs.apiurl = function(path) {
return api_url + path;
}
rs.counting = function(path, counterfnkt) {
return function () {
var data=rs(path);
if (data != undefined) {
return " (" + counterfnkt(data) + ")";
}
return "";
}
}