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 SettingsInputAntennaIcon from '@material-ui/icons/SettingsInputAntenna';
|
|
|
|
import DeviceHubIcon from '@material-ui/icons/DeviceHub';
|
|
|
|
import ComputerIcon from '@material-ui/icons/Computer';
|
2018-02-26 00:11:31 +00:00
|
|
|
|
2019-05-24 12:19:27 +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
|
|
|
import SectionContent from '../components/SectionContent'
|
|
|
|
|
|
|
|
import * as Highlight from '../constants/Highlight';
|
2019-05-24 12:19:27 +01:00
|
|
|
import { AP_STATUS_ENDPOINT } from '../constants/Endpoints';
|
2018-02-26 00:11:31 +00:00
|
|
|
|
|
|
|
const styles = theme => ({
|
|
|
|
["apStatus_" + Highlight.SUCCESS]: {
|
|
|
|
backgroundColor: theme.palette.highlight_success
|
|
|
|
},
|
|
|
|
["apStatus_" + Highlight.IDLE]: {
|
|
|
|
backgroundColor: theme.palette.highlight_idle
|
|
|
|
},
|
|
|
|
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 APStatus 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 12:19:27 +01:00
|
|
|
apStatusHighlight(data) {
|
2018-03-04 16:49:24 +00:00
|
|
|
return data.active ? Highlight.SUCCESS : Highlight.IDLE;
|
2018-02-26 00:11:31 +00:00
|
|
|
}
|
|
|
|
|
2019-05-24 12:19:27 +01:00
|
|
|
apStatus(data) {
|
2018-03-04 16:49:24 +00:00
|
|
|
return data.active ? "Active" : "Inactive";
|
2018-02-26 00:11:31 +00:00
|
|
|
}
|
|
|
|
|
2019-05-24 12:19:27 +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["apStatus_" + this.apStatusHighlight(data)]}>
|
|
|
|
<SettingsInputAntennaIcon />
|
|
|
|
</Avatar>
|
|
|
|
</ListItemAvatar>
|
2018-03-06 20:58:36 +00:00
|
|
|
<ListItemText primary="Status" secondary={this.apStatus(data)} />
|
|
|
|
</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.ip_address} />
|
|
|
|
</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>
|
|
|
|
<DeviceHubIcon />
|
|
|
|
</Avatar>
|
|
|
|
</ListItemAvatar>
|
2018-03-06 20:58:36 +00:00
|
|
|
<ListItemText primary="MAC Address" secondary={data.mac_address} />
|
|
|
|
</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>
|
|
|
|
<ComputerIcon />
|
|
|
|
</Avatar>
|
|
|
|
</ListItemAvatar>
|
2018-03-06 20:58:36 +00:00
|
|
|
<ListItemText primary="AP Clients" secondary={data.station_num} />
|
|
|
|
</ListItem>
|
2019-04-29 00:29:31 +01: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 12:19:27 +01:00
|
|
|
renderAPStatus(data, classes) {
|
|
|
|
return (
|
2018-02-26 00:11:31 +00:00
|
|
|
<div>
|
|
|
|
<List>
|
2019-07-06 23:56:30 +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 { fetched, errorMessage, data, loadData, classes } = this.props;
|
2018-02-26 00:11:31 +00:00
|
|
|
return (
|
|
|
|
<SectionContent title="AP Status">
|
2019-08-09 18:21:28 +01:00
|
|
|
<LoadingNotification
|
|
|
|
onReset={loadData}
|
|
|
|
fetched={fetched}
|
|
|
|
errorMessage={errorMessage}>
|
|
|
|
{this.renderAPStatus(data, classes)}
|
|
|
|
</LoadingNotification>
|
2018-02-26 00:11:31 +00:00
|
|
|
</SectionContent>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-04 16:49:24 +00:00
|
|
|
export default restComponent(AP_STATUS_ENDPOINT, withStyles(styles)(APStatus));
|