Frontend pinger

This commit is contained in:
Martin/Geno 2019-06-10 13:38:21 +02:00 committed by genofire
parent f2bcfe014c
commit ecf2383927
4 changed files with 43 additions and 12 deletions

View File

@ -1,6 +1,6 @@
package data
type PingResult struct {
True []string `json:"true"`
False []string `json:"false"`
True []string `json:"true,omitempty"`
False []string `json:"false,omitempty"`
}

View File

@ -23,6 +23,16 @@ span.online {
span.offline {
color: #dc0067;
}
.pinger div {
display: inline-block;
width: 4px;
height: 4px;
margin-right: 2px;
background-color: red;
}
.pinger .online {
background-color: green;
}
h1 {
border-bottom: 4px solid #dc0067;
}

View File

@ -1,7 +1,8 @@
import config from './config';
const list = {},
storeMaxPing = 5;
pingState = {},
storeMaxPing = 10;
// Returns the node with specified id (or null if node doesn't exist).
export function getNode (nodeid) {
@ -11,6 +12,11 @@ export function getNode (nodeid) {
let node = list[nodeid];
// keep structur for pings later
if(pingState[nodeid]) {
node.pingstate = pingState[nodeid];
}else{
node.pingstate = [];
}
return node;
};
@ -26,13 +32,13 @@ export function createNode (nodeid) {
'channel5': config.node.channel5,
},
'location': {},
'pingstate':[]
};
};
// Overwrites the values for the specified node (identified by its node_id) with new values.
export function updateNode (node) {
list[node.node_id] = node;
};
function updateNodePingTo(value){
@ -40,16 +46,24 @@ function updateNodePingTo(value){
if (!list[nodeid]) {
return;
}
list[nodeid]['pingstate'].unshift(value);
if (list[nodeid]['pingstate'].length > storeMaxPing) {
list[nodeid]['pingstate'].length = storeMaxPing;
if(pingState[nodeid] === undefined) {
pingState[nodeid] = [value];
return
}
pingState[nodeid].unshift(value);
if (pingState[nodeid].length > storeMaxPing) {
pingState[nodeid].length = storeMaxPing;
}
}
}
export function updateNodePing(ping) {
ping["true"].forEach(updateNodePingTo(true));
ping["false"].forEach(updateNodePingTo(false));
if(ping['true']) {
ping['true'].forEach(updateNodePingTo(true));
}
if(ping['false']) {
ping['false'].forEach(updateNodePingTo(false));
}
};
// Returns a list of all known nodes.

View File

@ -80,7 +80,8 @@ export class ListView extends View {
renderRow (node) {
const startdate = new Date(),
channel24Options = [],
channel5Options = [];
channel5Options = [],
pingerResult = [];
startdate.setMinutes(startdate.getMinutes() - config.node.offline);
@ -97,12 +98,18 @@ export class ListView extends View {
'selected': (store.channelsWifi5[i] === node.wireless.channel5),
}, store.channelsWifi5[i]));
}
for (i = 0; i < node.pingstate.length; i++) {
pingerResult.push(V.h('div',{'class':node.pingstate[i]?'online':''}));
}
return V.h('tr', {},[
V.h('td', {
'class':(new Date(node.lastseen) < startdate)?'offline':(!node.wireless_respondd)?'unseen':''
}, FromNowAgo(node.lastseen)),
},[
V.h('span', {}, FromNowAgo(node.lastseen)),
V.h('span', {'class': 'pinger'}, pingerResult),
]),
V.h('td', {}, node.node_id),
V.h('td', {}, V.h('input',{
'value': this._hostname || node.hostname,