Skip to content

Commit 758f635

Browse files
CSV browser download.
1 parent f7a2989 commit 758f635

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

geophires/geophires-ui.css

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,12 @@ a:not([href]) {
6060
cursor: help;
6161
}
6262

63-
#params-deeplink {
63+
#result-actions {
6464
font-size: 0.5em;
65+
margin-left: 1em;
6566
}
6667

67-
#download-csv, #download-csv:hover {
68+
#result-actions a, #result-actions a:hover {
6869
cursor: pointer;
70+
color: #2196F3 !important;
6971
}

geophires/geophires-ui.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ function setLoading(isLoading) {
33
if (isLoading) {
44
setVisible(loader, true)
55
resetGenerationProfileGraphs()
6-
setVisible($('#params-deeplink'), false)
6+
setVisible($('#result-actions'), false)
77
} else {
88
setVisible(loader, false)
99
}
@@ -225,7 +225,7 @@ function submitForm(oFormElement) {
225225

226226
renderGenerationProfileGraphs(resultsData)
227227

228-
setVisible($('#params-deeplink'), true)
228+
setVisible($('#result-actions'), true)
229229
}
230230

231231
xhr.onerror = function () {

geophires/geophires.vue.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,15 @@ createApp({
1717
}
1818
},
1919
methods: {
20+
downloadURI: function (uri, name) {
21+
let link = document.createElement('a')
22+
link.download = name
23+
link.href = uri
24+
document.body.appendChild(link)
25+
link.click()
26+
document.body.removeChild(link)
27+
},
2028
downloadCsv: function (event) {
21-
2229
fetch(
2330
document.querySelector('#geophires_param_form').getAttribute('action'),
2431
{
@@ -30,7 +37,10 @@ createApp({
3037
}
3138
)
3239
.then(response => response.json())
33-
.then(data => alert(data));
40+
.then(data => {
41+
console.debug('CSV download got data:',data)
42+
this.downloadURI(`data:text/csv,${encodeURI(data['csv'])}`, 'geophires-result.csv')
43+
});
3444
}
3545
}
3646
}).mount('#app')

geophires/index.html

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,20 @@ <h3>
150150
<h3>
151151
Result
152152

153+
<span id="result-actions" class="hidden">
153154
<a id="params-deeplink"
154-
class="hidden"
155-
title="Right-click to copy a deeplink to the parameters for this result"
156-
>&#128279;</a>
157-
155+
title="Right-click to copy a deeplink to the parameters for this result">
156+
<!--&#128279;-->
157+
link
158+
</a>
159+
&nbsp;&centerdot;&nbsp;
158160
<a id="download-csv"
159161
title="Download result as CSV"
160-
@click="downloadCsv"
161-
>&DownArrowBar;</a>
162+
@click="downloadCsv">
163+
<!--&DownArrowBar;-->
164+
csv
165+
</a>
166+
</span>
162167

163168
</h3>
164169
<span id="loading" class="hidden loader">Running...</span>

0 commit comments

Comments
 (0)