diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2020-11-14 23:10:22 -0800 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2020-11-14 23:10:22 -0800 |
commit | 604eabcd97c6e7ddb42316a5a1fb0abc24e8dc7f (patch) | |
tree | 79a1ad01487fa95ac8ba6257d5b423011cba7873 /modern/src/reports/RouteReportPage.js | |
parent | cfb788f1f8738b0b29ffb6d27ca8790f1ef7b49a (diff) | |
download | trackermap-web-604eabcd97c6e7ddb42316a5a1fb0abc24e8dc7f.tar.gz trackermap-web-604eabcd97c6e7ddb42316a5a1fb0abc24e8dc7f.tar.bz2 trackermap-web-604eabcd97c6e7ddb42316a5a1fb0abc24e8dc7f.zip |
Support excel reports
Diffstat (limited to 'modern/src/reports/RouteReportPage.js')
-rw-r--r-- | modern/src/reports/RouteReportPage.js | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/modern/src/reports/RouteReportPage.js b/modern/src/reports/RouteReportPage.js index 7ff5d409..43d310be 100644 --- a/modern/src/reports/RouteReportPage.js +++ b/modern/src/reports/RouteReportPage.js @@ -5,15 +5,23 @@ import { formatPosition } from '../common/formatter'; import ReportFilter from './ReportFilter'; import ReportLayoutPage from './ReportLayoutPage'; -const ReportFilterForm = ({ onResult }) => { +const ReportFilterForm = ({ setItems }) => { - const handleSubmit = async (deviceId, from, to) => { - const query = new URLSearchParams({ deviceId, from, to }); - const response = await fetch(`/api/reports/route?${query.toString()}`, { headers: { Accept: 'application/json' } }); + const handleSubmit = async (deviceId, from, to, mail, headers) => { + const query = new URLSearchParams({ deviceId, from, to, mail }); + const response = await fetch(`/api/reports/route?${query.toString()}`, { headers }); if (response.ok) { - onResult(await response.json()); + const contentType = response.headers.get('content-type'); + if (contentType) { + if (contentType === 'application/json') { + setItems(await response.json()); + } else { + window.location.assign(window.URL.createObjectURL(await response.blob())); + } + } } } + return <ReportFilter handleSubmit={handleSubmit} />; }; |