2018-02-26 00:11:31 +00:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
|
|
|
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-04 16:49:24 +00:00
|
|
|
renderNTPStatus(data, fullDetails, classes){
|
2018-02-26 00:11:31 +00:00
|
|
|
const listItems = [];
|
|
|
|
|
|
|
|
listItems.push(
|
|
|
|
<ListItem key="ntp_status">
|
2018-03-04 16:49:24 +00:00
|
|
|
<Avatar className={classes["ntpStatus_" + ntpStatusHighlight(data)]}>
|
2018-02-26 00:11:31 +00:00
|
|
|
<UpdateIcon />
|
|
|
|
</Avatar>
|
2018-03-04 16:49:24 +00:00
|
|
|
<ListItemText primary="Status" secondary={ntpStatus(data)} />
|
2018-02-26 00:11:31 +00:00
|
|
|
</ListItem>
|
|
|
|
);
|
|
|
|
listItems.push(<Divider key="ntp_status_divider" inset component="li" />);
|
|
|
|
|
2018-03-04 16:49:24 +00:00
|
|
|
if (isSynchronized(data)) {
|
2018-02-26 00:11:31 +00:00
|
|
|
listItems.push(
|
|
|
|
<ListItem key="time_now">
|
|
|
|
<Avatar>
|
|
|
|
<AccessTimeIcon />
|
|
|
|
</Avatar>
|
2018-03-04 16:49:24 +00:00
|
|
|
<ListItemText primary="Time Now" secondary={unixTimeToTimeAndDate(data.now)} />
|
2018-02-26 00:11:31 +00:00
|
|
|
</ListItem>
|
|
|
|
);
|
|
|
|
listItems.push(<Divider key="time_now_divider" inset component="li" />);
|
|
|
|
}
|
|
|
|
|
|
|
|
listItems.push(
|
|
|
|
<ListItem key="last_sync">
|
|
|
|
<Avatar>
|
|
|
|
<SwapVerticalCircleIcon />
|
|
|
|
</Avatar>
|
2018-03-04 16:49:24 +00:00
|
|
|
<ListItemText primary="Last Sync" secondary={data.last_sync > 0 ? unixTimeToTimeAndDate(data.last_sync) : "never" } />
|
2018-02-26 00:11:31 +00:00
|
|
|
</ListItem>
|
|
|
|
);
|
|
|
|
listItems.push(<Divider key="last_sync_divider" inset component="li" />);
|
|
|
|
|
|
|
|
listItems.push(
|
|
|
|
<ListItem key="ntp_server">
|
|
|
|
<Avatar>
|
|
|
|
<DNSIcon />
|
|
|
|
</Avatar>
|
2018-03-04 16:49:24 +00:00
|
|
|
<ListItemText primary="NTP Server" secondary={data.server} />
|
2018-02-26 00:11:31 +00:00
|
|
|
</ListItem>
|
|
|
|
);
|
|
|
|
listItems.push(<Divider key="ntp_server_divider" inset component="li" />);
|
|
|
|
|
|
|
|
listItems.push(
|
|
|
|
<ListItem key="sync_interval">
|
|
|
|
<Avatar>
|
|
|
|
<TimerIcon />
|
|
|
|
</Avatar>
|
2018-03-04 16:49:24 +00:00
|
|
|
<ListItemText primary="Sync Interval" secondary={moment.duration(data.interval, 'seconds').humanize()} />
|
2018-02-26 00:11:31 +00:00
|
|
|
</ListItem>
|
|
|
|
);
|
|
|
|
listItems.push(<Divider key="sync_interval_divider" inset component="li" />);
|
|
|
|
|
|
|
|
listItems.push(
|
|
|
|
<ListItem key="uptime">
|
|
|
|
<Avatar>
|
|
|
|
<AvTimerIcon />
|
|
|
|
</Avatar>
|
2018-03-04 16:49:24 +00:00
|
|
|
<ListItemText primary="Uptime" secondary={moment.duration(data.uptime, 'seconds').humanize()} />
|
2018-02-26 00:11:31 +00:00
|
|
|
</ListItem>
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<List>
|
|
|
|
{listItems}
|
|
|
|
</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));
|