import React, { useState } from 'react'; import { IconButton, Table, TableBody, TableCell, TableHead, TableRow, } from '@mui/material'; import { makeStyles } from '@mui/styles'; import GpsFixedIcon from '@mui/icons-material/GpsFixed'; import LocationSearchingIcon from '@mui/icons-material/LocationSearching'; import ReportFilter from './components/ReportFilter'; import { useTranslation } from '../common/components/LocalizationProvider'; import PageLayout from '../common/components/PageLayout'; import ReportsMenu from './components/ReportsMenu'; import usePersistedState from '../common/util/usePersistedState'; import PositionValue from '../common/components/PositionValue'; import ColumnSelect from './components/ColumnSelect'; import usePositionAttributes from '../common/attributes/usePositionAttributes'; import { useCatch } from '../reactHelper'; import Map from '../map/core/Map'; import MapRoutePath from '../map/MapRoutePath'; import MapPositions from '../map/MapPositions'; const useStyles = makeStyles((theme) => ({ container: { height: '100%', display: 'flex', flexDirection: 'column', }, containerMap: { flexBasis: '40%', flexShrink: 0, }, containerMain: { overflow: 'auto', }, header: { position: 'sticky', left: 0, display: 'flex', flexDirection: 'column', alignItems: 'stretch', }, columnAction: { width: '1%', paddingLeft: theme.spacing(1), }, })); const RouteReportPage = () => { const classes = useStyles(); const t = useTranslation(); const positionAttributes = usePositionAttributes(t); const [columns, setColumns] = usePersistedState('routeColumns', ['fixTime', 'latitude', 'longitude', 'speed', 'address']); const [items, setItems] = useState([]); const [selectedItem, setSelectedItem] = useState(null); const handleSubmit = useCatch(async (deviceId, from, to, mail, headers) => { const query = new URLSearchParams({ deviceId, from, to, mail, }); const response = await fetch(`/api/reports/route?${query.toString()}`, { headers }); if (response.ok) { const contentType = response.headers.get('content-type'); if (contentType) { if (contentType === 'application/json') { setItems(await response.json()); } else { window.location.assign(window.URL.createObjectURL(await response.blob())); } } } else { throw Error(await response.text()); } }); return ( } breadcrumbs={['reportTitle', 'reportRoute']}>
{selectedItem && (
)}
{columns.map((key) => ({positionAttributes[key].name}))} {items.map((item) => ( {selectedItem === item ? ( setSelectedItem(null)}> ) : ( setSelectedItem(item)}> )} {columns.map((key) => ( ))} ))}
); }; export default RouteReportPage;