diff options
author | Ashutosh Bishnoi <mail2bishnoi@gmail.com> | 2020-11-10 13:02:20 +0530 |
---|---|---|
committer | Ashutosh Bishnoi <mail2bishnoi@gmail.com> | 2020-11-10 13:02:20 +0530 |
commit | a948981184f4f2884b7a35b67b2389ddcd1f52a8 (patch) | |
tree | 9187834b5246734da8549735f64d2e5546c60e1e /modern/src/reports | |
parent | 5a116350b3e402ef123a75451737c268a9ebddff (diff) | |
parent | 1af1545dc7ba3cfdf73a58031b37bea0ecff2e54 (diff) | |
download | trackermap-web-a948981184f4f2884b7a35b67b2389ddcd1f52a8.tar.gz trackermap-web-a948981184f4f2884b7a35b67b2389ddcd1f52a8.tar.bz2 trackermap-web-a948981184f4f2884b7a35b67b2389ddcd1f52a8.zip |
Resolving conflicts with master
Diffstat (limited to 'modern/src/reports')
-rw-r--r-- | modern/src/reports/FilterForm.js | 88 | ||||
-rw-r--r-- | modern/src/reports/ReplayPage.js | 121 |
2 files changed, 209 insertions, 0 deletions
diff --git a/modern/src/reports/FilterForm.js b/modern/src/reports/FilterForm.js new file mode 100644 index 00000000..86339d2d --- /dev/null +++ b/modern/src/reports/FilterForm.js @@ -0,0 +1,88 @@ +import React, { useEffect, useState } from 'react'; +import { FormControl, InputLabel, Select, MenuItem, TextField } from '@material-ui/core'; +import t from '../common/localization'; +import { useSelector } from 'react-redux'; +import moment from 'moment'; + +const FilterForm = ({ deviceId, setDeviceId, from, setFrom, to, setTo }) => { + const devices = useSelector(state => Object.values(state.devices.items)); + + const [period, setPeriod] = useState('today'); + + useEffect(() => { + switch (period) { + default: + case 'today': + setFrom(moment().startOf('day')); + setTo(moment().endOf('day')); + break; + case 'yesterday': + setFrom(moment().subtract(1, 'day').startOf('day')); + setTo(moment().subtract(1, 'day').endOf('day')); + break; + case 'thisWeek': + setFrom(moment().startOf('week')); + setTo(moment().endOf('week')); + break; + case 'previousWeek': + setFrom(moment().subtract(1, 'week').startOf('week')); + setTo(moment().subtract(1, 'week').endOf('week')); + break; + case 'thisMonth': + setFrom(moment().startOf('month')); + setTo(moment().endOf('month')); + break; + case 'previousMonth': + setFrom(moment().subtract(1, 'month').startOf('month')); + setTo(moment().subtract(1, 'month').endOf('month')); + break; + } + }, [period, setFrom, setTo]); + + return ( + <> + <FormControl variant='filled' margin='normal' fullWidth> + <InputLabel>{t('reportDevice')}</InputLabel> + <Select value={deviceId || ''} onChange={e => setDeviceId(e.target.value)}> + {devices.map((device) => ( + <MenuItem key={device.id} value={device.id}>{device.name}</MenuItem> + ))} + </Select> + </FormControl> + <FormControl variant='filled' margin='normal' fullWidth> + <InputLabel>{t('reportPeriod')}</InputLabel> + <Select value={period} onChange={e => setPeriod(e.target.value)}> + <MenuItem key='today' value='today'>{t('reportToday')}</MenuItem> + <MenuItem key='yesterday' value='yesterday'>{t('reportYesterday')}</MenuItem> + <MenuItem key='thisWeek' value='thisWeek'>{t('reportThisWeek')}</MenuItem> + <MenuItem key='previousWeek' value='previousWeek'>{t('reportPreviousWeek')}</MenuItem> + <MenuItem key='thisMonth' value='thisMonth'>{t('reportThisMonth')}</MenuItem> + <MenuItem key='previousMonth' value='previousMonth'>{t('reportPreviousMonth')}</MenuItem> + <MenuItem key='custom' value='custom'>{t('reportCustom')}</MenuItem> + </Select> + </FormControl> + {period === 'custom' && + <TextField + margin='normal' + variant='filled' + label={t('reportFrom')} + type='datetime-local' + value={from.format(moment.HTML5_FMT.DATETIME_LOCAL)} + onChange={e => setFrom(moment(e.target.value, moment.HTML5_FMT.DATETIME_LOCAL))} + fullWidth /> + } + {period === 'custom' && + <TextField + margin='normal' + variant='filled' + label={t('reportTo')} + type='datetime-local' + value={to.format(moment.HTML5_FMT.DATETIME_LOCAL)} + onChange={(e) => setTo(moment(e.target.value, moment.HTML5_FMT.DATETIME_LOCAL))} + fullWidth /> + } + </> + ); +} + +export default FilterForm; diff --git a/modern/src/reports/ReplayPage.js b/modern/src/reports/ReplayPage.js new file mode 100644 index 00000000..6b84d4d9 --- /dev/null +++ b/modern/src/reports/ReplayPage.js @@ -0,0 +1,121 @@ +import React, { useState } from 'react'; +import { Accordion, AccordionDetails, AccordionSummary, Button, Container, FormControl, makeStyles, Paper, Slider, Tooltip, Typography } from '@material-ui/core'; +import ExpandMoreIcon from '@material-ui/icons/ExpandMore'; +import MainToolbar from '../MainToolbar'; +import Map from '../map/Map'; +import t from '../common/localization'; +import FilterForm from './FilterForm'; +import ReplayPathMap from '../map/ReplayPathMap'; +import PositionsMap from '../map/PositionsMap'; +import { formatPosition } from '../common/formatter'; + +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 }) => { + return ( + <Tooltip open={open} enterTouchDelay={0} placement="top" title={value}> + {children} + </Tooltip> + ); +}; + +const ReplayPage = () => { + const classes = useStyles(); + + const [expanded, setExpanded] = useState(true); + + const [deviceId, setDeviceId] = useState(); + const [from, setFrom] = useState(); + const [to, setTo] = useState(); + + const [positions, setPositions] = useState([]); + + const [index, setIndex] = useState(0); + + const handleShow = async () => { + const query = new URLSearchParams({ + deviceId, + from: from.toISOString(), + to: to.toISOString(), + }); + const response = await fetch(`/api/positions?${query.toString()}`, { headers: { 'Accept': 'application/json' } }); + 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}> + <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') : ''} + ValueLabelComponent={TimeLabel} + /> + </Paper> + } + <div> + <Accordion expanded={expanded} onChange={() => setExpanded(!expanded)}> + <AccordionSummary expandIcon={<ExpandMoreIcon />}> + <Typography align='center'> + {t('reportConfigure')} + </Typography> + </AccordionSummary> + <AccordionDetails className={classes.configForm}> + <FilterForm + deviceId={deviceId} + setDeviceId={setDeviceId} + from={from} + setFrom={setFrom} + to={to} + setTo={setTo} /> + <FormControl margin='normal' fullWidth> + <Button type='button' color='primary' variant='contained' disabled={!deviceId} onClick={handleShow}> + {t('reportShow')} + </Button> + </FormControl> + </AccordionDetails> + </Accordion> + </div> + </Container> + </div> + ); +} + +export default ReplayPage; |