2018-03-06 20:58:36 +00:00
|
|
|
import React, { Component, Fragment } from 'react';
|
2018-02-26 00:11:31 +00:00
|
|
|
|
|
|
|
import { withStyles } from 'material-ui/styles';
|
|
|
|
import Button from 'material-ui/Button';
|
|
|
|
import { LinearProgress } from 'material-ui/Progress';
|
|
|
|
import Typography from 'material-ui/Typography';
|
|
|
|
import List, { ListItem, ListItemText } from 'material-ui/List';
|
|
|
|
import Avatar from 'material-ui/Avatar';
|
|
|
|
import Divider from 'material-ui/Divider';
|
|
|
|
import SwapVerticalCircleIcon from 'material-ui-icons/SwapVerticalCircle';
|
|
|
|
import AccessTimeIcon from 'material-ui-icons/AccessTime';
|
|
|
|
import DNSIcon from 'material-ui-icons/Dns';
|
|
|
|
import TimerIcon from 'material-ui-icons/Timer';
|
|
|
|
import UpdateIcon from 'material-ui-icons/Update';
|
|
|
|
import AvTimerIcon from 'material-ui-icons/AvTimer';
|
|
|
|
|
|
|
|
import { isSynchronized, ntpStatusHighlight, ntpStatus } from '../constants/NTPStatus';
|
|
|
|
import * as Highlight from '../constants/Highlight';
|
|
|
|
import { unixTimeToTimeAndDate } from '../constants/TimeFormat';
|
|
|
|
import { NTP_STATUS_ENDPOINT } from '../constants/Endpoints';
|
|
|
|
|
2018-03-04 16:49:24 +00:00
|
|
|
import { restComponent } from '../components/RestComponent';
|
2018-02-26 00:11:31 +00:00
|
|
|
import SectionContent from '../components/SectionContent';
|
|
|
|
|
|
|
|
import moment from 'moment';
|
|
|
|
|
|
|
|
const styles = theme => ({
|
|
|
|
["ntpStatus_" + Highlight.SUCCESS]: {
|
|
|
|
backgroundColor: theme.palette.highlight_success
|
|
|
|
},
|
|
|
|
["ntpStatus_" + Highlight.ERROR]: {
|
|
|
|
backgroundColor: theme.palette.highlight_error
|
|
|
|
},
|
|
|
|
["ntpStatus_" + Highlight.WARN]: {
|
|
|
|
backgroundColor: theme.palette.highlight_warn
|
|
|
|
},
|
|
|
|
fetching: {
|
|
|
|
margin: theme.spacing.unit * 4,
|
|
|
|
textAlign: "center"
|
|
|
|
},
|
|
|
|
button: {
|
|
|
|
marginRight: theme.spacing.unit * 2,
|
|
|
|
marginTop: theme.spacing.unit * 2,
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
class NTPStatus extends Component {
|
|
|
|
|
|
|
|
componentDidMount() {
|
2018-03-04 16:49:24 +00:00
|
|
|
this.props.loadData();
|
2018-02-26 00:11:31 +00:00
|
|
|
}
|
|
|
|
|
2018-03-06 20:58:36 +00:00
|
|
|
createListItems(data, fullDetails, classes){
|
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<ListItem>
|
|
|
|
<Avatar className={classes["ntpStatus_" + ntpStatusHighlight(data)]}>
|
|
|
|
<UpdateIcon />
|
|
|
|
</Avatar>
|
|
|
|
<ListItemText primary="Status" secondary={ntpStatus(data)} />
|
|
|
|
</ListItem>
|
|
|
|
<Divider inset component="li" />
|
|
|
|
{ isSynchronized(data) &&
|
|
|
|
<Fragment>
|
|
|
|
<ListItem>
|
|
|
|
<Avatar>
|
|
|
|
<AccessTimeIcon />
|
|
|
|
</Avatar>
|
|
|
|
<ListItemText primary="Time Now" secondary={unixTimeToTimeAndDate(data.now)} />
|
|
|
|
</ListItem>
|
|
|
|
<Divider inset component="li" />
|
|
|
|
<ListItem>
|
|
|
|
<Avatar>
|
|
|
|
<SwapVerticalCircleIcon />
|
|
|
|
</Avatar>
|
|
|
|
<ListItemText primary="Last Sync" secondary={data.last_sync > 0 ? unixTimeToTimeAndDate(data.last_sync) : "never" } />
|
|
|
|
</ListItem>
|
|
|
|
<Divider inset component="li" />
|
|
|
|
</Fragment>
|
|
|
|
}
|
|
|
|
<ListItem>
|
2018-02-26 00:11:31 +00:00
|
|
|
<Avatar>
|
2018-03-06 20:58:36 +00:00
|
|
|
<DNSIcon />
|
2018-02-26 00:11:31 +00:00
|
|
|
</Avatar>
|
2018-03-06 20:58:36 +00:00
|
|
|
<ListItemText primary="NTP Server" secondary={data.server} />
|
2018-02-26 00:11:31 +00:00
|
|
|
</ListItem>
|
2018-03-06 20:58:36 +00:00
|
|
|
<Divider inset component="li" />
|
|
|
|
<ListItem>
|
|
|
|
<Avatar>
|
|
|
|
<TimerIcon />
|
|
|
|
</Avatar>
|
|
|
|
<ListItemText primary="Sync Interval" secondary={moment.duration(data.interval, 'seconds').humanize()} />
|
|
|
|
</ListItem>
|
|
|
|
<Divider inset component="li" />
|
|
|
|
<ListItem>
|
|
|
|
<Avatar>
|
|
|
|
<AvTimerIcon />
|
|
|
|
</Avatar>
|
|
|
|
<ListItemText primary="Uptime" secondary={moment.duration(data.uptime, 'seconds').humanize()} />
|
|
|
|
</ListItem>
|
|
|
|
<Divider inset component="li" />
|
|
|
|
</Fragment>
|
2018-02-26 00:11:31 +00:00
|
|
|
);
|
2018-03-06 20:58:36 +00:00
|
|
|
}
|
2018-02-26 00:11:31 +00:00
|
|
|
|
2018-03-06 20:58:36 +00:00
|
|
|
renderNTPStatus(data, fullDetails, classes){
|
2018-02-26 00:11:31 +00:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<List>
|
2018-03-06 20:58:36 +00:00
|
|
|
{this.createListItems(data, fullDetails, classes)}
|
2018-02-26 00:11:31 +00:00
|
|
|
</List>
|
2018-03-04 16:49:24 +00:00
|
|
|
<Button variant="raised" color="secondary" className={classes.button} onClick={this.props.loadData}>
|
2018-02-26 00:11:31 +00:00
|
|
|
Refresh
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2018-03-04 16:49:24 +00:00
|
|
|
const { data, fetched, errorMessage, classes, fullDetails } = this.props;
|
2018-02-26 00:11:31 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<SectionContent title="NTP Status">
|
|
|
|
{
|
|
|
|
!fetched ?
|
|
|
|
<div>
|
|
|
|
<LinearProgress className={classes.fetching}/>
|
|
|
|
<Typography variant="display1" className={classes.fetching}>
|
|
|
|
Loading...
|
|
|
|
</Typography>
|
|
|
|
</div>
|
|
|
|
:
|
2018-03-04 16:49:24 +00:00
|
|
|
data ? this.renderNTPStatus(data, fullDetails, classes)
|
2018-02-26 00:11:31 +00:00
|
|
|
:
|
|
|
|
<div>
|
|
|
|
<Typography variant="display1" className={classes.fetching}>
|
|
|
|
{errorMessage}
|
|
|
|
</Typography>
|
2018-03-04 16:49:24 +00:00
|
|
|
<Button variant="raised" color="secondary" className={classes.button} onClick={this.props.loadData}>
|
2018-02-26 00:11:31 +00:00
|
|
|
Refresh
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
</SectionContent>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-04 16:49:24 +00:00
|
|
|
export default restComponent(NTP_STATUS_ENDPOINT, withStyles(styles)(NTPStatus));
|