1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
import React, { useState } from 'react';
import { useParams } from 'react-router-dom';
import {
Accordion, AccordionDetails, AccordionSummary, Container, makeStyles, Paper, Slider, Tooltip, Typography, IconButton, Box
} from '@material-ui/core';
import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
import SkipNextIcon from '@material-ui/icons/SkipNext';
import SkipPreviousIcon from '@material-ui/icons/SkipPrevious';
import MainToolbar from '../MainToolbar';
import Map from '../map/Map';
import ReplayPathMap from '../map/ReplayPathMap';
import PositionsMap from '../map/PositionsMap';
import { formatPosition, formatSpeed } from '../common/formatter';
import ReportFilter from './ReportFilter';
import { useTranslation } from '../LocalizationProvider';
import { useAttributePreference } from '../common/preferences';
const useStyles = makeStyles((theme) => ({
root: {
height: '100%',
display: 'flex',
flexDirection: 'column',
},
controlPanel: {
position: 'absolute',
bottom: theme.spacing(5),
left: '50%',
transform: 'translateX(-50%)',
},
controlContent: {
padding: theme.spacing(2),
marginBottom: theme.spacing(2),
},
configForm: {
display: 'flex',
flexDirection: 'column',
},
}));
const TimeLabel = ({ children, open, value }) => (
<Tooltip open={open} enterTouchDelay={0} placement="top" title={value}>
{children}
</Tooltip>
);
const ReplayPage = () => {
const classes = useStyles();
const { id } = useParams();
const t = useTranslation();
const speedUnit = useAttributePreference('speedUnit');
const [expanded, setExpanded] = useState(true);
const [positions, setPositions] = useState([]);
const [index, setIndex] = useState(0);
const handleSubmit = async (deviceId, from, to, _, headers) => {
const query = new URLSearchParams({ deviceId, from, to });
const response = await fetch(`/api/positions?${query.toString()}`, { headers });
if (response.ok) {
setIndex(0);
setPositions(await response.json());
setExpanded(false);
}
};
return (
<div className={classes.root}>
<MainToolbar />
<Map>
<ReplayPathMap positions={positions} />
{index < positions.length
&& <PositionsMap positions={[positions[index]]} />}
</Map>
<Container maxWidth="sm" className={classes.controlPanel}>
{!!positions.length
&& (
<Paper className={classes.controlContent}>
<Box maxWidth="sm" display="flex">
{/* Previous position button */}
<IconButton color="primary" disabled={index === 0} onClick={() => setIndex(index - 1)}>
<SkipPreviousIcon />
</IconButton>
<Box flexGrow={1} textAlign="center">
{/* Date time */}
<Typography variant="button">{formatPosition(positions[index], 'fixTime', t)}</Typography>
{/* Speed */}
{positions[index].speed != undefined &&
<>
<br/><Typography variant="secondary">{formatSpeed(positions[index].speed, speedUnit, t)}</Typography>
</>}
</Box>
{/* Speed */}
{/* Next position button*/}
<IconButton color="primary" disabled={index === positions.length - 1} onClick={() => setIndex(index + 1)}>
<SkipNextIcon />
</IconButton>
</Box>
<Slider
max={positions.length - 1}
step={null}
marks={positions.map((_, index) => ({ value: index }))}
value={index}
onChange={(_, index) => setIndex(index)}
valueLabelDisplay="auto"
valueLabelFormat={(i) => (i < positions.length ? formatPosition(positions[i], 'fixTime', t) : '')}
ValueLabelComponent={TimeLabel}
/>
</Paper>
)}
<div>
<Accordion expanded={expanded} onChange={() => setExpanded(!expanded)}>
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
<Typography align="center">
{t('reportConfigure')}
</Typography>
</AccordionSummary>
<AccordionDetails className={classes.configForm}>
<ReportFilter handleSubmit={handleSubmit} showOnly defaultSelected={id} />
</AccordionDetails>
</Accordion>
</div>
</Container>
</div>
);
};
export default ReplayPage;
|