Make context ranking ajax called every 1s

This commit is contained in:
cuom1999 2021-07-01 20:18:03 -05:00
parent 231687e081
commit 1a8702349f

View file

@ -284,12 +284,30 @@
} }
} }
function renew_filter() {
var checkboxes = [
'#show-organizations-checkbox',
'#show-fullnames-checkbox',
'#show-friends-checkbox',
'#show-total-score-checkbox',
];
for (var i of checkboxes) {
var $box = $(i);
if ($box.is(':checked')) {
$box.click();
$box.click();
}
}
}
function update_ranking() { function update_ranking() {
$.get({ $.get({
url: '/contest/{{contest.key}}/ranking/ajax', url: '/contest/{{contest.key}}/ranking/ajax',
success: function(HTML) { success: function(HTML) {
$('#users-table').html(HTML); $('#users-table').html(HTML);
highlightFirstSolve(); highlightFirstSolve();
renew_filter();
}, },
fail: function() { fail: function() {
console.log('Fail to update ranking'); console.log('Fail to update ranking');
@ -297,21 +315,24 @@
}); });
} }
window.load_dynamic_update = function (last_msg) { // window.load_dynamic_update = function (last_msg) {
return new EventReceiver( // return new EventReceiver(
"{{ EVENT_DAEMON_LOCATION }}", "{{ EVENT_DAEMON_POLL_LOCATION }}", // "{{ EVENT_DAEMON_LOCATION }}", "{{ EVENT_DAEMON_POLL_LOCATION }}",
['contest_{{contest.id}}'], last_msg, function (message) { // ['contest_{{contest.id}}'], last_msg, function (message) {
switch (message.type) { // switch (message.type) {
case 'update': // case 'update':
update_ranking(); // update_ranking();
break; // break;
} // }
} // }
); // );
} // }
$(function () { $(function () {
load_dynamic_update({{last_msg}}); // load_dynamic_update({{last_msg}});
{% if request.in_contest %}
setInterval(update_ranking, 60 * 1000);
{% endif %}
var url = '{{ url('contest_participation', contest.key, '__username__') }}'; var url = '{{ url('contest_participation', contest.key, '__username__') }}';
var placeholder = $('#search-contest').replaceWith($('<select>').attr({ var placeholder = $('#search-contest').replaceWith($('<select>').attr({