Skip to content

Commit f1dbecb

Browse files
Show loader while CSV downloading
1 parent 758f635 commit f1dbecb

File tree

3 files changed

+30
-16
lines changed

3 files changed

+30
-16
lines changed

geophires/geophires-ui.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,9 @@ a:not([href]) {
6969
cursor: pointer;
7070
color: #2196F3 !important;
7171
}
72+
73+
#download-csv.loading::after {
74+
content: '\21BB';
75+
display: inline-block;
76+
animation: rotating 2s linear infinite
77+
}

geophires/geophires.vue.js

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ createApp({
1313
data() {
1414
return {
1515
locationOrigin: `${getLocationOrigin()}?ref=geophires-ui`,
16-
locationHost: getLocationHost()
16+
locationHost: getLocationHost(),
17+
isCsvDownloading: ref(false)
1718
}
1819
},
1920
methods: {
@@ -26,21 +27,27 @@ createApp({
2627
document.body.removeChild(link)
2728
},
2829
downloadCsv: function (event) {
29-
fetch(
30-
document.querySelector('#geophires_param_form').getAttribute('action'),
31-
{
32-
method: 'POST',
33-
body: JSON.stringify({
34-
geophires_input_parameters: JSON.parse(event.target.dataset.geophires_input_parameters),
35-
output_format: 'csv'
30+
if(!this.isCsvDownloading) {
31+
this.isCsvDownloading = ref(true)
32+
fetch(
33+
document.querySelector('#geophires_param_form').getAttribute('action'),
34+
{
35+
method: 'POST',
36+
body: JSON.stringify({
37+
geophires_input_parameters: JSON.parse(event.target.dataset.geophires_input_parameters),
38+
output_format: 'csv'
39+
})
40+
}
41+
)
42+
.then(response => {
43+
this.isCsvDownloading = ref(false)
44+
console.debug('CSV download got response:', response)
45+
return response.json()
3646
})
37-
}
38-
)
39-
.then(response => response.json())
40-
.then(data => {
41-
console.debug('CSV download got data:',data)
42-
this.downloadURI(`data:text/csv,${encodeURI(data['csv'])}`, 'geophires-result.csv')
43-
});
47+
.then(data => {
48+
this.downloadURI(`data:text/csv,${encodeURI(data['csv'])}`, 'geophires-result.csv')
49+
});
50+
}
4451
}
4552
}
4653
}).mount('#app')

geophires/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ <h3>
159159
&nbsp;&centerdot;&nbsp;
160160
<a id="download-csv"
161161
title="Download result as CSV"
162-
@click="downloadCsv">
162+
@click="downloadCsv"
163+
:class="{ loading: isCsvDownloading }">
163164
<!--&DownArrowBar;-->
164165
csv
165166
</a>

0 commit comments

Comments
 (0)