aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshutosh Bishnoi <mail2bishnoi@gmail.com>2021-04-01 12:35:05 +0530
committerAshutosh Bishnoi <mail2bishnoi@gmail.com>2021-04-01 12:35:05 +0530
commitf8a35be5076e44b7c7e37978bf9c6822be965475 (patch)
tree2623793b785c236bc8cbd6c097d89b968395e2c5
parentcee6b4ed848f5178881f5d48a4092fb2bec2bd6b (diff)
downloadetbsa-traccar-web-f8a35be5076e44b7c7e37978bf9c6822be965475.tar.gz
etbsa-traccar-web-f8a35be5076e44b7c7e37978bf9c6822be965475.tar.bz2
etbsa-traccar-web-f8a35be5076e44b7c7e37978bf9c6822be965475.zip
trip data-grid implementation
-rw-r--r--modern/src/reports/TripReportPage.js117
1 files changed, 85 insertions, 32 deletions
diff --git a/modern/src/reports/TripReportPage.js b/modern/src/reports/TripReportPage.js
index c1ba664..82c5439 100644
--- a/modern/src/reports/TripReportPage.js
+++ b/modern/src/reports/TripReportPage.js
@@ -1,7 +1,7 @@
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 { formatDistance, formatSpeed, formatHours, formatDate } from '../common/formatter';
+import { formatDistance, formatSpeed, formatHours, formatDate, formatVolume } from '../common/formatter';
import ReportFilter from './ReportFilter';
import ReportLayoutPage from './ReportLayoutPage';
import { useAttributePreference } from '../common/preferences';
@@ -30,40 +30,93 @@ const TripReportPage = () => {
const distanceUnit = useAttributePreference('distanceUnit');
const speedUnit = useAttributePreference('speedUnit');
+ const volumeUnit = useAttributePreference('volumeUnit');
+
const [items, setItems] = useState([]);
+ const columns = [{
+ headerName: t('reportStartTime'),
+ field: 'startTime',
+ type: 'dateTime',
+ flex: 1,
+ valueFormatter: ({ value }) => formatDate(value),
+ }, {
+ headerName: t('reportStartOdometer'),
+ field: 'startOdometer',
+ type: 'number',
+ flex: 1,
+ valueFormatter: ({ value }) => formatDistance(value, distanceUnit),
+ }, {
+ headerName: t('reportStartAddress'),
+ field: 'startAddress',
+ type: 'string',
+ hide: true,
+ flex: 1,
+ }, {
+ headerName: t('reportEndTime'),
+ field: 'endTime',
+ type: 'dateTime',
+ flex: 1,
+ valueFormatter: ({ value }) => formatDate(value),
+ }, {
+ headerName: t('reportStartOdometer'),
+ field: 'endOdometer',
+ type: 'number',
+ flex: 1,
+ valueFormatter: ({ value }) => formatDistance(value, distanceUnit),
+ }, {
+ headerName: t('reportEndAddress'),
+ field: 'endAddress',
+ type: 'string',
+ hide: true,
+ flex: 1,
+ }, {
+ headerName: t('sharedDistance'),
+ field: 'distance',
+ type: 'number',
+ flex: 1,
+ valueFormatter: ({ value }) => formatDistance(value, distanceUnit),
+ }, {
+ headerName: t('reportAverageSpeed'),
+ field: 'averageSpeed',
+ type: 'number',
+ flex: 1,
+ valueFormatter: ({ value }) => formatSpeed(value, speedUnit),
+ }, {
+ headerName: t('reportMaximumSpeed'),
+ field: 'maxSpeed',
+ type: 'number',
+ flex: 1,
+ valueFormatter: ({ value }) => formatSpeed(value, speedUnit),
+ }, {
+ headerName: t('reportDuration'),
+ field: 'duration',
+ type: 'string',
+ flex: 1,
+ valueFormatter: ({ value }) => formatHours(value),
+ }, {
+ headerName: t('reportSpentFuel'),
+ field: 'spentFuel',
+ type: 'number',
+ flex: 1,
+ hide: true,
+ valueFormatter: ({ value }) => formatVolume(value, volumeUnit),
+ }, {
+ headerName: t('sharedDriver'),
+ field: 'driverName',
+ type: 'string',
+ flex: 1,
+ hide: true
+ }]
+
return (
<ReportLayoutPage filter={<Filter setItems={setItems} />}>
- <TableContainer component={Paper}>
- <Table>
- <TableHead>
- <TableRow>
- <TableCell>{t('reportStartTime')}</TableCell>
- <TableCell>{t('reportStartOdometer')}</TableCell>
- <TableCell>{t('reportEndTime')}</TableCell>
- <TableCell>{t('reportEndOdometer')}</TableCell>
- <TableCell>{t('sharedDistance')}</TableCell>
- <TableCell>{t('reportAverageSpeed')}</TableCell>
- <TableCell>{t('reportMaximumSpeed')}</TableCell>
- <TableCell>{t('reportDuration')}</TableCell>
- </TableRow>
- </TableHead>
- <TableBody>
- {items.map((item) => (
- <TableRow key={item.id}>
- <TableCell>{formatDate(item.startTime)}</TableCell>
- <TableCell>{formatDistance(item.startOdometer, distanceUnit)}</TableCell>
- <TableCell>{formatDate(item.endTime)}</TableCell>
- <TableCell>{formatDistance(item.endOdometer, distanceUnit)}</TableCell>
- <TableCell>{formatDistance(item.distance, distanceUnit)}</TableCell>
- <TableCell>{formatSpeed(item.averageSpeed, speedUnit)}</TableCell>
- <TableCell>{formatSpeed(item.maxSpeed, speedUnit)}</TableCell>
- <TableCell>{formatHours(item.duration)}</TableCell>
- </TableRow>
- ))}
- </TableBody>
- </Table>
- </TableContainer>
+ <DataGrid
+ rows={items}
+ columns={columns}
+ hideFooter
+ autoHeight
+ getRowId={() => Math.random()} />
</ReportLayoutPage>
);
}