freifunkmanager/webroot/js/store.js

38 lines
690 B
JavaScript
Raw Normal View History

const current = {},
list = {};
2017-05-16 16:00:32 +02:00
export function getNode (nodeid) {
let node = {};
2017-05-16 19:18:35 +02:00
if (list[nodeid]) {
node = list[nodeid];
if (current[nodeid]) {
const cNode = current[nodeid];
2017-05-16 19:18:35 +02:00
// 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;
};
2017-05-30 14:35:11 +02:00
export function updateNode (node, system) {
if (system) {
list[node.node_id] = node;
} else {
current[node.node_id] = node;
}
};
2017-05-30 14:35:11 +02:00
export function getNodes () {
return Object.keys(list).map(getNode);
};