diff options
Diffstat (limited to 'modern/src/reports/EventReportPage.js')
-rw-r--r-- | modern/src/reports/EventReportPage.js | 54 |
1 files changed, 42 insertions, 12 deletions
diff --git a/modern/src/reports/EventReportPage.js b/modern/src/reports/EventReportPage.js index 3ed80e7..7c4a24c 100644 --- a/modern/src/reports/EventReportPage.js +++ b/modern/src/reports/EventReportPage.js @@ -41,18 +41,32 @@ const Filter = ({ setItems }) => { } const handleSubmit = async (deviceId, from, to, mail, headers) => { + let items = {}; const query = new URLSearchParams({ deviceId, from, to, mail, }); + /* fetch events */ eventTypes.forEach((it) => query.append('type', it)); const response = await fetch(`/api/reports/events?${query.toString()}`, { headers }); if (response.ok) { const contentType = response.headers.get('content-type'); if (contentType) { if (contentType === 'application/json') { - setItems(await response.json()); + items['events'] = await response.json(); } else { window.location.assign(window.URL.createObjectURL(await response.blob())); + return; + } + } + } + /* fetch positions, but only if application/json */ + const response2 = await fetch(`/api/reports/route?${query.toString()}`, { headers }); + if (response2.ok) { + const contentType = response2.headers.get('content-type'); + if (contentType) { + if (contentType === 'application/json') { + items['positions'] = await response2.json(); + setItems(items); } } } @@ -95,14 +109,23 @@ const EventReportPage = () => { const geofences = useSelector((state) => state.geofences.items); - const [items, setItems] = useState([]); + const [items, setItems] = useState({positions: [], events: []}); const formatGeofence = (value) => { if (value > 0) { const geofence = geofences[value]; return geofence ? geofence.name : ''; } - return null; + return ''; + }; + + const formatAddress = (value) => { + if (value > 0) { + const position = items.positions.find(p => p.id === value); + console.log ('position ' + value + ' is: ', position); + return position && position.address ? position.address : ''; + } + return ''; }; const columns = [{ @@ -126,20 +149,27 @@ const EventReportPage = () => { headerName: t('sharedMaintenance'), field: 'maintenanceId', type: 'number', + hide: true, + width: theme.dimensions.columnWidthString, + }, { + headerName: t('positionAddress'), + field: 'positionId', + type: 'string', width: theme.dimensions.columnWidthString, + valueFormatter: ({ value }) => formatAddress(value), }]; return ( <ReportLayout filter={<Filter setItems={setItems} />}> - <DataGrid - rows={items} - columns={columns} - components={{ - NoRowsOverlay: NoRowsOverlay, - }} - hideFooter - autoHeight - /> + <DataGrid + rows={items.events} + columns={columns} + components={{ + NoRowsOverlay: NoRowsOverlay, + }} + hideFooter + autoHeight + /> </ReportLayout> ); }; |