diff options
Diffstat (limited to 'modern/src/reports')
-rw-r--r-- | modern/src/reports/ChartReportPage.js | 21 | ||||
-rw-r--r-- | modern/src/reports/ReportLayoutPage.js | 11 |
2 files changed, 18 insertions, 14 deletions
diff --git a/modern/src/reports/ChartReportPage.js b/modern/src/reports/ChartReportPage.js index 5aefca15..19ec9c12 100644 --- a/modern/src/reports/ChartReportPage.js +++ b/modern/src/reports/ChartReportPage.js @@ -3,7 +3,8 @@ import { Box, Paper } from '@material-ui/core'; import ReportFilter from './ReportFilter'; import ReportLayoutPage from './ReportLayoutPage'; import { useAttributePreference } from '../common/preferences'; -import { getConverter, formatDate } from '../common/formatter'; +import { formatDate } from '../common/formatter'; +import { getConverter } from '../common/converter'; import {LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts'; const ReportFilterForm = ({ setItems }) => { @@ -14,13 +15,17 @@ const ReportFilterForm = ({ setItems }) => { const query = new URLSearchParams({ deviceId, from, to, mail }); const response = await fetch(`/api/reports/route?${query.toString()}`, { headers }); if (response.ok) { + const data = await response.json(); - let formattedData = data.map((obj)=>{ - return Object.assign(obj, - {speed: Number(getConverter('speed')(obj.speed, speedUnit))}, - {fixTime: formatDate(obj.fixTime)} - ); - }) + + let formattedData = data.map(obj => { + return Object.assign( + obj, + {speed: Number(getConverter('speed')(obj.speed, speedUnit))}, + {fixTime: formatDate(obj.fixTime)} + ); + }); + setItems(formattedData); } } @@ -46,7 +51,7 @@ const ChartReportPage = () => { const [type, setType] = useState('speed'); return ( - <ReportLayoutPage reportFilterForm={ReportFilterForm} setItems={setItems} setType={setType} showChartType> + <ReportLayoutPage reportFilterForm={ReportFilterForm} setItems={setItems} type={type} setType={setType} showChartType> <Paper> <Box height={400}> <ResponsiveContainer> diff --git a/modern/src/reports/ReportLayoutPage.js b/modern/src/reports/ReportLayoutPage.js index 53b7039a..51e41010 100644 --- a/modern/src/reports/ReportLayoutPage.js +++ b/modern/src/reports/ReportLayoutPage.js @@ -1,7 +1,6 @@ import React from 'react'; import { Grid, Paper, makeStyles, FormControl, InputLabel, Select, MenuItem } from '@material-ui/core'; import MainToolbar from '../MainToolbar'; -import { chartTypes } from '../common/chartTypes'; import t from '../common/localization'; const useStyles = makeStyles(theme => ({ @@ -24,7 +23,7 @@ const useStyles = makeStyles(theme => ({ }, })); -const ReportLayoutPage = ({ reportFilterForm:ReportFilterForm, setItems, setType, showChartType, children }) => { +const ReportLayoutPage = ({ reportFilterForm:ReportFilterForm, setItems, type, setType, showChartType, children }) => { const classes = useStyles(); return ( <div className={classes.root}> @@ -39,10 +38,10 @@ const ReportLayoutPage = ({ reportFilterForm:ReportFilterForm, setItems, setType <Paper className={classes.chart}> <FormControl variant="filled" margin="normal" fullWidth> <InputLabel>{t('reportChartType')}</InputLabel> - <Select defaultValue="speed" onChange={e => setType(e.target.value)}> - {chartTypes.map(item => ( - <MenuItem key={item.id} value={item.id}>{item.name}</MenuItem> - ))} + <Select value={type} onChange={e => setType(e.target.value)}> + <MenuItem value="speed">{t('positionSpeed')}</MenuItem> + <MenuItem value="accuracy">{t('positionAccuracy')}</MenuItem> + <MenuItem value="altitude">{t('positionAltitude')}</MenuItem> </Select> </FormControl> </Paper> |