From 5d3d2df0d0ee2d95cc6e0f855f9f163be48d5ddd Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 2 Feb 2023 15:34:48 -0800 Subject: Base combined report --- modern/src/reports/CombinedReportPage.js | 91 ++++++++++++++++++++++++++++ modern/src/reports/components/ReportsMenu.js | 7 +++ 2 files changed, 98 insertions(+) create mode 100644 modern/src/reports/CombinedReportPage.js (limited to 'modern/src/reports') diff --git a/modern/src/reports/CombinedReportPage.js b/modern/src/reports/CombinedReportPage.js new file mode 100644 index 00000000..a5d994fe --- /dev/null +++ b/modern/src/reports/CombinedReportPage.js @@ -0,0 +1,91 @@ +import React, { useState } from 'react'; +import { useSelector } from 'react-redux'; +import { + Table, TableBody, TableCell, TableHead, TableRow, +} from '@mui/material'; +import ReportFilter from './components/ReportFilter'; +import { useTranslation } from '../common/components/LocalizationProvider'; +import PageLayout from '../common/components/PageLayout'; +import ReportsMenu from './components/ReportsMenu'; +import { useCatch } from '../reactHelper'; +import MapView from '../map/core/MapView'; +import MapRoutePath from '../map/MapRoutePath'; +import useReportStyles from './common/useReportStyles'; +import TableShimmer from '../common/components/TableShimmer'; +import MapCamera from '../map/MapCamera'; +import MapGeofence from '../map/MapGeofence'; +import { formatTime } from '../common/util/formatter'; +import { usePreference } from '../common/util/preferences'; +import { prefixString } from '../common/util/stringUtils'; + +const CombinedReportPage = () => { + const classes = useReportStyles(); + const t = useTranslation(); + + const devices = useSelector((state) => state.devices.items); + + const hours12 = usePreference('twelveHourFormat'); + + const [items, setItems] = useState([]); + const [loading, setLoading] = useState(false); + + const handleSubmit = useCatch(async ({ deviceIds, groupIds, from, to }) => { + const query = new URLSearchParams({ from, to }); + deviceIds.forEach((deviceId) => query.append('deviceId', deviceId)); + groupIds.forEach((groupId) => query.append('groupId', groupId)); + setLoading(true); + try { + const response = await fetch(`/api/reports/combined?${query.toString()}`); + if (response.ok) { + setItems(await response.json()); + } else { + throw Error(await response.text()); + } + } finally { + setLoading(false); + } + }); + + return ( + } breadcrumbs={['reportTitle', 'reportRoute']}> +
+ {Boolean(items.length) && ( +
+ + + {items.map((item) => ( + + ))} + + item.route)} /> +
+ )} +
+
+ +
+ + + + {t('sharedDevice')} + {t('positionFixTime')} + {t('sharedType')} + + + + {!loading ? items.flatMap((item) => item.events.map((event, index) => ( + + {index ? '' : devices[item.deviceId].name} + {formatTime(event.eventTime, 'seconds', hours12)} + {t(prefixString('event', event.type))} + + ))) : ()} + +
+
+
+
+ ); +}; + +export default CombinedReportPage; diff --git a/modern/src/reports/components/ReportsMenu.js b/modern/src/reports/components/ReportsMenu.js index a31c3afe..c65a4c12 100644 --- a/modern/src/reports/components/ReportsMenu.js +++ b/modern/src/reports/components/ReportsMenu.js @@ -11,6 +11,7 @@ import TrendingUpIcon from '@mui/icons-material/TrendingUp'; import BarChartIcon from '@mui/icons-material/BarChart'; import RouteIcon from '@mui/icons-material/Route'; import EventRepeatIcon from '@mui/icons-material/EventRepeat'; +import StarIcon from '@mui/icons-material/Star'; import { Link, useLocation } from 'react-router-dom'; import { useTranslation } from '../../common/components/LocalizationProvider'; import { useAdministrator, useRestriction } from '../../common/util/permissions'; @@ -34,6 +35,12 @@ const ReportsMenu = () => { return ( <> + } + selected={location.pathname === '/reports/combined'} + />