Report shows message if no monkeys have been run before

This commit is contained in:
Itay Mizeretz 2017-12-12 15:44:38 +02:00
parent 09e04a3763
commit 483394d7f5
1 changed files with 25 additions and 14 deletions

View File

@ -31,25 +31,27 @@ class ReportPageComponent extends React.Component {
this.state = { this.state = {
report: {}, report: {},
graph: {nodes: [], edges: []}, graph: {nodes: [], edges: []},
allMonkeysAreDead: false allMonkeysAreDead: false,
runStarted: true
}; };
} }
componentDidMount() { componentDidMount() {
this.getReportFromServer(); this.updateMonkeysRunning().then(res => this.getReportFromServer(res));
this.updateMapFromServer(); this.updateMapFromServer();
this.updateMonkeysRunning();
this.interval = setInterval(this.updateMapFromServer, 1000); this.interval = setInterval(this.updateMapFromServer, 1000);
} }
updateMonkeysRunning = () => { updateMonkeysRunning = () => {
fetch('/api') return fetch('/api')
.then(res => res.json()) .then(res => res.json())
.then(res => { .then(res => {
// This check is used to prevent unnecessary re-rendering // This check is used to prevent unnecessary re-rendering
this.setState({ this.setState({
allMonkeysAreDead: (!res['completed_steps']['run_monkey']) || (res['completed_steps']['infection_done']) allMonkeysAreDead: (!res['completed_steps']['run_monkey']) || (res['completed_steps']['infection_done']),
runStarted: res['completed_steps']['run_monkey']
}); });
return res;
}); });
}; };
@ -69,14 +71,16 @@ class ReportPageComponent extends React.Component {
}); });
}; };
getReportFromServer() { getReportFromServer(res) {
fetch('/api/report') if (res['completed_steps']['run_monkey']) {
.then(res => res.json()) fetch('/api/report')
.then(res => { .then(res => res.json())
this.setState({ .then(res => {
report: res this.setState({
report: res
});
}); });
}); }
} }
generateInfoBadges(data_array) { generateInfoBadges(data_array) {
@ -353,11 +357,18 @@ class ReportPageComponent extends React.Component {
}; };
render() { render() {
let content; let content;
if (Object.keys(this.state.report).length === 0) { if (Object.keys(this.state.report).length === 0) {
content = (<h1>Generating Report...</h1>); if (this.state.runStarted) {
content = (<h1>Generating Report...</h1>);
} else {
content =
<p className="alert alert-warning">
<i className="glyphicon glyphicon-warning-sign" style={{'marginRight': '5px'}}/>
You have to run a monkey before generating a report!
</p>;
}
} else { } else {
let exploitPercentage = let exploitPercentage =
(100 * this.state.report.glance.exploited.length) / this.state.report.glance.scanned.length; (100 * this.state.report.glance.exploited.length) / this.state.report.glance.scanned.length;