2018-03-06 20:58:36 +00:00
|
|
|
import React, { Component, Fragment } from 'react';
|
2018-02-26 00:11:31 +00:00
|
|
|
|
2018-05-18 22:29:14 +00:00
|
|
|
import { withStyles } from '@material-ui/core/styles';
|
|
|
|
import Button from '@material-ui/core/Button';
|
|
|
|
import List from '@material-ui/core/List';
|
|
|
|
import ListItem from '@material-ui/core/ListItem';
|
2019-05-24 11:19:27 +00:00
|
|
|
import ListItemAvatar from '@material-ui/core/ListItemAvatar';
|
2018-05-18 22:29:14 +00:00
|
|
|
import ListItemText from '@material-ui/core/ListItemText';
|
|
|
|
import Avatar from '@material-ui/core/Avatar';
|
|
|
|
import Divider from '@material-ui/core/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';
|
2018-02-26 00:11:31 +00:00
|
|
|
|
2019-05-24 11:19:27 +00:00
|
|
|
import { isSynchronized, ntpStatusHighlight, ntpStatus } from '../constants/NTPStatus';
|
2018-02-26 00:11:31 +00:00
|
|
|
import * as Highlight from '../constants/Highlight';
|
|
|
|
import { unixTimeToTimeAndDate } from '../constants/TimeFormat';
|
2019-05-24 11:19:27 +00:00
|
|
|
import { NTP_STATUS_ENDPOINT } from '../constants/Endpoints';
|
2018-03-04 16:49:24 +00:00
|
|
|
import { restComponent } from '../components/RestComponent';
|
2019-08-09 17:21:28 +00:00
|
|
|
import LoadingNotification from '../components/LoadingNotification';
|
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
|
|
|
|
},
|
|
|
|
button: {
|
2019-06-02 18:01:06 +00:00
|
|
|
marginRight: theme.spacing(2),
|
|
|
|
marginTop: theme.spacing(2),
|
2018-02-26 00:11:31 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
class NTPStatus extends Component {
|
|
|
|
|
|
|
|
componentDidMount() {
|
2018-03-04 16:49:24 +00:00
|
|
|
this.props.loadData();
|
2018-02-26 00:11:31 +00:00
|
|
|
}
|
|
|
|
|
2019-05-24 11:19:27 +00:00
|
|
|
createListItems(data, classes) {
|
2018-03-06 20:58:36 +00:00
|
|
|
return (
|
|
|
|
<Fragment>
|
2019-05-24 11:19:27 +00:00
|
|
|
<ListItem >
|
|
|
|
<ListItemAvatar>
|
|
|
|
<Avatar className={classes["ntpStatus_" + ntpStatusHighlight(data)]}>
|
|
|
|
<UpdateIcon />
|
|
|
|
</Avatar>
|
|
|
|
</ListItemAvatar>
|
2018-03-06 20:58:36 +00:00
|
|
|
<ListItemText primary="Status" secondary={ntpStatus(data)} />
|
|
|
|
</ListItem>
|
2019-04-28 23:29:31 +00:00
|
|
|
<Divider variant="inset" component="li" />
|
2019-05-24 11:19:27 +00:00
|
|
|
{isSynchronized(data) &&
|
2018-03-06 20:58:36 +00:00
|
|
|
<Fragment>
|
|
|
|
<ListItem>
|
2019-05-24 11:19:27 +00:00
|
|
|
<ListItemAvatar>
|
|
|
|
<Avatar>
|
|
|
|
<AccessTimeIcon />
|
|
|
|
</Avatar>
|
|
|
|
</ListItemAvatar>
|
2018-03-06 20:58:36 +00:00
|
|
|
<ListItemText primary="Time Now" secondary={unixTimeToTimeAndDate(data.now)} />
|
|
|
|
</ListItem>
|
2019-04-28 23:29:31 +00:00
|
|
|
<Divider variant="inset" component="li" />
|
2018-03-06 20:58:36 +00:00
|
|
|
<ListItem>
|
2019-05-24 11:19:27 +00:00
|
|
|
<ListItemAvatar>
|
|
|
|
<Avatar>
|
|
|
|
<SwapVerticalCircleIcon />
|
2019-05-26 21:02:27 +00:00
|
|
|
</Avatar>
|
|
|
|
</ListItemAvatar>
|
2019-05-24 11:19:27 +00:00
|
|
|
<ListItemText primary="Last Sync" secondary={data.last_sync > 0 ? unixTimeToTimeAndDate(data.last_sync) : "never"} />
|
2018-03-06 20:58:36 +00:00
|
|
|
</ListItem>
|
2019-04-28 23:29:31 +00:00
|
|
|
<Divider variant="inset" component="li" />
|
2018-03-06 20:58:36 +00:00
|
|
|
</Fragment>
|
|
|
|
}
|
|
|
|
<ListItem>
|
2019-05-24 11:19:27 +00:00
|
|
|
<ListItemAvatar>
|
|
|
|
<Avatar>
|
|
|
|
<DNSIcon />
|
|
|
|
</Avatar>
|
|
|
|
</ListItemAvatar>
|
2018-03-06 20:58:36 +00:00
|
|
|
<ListItemText primary="NTP Server" secondary={data.server} />
|
2018-02-26 00:11:31 +00:00
|
|
|
</ListItem>
|
2019-04-28 23:29:31 +00:00
|
|
|
<Divider variant="inset" component="li" />
|
2018-03-06 20:58:36 +00:00
|
|
|
<ListItem>
|
2019-05-24 11:19:27 +00:00
|
|
|
<ListItemAvatar>
|
|
|
|
<Avatar>
|
|
|
|
<TimerIcon />
|
2019-05-26 21:02:27 +00:00
|
|
|
</Avatar>
|
|
|
|
</ListItemAvatar>
|
2018-03-06 20:58:36 +00:00
|
|
|
<ListItemText primary="Sync Interval" secondary={moment.duration(data.interval, 'seconds').humanize()} />
|
|
|
|
</ListItem>
|
2019-04-28 23:29:31 +00:00
|
|
|
<Divider variant="inset" component="li" />
|
2018-03-06 20:58:36 +00:00
|
|
|
<ListItem>
|
2019-05-24 11:19:27 +00:00
|
|
|
<ListItemAvatar>
|
|
|
|
<Avatar>
|
|
|
|
<AvTimerIcon />
|
2019-05-26 21:02:27 +00:00
|
|
|
</Avatar>
|
|
|
|
</ListItemAvatar>
|
2018-03-06 20:58:36 +00:00
|
|
|
<ListItemText primary="Uptime" secondary={moment.duration(data.uptime, 'seconds').humanize()} />
|
|
|
|
</ListItem>
|
2019-04-28 23:29:31 +00:00
|
|
|
<Divider variant="inset" component="li" />
|
2018-03-06 20:58:36 +00:00
|
|
|
</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
|
|
|
|
2019-05-24 11:19:27 +00:00
|
|
|
renderNTPStatus(data, classes) {
|
|
|
|
return (
|
2018-02-26 00:11:31 +00:00
|
|
|
<div>
|
|
|
|
<List>
|
2019-04-29 20:52:11 +00:00
|
|
|
{this.createListItems(data, classes)}
|
2018-02-26 00:11:31 +00:00
|
|
|
</List>
|
2019-04-28 23:29:31 +00:00
|
|
|
<Button variant="contained" color="secondary" className={classes.button} onClick={this.props.loadData}>
|
2018-02-26 00:11:31 +00:00
|
|
|
Refresh
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-08-09 17:21:28 +00:00
|
|
|
const { data, fetched, errorMessage, loadData, classes } = this.props;
|
2018-02-26 00:11:31 +00:00
|
|
|
return (
|
|
|
|
<SectionContent title="NTP Status">
|
2019-08-09 17:21:28 +00:00
|
|
|
<LoadingNotification
|
|
|
|
onReset={loadData}
|
|
|
|
fetched={fetched}
|
|
|
|
errorMessage={errorMessage}>
|
|
|
|
{this.renderNTPStatus(data, classes)}
|
|
|
|
</LoadingNotification>
|
2018-02-26 00:11:31 +00:00
|
|
|
</SectionContent>
|
2019-08-09 17:21:28 +00:00
|
|
|
);
|
2018-02-26 00:11:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-04 16:49:24 +00:00
|
|
|
export default restComponent(NTP_STATUS_ENDPOINT, withStyles(styles)(NTPStatus));
|