freifunkmanager/webroot/js/store.js

52 lines
1.1 KiB
JavaScript
Raw Normal View History

import config from './config';
const current = {},
list = {};
2017-05-16 16:00:32 +02:00
// Returns the node with specified id (or null if node doesn't exist).
export function getNode (nodeid) {
if (!list[nodeid]) {
return null;
}
2017-05-16 19:18:35 +02:00
let 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
}
return node;
};
2017-05-30 14:35:11 +02:00
// Creates an empty node, but doesn't add it to the list.
export function createNode (nodeid) {
return {
'node_id': nodeid,
'hostname': '',
'owner': '',
'lastseen': null,
'wireless': {
'channel24': config.node.channel24,
'channel5': config.node.channel5,
},
'location': {}
};
};
// Overwrites the values for the specified node (identified by its node_id) with new values.
// If system==false, the special "current" node will be modified instead.
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
// Returns a list of all known nodes.
export function getNodes () {
return Object.keys(list).map(getNode);
};