aboutsummaryrefslogtreecommitdiff
path: root/modern/src/reports/EventReportPage.js
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2020-11-14 23:10:22 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2020-11-14 23:10:22 -0800
commit604eabcd97c6e7ddb42316a5a1fb0abc24e8dc7f (patch)
tree79a1ad01487fa95ac8ba6257d5b423011cba7873 /modern/src/reports/EventReportPage.js
parentcfb788f1f8738b0b29ffb6d27ca8790f1ef7b49a (diff)
downloadtrackermap-web-604eabcd97c6e7ddb42316a5a1fb0abc24e8dc7f.tar.gz
trackermap-web-604eabcd97c6e7ddb42316a5a1fb0abc24e8dc7f.tar.bz2
trackermap-web-604eabcd97c6e7ddb42316a5a1fb0abc24e8dc7f.zip
Support excel reports
Diffstat (limited to 'modern/src/reports/EventReportPage.js')
-rw-r--r--modern/src/reports/EventReportPage.js23
1 files changed, 15 insertions, 8 deletions
diff --git a/modern/src/reports/EventReportPage.js b/modern/src/reports/EventReportPage.js
index b11933a3..13e081e2 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 }) => {
<ReportFilter handleSubmit={handleSubmit}>
<FormControl variant="filled" margin="normal" fullWidth>
<InputLabel>{t('reportEventTypes')}</InputLabel>
- <Select value={eventType} onChange={e => setEventType(e.target.value)} multiple>
+ <Select value={eventTypes} onChange={e => setEventTypes(e.target.value)} multiple>
<MenuItem value="allEvents">{t('eventAll')}</MenuItem>
<MenuItem value="deviceOnline">{t('eventDeviceOnline')}</MenuItem>
<MenuItem value="deviceUnknown">{t('eventDeviceUnknown')}</MenuItem>