forked from p15670423/monkey
UI: Compare version numbers in VersionComponent
This commit is contained in:
parent
f13d55d89a
commit
ae468f9832
|
@ -7,8 +7,8 @@ class VersionComponent extends React.Component {
|
|||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
currentVersion: undefined,
|
||||
newerVersion: undefined,
|
||||
versionNumber: undefined,
|
||||
latestVersion: undefined,
|
||||
downloadLink: undefined
|
||||
}
|
||||
}
|
||||
|
@ -18,19 +18,27 @@ class VersionComponent extends React.Component {
|
|||
.then(res => res.json())
|
||||
.then(res => {
|
||||
this.setState({
|
||||
currentVersion: res['current_version'],
|
||||
newerVersion: res['newer_version'],
|
||||
versionNumber: res['version_number'],
|
||||
latestVersion: res['latest_version'],
|
||||
downloadLink: res['download_link']
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
newerVersionAvailable() {
|
||||
const semverGt = require('semver/functions/gt');
|
||||
if(this.state.latestVersion !== undefined && this.state.versionNumber !== undefined) {
|
||||
return semverGt(this.state.latestVersion, this.state.versionNumber);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className="version-text text-center">
|
||||
Infection Monkey Version: {this.state.currentVersion}
|
||||
Infection Monkey Version: {this.state.versionNumber}
|
||||
{
|
||||
this.state.newerVersion ?
|
||||
this.newerVersionAvailable() ?
|
||||
<div>
|
||||
<b>Newer version available!</b>
|
||||
<br/>
|
||||
|
|
Loading…
Reference in New Issue