Skip to content

Commit

Permalink
Made online output tools available for async-watched exports
Browse files Browse the repository at this point in the history
  • Loading branch information
GuilhemSempere committed Aug 27, 2024
1 parent 1209814 commit 290fc2f
Show file tree
Hide file tree
Showing 4 changed files with 355 additions and 283 deletions.
229 changes: 146 additions & 83 deletions src/main/webapp/ProgressWatch.jsp
Original file line number Diff line number Diff line change
@@ -1,84 +1,147 @@
<%--
* GIGWA - Genotype Investigator for Genome Wide Analyses
* Copyright (C) 2016 - 2019, <CIRAD> <IRD>
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License, version 3 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* See <http://www.gnu.org/licenses/agpl.html> for details about GNU General
* Public License V3.
--%>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="UTF-8" import="fr.cirad.web.controller.gigwa.GigwaRestController"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<html>

<head>
<script type="text/javascript" src="js/jquery-1.12.4.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="<c:url value="/js/common.js" />"></script>
<link rel="shortcut icon" href="images/favicon.png" type="image/x-icon" />
<link type="text/css" rel="stylesheet" href="css/bootstrap.min.css">
<link type="text/css" rel="stylesheet" href="css/main.css">
<script type="text/javascript">
var progressUrl = "<c:url value='<%=GigwaRestController.REST_PATH + GigwaRestController.BASE_URL + GigwaRestController.PROGRESS_PATH%>' />";
var abortUrl = "<c:url value='<%=GigwaRestController.REST_PATH + GigwaRestController.BASE_URL + GigwaRestController.ABORT_PROCESS_PATH%>' />";
var destinationLink = "${param.successURL}";
var fileName = destinationLink.substring(destinationLink.lastIndexOf("/") + 1);
if (fileName.startsWith("?"))
fileName = location.origin + '<c:url value='/' />' + fileName;
var processAborted = false;
function watchProgress()
{
$.ajax({
url: progressUrl<c:if test="${param.process != null}">+'?progressToken=${param.process}'</c:if>,
type: "GET",
async: false,
<c:if test="${param.token != null}">headers: { "Authorization": "Bearer ${param.token}" },</c:if>
success: function (jsonResult) {
if (jsonResult == null)
$('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>');
else
{
$('#progress').modal({backdrop: 'static', keyboard: false, show: true});
$('.modal-backdrop.in').css('opacity', '0.1');
displayProcessProgress(5, <c:choose><c:when test="${param.token != null}">'${param.token}'</c:when><c:otherwise>null</c:otherwise></c:choose>, '${param.process}');
$('#progress').on('hidden.bs.modal', function () {
if (processAborted)
$('body').append('<center><p style="margin-top:60px;" class="bold">Process aborted</p></center>');
else if (!$('#progress').data('error'))
$('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>');
});
}
},
error: function (xhr, ajaxOptions, thrownError) {
handleError(xhr, thrownError);
}
});
$("div.modal-backdrop").remove();
}
</script>
<title>Gigwa process watcher</title>
</head>

<body style='background-color:#f0f0f0;' onload="$('button#abortButton').css('display', ${param.abortable eq 'true'} ? 'inline' : 'none'); watchProgress();">
<div style='background-color:white; width:100%; padding:5px;'><img src="<c:url value='/images/logo.png' />" height="25"></div>
<div id='progress' style='margin-top:50px; margin-left:20%; width:60%; display:block; text-align:center; display:none;'>
<p>This process is running as a background task.</p>
<p>You may leave the main Gigwa page and either keep this one open or copy its URL to check again later.</p>
<h2 id="progressText" class="loading-message" style='margin-top:50px'>Please wait...</h2>
<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>
</div>
</body>

<%--
* GIGWA - Genotype Investigator for Genome Wide Analyses
* Copyright (C) 2016 - 2019, <CIRAD> <IRD>
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License, version 3 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* See <http://www.gnu.org/licenses/agpl.html> for details about GNU General
* Public License V3.
--%>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="UTF-8" import="fr.cirad.web.controller.gigwa.GigwaRestController"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<jsp:useBean id="appConfig" class="fr.cirad.tools.AppConfig" />

<html>

<head>
<script type="text/javascript" src="js/jquery-1.12.4.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="<c:url value="/js/common.js" />"></script>
<link rel="shortcut icon" href="images/favicon.png" type="image/x-icon" />
<link type="text/css" rel="stylesheet" href="css/bootstrap.min.css">
<link type="text/css" rel="stylesheet" href="css/main.css">
<script type="text/javascript">
var progressUrl = "<c:url value='<%=GigwaRestController.REST_PATH + GigwaRestController.BASE_URL + GigwaRestController.PROGRESS_PATH%>' />";
var abortUrl = "<c:url value='<%=GigwaRestController.REST_PATH + GigwaRestController.BASE_URL + GigwaRestController.ABORT_PROCESS_PATH%>' />";
var downloadURL = "${param.successURL}";
var fileName = downloadURL.substring(downloadURL.lastIndexOf("/") + 1);
if (fileName.startsWith("?"))
fileName = location.origin + '<c:url value='/' />' + fileName;
var processAborted = false;
<c:if test="${param.exportFormat != null}">
var galaxyPushURL = '<c:url value="<%=GigwaRestController.REST_PATH + GigwaRestController.BASE_URL + GigwaRestController.GALAXY_HISTORY_PUSH%>" />';
var onlineOutputTools = null;
var igvDataLoadPort, igvGenomeListUrl;
<c:set var="igvDataLoadPort" value="<%= appConfig.get(\"igvDataLoadPort\") %>"></c:set>
<c:set var="igvGenomeListUrl" value="<%= appConfig.get(\"igvGenomeListUrl\") %>"></c:set>
<c:if test='${!fn:startsWith(igvDataLoadPort, "??") && !empty igvDataLoadPort && !fn:startsWith(igvGenomeListUrl, "??") && !empty igvGenomeListUrl}'>
igvDataLoadPort = ${igvDataLoadPort};
igvGenomeListUrl = '<c:url value="<%=GigwaRestController.REST_PATH + GigwaRestController.BASE_URL + GigwaRestController.IGV_GENOME_LIST_URL %>" />';
</c:if>
$.ajax({
url: '<c:url value="<%=GigwaRestController.REST_PATH + GigwaRestController.BASE_URL + GigwaRestController.ONLINE_OUTPUT_TOOLS_URL%>" />',
async: true,
type: "GET",
contentType: "application/json;charset=utf-8",
success: function(labelsAndURLs) {
onlineOutputTools = labelsAndURLs;
onlineOutputTools["Custom tool"] = {"url" : "", "formats" : ""};
},
error: function(xhr, thrownError) {
handleError(xhr, thrownError);
}
});
</c:if>
function watchProgress()
{
$.ajax({
url: progressUrl<c:if test="${param.process != null}">+'?progressToken=${param.process}'</c:if>,
type: "GET",
async: false,
<c:if test="${param.token != null}">headers: { "Authorization": "Bearer ${param.token}" },</c:if>
success: function (jsonResult) {
if (jsonResult == null) {
$('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>');
<c:if test="${param.exportFormat != null}">
$.ajax({
type: 'HEAD',
url: downloadURL,
success: function(data, textStatus, jqXHR) {
if (jqXHR.status >= 200 && jqXHR.status < 300) {
successFunction();
$("#defaultMsg").remove();
}
}
});
</c:if>
}
else
{
$('#progress').modal({backdrop: 'static', keyboard: false, show: true});
$('.modal-backdrop.in').css('opacity', '0.1');
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>);
$('#progress').on('hidden.bs.modal', function () {
if (processAborted)
$('body').append('<center><p style="margin-top:60px;" class="bold">Process aborted</p></center>');
<c:if test="${param.exportFormat == null}">
else if (!$('#progress').data('error'))
$('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>');
</c:if>
$('#progress').off('hidden.bs.modal');
});
}
},
error: function (xhr, ajaxOptions, thrownError) {
handleError(xhr, thrownError);
}
});
$("div.modal-backdrop").remove();
}
<c:if test="${param.exportFormat != null}">
function successFunction() {
let fileExtensions = "${param.exportFormatExtensions}".split(";");
<c:if test="${param.exportedTsvMetadata eq true}">
fileExtensions.push("tsv");
</c:if>
showServerExportBox(fileExtensions);
}
</c:if>
</script>
<title>Gigwa process watcher</title>
</head>
<body style='background-color:#f0f0f0;' onload="$('button#abort').css('display', ${param.abortable eq 'true'} ? 'inline' : 'none'); watchProgress();">
<c:if test="${param.exportFormat != null}">
<input type="hidden" id="exportFormat" value="${param.exportFormat}" />
<input type="hidden" id="module" value="${param.module}" />
<input type="hidden" id="galaxyInstanceURL" value="${param.galaxyInstanceUrl}" />
<input type="hidden" id="exportedIndividualCount" value="${param.exportedIndividualCount}" />
<input type="hidden" id="count" value="${param.exportedVariantCount}" />
</c:if>
<div style='background-color:white; width:100%; padding:5px;'><img src="<c:url value='/images/logo.png' />" height="25"></div>
<div id='progress' style='margin-top:50px; margin-left:20%; width:60%; display:block; text-align:center; display:none;'>
<p>This process is running as a background task.</p>
<p>You may leave the main Gigwa page and either keep this one open or copy its URL to check again later.</p>
<h2 id="progressText" class="loading-message" style='margin-top:100px'>Please wait...</h2>
<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>
</div>
<div id="serverExportBox" class="panel" style="position:absolute; margin:0; top:50px; left:calc(50% - 250px); width:400px;"></div>
</body>
</html>
11 changes: 8 additions & 3 deletions src/main/webapp/index.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ https://doi.org/10.1093/gigascience/giz051</pre>
<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>
<br/>
<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>
<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>
<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>
</div>
</div>
</div>
Expand Down Expand Up @@ -784,7 +784,7 @@ https://doi.org/10.1093/gigascience/giz051</pre>
});
$.ajax({
url: '<c:url value="<%=GigwaRestController.REST_PATH + GigwaRestController.BASE_URL + GigwaRestController.ONLINE_OUTPUT_TOOLS_URL%>" />?module=' + referenceset,
url: '<c:url value="<%=GigwaRestController.REST_PATH + GigwaRestController.BASE_URL + GigwaRestController.ONLINE_OUTPUT_TOOLS_URL%>" />',
async: false,
type: "GET",
contentType: "application/json;charset=utf-8",
Expand Down Expand Up @@ -1961,7 +1961,12 @@ https://doi.org/10.1093/gigascience/giz051</pre>
$("div#exportPanel").hide();
$("a#exportBoxToggleButton").removeClass("active");
}
displayProcessProgress(2, "export_" + token, null, showServerExportBox);
displayProcessProgress(2, "export_" + token, null, function() {
let fileExtensions = $("#exportFormat option:selected").data('ext').split(";");
if ($('#exportPanel input#exportedIndividualMetadataCheckBox').is(':checked') && "FLAPJACK" != $('#exportFormat').val() && "DARWIN" != $('#exportFormat').val() /* these two already have their own metadata file format*/)
fileExtensions.push("tsv");
showServerExportBox(fileExtensions);
});
}
function postDataToIFrame(frameName, url, params)
Expand Down
Loading

0 comments on commit 290fc2f

Please sign in to comment.