From 0d9573c2145a6e2df3d43ef4e192529654bc65de Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 2 Aug 2022 07:50:08 -0700 Subject: Multi device route (fix #998) --- modern/src/reports/RouteReportPage.js | 16 ++++++++++++---- modern/src/reports/SummaryReportPage.js | 7 ++++--- modern/src/reports/components/ReportFilter.js | 4 ++-- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/modern/src/reports/RouteReportPage.js b/modern/src/reports/RouteReportPage.js index fb05f1b1..d60b241c 100644 --- a/modern/src/reports/RouteReportPage.js +++ b/modern/src/reports/RouteReportPage.js @@ -1,4 +1,5 @@ import React, { useState } from 'react'; +import { useSelector } from 'react-redux'; import { IconButton, Table, TableBody, TableCell, TableHead, TableRow, } from '@mui/material'; @@ -26,13 +27,16 @@ const RouteReportPage = () => { const positionAttributes = usePositionAttributes(t); + const devices = useSelector((state) => state.devices.items); + const [columns, setColumns] = usePersistedState('routeColumns', ['fixTime', 'latitude', 'longitude', 'speed', 'address']); const [items, setItems] = useState([]); const [loading, setLoading] = useState(false); const [selectedItem, setSelectedItem] = useState(null); - const handleSubmit = useCatch(async ({ deviceId, from, to, type }) => { - const query = new URLSearchParams({ deviceId, from, to }); + const handleSubmit = useCatch(async ({ deviceIds, from, to, type }) => { + const query = new URLSearchParams({ from, to }); + deviceIds.forEach((deviceId) => query.append('deviceId', deviceId)); if (type === 'export') { window.location.assign(`/api/reports/route/xlsx?${query.toString()}`); } else if (type === 'mail') { @@ -63,7 +67,9 @@ const RouteReportPage = () => { {selectedItem && (
- + {[...new Set(items.map((it) => it.deviceId))].map((deviceId) => ( + position.deviceId === deviceId)} /> + ))} @@ -71,7 +77,7 @@ const RouteReportPage = () => { )}
- + { + {t('sharedDevice')} {columns.map((key) => ({positionAttributes[key].name}))} @@ -100,6 +107,7 @@ const RouteReportPage = () => { )} + {devices[item.deviceId].name} {columns.map((key) => ( { const speedUnit = useAttributePreference('speedUnit'); const volumeUnit = useAttributePreference('volumeUnit'); - const [columns, setColumns] = usePersistedState('summaryColumns', ['deviceId', 'startTime', 'distance', 'averageSpeed']); + const [columns, setColumns] = usePersistedState('summaryColumns', ['startTime', 'distance', 'averageSpeed']); const [daily, setDaily] = useState(false); const [items, setItems] = useState([]); const [loading, setLoading] = useState(false); @@ -98,7 +97,7 @@ const SummaryReportPage = () => { return ( } breadcrumbs={['reportTitle', 'reportSummary']}>
- +
{t('sharedType')} @@ -114,12 +113,14 @@ const SummaryReportPage = () => { + {t('sharedDevice')} {columns.map((key) => ({t(columnsMap.get(key))}))} {!loading ? items.map((item) => ( + {devices[item.deviceId].name} {columns.map((key) => ( {formatValue(item, key)} diff --git a/modern/src/reports/components/ReportFilter.js b/modern/src/reports/components/ReportFilter.js index 816fde8d..d223b086 100644 --- a/modern/src/reports/components/ReportFilter.js +++ b/modern/src/reports/components/ReportFilter.js @@ -7,7 +7,7 @@ import moment from 'moment'; import { useTranslation } from '../../common/components/LocalizationProvider'; import useReportStyles from '../common/useReportStyles'; -const ReportFilter = ({ children, handleSubmit, showOnly, ignoreDevice, multiDevice }) => { +const ReportFilter = ({ children, handleSubmit, showOnly, ignoreDevice, multiDevice, includeGroups }) => { const classes = useReportStyles(); const t = useTranslation(); @@ -87,7 +87,7 @@ const ReportFilter = ({ children, handleSubmit, showOnly, ignoreDevice, multiDev )} - {multiDevice && ( + {includeGroups && (
{t('settingsGroups')} -- cgit v1.2.3