From cce4095ecacc265882317b71f505cdd36c3e4a7c Mon Sep 17 00:00:00 2001 From: Ashutosh Bishnoi Date: Tue, 15 Feb 2022 12:05:44 +0530 Subject: Final routeplayback screen --- modern/src/reports/ReplayPage.js | 217 ++++++++++++++++++++++++++++++--------- 1 file changed, 169 insertions(+), 48 deletions(-) diff --git a/modern/src/reports/ReplayPage.js b/modern/src/reports/ReplayPage.js index bb32daa5..d3839c5c 100644 --- a/modern/src/reports/ReplayPage.js +++ b/modern/src/reports/ReplayPage.js @@ -1,9 +1,15 @@ -import React, { useState } from 'react'; +import React, { useState, useEffect, useRef } from 'react'; import { - Accordion, AccordionDetails, AccordionSummary, Container, makeStyles, Paper, Slider, Tooltip, Typography, + Grid, FormControlLabel, Switch, IconButton, TextField, makeStyles, Paper, Slider, Toolbar, Tooltip, Typography, } from '@material-ui/core'; -import ExpandMoreIcon from '@material-ui/icons/ExpandMore'; -import MainToolbar from '../MainToolbar'; +import ArrowBackIcon from '@material-ui/icons/ArrowBack'; +import SettingsIcon from '@material-ui/icons/Settings'; +import PlayArrowIcon from '@material-ui/icons/PlayArrow'; +import PauseIcon from '@material-ui/icons/Pause'; +import FastForwardIcon from '@material-ui/icons/FastForward'; +import FastRewindIcon from '@material-ui/icons/FastRewind'; +import { useHistory } from 'react-router-dom'; +import { useSelector } from 'react-redux'; import Map from '../map/Map'; import ReplayPathMap from '../map/ReplayPathMap'; import PositionsMap from '../map/PositionsMap'; @@ -13,23 +19,38 @@ import { useTranslation } from '../LocalizationProvider'; const useStyles = makeStyles((theme) => ({ root: { - height: '100%', - display: 'flex', - flexDirection: 'column', + height: '100vh', + }, + title: { + ...theme.typography.title, }, - controlPanel: { + sidebar: { position: 'absolute', - bottom: theme.spacing(5), - left: '50%', - transform: 'translateX(-50%)', + left: 0, + top: 0, + margin: theme.spacing(1.5), + width: theme.dimensions.drawerWidthDesktop, + [theme.breakpoints.down('md')]: { + width: '100%', + margin: 0, + }, + }, + formControlLabel: { + height: '100%', + width: '100%', + paddingRight: theme.spacing(1), + justifyContent: 'space-between', + alignItems: 'center', }, - controlContent: { + reportFilterContainer: { + flex: 1, padding: theme.spacing(2), - marginBottom: theme.spacing(2), + [theme.breakpoints.down('md')]: { + margin: theme.spacing(1), + }, }, - configForm: { - display: 'flex', - flexDirection: 'column', + sliderContainer: { + padding: theme.spacing(2), }, })); @@ -40,14 +61,42 @@ const TimeLabel = ({ children, open, value }) => ( ); const ReplayPage = () => { - const classes = useStyles(); const t = useTranslation(); + const classes = useStyles(); + const history = useHistory(); + const timerRef = useRef(); - const [expanded, setExpanded] = useState(true); const [positions, setPositions] = useState([]); const [index, setIndex] = useState(0); + const [selectedDeviceId, setSelectedDeviceId] = useState(); + const [playbackSpeed, setPlaybackSpeed] = useState(''); + const [expanded, setExpanded] = useState(true); + const [isPlaying, setIsPlaying] = useState(false); + + const deviceName = useSelector((state) => { + if (selectedDeviceId) { + const device = state.devices.items[selectedDeviceId]; + if (device) { + return device.name; + } + } + return null; + }); + + useEffect(() => { + if (isPlaying && positions.length > 0) { + timerRef.current = setInterval(() => { + setIndex((index) => index + 1); + }, 500); + } else { + clearInterval(timerRef.current); + } + + return () => clearInterval(timerRef.current); + }, [isPlaying, positions]); const handleSubmit = async (deviceId, from, to, _, headers) => { + setSelectedDeviceId(deviceId); const query = new URLSearchParams({ deviceId, from, to }); const response = await fetch(`/api/positions?${query.toString()}`, { headers }); if (response.ok) { @@ -59,41 +108,113 @@ const ReplayPage = () => { return (
- {index < positions.length && } - - {!!positions.length - && ( - - ({ value: index }))} - value={index} - onChange={(_, index) => setIndex(index)} - valueLabelDisplay="auto" - valueLabelFormat={(i) => (i < positions.length ? formatPosition(positions[i], 'fixTime', t) : '')} - ValueLabelComponent={TimeLabel} - /> - - )} -
- setExpanded(!expanded)}> - }> - - {t('reportConfigure')} - - - - - - -
-
+
+ + + + + + + history.push('/')}> + + + + + + {t('reportReplay')} + + + {!expanded && ( + + setExpanded(true)}> + + + + )} + + + + + + {!expanded ? ( + + + + {deviceName} + + + ({ value: index }))} + value={index} + onChange={(_, index) => setIndex(index)} + valueLabelDisplay="auto" + valueLabelFormat={(i) => (i < positions.length ? formatPosition(positions[i], 'fixTime') : '')} + ValueLabelComponent={TimeLabel} + /> + + + {`${index}/${positions.length}`} + + setIndex((index) => index - 1)} disabled={isPlaying}> + + + + + setIsPlaying(!isPlaying)}> + {isPlaying ? : } + + + + setIndex((index) => index + 1)} disabled={isPlaying}> + + + + {formatPosition(positions[index], 'fixTime')} + + + + ) : ( + + + + setPlaybackSpeed(e.target.value)} + variant="filled" + /> + + + setIsPlaying(e.target.checked)} + name="autoPlay" + color="primary" + edge="start" + /> + )} + label={t('reportAutoPlay')} + labelPlacement="start" + /> + + + + )} + + +
); }; -- cgit v1.2.3