2019-05-26 23:04:29 +00:00
|
|
|
import React, { Component, Fragment } from 'react';
|
2020-02-09 10:21:13 +00:00
|
|
|
|
|
|
|
import { Avatar, Button, Divider, Dialog, DialogTitle, DialogContent, DialogActions } from '@material-ui/core';
|
|
|
|
import { List, ListItem, ListItemAvatar, ListItemText } from '@material-ui/core';
|
2019-11-30 12:34:52 +00:00
|
|
|
|
2019-05-26 23:04:29 +00:00
|
|
|
import DevicesIcon from '@material-ui/icons/Devices';
|
|
|
|
import MemoryIcon from '@material-ui/icons/Memory';
|
|
|
|
import ShowChartIcon from '@material-ui/icons/ShowChart';
|
|
|
|
import SdStorageIcon from '@material-ui/icons/SdStorage';
|
|
|
|
import DataUsageIcon from '@material-ui/icons/DataUsage';
|
2019-11-30 12:34:52 +00:00
|
|
|
import AutorenewIcon from '@material-ui/icons/Autorenew';
|
|
|
|
import RefreshIcon from '@material-ui/icons/Refresh';
|
2019-05-26 23:04:29 +00:00
|
|
|
|
2020-02-09 10:21:13 +00:00
|
|
|
import { redirectingAuthorizedFetch } from '../authentication';
|
|
|
|
import { RestFormProps, FormButton, FormActions } from '../components';
|
|
|
|
import { RESTART_ENDPOINT } from '../api';
|
2019-05-26 23:04:29 +00:00
|
|
|
|
2020-02-09 10:21:13 +00:00
|
|
|
import { SystemStatus } from './types';
|
2019-05-26 23:04:29 +00:00
|
|
|
|
2020-02-09 10:21:13 +00:00
|
|
|
interface SystemStatusFormState {
|
|
|
|
confirmRestart: boolean;
|
|
|
|
processing: boolean;
|
|
|
|
}
|
2019-05-26 23:04:29 +00:00
|
|
|
|
2020-02-09 10:21:13 +00:00
|
|
|
type SystemStatusFormProps = RestFormProps<SystemStatus>;
|
2019-11-30 12:34:52 +00:00
|
|
|
|
2020-02-09 10:21:13 +00:00
|
|
|
class SystemStatusForm extends Component<SystemStatusFormProps, SystemStatusFormState> {
|
2019-11-30 12:34:52 +00:00
|
|
|
|
2020-02-09 10:21:13 +00:00
|
|
|
state: SystemStatusFormState = {
|
|
|
|
confirmRestart: false,
|
|
|
|
processing: false
|
2019-11-30 12:34:52 +00:00
|
|
|
}
|
|
|
|
|
2020-02-09 10:21:13 +00:00
|
|
|
createListItems() {
|
|
|
|
const { data } = this.props
|
2019-05-26 23:04:29 +00:00
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<ListItem >
|
|
|
|
<ListItemAvatar>
|
|
|
|
<Avatar>
|
|
|
|
<DevicesIcon />
|
|
|
|
</Avatar>
|
|
|
|
</ListItemAvatar>
|
|
|
|
<ListItemText primary="Platform" secondary={data.esp_platform} />
|
|
|
|
</ListItem>
|
|
|
|
<Divider variant="inset" component="li" />
|
|
|
|
<ListItem >
|
|
|
|
<ListItemAvatar>
|
|
|
|
<Avatar>
|
|
|
|
<ShowChartIcon />
|
|
|
|
</Avatar>
|
|
|
|
</ListItemAvatar>
|
|
|
|
<ListItemText primary="CPU Frequency" secondary={data.cpu_freq_mhz + ' MHz'} />
|
|
|
|
</ListItem>
|
|
|
|
<Divider variant="inset" component="li" />
|
|
|
|
<ListItem >
|
|
|
|
<ListItemAvatar>
|
|
|
|
<Avatar>
|
|
|
|
<MemoryIcon />
|
|
|
|
</Avatar>
|
|
|
|
</ListItemAvatar>
|
|
|
|
<ListItemText primary="Free Heap" secondary={data.free_heap + ' bytes'} />
|
|
|
|
</ListItem>
|
|
|
|
<Divider variant="inset" component="li" />
|
|
|
|
<ListItem >
|
|
|
|
<ListItemAvatar>
|
|
|
|
<Avatar>
|
|
|
|
<DataUsageIcon />
|
|
|
|
</Avatar>
|
|
|
|
</ListItemAvatar>
|
|
|
|
<ListItemText primary="Sketch Size (used/max)" secondary={data.sketch_size + ' / ' + data.free_sketch_space + ' bytes'} />
|
|
|
|
</ListItem>
|
|
|
|
<Divider variant="inset" component="li" />
|
|
|
|
<ListItem >
|
|
|
|
<ListItemAvatar>
|
|
|
|
<Avatar>
|
|
|
|
<SdStorageIcon />
|
|
|
|
</Avatar>
|
|
|
|
</ListItemAvatar>
|
|
|
|
<ListItemText primary="Flash Chip Size" secondary={data.flash_chip_size + ' bytes'} />
|
|
|
|
</ListItem>
|
2019-08-09 17:21:28 +00:00
|
|
|
<Divider variant="inset" component="li" />
|
2019-05-26 23:04:29 +00:00
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-02-09 10:21:13 +00:00
|
|
|
renderRestartDialog() {
|
2019-05-26 23:04:29 +00:00
|
|
|
return (
|
2020-02-09 10:21:13 +00:00
|
|
|
<Dialog
|
|
|
|
open={this.state.confirmRestart}
|
|
|
|
onClose={this.onRestartRejected}
|
|
|
|
>
|
|
|
|
<DialogTitle>Confirm Restart</DialogTitle>
|
|
|
|
<DialogContent dividers={true}>
|
|
|
|
Are you sure you want to restart the device?
|
|
|
|
</DialogContent>
|
|
|
|
<DialogActions>
|
|
|
|
<Button startIcon={<AutorenewIcon />} variant="contained" onClick={this.onRestartConfirmed} disabled={this.state.processing} color="primary" autoFocus>
|
|
|
|
Restart
|
|
|
|
</Button>
|
|
|
|
<Button variant="contained" onClick={this.onRestartRejected} color="secondary">
|
|
|
|
Cancel
|
|
|
|
</Button>
|
|
|
|
</DialogActions>
|
|
|
|
</Dialog>
|
|
|
|
)
|
2019-05-26 23:04:29 +00:00
|
|
|
}
|
|
|
|
|
2019-12-01 08:28:40 +00:00
|
|
|
onRestart = () => {
|
|
|
|
this.setState({ confirmRestart: true });
|
2019-11-30 12:34:52 +00:00
|
|
|
}
|
|
|
|
|
2019-12-01 08:28:40 +00:00
|
|
|
onRestartRejected = () => {
|
|
|
|
this.setState({ confirmRestart: false });
|
2019-11-30 12:34:52 +00:00
|
|
|
}
|
|
|
|
|
2019-12-01 08:28:40 +00:00
|
|
|
onRestartConfirmed = () => {
|
2019-11-30 12:34:52 +00:00
|
|
|
this.setState({ processing: true });
|
2019-12-01 08:28:40 +00:00
|
|
|
redirectingAuthorizedFetch(RESTART_ENDPOINT, { method: 'POST' })
|
2019-11-30 12:34:52 +00:00
|
|
|
.then(response => {
|
|
|
|
if (response.status === 200) {
|
2019-12-01 08:28:40 +00:00
|
|
|
this.props.enqueueSnackbar("Device is restarting", { variant: 'info' });
|
|
|
|
this.setState({ processing: false, confirmRestart: false });
|
2019-11-30 12:34:52 +00:00
|
|
|
} else {
|
|
|
|
throw Error("Invalid status code: " + response.status);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(error => {
|
2019-12-01 08:28:40 +00:00
|
|
|
this.props.enqueueSnackbar(error.message || "Problem restarting device", { variant: 'error' });
|
|
|
|
this.setState({ processing: false, confirmRestart: false });
|
2019-11-30 12:34:52 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-05-26 23:04:29 +00:00
|
|
|
render() {
|
|
|
|
return (
|
2020-02-09 10:21:13 +00:00
|
|
|
<Fragment>
|
|
|
|
<List>
|
|
|
|
{this.createListItems()}
|
|
|
|
</List>
|
|
|
|
<FormActions>
|
|
|
|
<FormButton startIcon={<RefreshIcon />} variant="contained" color="secondary" onClick={this.props.loadData}>
|
|
|
|
Refresh
|
|
|
|
</FormButton>
|
|
|
|
<FormButton startIcon={<AutorenewIcon />} variant="contained" color="primary" onClick={this.onRestart}>
|
|
|
|
Restart
|
|
|
|
</FormButton>
|
|
|
|
</FormActions>
|
2019-12-01 08:28:40 +00:00
|
|
|
{this.renderRestartDialog()}
|
2020-02-09 10:21:13 +00:00
|
|
|
</Fragment>
|
|
|
|
);
|
2019-05-26 23:04:29 +00:00
|
|
|
}
|
2019-11-30 12:34:52 +00:00
|
|
|
|
2019-05-26 23:04:29 +00:00
|
|
|
}
|
|
|
|
|
2020-02-09 10:21:13 +00:00
|
|
|
export default SystemStatusForm;
|