freifunkmanager/webroot/js/store.js

60 lines
1006 B
JavaScript
Raw Normal View History

2017-05-16 16:00:32 +02:00
/* exported store */
2017-05-16 19:18:35 +02:00
const store = {
'stats': {
'Clients': 0,
'ClientsWifi': 0,
'ClientsWifi24': 0,
'ClientsWifi5': 0,
'Firmwares': {},
'Gateways': 0,
'Models': {},
'Nodes': 0
}
2017-05-08 19:13:29 +02:00
};
2017-05-16 19:18:35 +02:00
(function init () {
'use strict';
const current = {},
list = {};
2017-05-16 19:18:35 +02:00
function getNode (nodeid) {
let node = {};
if (list[nodeid]) {
2017-05-16 19:18:35 +02:00
node = list[nodeid];
if (current[nodeid]) {
const cNode = current[nodeid];
// eslint-disable-next-line no-underscore-dangle
node._wireless = cNode.wireless;
node.lastseen = cNode.lastseen;
}
2017-05-16 19:18:35 +02:00
} else {
// eslint-disable-next-line camelcase
node.node_id = nodeid;
node.wireless = {};
node.location = {};
list[nodeid] = node;
2017-05-16 19:18:35 +02:00
}
return node;
}
store.updateNode = function updateNode (node, system) {
if (system) {
2017-05-16 19:18:35 +02:00
list[node.node_id] = node;
} else {
current[node.node_id] = node;
2017-05-16 19:18:35 +02:00
}
};
store.getNode = getNode;
2017-05-15 21:59:48 +02:00
2017-05-16 19:18:35 +02:00
store.getNodes = function getNodes () {
return Object.keys(list).map(getNode);
};
2017-05-08 19:13:29 +02:00
})();