From b6bb69df7a1097ee7ec41633e3ee49992a447f89 Mon Sep 17 00:00:00 2001 From: zeners Date: Sat, 16 Jan 2016 17:25:12 +0100 Subject: [PATCH] webui: adding counting feature for menu --- libresapi/src/webui-src/app/menu.js | 11 +++++++++-- libresapi/src/webui-src/app/menudef.js | 20 ++++++++++++++++++++ libresapi/src/webui-src/app/peers.js | 2 +- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/libresapi/src/webui-src/app/menu.js b/libresapi/src/webui-src/app/menu.js index 73ea862b5..e01ec10c4 100644 --- a/libresapi/src/webui-src/app/menu.js +++ b/libresapi/src/webui-src/app/menu.js @@ -16,6 +16,13 @@ function buildmenu(menu, tagname, runstate, ignore){ && (menu.path === undefined || !menu.path.contains(":")) && (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) { return m(tagname , { onclick: function(){ @@ -23,9 +30,9 @@ function buildmenu(menu, tagname, runstate, ignore){ menu.path != undefined ? menu.path : "/" + menu.name ) } - }, menu.name); + }, name); } else { - return m(tagname, {onclick: function(){menu.action(rs,m)}}, menu.name); + return m(tagname, {onclick: function(){menu.action(rs,m)}}, name); } } } diff --git a/libresapi/src/webui-src/app/menudef.js b/libresapi/src/webui-src/app/menudef.js index 67e064e00..9da066caa 100644 --- a/libresapi/src/webui-src/app/menudef.js +++ b/libresapi/src/webui-src/app/menudef.js @@ -11,6 +11,22 @@ module.exports = { nodes: [ { name: "peers", 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", @@ -29,6 +45,10 @@ module.exports = { nodes: [ { name: "downloads", runstate: "running_ok.*", + counter: "transfers/downloads", + counterfnkt: function(data){ + return data.length; + } }, { name: "chat", diff --git a/libresapi/src/webui-src/app/peers.js b/libresapi/src/webui-src/app/peers.js index 763a3ca10..f22e96e46 100644 --- a/libresapi/src/webui-src/app/peers.js +++ b/libresapi/src/webui-src/app/peers.js @@ -5,7 +5,7 @@ var rs = require("retroshare"); module.exports = {view: function(){ var peers = rs("peers"); - console.log("peers:" + peers); + //console.log("peers:" + peers); //waiting for peerlist ... if(peers === undefined){