Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UX: XHR to prevent page from flickering while polling for results #85

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions excalibur/www/static/js/job.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
const pollUntilServerIsReady = function () {
window.setInterval(() => {
const httpRequest = new XMLHttpRequest();
httpRequest.onloadend = () => {
if (httpRequest.status < 300) {
if(httpRequest.responseText.indexOf('__please-wait-symbol__') == -1) {
window.location.reload(true);
}
}
};

httpRequest.open("GET", window.location);
httpRequest.send();
}, 500);
};

$(document).ready(function () {

if(document.getElementById('__please-wait-symbol__') != null) {
pollUntilServerIsReady();
}

var loc = window.location.pathname.split('/');

$('#download').click(function () {
Expand Down
20 changes: 20 additions & 0 deletions excalibur/www/static/js/workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ const compare = function (a, b) {
return a - b;
}

const pollUntilServerIsReady = function () {
window.setInterval(() => {
const httpRequest = new XMLHttpRequest();
httpRequest.onloadend = () => {
if (httpRequest.status < 300) {
if(httpRequest.responseText.indexOf('__please-wait-symbol__') == -1) {
window.location.reload(true);
}
}
};

httpRequest.open("GET", window.location);
httpRequest.send();
}, 500);
};

const getTableAreasForRender = function (page, detectedAreas) {
const imageWidth = $('#image-{0}'.format(page)).width();
const imageHeight = $('#image-{0}'.format(page)).height();
Expand Down Expand Up @@ -332,6 +348,10 @@ const debugQtyAreas = function (event, id, areas) {
};

$(document).ready(function () {
if(document.getElementById('__please-wait-symbol__') != null) {
pollUntilServerIsReady();
}

$('.image-area').selectAreas({
onChanged: debugQtyAreas
});
Expand Down
2 changes: 1 addition & 1 deletion excalibur/www/templates/job.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ <h4>Extracted Data</h4>
{% endfor %}
</div>
{% else %}
<meta http-equiv="refresh" content="0.5" >
<div class="container">
<div class="jumbotron">
<h1 class="display-4">Processing</h1>
<p class="lead">Please wait while the tables are extracted.</p>
<input type='hidden' id='__please-wait-symbol__'></input>
</div>
</div>
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion excalibur/www/templates/workspace.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ <h6><a href="https://camelot-py.readthedocs.io/en/master/user/advanced.html" tar
</div>
</div>
{% else %}
<meta http-equiv="refresh" content="0.5" >
<div class="container">
<div class="jumbotron">
<h1 class="display-4">Processing</h1>
<p class="lead">Please wait while the pages are converted to images.</p>
<input type='hidden' id='__please-wait-symbol__'></input>
</div>
</div>
{% endif %}
Expand Down