From f75cf89d3b4bdb160b4cc7f0a938fe074aed7192 Mon Sep 17 00:00:00 2001 From: Ashutosh Bishnoi Date: Fri, 30 Oct 2020 14:02:16 +0530 Subject: Added Event report with Report Filter as a seperate component --- modern/src/reports/EventReportPage.js | 95 +++++++++++++++++++++++++++ modern/src/reports/ReportFilter.js | 119 ++++++++++++++++++++++++++++++++++ 2 files changed, 214 insertions(+) create mode 100644 modern/src/reports/EventReportPage.js create mode 100644 modern/src/reports/ReportFilter.js (limited to 'modern/src/reports') diff --git a/modern/src/reports/EventReportPage.js b/modern/src/reports/EventReportPage.js new file mode 100644 index 0000000..acd6f63 --- /dev/null +++ b/modern/src/reports/EventReportPage.js @@ -0,0 +1,95 @@ +import React, { useState } from "react"; +import MainToolbar from "../MainToolbar"; +import { + Grid, + TableContainer, + Table, + TableRow, + TableCell, + TableHead, + TableBody, + Paper, + makeStyles, +} from "@material-ui/core"; +import t from "../common/localization"; +import { formatPosition } from "../common/formatter"; +import ReportFilter from "./ReportFilter"; + +const useStyles = makeStyles((theme) => ({ + root: { + height: "100%", + display: "flex", + flexDirection: "column", + }, + content: { + flex: 1, + overflow: "auto", + padding: theme.spacing(2), + }, + form: { + padding: theme.spacing(1, 2, 2), + }, +})); + +const EventReportPage = () => { + const classes = useStyles(); + const [data, setData] = useState([]); + + const handleSubmit = (deviceId, from, to) => { + const query = new URLSearchParams({ + deviceId, + from: from.toISOString(), + to: to.toISOString(), + }); + fetch(`/api/reports/events?${query.toString()}`, { + headers: { Accept: "application/json" }, + }).then((response) => { + if (response.ok) { + response.json().then(setData); + } + }); + }; + + return ( +
+ +
+ + + + + + + + + + + + {t("positionFixTime")} + {t("sharedType")} + {t("sharedGeofence")} + {t("sharedMaintenance")} + + + + {data.map((item) => ( + + + {formatPosition(item, "serverTime")} + + {item.type} + {} + {} + + ))} + +
+
+
+
+
+
+ ); +}; + +export default EventReportPage; diff --git a/modern/src/reports/ReportFilter.js b/modern/src/reports/ReportFilter.js new file mode 100644 index 0000000..91fc9fa --- /dev/null +++ b/modern/src/reports/ReportFilter.js @@ -0,0 +1,119 @@ +import React, { useState } from "react"; +import { + FormControl, + InputLabel, + Select, + MenuItem, + Button, + TextField, +} from "@material-ui/core"; +import t from "../common/localization"; +import { useSelector } from "react-redux"; +import moment from "moment"; + +const ReportFilter = (props) => { + const devices = useSelector((state) => Object.values(state.devices.items)); + const [deviceId, setDeviceId] = useState(); + const [period, setPeriod] = useState("today"); + const [from, setFrom] = useState(moment().subtract(1, "hour")); + const [to, setTo] = useState(moment()); + const handleShow = () => { + let selectedFrom; + let selectedTo; + switch (period) { + case "today": + selectedFrom = moment().startOf("day"); + selectedTo = moment().endOf("day"); + break; + case "yesterday": + selectedFrom = moment().subtract(1, "day").startOf("day"); + selectedTo = moment().subtract(1, "day").endOf("day"); + break; + case "thisWeek": + selectedFrom = moment().startOf("week"); + selectedTo = moment().endOf("week"); + break; + case "previousWeek": + selectedFrom = moment().subtract(1, "week").startOf("week"); + selectedTo = moment().subtract(1, "week").endOf("week"); + break; + case "thisMonth": + selectedFrom = moment().startOf("month"); + selectedTo = moment().endOf("month"); + break; + case "previousMonth": + selectedFrom = moment().subtract(1, "month").startOf("month"); + selectedTo = moment().subtract(1, "month").endOf("month"); + break; + default: + selectedFrom = from; + selectedTo = to; + break; + } + + props.handleSubmit(deviceId, selectedFrom, selectedTo); + }; + return ( + <> + + {t("reportDevice")} + + + + {t("reportPeriod")} + + + {period === "custom" && ( + + setFrom(moment(e.target.value, moment.HTML5_FMT.DATETIME_LOCAL)) + } + fullWidth + /> + )} + {period === "custom" && ( + + setTo(moment(e.target.value, moment.HTML5_FMT.DATETIME_LOCAL)) + } + fullWidth + /> + )} + + + + + ); +}; + +export default ReportFilter; -- cgit v1.2.3