diff options
-rw-r--r-- | modern/src/reports/EventReportPage.js | 12 | ||||
-rw-r--r-- | modern/src/reports/FilterForm.js | 88 | ||||
-rw-r--r-- | modern/src/reports/ReplayPage.js | 31 | ||||
-rw-r--r-- | modern/src/reports/ReportFilter.js | 4 | ||||
-rw-r--r-- | modern/src/reports/RouteReportPage.js | 11 | ||||
-rw-r--r-- | modern/src/reports/StopReportPage.js | 11 | ||||
-rw-r--r-- | modern/src/reports/SummaryReportPage.js | 9 | ||||
-rw-r--r-- | modern/src/reports/TripReportPage.js | 6 |
8 files changed, 21 insertions, 151 deletions
diff --git a/modern/src/reports/EventReportPage.js b/modern/src/reports/EventReportPage.js index 3e12af9..a0ba5f0 100644 --- a/modern/src/reports/EventReportPage.js +++ b/modern/src/reports/EventReportPage.js @@ -10,17 +10,13 @@ const ReportFilterForm = ({ onResult }) => { const [eventType, setEventType] = useState(['allEvents']); const handleSubmit = async (deviceId, from, to) => { - const query = new URLSearchParams({ - deviceId, - from: from.toISOString(), - to: to.toISOString(), - }); - eventType.map(t=>query.append('type',t)); + const query = new URLSearchParams({ deviceId, from, to }); + eventType.map(it => query.append('type', it)); const response = await fetch(`/api/reports/events?${query.toString()}`, { headers: { Accept: 'application/json' } }); - if(response.ok) { + if (response.ok) { onResult(await response.json()); } - } + }; return ( <ReportFilter handleSubmit={handleSubmit}> diff --git a/modern/src/reports/FilterForm.js b/modern/src/reports/FilterForm.js deleted file mode 100644 index 86339d2..0000000 --- a/modern/src/reports/FilterForm.js +++ /dev/null @@ -1,88 +0,0 @@ -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 index 6b84d4d..5c27cb5 100644 --- a/modern/src/reports/ReplayPage.js +++ b/modern/src/reports/ReplayPage.js @@ -1,13 +1,13 @@ import React, { useState } from 'react'; -import { Accordion, AccordionDetails, AccordionSummary, Button, Container, FormControl, makeStyles, Paper, Slider, Tooltip, Typography } from '@material-ui/core'; +import { Accordion, AccordionDetails, AccordionSummary, Container, 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'; +import ReportFilter from './ReportFilter'; const useStyles = makeStyles(theme => ({ root: { @@ -43,21 +43,11 @@ 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 handleSubmit = async (deviceId, from, to) => { + const query = new URLSearchParams({ deviceId, from, to }); const response = await fetch(`/api/positions?${query.toString()}`, { headers: { 'Accept': 'application/json' } }); if (response.ok) { setIndex(0); @@ -98,18 +88,7 @@ const ReplayPage = () => { </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> + <ReportFilter handleSubmit={handleSubmit} />; </AccordionDetails> </Accordion> </div> diff --git a/modern/src/reports/ReportFilter.js b/modern/src/reports/ReportFilter.js index 8fc5ca7..9bc88bb 100644 --- a/modern/src/reports/ReportFilter.js +++ b/modern/src/reports/ReportFilter.js @@ -5,7 +5,7 @@ import { useSelector } from 'react-redux'; import moment from 'moment'; const ReportFilter = ({ children, handleSubmit }) => { - const devices = useSelector((state) => Object.values(state.devices.items)); + const devices = useSelector(state => Object.values(state.devices.items)); const [deviceId, setDeviceId] = useState(); const [period, setPeriod] = useState('today'); const [from, setFrom] = useState(moment().subtract(1, 'hour')); @@ -45,7 +45,7 @@ const ReportFilter = ({ children, handleSubmit }) => { break; } - handleSubmit(deviceId, selectedFrom, selectedTo); + handleSubmit(deviceId, selectedFrom.toISOString(), selectedTo.toISOString()); } return ( diff --git a/modern/src/reports/RouteReportPage.js b/modern/src/reports/RouteReportPage.js index 0f8d98a..d2a1b68 100644 --- a/modern/src/reports/RouteReportPage.js +++ b/modern/src/reports/RouteReportPage.js @@ -8,21 +8,18 @@ import ReportLayoutPage from './ReportLayoutPage'; const ReportFilterForm = ({ onResult }) => { const handleSubmit = async (deviceId, from, to) => { - const query = new URLSearchParams({ - deviceId, - from: from.toISOString(), - to: to.toISOString(), - }); + const query = new URLSearchParams({ deviceId, from, to }); const response = await fetch(`/api/reports/route?${query.toString()}`, { headers: { Accept: 'application/json' } }); if(response.ok) { onResult(await response.json()); } } return <ReportFilter handleSubmit={handleSubmit} />; -} +}; const RouteReportPage = () => { const [items, setItems] = useState([]); + return ( <ReportLayoutPage reportFilterForm={ReportFilterForm} setItems={setItems}> <TableContainer component={Paper}> @@ -51,6 +48,6 @@ const RouteReportPage = () => { </TableContainer> </ReportLayoutPage> ); -} +}; export default RouteReportPage; diff --git a/modern/src/reports/StopReportPage.js b/modern/src/reports/StopReportPage.js index c9e50c8..751909d 100644 --- a/modern/src/reports/StopReportPage.js +++ b/modern/src/reports/StopReportPage.js @@ -9,21 +9,16 @@ import { useAttributePreference } from '../common/preferences'; const ReportFilterForm = ({ onResult }) => { const handleSubmit = async (deviceId, from, to) => { - const query = new URLSearchParams({ - deviceId, - from: from.toISOString(), - to: to.toISOString(), - }); + const query = new URLSearchParams({ deviceId, from, to }); const response = await fetch(`/api/reports/stops?${query.toString()}`, { headers: { Accept: 'application/json' } }); if (response.ok) { onResult(await response.json()); } } return <ReportFilter handleSubmit={handleSubmit} />; -} +}; const StopReportPage = () => { - const distanceUnit = useAttributePreference('distanceUnit'); const [items, setItems] = useState([]); @@ -57,6 +52,6 @@ const StopReportPage = () => { </TableContainer> </ReportLayoutPage> ); -} +}; export default StopReportPage; diff --git a/modern/src/reports/SummaryReportPage.js b/modern/src/reports/SummaryReportPage.js index c90ddb4..4cb37aa 100644 --- a/modern/src/reports/SummaryReportPage.js +++ b/modern/src/reports/SummaryReportPage.js @@ -11,12 +11,7 @@ const ReportFilterForm = ({ onResult }) => { const [daily, setDaily] = useState(false); const handleSubmit = async (deviceId, from, to) => { - const query = new URLSearchParams({ - deviceId, - from: from.toISOString(), - to: to.toISOString(), - daily - }); + const query = new URLSearchParams({ deviceId, from, to, daily }); const response = await fetch(`/api/reports/summary?${query.toString()}`, { headers: { Accept: 'application/json' } }); if (response.ok) { onResult(await response.json()); @@ -25,7 +20,7 @@ const ReportFilterForm = ({ onResult }) => { return ( <ReportFilter handleSubmit={handleSubmit}> <FormControlLabel - control={<Checkbox checked={daily} onChange={event => setDaily(event.target.checked)} />} + control={<Checkbox checked={daily} onChange={e => setDaily(e.target.checked)} />} label={t('reportDaily')} /> </ReportFilter> ); diff --git a/modern/src/reports/TripReportPage.js b/modern/src/reports/TripReportPage.js index 15e21f5..bb987e1 100644 --- a/modern/src/reports/TripReportPage.js +++ b/modern/src/reports/TripReportPage.js @@ -9,11 +9,7 @@ import { useAttributePreference } from '../common/preferences'; const ReportFilterForm = ({ onResult }) => { const handleSubmit = async (deviceId, from, to) => { - const query = new URLSearchParams({ - deviceId, - from: from.toISOString(), - to: to.toISOString(), - }); + const query = new URLSearchParams({ deviceId, from, to }); const response = await fetch(`/api/reports/trips?${query.toString()}`, { headers: { Accept: 'application/json' } }); if (response.ok) { onResult(await response.json()); |