Skip to content

Commit 048788b

Browse files
committed
Restored lost spinner.
1 parent dee3b95 commit 048788b

File tree

1 file changed

+56
-47
lines changed

1 file changed

+56
-47
lines changed

src/www/app/templates/logical_device_form.html

+56-47
Original file line numberDiff line numberDiff line change
@@ -51,55 +51,64 @@
5151
console.log(dialog.returnValue);
5252

5353
if ('Export'.localeCompare(dialog.returnValue) === 0) {
54-
console.log('Exporting data');
55-
const formElement = document.getElementById('single-ld-export');
56-
const formData = new FormData(formElement);
57-
console.log(formData);
58-
fetch(formElement.action, {
59-
method: 'POST',
60-
body: formData
61-
})
62-
.then(async response => {
63-
if (response.status == 204) {
64-
alert('No messages found in selected date range.');
65-
return;
66-
}
67-
68-
if (!response.ok) {
69-
throw new Error('Network response was not ok');
70-
}
71-
const blob = await response.blob();
72-
const filename = response.headers.get('Content-Disposition')?.split('filename=')[1]?.replace(/['"]/g, '') || 'download.csv';
73-
74-
// Check if the showSaveFilePicker API is available
75-
if ('showSaveFilePicker' in window) {
76-
try {
77-
const handle = await window.showSaveFilePicker({
78-
suggestedName: filename,
79-
types: [{
80-
description: 'CSV File',
81-
accept: {'text/csv': ['.csv']},
82-
}],
83-
});
84-
const writable = await handle.createWritable();
85-
await writable.write(blob);
86-
await writable.close();
87-
} catch (err) {
88-
if (err.name !== 'AbortError') {
89-
console.error('Failed to save file:', err);
90-
// Fallback to the older method
91-
saveBlobAsFile(blob, filename);
54+
try {
55+
showSpinner();
56+
57+
console.log('Exporting data');
58+
const formElement = document.getElementById('single-ld-export');
59+
const formData = new FormData(formElement);
60+
console.log(formData);
61+
x = fetch(formElement.action, {
62+
method: 'POST',
63+
body: formData
64+
})
65+
.then(async response => {
66+
if (response.status == 204) {
67+
alert('No messages found in selected date range.');
68+
return;
9269
}
70+
71+
if (!response.ok) {
72+
throw new Error('Network response was not ok');
9373
}
94-
} else {
95-
// Fallback for browsers that don't support showSaveFilePicker
96-
saveBlobAsFile(blob, filename);
97-
}
98-
})
99-
.catch(error => {
100-
console.error('Error:', error);
101-
alert("Error occured on submission", error);
102-
});
74+
const blob = await response.blob();
75+
const filename = response.headers.get('Content-Disposition')?.split('filename=')[1]?.replace(/['"]/g, '') || 'download.csv';
76+
77+
// Check if the showSaveFilePicker API is available
78+
if ('showSaveFilePicker' in window) {
79+
try {
80+
const handle = await window.showSaveFilePicker({
81+
suggestedName: filename,
82+
types: [{
83+
description: 'CSV File',
84+
accept: {'text/csv': ['.csv']},
85+
}],
86+
});
87+
const writable = await handle.createWritable();
88+
await writable.write(blob);
89+
await writable.close();
90+
} catch (err) {
91+
if (err.name !== 'AbortError') {
92+
console.error('Failed to save file:', err);
93+
// Fallback to the older method
94+
saveBlobAsFile(blob, filename);
95+
}
96+
}
97+
} else {
98+
// Fallback for browsers that don't support showSaveFilePicker
99+
saveBlobAsFile(blob, filename);
100+
}
101+
})
102+
.catch(error => {
103+
console.error('Error:', error);
104+
alert("Error occured on submission", error);
105+
});
106+
107+
// Wait for the fetch to finish so the spinner shows up.
108+
await x;
109+
} finally {
110+
hideSpinner();
111+
}
103112
}
104113
}
105114

0 commit comments

Comments
 (0)