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 SettingsInputAntennaIcon from 'material-ui-icons/SettingsInputAntenna';
|
|
|
|
import DeviceHubIcon from 'material-ui-icons/DeviceHub';
|
|
|
|
import ComputerIcon from 'material-ui-icons/Computer';
|
|
|
|
|
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 * as Highlight from '../constants/Highlight';
|
|
|
|
import { AP_STATUS_ENDPOINT } from '../constants/Endpoints';
|
|
|
|
|
|
|
|
const styles = theme => ({
|
|
|
|
["apStatus_" + Highlight.SUCCESS]: {
|
|
|
|
backgroundColor: theme.palette.highlight_success
|
|
|
|
},
|
|
|
|
["apStatus_" + Highlight.IDLE]: {
|
|
|
|
backgroundColor: theme.palette.highlight_idle
|
|
|
|
},
|
|
|
|
fetching: {
|
|
|
|
margin: theme.spacing.unit * 4,
|
|
|
|
textAlign: "center"
|
|
|
|
},
|
|
|
|
button: {
|
|
|
|
marginRight: theme.spacing.unit * 2,
|
|
|
|
marginTop: theme.spacing.unit * 2,
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
class APStatus 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
|
|
|
apStatusHighlight(data){
|
|
|
|
return data.active ? Highlight.SUCCESS : Highlight.IDLE;
|
2018-02-26 00:11:31 +00:00
|
|
|
}
|
|
|
|
|
2018-03-04 16:49:24 +00:00
|
|
|
apStatus(data){
|
|
|
|
return data.active ? "Active" : "Inactive";
|
2018-02-26 00:11:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// active, ip_address, mac_address, station_num
|
|
|
|
|
2018-03-04 16:49:24 +00:00
|
|
|
renderAPStatus(data, fullDetails, classes){
|
2018-02-26 00:11:31 +00:00
|
|
|
const listItems = [];
|
|
|
|
|
|
|
|
listItems.push(
|
|
|
|
<ListItem key="ap_status">
|
2018-03-04 16:49:24 +00:00
|
|
|
<Avatar className={classes["apStatus_" + this.apStatusHighlight(data)]}>
|
2018-02-26 00:11:31 +00:00
|
|
|
<SettingsInputAntennaIcon />
|
|
|
|
</Avatar>
|
2018-03-04 16:49:24 +00:00
|
|
|
<ListItemText primary="Status" secondary={this.apStatus(data)} />
|
2018-02-26 00:11:31 +00:00
|
|
|
</ListItem>
|
|
|
|
);
|
|
|
|
listItems.push(<Divider key="ap_status_divider" inset component="li" />);
|
|
|
|
|
|
|
|
listItems.push(
|
|
|
|
<ListItem key="ip_address">
|
|
|
|
<Avatar>IP</Avatar>
|
2018-03-04 16:49:24 +00:00
|
|
|
<ListItemText primary="IP Address" secondary={data.ip_address} />
|
2018-02-26 00:11:31 +00:00
|
|
|
</ListItem>
|
|
|
|
);
|
|
|
|
listItems.push(<Divider key="ip_address_divider" inset component="li" />);
|
|
|
|
|
|
|
|
listItems.push(
|
|
|
|
<ListItem key="mac_address">
|
|
|
|
<Avatar>
|
|
|
|
<DeviceHubIcon />
|
|
|
|
</Avatar>
|
2018-03-04 16:49:24 +00:00
|
|
|
<ListItemText primary="MAC Address" secondary={data.mac_address} />
|
2018-02-26 00:11:31 +00:00
|
|
|
</ListItem>
|
|
|
|
);
|
|
|
|
listItems.push(<Divider key="mac_address_divider" inset component="li" />);
|
|
|
|
|
|
|
|
listItems.push(
|
|
|
|
<ListItem key="station_num">
|
|
|
|
<Avatar>
|
|
|
|
<ComputerIcon />
|
|
|
|
</Avatar>
|
2018-03-04 16:49:24 +00:00
|
|
|
<ListItemText primary="AP Clients" secondary={data.station_num} />
|
2018-02-26 00:11:31 +00:00
|
|
|
</ListItem>
|
|
|
|
);
|
2018-03-03 18:06:43 +00:00
|
|
|
listItems.push(<Divider key="station_num_divider" inset component="li" />);
|
2018-02-26 00:11:31 +00:00
|
|
|
|
|
|
|
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="AP 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.renderAPStatus(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(AP_STATUS_ENDPOINT, withStyles(styles)(APStatus));
|