From d69bb2b2c3053c2c61e4e5d7029751debcfb0dd9 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 25 Jul 2020 12:36:19 -0700 Subject: Implement simple route report --- modern/src/reports/RouteReportPage.js | 168 ++++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 modern/src/reports/RouteReportPage.js (limited to 'modern/src/reports') diff --git a/modern/src/reports/RouteReportPage.js b/modern/src/reports/RouteReportPage.js new file mode 100644 index 00000000..eb0ccc55 --- /dev/null +++ b/modern/src/reports/RouteReportPage.js @@ -0,0 +1,168 @@ +import React, { useState } from 'react'; +import MainToobar from '../MainToolbar'; +import { useHistory } from 'react-router-dom'; +import { Grid, TableContainer, Table, TableRow, TableCell, TableHead, TableBody, Paper, makeStyles, FormControl, InputLabel, Select, MenuItem, Button, TextField } from '@material-ui/core'; +import t from '../common/localization'; +import { useSelector } from 'react-redux'; +import moment from 'moment'; +import formatter from '../common/formatter'; + +const useStyles = makeStyles(theme => ({ + root: { + height: '100%', + display: 'flex', + flexDirection: 'column', + }, + content: { + flex: 1, + overflow: 'auto', + padding: theme.spacing(2), + }, + form: { + padding: theme.spacing(1, 2, 2), + }, +})); + +const RouteReportPage = () => { + const history = useHistory(); + const classes = useStyles(); + 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')); + const [to, setTo] = useState(moment()); + const [data, setData] = useState([]); + + const handleShow = () => { + let selectedFrom; + let selectedTo; + switch (period) { + case 'today': + selectedFrom = moment().startOf('day'); + selectedTo = moment().endOf('day'); + break; + case 'yesterday': + selectedFrom = moment().subtract(1, 'day').startOf('day'); + selectedTo = moment().subtract(1, 'day').endOf('day'); + break; + case 'thisWeek': + selectedFrom = moment().startOf('week'); + selectedTo = moment().endOf('week'); + break; + case 'previousWeek': + selectedFrom = moment().subtract(1, 'week').startOf('week'); + selectedTo = moment().subtract(1, 'week').endOf('week'); + break; + case 'thisMonth': + selectedFrom = moment().startOf('month'); + selectedTo = moment().endOf('month'); + break; + case 'previousMonth': + selectedFrom = moment().subtract(1, 'month').startOf('month'); + selectedTo = moment().subtract(1, 'month').endOf('month'); + break; + default: + selectedFrom = from; + selectedTo = to; + break; + } + const query = new URLSearchParams({ + deviceId, + from: selectedFrom.toISOString(), + to: selectedTo.toISOString(), + }); + fetch(`/api/reports/route?${query.toString()}`, { headers: { 'Accept': 'application/json' } }) + .then(response => { + if (response.ok) { + response.json().then(setData); + } + }); + } + + 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 /> + } + + + + + + + + + + + {t('positionFixTime')} + {t('positionLatitude')} + {t('positionLongitude')} + {t('positionSpeed')} + {t('positionAddress')} + + + + {data.map((item) => ( + + {formatter(item, 'fixTime')} + {formatter(item, 'latitude')} + {formatter(item, 'longitude')} + {formatter(item, 'speed')} + {formatter(item, 'address')} + + ))} + +
+
+
+
+
+
+ ); +} + +export default RouteReportPage; -- cgit v1.2.3