Made map refresh periodically

This commit is contained in:
Itay Mizeretz 2017-09-21 17:06:34 +03:00
parent f70493f3ce
commit 62702f0322
1 changed files with 14 additions and 5 deletions

View File

@ -75,6 +75,15 @@ class MapPageComponent extends React.Component {
} }
componentDidMount() { componentDidMount() {
this.updateMapFromServer();
this.interval = setInterval(this.updateMapFromServer, 1000);
}
componentWillUnmount() {
clearInterval(this.interval);
}
updateMapFromServer = () => {
fetch('/api/netmap') fetch('/api/netmap')
.then(res => res.json()) .then(res => res.json())
.then(res => { .then(res => {
@ -84,7 +93,7 @@ class MapPageComponent extends React.Component {
this.setState({graph: res}); this.setState({graph: res});
this.props.onStatusChange(); this.props.onStatusChange();
}); });
} };
selectionChanged(event) { selectionChanged(event) {
if (event.nodes.length === 1) { if (event.nodes.length === 1) {
@ -110,13 +119,13 @@ class MapPageComponent extends React.Component {
console.log('selection cleared.'); // eslint-disable-line no-console console.log('selection cleared.'); // eslint-disable-line no-console
this.setState({selected: null, selectedType: null}); this.setState({selected: null, selectedType: null});
} }
} };
killAllMonkeys = () => { killAllMonkeys = () => {
fetch('/api?action=killall') fetch('/api?action=killall')
.then(res => res.json()) .then(res => res.json())
.then(res => this.setState({killPressed: (res.status=="OK")})); .then(res => this.setState({killPressed: (res.status==="OK")}));
} };
render() { render() {
return ( return (
@ -135,7 +144,7 @@ class MapPageComponent extends React.Component {
<div style={{'overflow': 'auto', 'marginBottom': '1em'}}> <div style={{'overflow': 'auto', 'marginBottom': '1em'}}>
<Link to="/infection/telemetry" className="btn btn-default pull-left" style={{'width': '48%'}}>Monkey Telemetry</Link> <Link to="/infection/telemetry" className="btn btn-default pull-left" style={{'width': '48%'}}>Monkey Telemetry</Link>
<button onClick={this.killAllMonkeys} className="btn btn-danger pull-right" style={{'width': '48%'}}> <button onClick={this.killAllMonkeys} className="btn btn-danger pull-right" style={{'width': '48%'}}>
<Icon name="stop-circle" style={{'marginRight': '0.5em'}}></Icon> <Icon name="stop-circle" style={{'marginRight': '0.5em'}} />
Kill All Monkeys Kill All Monkeys
</button> </button>
</div> </div>