From d7bfb9ac6fabf09f4675ea58bc58e12dbd04eee9 Mon Sep 17 00:00:00 2001 From: Ashutosh Bishnoi Date: Thu, 12 Nov 2020 16:03:33 +0530 Subject: Implementing Trip Report with attribute formating --- modern/src/reports/TripReportPage.js | 65 ++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 modern/src/reports/TripReportPage.js (limited to 'modern/src/reports/TripReportPage.js') diff --git a/modern/src/reports/TripReportPage.js b/modern/src/reports/TripReportPage.js new file mode 100644 index 00000000..89f22408 --- /dev/null +++ b/modern/src/reports/TripReportPage.js @@ -0,0 +1,65 @@ +import React, { useState } from 'react'; +import { TableContainer, Table, TableRow, TableCell, TableHead, TableBody, Paper } from '@material-ui/core'; +import t from '../common/localization'; +import { formatPosition, formatDistance, formatSpeed, formatHours } from '../common/formatter'; +import ReportFilter from './ReportFilter'; +import ReportLayoutPage from './ReportLayoutPage'; +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 response = await fetch(`/api/reports/trips?${query.toString()}`, { headers: { Accept: 'application/json' } }); + if(response.ok) { + onResult(await response.json()); + } + } + return ; +} + +const TripReportPage = () => { + const distanceUnit = useAttributePreference('distanceUnit'); + const speedUnit = useAttributePreference('speedUnit'); + const [items, setItems] = useState([]); + return ( + + + + + + {t('reportStartTime')} + {t('reportStartOdometer')} + {t('reportEndTime')} + {t('reportEndOdometer')} + {t('sharedDistance')} + {t('reportAverageSpeed')} + {t('reportMaximumSpeed')} + {t('reportDuration')} + + + + {items.map((item) => ( + + {formatPosition(item, 'startTime')} + {formatDistance(item.startOdometer, distanceUnit)} + {formatPosition(item, 'endTime')} + {formatDistance(item.endOdometer, distanceUnit)} + {formatDistance(item.distance, distanceUnit)} + {formatSpeed(item.averageSpeed, speedUnit)} + {formatSpeed(item.maxSpeed, speedUnit)} + {formatHours(item.duration)} + + ))} + +
+
+
+ ); +} + +export default TripReportPage; -- cgit v1.2.3