Skip to content

Commit 8ba9726

Browse files
Merge branch 'csv-download'
2 parents 9a3dd83 + f1dbecb commit 8ba9726

File tree

4 files changed

+77
-14
lines changed

4 files changed

+77
-14
lines changed

geophires/geophires-ui.css

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ a:not([href]) {
6060
cursor: help;
6161
}
6262

63-
#params-deeplink {
63+
#result-actions {
6464
font-size: 0.5em;
65+
margin-left: 1em;
66+
}
67+
68+
#result-actions a, #result-actions a:hover {
69+
cursor: pointer;
70+
color: #2196F3 !important;
71+
}
72+
73+
#download-csv.loading::after {
74+
content: '\21BB';
75+
display: inline-block;
76+
animation: rotating 2s linear infinite
6577
}

geophires/geophires-ui.js

Lines changed: 5 additions & 3 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 () {
@@ -235,7 +235,8 @@ function submitForm(oFormElement) {
235235

236236
xhr.open(oFormElement.method, oFormElement.getAttribute("action"))
237237
xhr.send(JSON.stringify({
238-
'geophires_input_parameters': parsed_params
238+
'geophires_input_parameters': parsed_params,
239+
'output_format': 'json'
239240
}))
240241

241242
setLoading(true)
@@ -247,6 +248,7 @@ function submitForm(oFormElement) {
247248
let url = new URL(location.href)
248249
url.hash = btoa(hashParams.toString())
249250
$('#params-deeplink').attr('href', url)
251+
$('#download-csv').attr('data-geophires_input_parameters', JSON.stringify(parsed_params))
250252

251253
return false
252254
}

geophires/geophires.vue.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,41 @@ createApp({
1313
data() {
1414
return {
1515
locationOrigin: `${getLocationOrigin()}?ref=geophires-ui`,
16-
locationHost: getLocationHost()
16+
locationHost: getLocationHost(),
17+
isCsvDownloading: ref(false)
18+
}
19+
},
20+
methods: {
21+
downloadURI: function (uri, name) {
22+
let link = document.createElement('a')
23+
link.download = name
24+
link.href = uri
25+
document.body.appendChild(link)
26+
link.click()
27+
document.body.removeChild(link)
28+
},
29+
downloadCsv: function (event) {
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()
46+
})
47+
.then(data => {
48+
this.downloadURI(`data:text/csv,${encodeURI(data['csv'])}`, 'geophires-result.csv')
49+
});
50+
}
1751
}
1852
}
1953
}).mount('#app')

geophires/index.html

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ <h1 class="mui--text-title">
5353
<div class="mui-divider"></div>
5454
<br/>
5555

56-
<img src="earth-core-logo.png" alt="GEOPHIRES logo" id="header-core-o"/><span class="header-text">GEOPHIRES</span>
56+
<img src="earth-core-logo.png" alt="GEOPHIRES logo" id="header-core-o"/><span
57+
class="header-text">GEOPHIRES</span>
5758
</h1>
5859

5960
<div class="mui--text-body1">
@@ -75,7 +76,8 @@ <h1 class="mui--text-title">
7576
href='https://github.com/NREL/python-geophires-x'>github.com/NREL/python-geophires-x</a>.
7677
</p>
7778
<p>
78-
You may also be interested in the <a href="/geothermal/hip-ra">HIP RA (Heat in Place calculation)</a> tool.
79+
You may also be interested in the <a href="/geothermal/hip-ra">HIP RA (Heat in Place calculation)</a>
80+
tool.
7981
</p>
8082
</div>
8183
</div>
@@ -86,9 +88,9 @@ <h1 class="mui--text-title">
8688

8789
<h3>
8890
<sup><a
89-
href="https://softwareengineerprogrammer.github.io/GEOPHIRES-X/parameters.html"
90-
target="_blank"
91-
title="Open Parameters Reference in a separate tab">&#8505;</a>
91+
href="https://softwareengineerprogrammer.github.io/GEOPHIRES-X/parameters.html"
92+
target="_blank"
93+
title="Open Parameters Reference in a separate tab">&#8505;</a>
9294
</sup>
9395

9496
Parameters
@@ -101,7 +103,8 @@ <h3>
101103
<li class="mui--is-active"><a data-mui-toggle="tab" data-mui-controls="pane-default-2">Guided</a>
102104
</li>
103105
<li><a data-mui-toggle="tab" data-mui-controls="pane-default-3">Text</a></li>
104-
<li><a id="json-input-tab" class="hidden" data-mui-toggle="tab" data-mui-controls="pane-default-4">JSON</a></li>
106+
<li><a id="json-input-tab" class="hidden" data-mui-toggle="tab" data-mui-controls="pane-default-4">JSON</a>
107+
</li>
105108
</ul>
106109
<div class="mui-tabs__pane" id="pane-default-1">
107110
<br/>
@@ -147,10 +150,22 @@ <h3>
147150
<h3>
148151
Result
149152

153+
<span id="result-actions" class="hidden">
150154
<a id="params-deeplink"
151-
class="hidden"
152-
title="Right-click to copy a deeplink to the parameters for this result"
153-
>&#128279;</a>
155+
title="Right-click to copy a deeplink to the parameters for this result">
156+
<!--&#128279;-->
157+
link
158+
</a>
159+
&nbsp;&centerdot;&nbsp;
160+
<a id="download-csv"
161+
title="Download result as CSV"
162+
@click="downloadCsv"
163+
:class="{ loading: isCsvDownloading }">
164+
<!--&DownArrowBar;-->
165+
csv
166+
</a>
167+
</span>
168+
154169
</h3>
155170
<span id="loading" class="hidden loader">Running...</span>
156171
<div id="results"></div>

0 commit comments

Comments
 (0)