aboutsummaryrefslogtreecommitdiff
path: root/modern/src/DevicesList.js
diff options
context:
space:
mode:
Diffstat (limited to 'modern/src/DevicesList.js')
-rw-r--r--modern/src/DevicesList.js77
1 files changed, 70 insertions, 7 deletions
diff --git a/modern/src/DevicesList.js b/modern/src/DevicesList.js
index 85b936ce..c774cdfe 100644
--- a/modern/src/DevicesList.js
+++ b/modern/src/DevicesList.js
@@ -3,21 +3,23 @@ import { useDispatch, useSelector } from 'react-redux';
import { makeStyles } from '@material-ui/core/styles';
import Avatar from '@material-ui/core/Avatar';
import Divider from '@material-ui/core/Divider';
-import IconButton from '@material-ui/core/IconButton';
import List from '@material-ui/core/List';
import ListItem from '@material-ui/core/ListItem';
import ListItemAvatar from '@material-ui/core/ListItemAvatar';
import ListItemSecondaryAction from '@material-ui/core/ListItemSecondaryAction';
+import Grid from '@material-ui/core/Grid';
import ListItemText from '@material-ui/core/ListItemText';
-import MoreVertIcon from '@material-ui/icons/MoreVert';
import { FixedSizeList } from 'react-window';
import AutoSizer from 'react-virtualized-auto-sizer';
+import BatteryFullIcon from '@material-ui/icons/BatteryFull';
+import VpnKeyIcon from '@material-ui/icons/VpnKey';
import { devicesActions } from './store';
import EditCollectionView from './EditCollectionView';
import { useEffectAsync } from './reactHelper';
+import { formatPosition } from './common/formatter';
-const useStyles = makeStyles(() => ({
+const useStyles = makeStyles(theme => ({
list: {
maxHeight: '100%',
},
@@ -26,8 +28,71 @@ const useStyles = makeStyles(() => ({
height: '25px',
filter: 'brightness(0) invert(1)',
},
+ batteryText: {
+ fontSize: '0.75rem',
+ fontWeight: 'normal',
+ lineHeight: '0.875rem'
+ },
+ green: {
+ color: theme.palette.common.green,
+ },
+ red: {
+ color: theme.palette.common.red,
+ },
+ gray: {
+ color: theme.palette.common.gray
+ }
}));
+const OnlineStatus =({ status }) => {
+
+ const classes = useStyles();
+
+ switch (status) {
+ case 'online':
+ return <span className={classes.green}>{status}</span>
+ case 'offline':
+ return <span className={classes.red}>{status}</span>
+ case 'unknown':
+ default:
+ return <span className={classes.gray}>{status}</span>
+ }
+}
+
+const DeviceStatus = ({ deviceId }) => {
+ const classes = useStyles();
+ let batteryClass = '';
+
+ const position = useSelector(state => state.positions.items[deviceId]);
+ if (!position) {
+ return null;
+ }
+ const batteryLevel = position.attributes.hasOwnProperty('batteryLevel') ? position.attributes.batteryLevel : 'undefined';
+
+ if (batteryLevel >= 70) {
+ batteryClass = classes.green;
+ } else if (batteryLevel > 30) {
+ batteryClass = classes.gray;
+ } else {
+ batteryClass = classes.red;
+ }
+ return (
+ <Grid container direction="row" alignItems="center" alignContent="center" spacing={1}>
+ {position.attributes.hasOwnProperty('ignition') && <Grid item>
+ <VpnKeyIcon className={`${position.attributes.ignition ? classes.green : classes.gray}`}/>
+ </Grid>}
+ {batteryLevel !== 'undefined' && <Grid item container xs alignItems="center" alignContent="center">
+ <Grid item>
+ <span className={classes.batteryText}>{formatPosition(batteryLevel, 'batteryLevel')}</span>
+ </Grid>
+ <Grid item>
+ <BatteryFullIcon className={batteryClass} />
+ </Grid>
+ </Grid>}
+ </Grid>
+ );
+}
+
const DeviceRow = ({ data, index, style }) => {
const classes = useStyles();
const dispatch = useDispatch();
@@ -44,11 +109,9 @@ const DeviceRow = ({ data, index, style }) => {
<img className={classes.icon} src={`images/icon/${item.category || 'default'}.svg`} alt="" />
</Avatar>
</ListItemAvatar>
- <ListItemText primary={item.name} secondary={item.uniqueId} />
+ <ListItemText primary={item.name} secondary={<OnlineStatus status={item.status} />} />
<ListItemSecondaryAction>
- <IconButton onClick={(event) => onMenuClick(event.currentTarget, item.id)}>
- <MoreVertIcon />
- </IconButton>
+ <DeviceStatus deviceId={item.id} />
</ListItemSecondaryAction>
</ListItem>
{index < items.length - 1 ? <Divider /> : null}