aboutsummaryrefslogtreecommitdiff
path: root/modern/src/reports/SummaryReportPage.js
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-07-08 16:52:45 -0700
committerAnton Tananaev <anton@traccar.org>2022-07-08 16:52:45 -0700
commit9200986d36b88f549ed40606246d4ef08c93f18f (patch)
tree1e1a2265ad4115af4af8b382bea7a956a89d4156 /modern/src/reports/SummaryReportPage.js
parentcbb5a320802031c102818f8221d853f8181b54f3 (diff)
downloadtrackermap-web-9200986d36b88f549ed40606246d4ef08c93f18f.tar.gz
trackermap-web-9200986d36b88f549ed40606246d4ef08c93f18f.tar.bz2
trackermap-web-9200986d36b88f549ed40606246d4ef08c93f18f.zip
Improve reports handling
Diffstat (limited to 'modern/src/reports/SummaryReportPage.js')
-rw-r--r--modern/src/reports/SummaryReportPage.js42
1 files changed, 23 insertions, 19 deletions
diff --git a/modern/src/reports/SummaryReportPage.js b/modern/src/reports/SummaryReportPage.js
index f6ec0691..b8ec9283 100644
--- a/modern/src/reports/SummaryReportPage.js
+++ b/modern/src/reports/SummaryReportPage.js
@@ -45,27 +45,31 @@ const SummaryReportPage = () => {
const [items, setItems] = useState([]);
const [loading, setLoading] = useState(false);
- const handleSubmit = useCatch(async ({ deviceIds, groupIds, from, to, mail, headers }) => {
- setLoading(true);
- try {
- const query = new URLSearchParams({ from, to, daily, mail });
- deviceIds.forEach((deviceId) => query.append('deviceId', deviceId));
- groupIds.forEach((groupId) => query.append('groupId', groupId));
- const response = await fetch(`/api/reports/summary?${query.toString()}`, { headers });
- if (response.ok) {
- 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()));
- }
- }
- } else {
+ const handleSubmit = useCatch(async ({ deviceIds, groupIds, from, to, type }) => {
+ const query = new URLSearchParams({ from, to, daily });
+ deviceIds.forEach((deviceId) => query.append('deviceId', deviceId));
+ groupIds.forEach((groupId) => query.append('groupId', groupId));
+ if (type === 'export') {
+ window.location.assign(`/api/reports/summary/xlsx?${query.toString()}`);
+ } else if (type === 'mail') {
+ const response = await fetch(`/api/reports/summary/mail?${query.toString()}`);
+ if (!response.ok) {
throw Error(await response.text());
}
- } finally {
- setLoading(false);
+ } else {
+ setLoading(true);
+ try {
+ const response = await fetch(`/api/reports/summary?${query.toString()}`, {
+ headers: { Accept: 'application/json' },
+ });
+ if (response.ok) {
+ setItems(await response.json());
+ } else {
+ throw Error(await response.text());
+ }
+ } finally {
+ setLoading(false);
+ }
}
});