From c615c9e2f0acf91684d4cb6d9555eccf403971d2 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 28 May 2022 07:47:41 -0700 Subject: Add map for trip report --- modern/src/reports/TripReportPage.js | 97 +++++++++++++++++++++++++++--------- 1 file changed, 73 insertions(+), 24 deletions(-) (limited to 'modern/src/reports') diff --git a/modern/src/reports/TripReportPage.js b/modern/src/reports/TripReportPage.js index 798f28d3..47f91ee3 100644 --- a/modern/src/reports/TripReportPage.js +++ b/modern/src/reports/TripReportPage.js @@ -1,7 +1,9 @@ import React, { useState } from 'react'; import { - Table, TableBody, TableCell, TableHead, TableRow, + IconButton, Table, TableBody, TableCell, TableHead, TableRow, } from '@mui/material'; +import GpsFixedIcon from '@mui/icons-material/GpsFixed'; +import LocationSearchingIcon from '@mui/icons-material/LocationSearching'; import { formatDistance, formatSpeed, formatHours, formatDate, formatVolume, } from '../common/util/formatter'; @@ -12,8 +14,10 @@ import PageLayout from '../common/components/PageLayout'; import ReportsMenu from './components/ReportsMenu'; import ColumnSelect from './components/ColumnSelect'; import usePersistedState from '../common/util/usePersistedState'; -import { useCatch } from '../reactHelper'; +import { useCatch, useEffectAsync } from '../reactHelper'; import useReportStyles from './common/useReportStyles'; +import MapView from '../map/core/MapView'; +import MapRoutePath from '../map/MapRoutePath'; const columnsArray = [ ['startTime', 'reportStartTime'], @@ -41,6 +45,28 @@ const TripReportPage = () => { const [columns, setColumns] = usePersistedState('tripColumns', ['startTime', 'endTime', 'distance', 'averageSpeed']); const [items, setItems] = useState([]); + const [selectedItem, setSelectedItem] = useState(null); + const [route, setRoute] = useState(null); + + useEffectAsync(async () => { + if (selectedItem) { + const query = new URLSearchParams({ + deviceId: selectedItem.deviceId, + from: selectedItem.startTime, + to: selectedItem.endTime, + }); + const response = await fetch(`/api/reports/route?${query.toString()}`, { + Accept: 'application/json', + }); + if (response.ok) { + setRoute(await response.json()); + } else { + throw Error(await response.text()); + } + } else { + setRoute(null); + } + }, [selectedItem]); const handleSubmit = useCatch(async (deviceId, from, to, mail, headers) => { const query = new URLSearchParams({ @@ -84,29 +110,52 @@ const TripReportPage = () => { return ( } breadcrumbs={['reportTitle', 'reportTrips']}> -
- - - -
- - - - {columns.map((key) => ({t(columnsMap.get(key))}))} - - - - {items.map((item) => ( - - {columns.map((key) => ( - - {formatValue(item, key)} - +
+ {selectedItem && ( +
+ + {route && } + +
+ )} +
+
+ + + +
+
+ + + + {columns.map((key) => ({t(columnsMap.get(key))}))} + + + + {items.map((item) => ( + + + {selectedItem === item ? ( + setSelectedItem(null)}> + + + ) : ( + setSelectedItem(item)}> + + + )} + + {columns.map((key) => ( + + {formatValue(item, key)} + + ))} + ))} - - ))} - -
+ + + +
); }; -- cgit v1.2.3