Skip to content

Commit 63cd35a

Browse files
authored
Merge pull request #32 from common-workflow-language/ajax-ro-download
Add AJAX loading for research object bundle download
2 parents f3ab2d2 + 990289a commit 63cd35a

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

src/main/resources/static/css/main.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ body {
2121
padding-top: 61px;
2222
}
2323

24+
.hide {
25+
display: none;
26+
}
27+
2428
:target {
2529
padding-top: 61px;
2630
margin-top: -61px;

src/main/resources/static/js/workflow.js renamed to src/main/resources/static/js/main.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,36 @@ require(['jquery', 'bootstrap.modal', 'renderer'],
110110
// Stop default button action
111111
event.preventDefault();
112112
});
113-
});
113+
});
114+
115+
/**
116+
* Code for including the link to the Research Object Bundle download
117+
* without refresh once generated
118+
*/
119+
require(['jquery'],
120+
function ($) {
121+
// AJAX function to add download link to page if generated
122+
function getDownloadLink() {
123+
$.ajax({
124+
type: 'HEAD',
125+
url: $('#download').attr('href'),
126+
dataType: "json",
127+
success: function (data) {
128+
$("#generating").addClass("hide");
129+
$("#generated").removeClass("hide");
130+
},
131+
error: function () {
132+
// Retry in 5 seconds if still not generated
133+
setTimeout(function () {
134+
getDownloadLink();
135+
}, 5000)
136+
}
137+
});
138+
}
139+
140+
// If ajaxRequired exists on the page the RO bundle link is not generated
141+
// at time of page load
142+
if ($("#ajaxRequired").length) {
143+
getDownloadLink();
144+
}
145+
});

src/main/resources/templates/workflow.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,10 @@ <h2>Workflow: <span th:text="${workflow.label}">Workflow Name</span></h2>
105105
<img id="githubLogo" src="../static/img/GitHub-Mark-32px.png" th:src="@{/img/GitHub-Mark-32px.png}" width="24" height="24" />
106106
</a>
107107
<i>Fetched <span th:text="${{workflow.retrievedOn}}">01/12/16 at 21:00</span></i>
108-
<span th:if="${workflow.roBundle == null}"> - Generating download link&hellip; [<a th:href="@{'/workflows/' + ${workflow.id}}" href="#">Refresh</a>]</span>
109-
<span th:if="${workflow.roBundle != null}">
110-
- <a th:href="@{'/workflows/' + ${workflow.id} + '/download'}" href="#" download="bundle.zip">Download as Research Object Bundle</a>
108+
<span th:if="${workflow.roBundle == null}" id="ajaxRequired"></span>
109+
<span th:class="${workflow.roBundle != null} ? hide : ''" id="generating"> - Generating download link <img alt="loading" src="/img/loading.svg" width="20" height="20" /></span>
110+
<span th:class="${workflow.roBundle == null} ? hide : ''" id="generated">
111+
- <a th:href="@{'/workflows/' + ${workflow.id} + '/download'}" id="download" href="#" download="bundle.zip">Download as Research Object Bundle</a>
111112
<a href="http://www.researchobject.org/" rel="noopener" target="_blank">[?]</a>
112113
</span>
113114
</p>
@@ -173,6 +174,6 @@ <h2>Outputs</h2>
173174

174175
<div th:replace="fragments/footer :: copy"></div>
175176

176-
<script src="/bower_components/requirejs/require.js" data-main="/js/workflow.js"></script>
177+
<script src="/bower_components/requirejs/require.js" data-main="/js/main.js"></script>
177178
</body>
178179
</html>

0 commit comments

Comments
 (0)