freifunkmanager/webroot/js/store.js

70 lines
1.1 KiB
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 = {},
2017-05-30 14:35:11 +02:00
list = {},
cmds = {};
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
}
};
2017-05-30 14:35:11 +02:00
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-30 14:35:11 +02:00
store.updateCMD = function updateCMD (cmd) {
cmds[cmd.id] = cmd;
};
store.getCMDs = function getCMDs () {
return cmds;
};
2017-05-08 19:13:29 +02:00
})();