Frontend pinger
This commit is contained in:
parent
f2bcfe014c
commit
ecf2383927
|
@ -1,6 +1,6 @@
|
||||||
package data
|
package data
|
||||||
|
|
||||||
type PingResult struct {
|
type PingResult struct {
|
||||||
True []string `json:"true"`
|
True []string `json:"true,omitempty"`
|
||||||
False []string `json:"false"`
|
False []string `json:"false,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,16 @@ span.online {
|
||||||
span.offline {
|
span.offline {
|
||||||
color: #dc0067;
|
color: #dc0067;
|
||||||
}
|
}
|
||||||
|
.pinger div {
|
||||||
|
display: inline-block;
|
||||||
|
width: 4px;
|
||||||
|
height: 4px;
|
||||||
|
margin-right: 2px;
|
||||||
|
background-color: red;
|
||||||
|
}
|
||||||
|
.pinger .online {
|
||||||
|
background-color: green;
|
||||||
|
}
|
||||||
h1 {
|
h1 {
|
||||||
border-bottom: 4px solid #dc0067;
|
border-bottom: 4px solid #dc0067;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import config from './config';
|
import config from './config';
|
||||||
|
|
||||||
const list = {},
|
const list = {},
|
||||||
storeMaxPing = 5;
|
pingState = {},
|
||||||
|
storeMaxPing = 10;
|
||||||
|
|
||||||
// Returns the node with specified id (or null if node doesn't exist).
|
// Returns the node with specified id (or null if node doesn't exist).
|
||||||
export function getNode (nodeid) {
|
export function getNode (nodeid) {
|
||||||
|
@ -11,6 +12,11 @@ export function getNode (nodeid) {
|
||||||
|
|
||||||
let node = list[nodeid];
|
let node = list[nodeid];
|
||||||
// keep structur for pings later
|
// keep structur for pings later
|
||||||
|
if(pingState[nodeid]) {
|
||||||
|
node.pingstate = pingState[nodeid];
|
||||||
|
}else{
|
||||||
|
node.pingstate = [];
|
||||||
|
}
|
||||||
return node;
|
return node;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -26,13 +32,13 @@ export function createNode (nodeid) {
|
||||||
'channel5': config.node.channel5,
|
'channel5': config.node.channel5,
|
||||||
},
|
},
|
||||||
'location': {},
|
'location': {},
|
||||||
'pingstate':[]
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// Overwrites the values for the specified node (identified by its node_id) with new values.
|
// Overwrites the values for the specified node (identified by its node_id) with new values.
|
||||||
export function updateNode (node) {
|
export function updateNode (node) {
|
||||||
list[node.node_id] = node;
|
list[node.node_id] = node;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function updateNodePingTo(value){
|
function updateNodePingTo(value){
|
||||||
|
@ -40,16 +46,24 @@ function updateNodePingTo(value){
|
||||||
if (!list[nodeid]) {
|
if (!list[nodeid]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
list[nodeid]['pingstate'].unshift(value);
|
if(pingState[nodeid] === undefined) {
|
||||||
if (list[nodeid]['pingstate'].length > storeMaxPing) {
|
pingState[nodeid] = [value];
|
||||||
list[nodeid]['pingstate'].length = storeMaxPing;
|
return
|
||||||
|
}
|
||||||
|
pingState[nodeid].unshift(value);
|
||||||
|
if (pingState[nodeid].length > storeMaxPing) {
|
||||||
|
pingState[nodeid].length = storeMaxPing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateNodePing(ping) {
|
export function updateNodePing(ping) {
|
||||||
ping["true"].forEach(updateNodePingTo(true));
|
if(ping['true']) {
|
||||||
ping["false"].forEach(updateNodePingTo(false));
|
ping['true'].forEach(updateNodePingTo(true));
|
||||||
|
}
|
||||||
|
if(ping['false']) {
|
||||||
|
ping['false'].forEach(updateNodePingTo(false));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Returns a list of all known nodes.
|
// Returns a list of all known nodes.
|
||||||
|
|
|
@ -80,7 +80,8 @@ export class ListView extends View {
|
||||||
renderRow (node) {
|
renderRow (node) {
|
||||||
const startdate = new Date(),
|
const startdate = new Date(),
|
||||||
channel24Options = [],
|
channel24Options = [],
|
||||||
channel5Options = [];
|
channel5Options = [],
|
||||||
|
pingerResult = [];
|
||||||
startdate.setMinutes(startdate.getMinutes() - config.node.offline);
|
startdate.setMinutes(startdate.getMinutes() - config.node.offline);
|
||||||
|
|
||||||
|
|
||||||
|
@ -97,12 +98,18 @@ export class ListView extends View {
|
||||||
'selected': (store.channelsWifi5[i] === node.wireless.channel5),
|
'selected': (store.channelsWifi5[i] === node.wireless.channel5),
|
||||||
}, store.channelsWifi5[i]));
|
}, 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', {},[
|
return V.h('tr', {},[
|
||||||
V.h('td', {
|
V.h('td', {
|
||||||
'class':(new Date(node.lastseen) < startdate)?'offline':(!node.wireless_respondd)?'unseen':''
|
'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', {}, node.node_id),
|
||||||
V.h('td', {}, V.h('input',{
|
V.h('td', {}, V.h('input',{
|
||||||
'value': this._hostname || node.hostname,
|
'value': this._hostname || node.hostname,
|
||||||
|
|
Loading…
Reference in New Issue