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) && (menu.show === undefined || menu.show)
) { ) {
var name = menu.name; var name = menu.name;
if (menu.counter != undefined && menu.counterfnkt != undefined) { if (menu.counter != undefined) {
var data=rs(menu.counter); name += menu.counter();
if (data != undefined) {
name += " (" + menu.counterfnkt(data) + ")";
}
} }
if (menu.action === undefined) { if (menu.action === undefined) {
return m(tagname , { return m(tagname , {
@ -32,7 +29,7 @@ function buildmenu(menu, tagname, runstate, ignore){
} }
}, name); }, name);
} else { } 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: [ module.exports = { nodes: [
{ {
name: "home", name: "home",
@ -17,8 +18,7 @@ module.exports = { nodes: [
{ {
name: "peers", name: "peers",
runstate: "running_ok.*", runstate: "running_ok.*",
counter: "peers", counter: rs.counting("peers", function(data){
counterfnkt: function(data){
var onlinecount = 0; var onlinecount = 0;
data.map(function(peer) { data.map(function(peer) {
var is_online = false; var is_online = false;
@ -32,7 +32,7 @@ module.exports = { nodes: [
} }
}); });
return onlinecount + "/" + data.length; return onlinecount + "/" + data.length;
} })
}, },
{ {
name: "addpeer", name: "addpeer",
@ -51,10 +51,9 @@ module.exports = { nodes: [
{ {
name: "downloads", name: "downloads",
runstate: "running_ok.*", runstate: "running_ok.*",
counter: "transfers/downloads", counter: rs.counting("transfers/downloads", function(data) {
counterfnkt: function(data){
return data.length; return data.length;
} })
}, },
{ {
name: "chat", name: "chat",
@ -63,7 +62,7 @@ module.exports = { nodes: [
{ {
name: "shutdown", name: "shutdown",
runstate: "running_ok|waiting_account_select", runstate: "running_ok|waiting_account_select",
action: function(rs, m){ action: function(m){
rs.request("control/shutdown",null,function(){ rs.request("control/shutdown",null,function(){
rs("control/runstate").runstate=null; rs("control/runstate").runstate=null;
rs.forceUpdate("control/runstate"); rs.forceUpdate("control/runstate");

View File

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