Skip to content

Commit 290fc2f

Browse files
Made online output tools available for async-watched exports
1 parent 1209814 commit 290fc2f

File tree

4 files changed

+355
-283
lines changed

4 files changed

+355
-283
lines changed

src/main/webapp/ProgressWatch.jsp

Lines changed: 146 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,147 @@
1-
<%--
2-
* GIGWA - Genotype Investigator for Genome Wide Analyses
3-
* Copyright (C) 2016 - 2019, <CIRAD> <IRD>
4-
*
5-
* This program is free software: you can redistribute it and/or modify it under
6-
* the terms of the GNU Affero General Public License, version 3 as published by
7-
* the Free Software Foundation.
8-
*
9-
* This program is distributed in the hope that it will be useful, but WITHOUT
10-
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11-
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
12-
* details.
13-
*
14-
* See <http://www.gnu.org/licenses/agpl.html> for details about GNU General
15-
* Public License V3.
16-
--%>
17-
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="UTF-8" import="fr.cirad.web.controller.gigwa.GigwaRestController"%>
18-
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
19-
20-
<html>
21-
22-
<head>
23-
<script type="text/javascript" src="js/jquery-1.12.4.min.js"></script>
24-
<script type="text/javascript" src="js/bootstrap.min.js"></script>
25-
<script type="text/javascript" src="<c:url value="/js/common.js" />"></script>
26-
<link rel="shortcut icon" href="images/favicon.png" type="image/x-icon" />
27-
<link type="text/css" rel="stylesheet" href="css/bootstrap.min.css">
28-
<link type="text/css" rel="stylesheet" href="css/main.css">
29-
<script type="text/javascript">
30-
var progressUrl = "<c:url value='<%=GigwaRestController.REST_PATH + GigwaRestController.BASE_URL + GigwaRestController.PROGRESS_PATH%>' />";
31-
var abortUrl = "<c:url value='<%=GigwaRestController.REST_PATH + GigwaRestController.BASE_URL + GigwaRestController.ABORT_PROCESS_PATH%>' />";
32-
33-
var destinationLink = "${param.successURL}";
34-
var fileName = destinationLink.substring(destinationLink.lastIndexOf("/") + 1);
35-
if (fileName.startsWith("?"))
36-
fileName = location.origin + '<c:url value='/' />' + fileName;
37-
38-
var processAborted = false;
39-
40-
function watchProgress()
41-
{
42-
$.ajax({
43-
url: progressUrl<c:if test="${param.process != null}">+'?progressToken=${param.process}'</c:if>,
44-
type: "GET",
45-
async: false,
46-
<c:if test="${param.token != null}">headers: { "Authorization": "Bearer ${param.token}" },</c:if>
47-
success: function (jsonResult) {
48-
if (jsonResult == null)
49-
$('body').append('<center><p style="margin-top:60px;" class="bold">No such process is running at the moment.</p><p>Refresh to try again or use the link below to access resulting data in case the process has already finished:<br/><br/><a style="cursor:pointer;" href="' + destinationLink + '">' + (fileName == '?' ? destinationLink : fileName) + '</a></p></center>');
50-
else
51-
{
52-
$('#progress').modal({backdrop: 'static', keyboard: false, show: true});
53-
$('.modal-backdrop.in').css('opacity', '0.1');
54-
displayProcessProgress(5, <c:choose><c:when test="${param.token != null}">'${param.token}'</c:when><c:otherwise>null</c:otherwise></c:choose>, '${param.process}');
55-
56-
$('#progress').on('hidden.bs.modal', function () {
57-
if (processAborted)
58-
$('body').append('<center><p style="margin-top:60px;" class="bold">Process aborted</p></center>');
59-
else if (!$('#progress').data('error'))
60-
$('body').append('<center><p style="margin-top:60px;" class="bold">Process has completed. Data is now <a style="cursor:pointer;" href="' + destinationLink + '">available here</a></center>');
61-
});
62-
}
63-
},
64-
error: function (xhr, ajaxOptions, thrownError) {
65-
handleError(xhr, thrownError);
66-
}
67-
});
68-
$("div.modal-backdrop").remove();
69-
}
70-
</script>
71-
<title>Gigwa process watcher</title>
72-
</head>
73-
74-
<body style='background-color:#f0f0f0;' onload="$('button#abortButton').css('display', ${param.abortable eq 'true'} ? 'inline' : 'none'); watchProgress();">
75-
<div style='background-color:white; width:100%; padding:5px;'><img src="<c:url value='/images/logo.png' />" height="25"></div>
76-
<div id='progress' style='margin-top:50px; margin-left:20%; width:60%; display:block; text-align:center; display:none;'>
77-
<p>This process is running as a background task.</p>
78-
<p>You may leave the main Gigwa page and either keep this one open or copy its URL to check again later.</p>
79-
<h2 id="progressText" class="loading-message" style='margin-top:50px'>Please wait...</h2>
80-
<button class="btn btn-danger btn-sm" id="abortButton" style="display:none;" type="button" name="abort" onclick="if (confirm('Are you sure?')) abort('${param.process}');">Abort</button>
81-
</div>
82-
</body>
83-
1+
<%--
2+
* GIGWA - Genotype Investigator for Genome Wide Analyses
3+
* Copyright (C) 2016 - 2019, <CIRAD> <IRD>
4+
*
5+
* This program is free software: you can redistribute it and/or modify it under
6+
* the terms of the GNU Affero General Public License, version 3 as published by
7+
* the Free Software Foundation.
8+
*
9+
* This program is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11+
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
12+
* details.
13+
*
14+
* See <http://www.gnu.org/licenses/agpl.html> for details about GNU General
15+
* Public License V3.
16+
--%>
17+
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="UTF-8" import="fr.cirad.web.controller.gigwa.GigwaRestController"%>
18+
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
19+
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
20+
<jsp:useBean id="appConfig" class="fr.cirad.tools.AppConfig" />
21+
22+
<html>
23+
24+
<head>
25+
<script type="text/javascript" src="js/jquery-1.12.4.min.js"></script>
26+
<script type="text/javascript" src="js/bootstrap.min.js"></script>
27+
<script type="text/javascript" src="<c:url value="/js/common.js" />"></script>
28+
<link rel="shortcut icon" href="images/favicon.png" type="image/x-icon" />
29+
<link type="text/css" rel="stylesheet" href="css/bootstrap.min.css">
30+
<link type="text/css" rel="stylesheet" href="css/main.css">
31+
<script type="text/javascript">
32+
var progressUrl = "<c:url value='<%=GigwaRestController.REST_PATH + GigwaRestController.BASE_URL + GigwaRestController.PROGRESS_PATH%>' />";
33+
var abortUrl = "<c:url value='<%=GigwaRestController.REST_PATH + GigwaRestController.BASE_URL + GigwaRestController.ABORT_PROCESS_PATH%>' />";
34+
35+
var downloadURL = "${param.successURL}";
36+
var fileName = downloadURL.substring(downloadURL.lastIndexOf("/") + 1);
37+
if (fileName.startsWith("?"))
38+
fileName = location.origin + '<c:url value='/' />' + fileName;
39+
40+
var processAborted = false;
41+
42+
<c:if test="${param.exportFormat != null}">
43+
var galaxyPushURL = '<c:url value="<%=GigwaRestController.REST_PATH + GigwaRestController.BASE_URL + GigwaRestController.GALAXY_HISTORY_PUSH%>" />';
44+
var onlineOutputTools = null;
45+
46+
var igvDataLoadPort, igvGenomeListUrl;
47+
<c:set var="igvDataLoadPort" value="<%= appConfig.get(\"igvDataLoadPort\") %>"></c:set>
48+
<c:set var="igvGenomeListUrl" value="<%= appConfig.get(\"igvGenomeListUrl\") %>"></c:set>
49+
<c:if test='${!fn:startsWith(igvDataLoadPort, "??") && !empty igvDataLoadPort && !fn:startsWith(igvGenomeListUrl, "??") && !empty igvGenomeListUrl}'>
50+
igvDataLoadPort = ${igvDataLoadPort};
51+
igvGenomeListUrl = '<c:url value="<%=GigwaRestController.REST_PATH + GigwaRestController.BASE_URL + GigwaRestController.IGV_GENOME_LIST_URL %>" />';
52+
</c:if>
53+
54+
$.ajax({
55+
url: '<c:url value="<%=GigwaRestController.REST_PATH + GigwaRestController.BASE_URL + GigwaRestController.ONLINE_OUTPUT_TOOLS_URL%>" />',
56+
async: true,
57+
type: "GET",
58+
contentType: "application/json;charset=utf-8",
59+
success: function(labelsAndURLs) {
60+
onlineOutputTools = labelsAndURLs;
61+
onlineOutputTools["Custom tool"] = {"url" : "", "formats" : ""};
62+
},
63+
error: function(xhr, thrownError) {
64+
handleError(xhr, thrownError);
65+
}
66+
});
67+
</c:if>
68+
69+
function watchProgress()
70+
{
71+
$.ajax({
72+
url: progressUrl<c:if test="${param.process != null}">+'?progressToken=${param.process}'</c:if>,
73+
type: "GET",
74+
async: false,
75+
<c:if test="${param.token != null}">headers: { "Authorization": "Bearer ${param.token}" },</c:if>
76+
success: function (jsonResult) {
77+
if (jsonResult == null) {
78+
$('body').append('<center id="defaultMsg"><p style="margin-top:60px;" class="bold">No such process is running at the moment.</p><p>Refresh to try again or use the link below to access resulting data in case the process has already finished:<br/><br/><a style="cursor:pointer;" href="' + downloadURL + '">' + (fileName == '?' ? downloadURL : fileName) + '</a></p></center>');
79+
<c:if test="${param.exportFormat != null}">
80+
$.ajax({
81+
type: 'HEAD',
82+
url: downloadURL,
83+
success: function(data, textStatus, jqXHR) {
84+
if (jqXHR.status >= 200 && jqXHR.status < 300) {
85+
successFunction();
86+
$("#defaultMsg").remove();
87+
}
88+
}
89+
});
90+
</c:if>
91+
}
92+
else
93+
{
94+
$('#progress').modal({backdrop: 'static', keyboard: false, show: true});
95+
$('.modal-backdrop.in').css('opacity', '0.1');
96+
displayProcessProgress(5, <c:choose><c:when test="${param.token != null}">'${param.token}'</c:when><c:otherwise>null</c:otherwise></c:choose>, '${param.process}'<c:if test="${param.exportFormat != null}">, successFunction</c:if>);
97+
98+
$('#progress').on('hidden.bs.modal', function () {
99+
if (processAborted)
100+
$('body').append('<center><p style="margin-top:60px;" class="bold">Process aborted</p></center>');
101+
<c:if test="${param.exportFormat == null}">
102+
else if (!$('#progress').data('error'))
103+
$('body').append('<center><p style="margin-top:60px;" class="bold">Process has completed. Data is now <a style="cursor:pointer;" href="' + downloadURL + '">available here</a></center>');
104+
</c:if>
105+
$('#progress').off('hidden.bs.modal');
106+
});
107+
}
108+
},
109+
error: function (xhr, ajaxOptions, thrownError) {
110+
handleError(xhr, thrownError);
111+
}
112+
});
113+
$("div.modal-backdrop").remove();
114+
}
115+
116+
<c:if test="${param.exportFormat != null}">
117+
function successFunction() {
118+
let fileExtensions = "${param.exportFormatExtensions}".split(";");
119+
<c:if test="${param.exportedTsvMetadata eq true}">
120+
fileExtensions.push("tsv");
121+
</c:if>
122+
showServerExportBox(fileExtensions);
123+
}
124+
</c:if>
125+
</script>
126+
<title>Gigwa process watcher</title>
127+
</head>
128+
129+
<body style='background-color:#f0f0f0;' onload="$('button#abort').css('display', ${param.abortable eq 'true'} ? 'inline' : 'none'); watchProgress();">
130+
<c:if test="${param.exportFormat != null}">
131+
<input type="hidden" id="exportFormat" value="${param.exportFormat}" />
132+
<input type="hidden" id="module" value="${param.module}" />
133+
<input type="hidden" id="galaxyInstanceURL" value="${param.galaxyInstanceUrl}" />
134+
<input type="hidden" id="exportedIndividualCount" value="${param.exportedIndividualCount}" />
135+
<input type="hidden" id="count" value="${param.exportedVariantCount}" />
136+
</c:if>
137+
<div style='background-color:white; width:100%; padding:5px;'><img src="<c:url value='/images/logo.png' />" height="25"></div>
138+
<div id='progress' style='margin-top:50px; margin-left:20%; width:60%; display:block; text-align:center; display:none;'>
139+
<p>This process is running as a background task.</p>
140+
<p>You may leave the main Gigwa page and either keep this one open or copy its URL to check again later.</p>
141+
<h2 id="progressText" class="loading-message" style='margin-top:100px'>Please wait...</h2>
142+
<button class="btn btn-danger btn-sm" id="abort" style="display:none;" type="button" name="abort" onclick="if (confirm('Are you sure?')) abort('${param.process}');">Abort</button>
143+
</div>
144+
<div id="serverExportBox" class="panel" style="position:absolute; margin:0; top:50px; left:calc(50% - 250px); width:400px;"></div>
145+
</body>
146+
84147
</html>

src/main/webapp/index.jsp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ https://doi.org/10.1093/gigascience/giz051</pre>
333333
<h3 class="loading-message"><span id="progressText" class="loading-message">Please wait...</span><span id="ddlWarning" style="display:none;"><br/><br/>Output file is being generated and will not be valid before this message disappears</span></h3>
334334
<br/>
335335
<button style="display:inline; margin-right:10px;" class="btn btn-danger btn-sm" type="button" name="abort" id='abort' onclick="abort($(this).attr('rel')); $('a#exportBoxToggleButton').removeClass('active');">Abort</button>
336-
<button style="display:inline; margin-left:10px;" id="asyncProgressButton" class="btn btn-info btn-sm" type="button" onclick="window.open('ProgressWatch.jsp?process=export_' + token + '&abortable=true&successURL=' + escape(downloadURL));" title="This will open a separate page allowing to watch export progress at any time. Leaving the current page will not abort the export process.">Open async progress watch page</button>
336+
<button style="display:inline; margin-left:10px;" id="asyncProgressButton" class="btn btn-info btn-sm" type="button" onclick="window.open('ProgressWatch.jsp?process=export_' + token + '&abortable=true&successURL=' + escape(downloadURL) + '&module=' + getModuleName() + '&exportFormat=' + $('#exportFormat').val() + '&galaxyInstanceUrl=' + $('#galaxyInstanceURL').val() + '&exportedVariantCount=' + count + '&exportedIndividualCount=' + exportedIndividualCount + '&exportFormatExtensions=' + $('#exportFormat option:selected').data('ext') + '&exportedTsvMetadata=' + ($('#exportPanel input#exportedIndividualMetadataCheckBox').is(':checked') && 'FLAPJACK' != $('#exportFormat').val() && 'DARWIN' != $('#exportFormat').val()));" title="This will open a separate page allowing to watch export progress at any time. Leaving the current page will not abort the export process.">Open async progress watch page</button>
337337
</div>
338338
</div>
339339
</div>
@@ -784,7 +784,7 @@ https://doi.org/10.1093/gigascience/giz051</pre>
784784
});
785785
786786
$.ajax({
787-
url: '<c:url value="<%=GigwaRestController.REST_PATH + GigwaRestController.BASE_URL + GigwaRestController.ONLINE_OUTPUT_TOOLS_URL%>" />?module=' + referenceset,
787+
url: '<c:url value="<%=GigwaRestController.REST_PATH + GigwaRestController.BASE_URL + GigwaRestController.ONLINE_OUTPUT_TOOLS_URL%>" />',
788788
async: false,
789789
type: "GET",
790790
contentType: "application/json;charset=utf-8",
@@ -1961,7 +1961,12 @@ https://doi.org/10.1093/gigascience/giz051</pre>
19611961
$("div#exportPanel").hide();
19621962
$("a#exportBoxToggleButton").removeClass("active");
19631963
}
1964-
displayProcessProgress(2, "export_" + token, null, showServerExportBox);
1964+
displayProcessProgress(2, "export_" + token, null, function() {
1965+
let fileExtensions = $("#exportFormat option:selected").data('ext').split(";");
1966+
if ($('#exportPanel input#exportedIndividualMetadataCheckBox').is(':checked') && "FLAPJACK" != $('#exportFormat').val() && "DARWIN" != $('#exportFormat').val() /* these two already have their own metadata file format*/)
1967+
fileExtensions.push("tsv");
1968+
showServerExportBox(fileExtensions);
1969+
});
19651970
}
19661971
19671972
function postDataToIFrame(frameName, url, params)

0 commit comments

Comments
 (0)