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';
|
|
|
|
|
2017-05-30 02:16:46 +02:00
|
|
|
const current = {},
|
|
|
|
list = {};
|
2017-05-16 19:18:35 +02:00
|
|
|
|
|
|
|
function getNode (nodeid) {
|
|
|
|
let node = {};
|
|
|
|
|
2017-05-30 02:16:46 +02:00
|
|
|
if (list[nodeid]) {
|
2017-05-16 19:18:35 +02:00
|
|
|
node = list[nodeid];
|
2017-05-30 02:16:46 +02:00
|
|
|
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 {
|
2017-05-30 02:16:46 +02:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2017-05-30 02:16:46 +02:00
|
|
|
store.updateNode = function updateNode (node, system) {
|
|
|
|
if (system) {
|
2017-05-16 19:18:35 +02:00
|
|
|
list[node.node_id] = node;
|
|
|
|
} else {
|
2017-05-30 02:16:46 +02:00
|
|
|
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
|
|
|
})();
|