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'; import {withNotifier} from '../components/SnackbarNotification'; import SectionContent from '../components/SectionContent'; import { simpleGet } from '../helpers/SimpleGet'; 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 { constructor(props) { super(props); this.state = { status:null, fetched: false, errorMessage:null }; this.setState = this.setState.bind(this); this.loadNTPStatus = this.loadNTPStatus.bind(this); } componentDidMount() { this.loadNTPStatus(); } loadNTPStatus() { simpleGet( NTP_STATUS_ENDPOINT, this.setState, this.props.raiseNotification ); } renderNTPStatus(status, fullDetails, classes){ const listItems = []; listItems.push( ); listItems.push(); if (isSynchronized(status)) { listItems.push( ); listItems.push(); } listItems.push( 0 ? unixTimeToTimeAndDate(status.last_sync) : "never" } /> ); listItems.push(); listItems.push( ); listItems.push(); listItems.push( ); listItems.push(); listItems.push( ); return (
{listItems}
); } render() { const { status, fetched, errorMessage } = this.state; const { classes, fullDetails } = this.props; return ( { !fetched ?
Loading...
: status ? this.renderNTPStatus(status, fullDetails, classes) :
{errorMessage}
}
) } } export default withNotifier(withStyles(styles)(NTPStatus));