From ecf23839276c37186389f8f5153b1e7d5f73b099 Mon Sep 17 00:00:00 2001 From: Martin/Geno Date: Mon, 10 Jun 2019 13:38:21 +0200 Subject: [PATCH] Frontend pinger --- data/ping_result.go | 4 ++-- webroot/css/styles.less | 10 ++++++++++ webroot/js/store.js | 28 +++++++++++++++++++++------- webroot/js/view/list.js | 13 ++++++++++--- 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/data/ping_result.go b/data/ping_result.go index 502341f..040c1c0 100644 --- a/data/ping_result.go +++ b/data/ping_result.go @@ -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"` } diff --git a/webroot/css/styles.less b/webroot/css/styles.less index a3c6526..3bc2f77 100644 --- a/webroot/css/styles.less +++ b/webroot/css/styles.less @@ -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; } diff --git a/webroot/js/store.js b/webroot/js/store.js index 399c1f8..12e0ddb 100644 --- a/webroot/js/store.js +++ b/webroot/js/store.js @@ -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. diff --git a/webroot/js/view/list.js b/webroot/js/view/list.js index e1f3fea..c1d20df 100644 --- a/webroot/js/view/list.js +++ b/webroot/js/view/list.js @@ -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,