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 23:29:14 +01: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';
|
|
|
|
import ListItemText from '@material-ui/core/ListItemText';
|
2019-05-24 12:19:27 +01:00
|
|
|
import ListItemAvatar from '@material-ui/core/ListItemAvatar';
|
2018-05-18 23:29:14 +01:00
|
|
|
import Avatar from '@material-ui/core/Avatar';
|
|
|
|
import Divider from '@material-ui/core/Divider';
|
|
|
|
import WifiIcon from '@material-ui/icons/Wifi';
|
|
|
|
import DNSIcon from '@material-ui/icons/Dns';
|
|
|
|
import SettingsInputComponentIcon from '@material-ui/icons/SettingsInputComponent';
|
|
|
|
import SettingsInputAntennaIcon from '@material-ui/icons/SettingsInputAntenna';
|
2019-04-29 22:15:07 +01:00
|
|
|
import DeviceHubIcon from '@material-ui/icons/DeviceHub';
|
2018-02-26 00:11:31 +00:00
|
|
|
|
|
|
|
import SectionContent from '../components/SectionContent';
|
2019-04-29 22:15:07 +01:00
|
|
|
import { WIFI_STATUS_ENDPOINT } from '../constants/Endpoints';
|
|
|
|
import { isConnected, connectionStatus, connectionStatusHighlight } from '../constants/WiFiConnectionStatus';
|
2018-02-26 00:11:31 +00:00
|
|
|
import * as Highlight from '../constants/Highlight';
|
2019-04-29 22:15:07 +01:00
|
|
|
import { restComponent } from '../components/RestComponent';
|
2019-08-09 18:21:28 +01:00
|
|
|
import LoadingNotification from '../components/LoadingNotification';
|
2018-02-26 00:11:31 +00:00
|
|
|
|
|
|
|
const styles = theme => ({
|
|
|
|
["wifiStatus_" + Highlight.IDLE]: {
|
|
|
|
backgroundColor: theme.palette.highlight_idle
|
|
|
|
},
|
|
|
|
["wifiStatus_" + Highlight.SUCCESS]: {
|
|
|
|
backgroundColor: theme.palette.highlight_success
|
|
|
|
},
|
|
|
|
["wifiStatus_" + Highlight.ERROR]: {
|
|
|
|
backgroundColor: theme.palette.highlight_error
|
|
|
|
},
|
|
|
|
["wifiStatus_" + Highlight.WARN]: {
|
|
|
|
backgroundColor: theme.palette.highlight_warn
|
|
|
|
},
|
|
|
|
button: {
|
2019-06-02 19:01:06 +01:00
|
|
|
marginRight: theme.spacing(2),
|
|
|
|
marginTop: theme.spacing(2),
|
2018-02-26 00:11:31 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
class WiFiStatus extends Component {
|
|
|
|
|
|
|
|
componentDidMount() {
|
2018-03-04 16:49:24 +00:00
|
|
|
this.props.loadData();
|
2018-02-26 00:11:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dnsServers(status) {
|
2019-04-29 22:15:07 +01:00
|
|
|
if (!status.dns_ip_1) {
|
2018-02-26 00:11:31 +00:00
|
|
|
return "none";
|
|
|
|
}
|
2019-04-29 22:15:07 +01:00
|
|
|
return status.dns_ip_1 + (status.dns_ip_2 ? ',' + status.dns_ip_2 : '');
|
2018-02-26 00:11:31 +00:00
|
|
|
}
|
|
|
|
|
2019-04-29 21:52:11 +01:00
|
|
|
createListItems(data, classes) {
|
2018-03-06 20:58:36 +00:00
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<ListItem>
|
2019-05-24 12:19:27 +01:00
|
|
|
<ListItemAvatar>
|
|
|
|
<Avatar className={classes["wifiStatus_" + connectionStatusHighlight(data)]}>
|
|
|
|
<WifiIcon />
|
|
|
|
</Avatar>
|
|
|
|
</ListItemAvatar>
|
2018-03-06 20:58:36 +00:00
|
|
|
<ListItemText primary="Connection Status" secondary={connectionStatus(data)} />
|
2018-02-26 00:11:31 +00:00
|
|
|
</ListItem>
|
2019-04-29 00:29:31 +01:00
|
|
|
<Divider variant="inset" component="li" />
|
2018-03-06 20:58:36 +00:00
|
|
|
{
|
2019-04-29 21:52:11 +01:00
|
|
|
isConnected(data) &&
|
2018-03-06 20:58:36 +00:00
|
|
|
<Fragment>
|
|
|
|
<ListItem>
|
2019-05-24 12:19:27 +01:00
|
|
|
<ListItemAvatar>
|
|
|
|
<Avatar>
|
|
|
|
<SettingsInputAntennaIcon />
|
|
|
|
</Avatar>
|
|
|
|
</ListItemAvatar>
|
2018-03-06 20:58:36 +00:00
|
|
|
<ListItemText primary="SSID" secondary={data.ssid} />
|
|
|
|
</ListItem>
|
2019-04-29 00:29:31 +01:00
|
|
|
<Divider variant="inset" component="li" />
|
2018-03-06 20:58:36 +00:00
|
|
|
<ListItem>
|
2019-05-24 12:19:27 +01:00
|
|
|
<ListItemAvatar>
|
|
|
|
<Avatar>IP</Avatar>
|
|
|
|
</ListItemAvatar>
|
2018-03-06 20:58:36 +00:00
|
|
|
<ListItemText primary="IP Address" secondary={data.local_ip} />
|
|
|
|
</ListItem>
|
2019-04-29 00:29:31 +01:00
|
|
|
<Divider variant="inset" component="li" />
|
2019-04-29 22:15:07 +01:00
|
|
|
<ListItem>
|
2019-05-24 12:19:27 +01:00
|
|
|
<ListItemAvatar>
|
|
|
|
<Avatar>
|
|
|
|
<DeviceHubIcon />
|
|
|
|
</Avatar>
|
|
|
|
</ListItemAvatar>
|
2019-04-29 22:15:07 +01:00
|
|
|
<ListItemText primary="MAC Address" secondary={data.mac_address} />
|
|
|
|
</ListItem>
|
|
|
|
<Divider variant="inset" component="li" />
|
2018-03-06 20:58:36 +00:00
|
|
|
<ListItem>
|
2019-05-24 12:19:27 +01:00
|
|
|
<ListItemAvatar>
|
|
|
|
<Avatar>#</Avatar>
|
|
|
|
</ListItemAvatar>
|
2018-03-06 20:58:36 +00:00
|
|
|
<ListItemText primary="Subnet Mask" secondary={data.subnet_mask} />
|
|
|
|
</ListItem>
|
2019-04-29 00:29:31 +01:00
|
|
|
<Divider variant="inset" component="li" />
|
2018-03-06 20:58:36 +00:00
|
|
|
<ListItem>
|
2019-05-24 12:19:27 +01:00
|
|
|
<ListItemAvatar>
|
|
|
|
<Avatar>
|
|
|
|
<SettingsInputComponentIcon />
|
|
|
|
</Avatar>
|
|
|
|
</ListItemAvatar>
|
2018-03-06 20:58:36 +00:00
|
|
|
<ListItemText primary="Gateway IP" secondary={data.gateway_ip ? data.gateway_ip : "none"} />
|
|
|
|
</ListItem>
|
2019-04-29 00:29:31 +01:00
|
|
|
<Divider variant="inset" component="li" />
|
2018-03-06 20:58:36 +00:00
|
|
|
<ListItem>
|
2019-05-24 12:19:27 +01:00
|
|
|
<ListItemAvatar>
|
|
|
|
<Avatar>
|
|
|
|
<DNSIcon />
|
|
|
|
</Avatar>
|
|
|
|
</ListItemAvatar>
|
2018-03-06 20:58:36 +00:00
|
|
|
<ListItemText primary="DNS Server IP" secondary={this.dnsServers(data)} />
|
|
|
|
</ListItem>
|
2019-04-29 00:29:31 +01:00
|
|
|
<Divider variant="inset" component="li" />
|
2018-03-06 20:58:36 +00:00
|
|
|
</Fragment>
|
|
|
|
}
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
2018-02-26 00:11:31 +00:00
|
|
|
|
2019-04-29 21:52:11 +01:00
|
|
|
renderWiFiStatus(data, classes) {
|
2019-04-29 22:15:07 +01:00
|
|
|
return (
|
2018-02-26 00:11:31 +00:00
|
|
|
<div>
|
|
|
|
<List>
|
2019-04-29 22:15:07 +01:00
|
|
|
{this.createListItems(data, classes)}
|
2018-02-26 00:11:31 +00:00
|
|
|
</List>
|
2019-04-29 00:29:31 +01: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 18:21:28 +01:00
|
|
|
const { data, fetched, errorMessage, loadData, classes } = this.props;
|
2018-02-26 00:11:31 +00:00
|
|
|
return (
|
|
|
|
<SectionContent title="WiFi Status">
|
2019-08-09 18:21:28 +01:00
|
|
|
<LoadingNotification
|
|
|
|
onReset={loadData}
|
|
|
|
fetched={fetched}
|
2019-08-09 18:55:11 +01:00
|
|
|
errorMessage={errorMessage}
|
|
|
|
render={
|
|
|
|
() => this.renderWiFiStatus(data, classes)
|
|
|
|
}
|
|
|
|
/>
|
2018-02-26 00:11:31 +00:00
|
|
|
</SectionContent>
|
2019-08-09 18:21:28 +01:00
|
|
|
);
|
2018-02-26 00:11:31 +00:00
|
|
|
}
|
2019-08-09 18:21:28 +01:00
|
|
|
|
2018-02-26 00:11:31 +00:00
|
|
|
}
|
|
|
|
|
2018-03-04 16:49:24 +00:00
|
|
|
export default restComponent(WIFI_STATUS_ENDPOINT, withStyles(styles)(WiFiStatus));
|