From 1a8702349f81636b2c4b5afbbaef570b95757f0b Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Thu, 1 Jul 2021 20:18:03 -0500 Subject: [PATCH] Make context ranking ajax called every 1s --- templates/contest/ranking.html | 47 ++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/templates/contest/ranking.html b/templates/contest/ranking.html index 071bac9..3715f28 100644 --- a/templates/contest/ranking.html +++ b/templates/contest/ranking.html @@ -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() { $.get({ url: '/contest/{{contest.key}}/ranking/ajax', success: function(HTML) { $('#users-table').html(HTML); highlightFirstSolve(); + renew_filter(); }, fail: function() { console.log('Fail to update ranking'); @@ -297,21 +315,24 @@ }); } - window.load_dynamic_update = function (last_msg) { - return new EventReceiver( - "{{ EVENT_DAEMON_LOCATION }}", "{{ EVENT_DAEMON_POLL_LOCATION }}", - ['contest_{{contest.id}}'], last_msg, function (message) { - switch (message.type) { - case 'update': - update_ranking(); - break; - } - } - ); - } + // window.load_dynamic_update = function (last_msg) { + // return new EventReceiver( + // "{{ EVENT_DAEMON_LOCATION }}", "{{ EVENT_DAEMON_POLL_LOCATION }}", + // ['contest_{{contest.id}}'], last_msg, function (message) { + // switch (message.type) { + // case 'update': + // update_ranking(); + // break; + // } + // } + // ); + // } $(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 placeholder = $('#search-contest').replaceWith($('