From ec8fed96e394ff252c7e98bed1ca2e5322ad650a Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 14 Nov 2020 16:13:58 -0800 Subject: More cleanup --- modern/src/reports/EventReportPage.js | 12 ++--- modern/src/reports/FilterForm.js | 88 --------------------------------- modern/src/reports/ReplayPage.js | 31 ++---------- modern/src/reports/ReportFilter.js | 4 +- modern/src/reports/RouteReportPage.js | 11 ++--- modern/src/reports/StopReportPage.js | 11 ++--- modern/src/reports/SummaryReportPage.js | 9 +--- modern/src/reports/TripReportPage.js | 6 +-- 8 files changed, 21 insertions(+), 151 deletions(-) delete mode 100644 modern/src/reports/FilterForm.js 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 ( 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 ( - <> - - {t('reportDevice')} - - - - {t('reportPeriod')} - - - {period === 'custom' && - setFrom(moment(e.target.value, moment.HTML5_FMT.DATETIME_LOCAL))} - fullWidth /> - } - {period === 'custom' && - 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 = () => { - - - - + ; 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 ; -} +}; const RouteReportPage = () => { const [items, setItems] = useState([]); + return ( @@ -51,6 +48,6 @@ const RouteReportPage = () => { ); -} +}; 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 ; -} +}; const StopReportPage = () => { - const distanceUnit = useAttributePreference('distanceUnit'); const [items, setItems] = useState([]); @@ -57,6 +52,6 @@ const StopReportPage = () => { ); -} +}; 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 ( setDaily(event.target.checked)} />} + control={ setDaily(e.target.checked)} />} label={t('reportDaily')} /> ); 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()); -- cgit v1.2.3