aboutsummaryrefslogtreecommitdiff
path: root/modern/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2021-03-24 22:11:19 -0700
committerGitHub <noreply@github.com>2021-03-24 22:11:19 -0700
commit323aaaebc3fd62cdcb6ab5580153af8afeac30e4 (patch)
treede453a6d4d62cc76c0c500f7ca7ca8ae048c519d /modern/src
parentc92c5c5a805dfe6927e5c45f677bb386861b4917 (diff)
parentcfa8947f3a4adda1ed649210da4adfe21f44af21 (diff)
downloadetbsa-traccar-web-323aaaebc3fd62cdcb6ab5580153af8afeac30e4.tar.gz
etbsa-traccar-web-323aaaebc3fd62cdcb6ab5580153af8afeac30e4.tar.bz2
etbsa-traccar-web-323aaaebc3fd62cdcb6ab5580153af8afeac30e4.zip
Merge pull request #828 from mail2bishnoi/custom_report_table
Cutome route table
Diffstat (limited to 'modern/src')
-rw-r--r--modern/src/common/formatter.js25
-rw-r--r--modern/src/reports/RouteReportPage.js83
2 files changed, 82 insertions, 26 deletions
diff --git a/modern/src/common/formatter.js b/modern/src/common/formatter.js
index 289a6d9..0d8ac4c 100644
--- a/modern/src/common/formatter.js
+++ b/modern/src/common/formatter.js
@@ -81,3 +81,28 @@ export const formatVolume = (value, unit) => {
export const formatHours = (value) => {
return moment.duration(value).humanize();
};
+
+export const formatCoordinate = (key, value, unit) => {
+ var hemisphere, degrees, minutes, seconds;
+ if (key === 'latitude') {
+ hemisphere = value >= 0 ? 'N' : 'S';
+ } else {
+ hemisphere = value >= 0 ? 'E' : 'W';
+ }
+
+ switch (unit) {
+ case 'ddm':
+ value = Math.abs(value);
+ degrees = Math.floor(value);
+ minutes = (value - degrees) * 60;
+ return degrees + '° ' + minutes.toFixed(6) + '\' ' + hemisphere;
+ case 'dms':
+ value = Math.abs(value);
+ degrees = Math.floor(value);
+ minutes = Math.floor((value - degrees) * 60);
+ seconds = Math.round((value - degrees - minutes / 60) * 3600);
+ return degrees + '° ' + minutes + '\' ' + seconds + '" ' + hemisphere;
+ default:
+ return value.toFixed(6) + '°';
+ }
+};
diff --git a/modern/src/reports/RouteReportPage.js b/modern/src/reports/RouteReportPage.js
index f2b0361..b8bad00 100644
--- a/modern/src/reports/RouteReportPage.js
+++ b/modern/src/reports/RouteReportPage.js
@@ -1,9 +1,10 @@
import React, { useState } from 'react';
-import { TableContainer, Table, TableRow, TableCell, TableHead, TableBody, Paper } from '@material-ui/core';
+import { DataGrid } from '@material-ui/data-grid';
import t from '../common/localization';
-import { formatPosition } from '../common/formatter';
+import { formatDistance, formatSpeed, formatBoolean, formatDate, formatCoordinate } from '../common/formatter';
import ReportFilter from './ReportFilter';
import ReportLayoutPage from './ReportLayoutPage';
+import { useAttributePreference, usePreference } from '../common/preferences';
const Filter = ({ setItems }) => {
@@ -26,35 +27,65 @@ const Filter = ({ setItems }) => {
};
const RouteReportPage = () => {
+ const distanceUnit = useAttributePreference('distanceUnit');
+ const speedUnit = useAttributePreference('speedUnit');
+ const coordinateFormat = usePreference('coordinateFormat');
+
+ const columns = [{
+ headerName: t('positionFixTime'),
+ field: 'fixTime',
+ type: 'dateTime',
+ flex: 1,
+ valueFormatter: ({ value }) => formatDate(value),
+ }, {
+ headerName: t('positionLatitude'),
+ field: 'latitude',
+ type: 'number',
+ flex: 1,
+ valueFormatter: ({ value }) => formatCoordinate('latitude', value, coordinateFormat),
+ }, {
+ headerName: t('positionLongitude'),
+ field: 'longitude',
+ type: 'number',
+ flex: 1,
+ valueFormatter: ({ value }) => formatCoordinate('longitude', value, coordinateFormat),
+ }, {
+ headerName: t('positionSpeed'),
+ field: 'speed',
+ type: 'number',
+ flex: 1,
+ valueFormatter: ({ value }) => formatSpeed(value, speedUnit),
+ }, {
+ headerName: t('positionAddress'),
+ field: 'address',
+ type: 'string',
+ flex: 1,
+ }, {
+ headerName: t('positionIgnition'),
+ field: 'ignition',
+ type: 'boolean',
+ flex: 1,
+ valueGetter: ({ row }) => row.attributes.ignition,
+ valueFormatter: ({ value }) => formatBoolean(value),
+ }, {
+ headerName: t('deviceTotalDistance'),
+ field: 'totalDistance',
+ type: 'number',
+ hide: true,
+ flex: 1,
+ valueGetter: ({ row }) => row.attributes.totalDistance,
+ valueFormatter: ({ value }) => formatDistance(value, distanceUnit),
+ }]
const [items, setItems] = useState([]);
return (
<ReportLayoutPage filter={<Filter setItems={setItems} />}>
- <TableContainer component={Paper}>
- <Table>
- <TableHead>
- <TableRow>
- <TableCell>{t('positionFixTime')}</TableCell>
- <TableCell>{t('positionLatitude')}</TableCell>
- <TableCell>{t('positionLongitude')}</TableCell>
- <TableCell>{t('positionSpeed')}</TableCell>
- <TableCell>{t('positionAddress')}</TableCell>
- </TableRow>
- </TableHead>
- <TableBody>
- {items.map((item) => (
- <TableRow key={item.id}>
- <TableCell>{formatPosition(item, 'fixTime')}</TableCell>
- <TableCell>{formatPosition(item, 'latitude')}</TableCell>
- <TableCell>{formatPosition(item, 'longitude')}</TableCell>
- <TableCell>{formatPosition(item, 'speed')}</TableCell>
- <TableCell>{formatPosition(item, 'address')}</TableCell>
- </TableRow>
- ))}
- </TableBody>
- </Table>
- </TableContainer>
+ <DataGrid
+ rows={items}
+ columns={columns}
+ hideFooter
+ autoHeight />
</ReportLayoutPage>
);
};