From 604eabcd97c6e7ddb42316a5a1fb0abc24e8dc7f Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 14 Nov 2020 23:10:22 -0800 Subject: Support excel reports --- modern/src/reports/EventReportPage.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'modern/src/reports/EventReportPage.js') diff --git a/modern/src/reports/EventReportPage.js b/modern/src/reports/EventReportPage.js index b11933a..13e081e 100644 --- a/modern/src/reports/EventReportPage.js +++ b/modern/src/reports/EventReportPage.js @@ -6,16 +6,23 @@ import { formatPosition } from '../common/formatter'; import ReportFilter from './ReportFilter'; import ReportLayoutPage from './ReportLayoutPage'; -const ReportFilterForm = ({ onResult }) => { +const ReportFilterForm = ({ setItems }) => { - const [eventType, setEventType] = useState(['allEvents']); + const [eventTypes, setEventTypes] = useState(['allEvents']); - const handleSubmit = async (deviceId, from, to) => { - const query = new URLSearchParams({ deviceId, from, to }); - eventType.forEach(it => query.append('type', it)); - const response = await fetch(`/api/reports/events?${query.toString()}`, { headers: { Accept: 'application/json' } }); + const handleSubmit = async (deviceId, from, to, mail, headers) => { + const query = new URLSearchParams({ deviceId, from, to, mail }); + eventTypes.forEach(it => query.append('type', it)); + const response = await fetch(`/api/reports/events?${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())); + } + } } }; @@ -23,7 +30,7 @@ const ReportFilterForm = ({ onResult }) => { {t('reportEventTypes')} - setEventTypes(e.target.value)} multiple> {t('eventAll')} {t('eventDeviceOnline')} {t('eventDeviceUnknown')} -- cgit v1.2.3