Make contest ranking dynamic

This commit is contained in:
cuom1999 2021-06-16 21:57:27 -05:00
parent 47e82adbad
commit b224b015a6
2 changed files with 30 additions and 4 deletions

View file

@ -227,6 +227,7 @@
}); });
</script> </script>
{% endif %} {% endif %}
<script type="text/javascript" src="{{ static('event.js') }}"></script>
<script type="text/javascript"> <script type="text/javascript">
function isFaster(time1, time2) { function isFaster(time1, time2) {
@ -283,7 +284,35 @@
} }
} }
function update_ranking() {
$.get({
url: 'ajax',
success: function(HTML) {
$('#users-table').html(HTML);
highlightFirstSolve();
},
fail: function() {
console.log('Fail to update ranking');
}
});
}
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 () { $(function () {
load_dynamic_update({{last_msg}});
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({
id: 'search-contest' id: 'search-contest'
@ -341,6 +370,7 @@
highlightFirstSolve(); highlightFirstSolve();
}); });
</script> </script>
{% include "contest/media-js.html" %} {% include "contest/media-js.html" %}

View file

@ -275,13 +275,10 @@
} }
function ticket_message(ticket) { function ticket_message(ticket) {
console.log('Fetching data for: ' + ticket.message);
$.ajax({ $.ajax({
url: '{{ url('ticket_message_ajax', ticket.id) }}', url: '{{ url('ticket_message_ajax', ticket.id) }}',
data: {message: ticket.message}, data: {message: ticket.message},
success: function (data) { success: function (data) {
console.log('Got data for: ' + ticket.message);
console.log(data);
$('#messages').append($(data.message)); $('#messages').append($(data.message));
}, },
error: function (data) { error: function (data) {
@ -299,7 +296,6 @@
return new EventReceiver( return new EventReceiver(
"{{ EVENT_DAEMON_LOCATION }}", "{{ EVENT_DAEMON_POLL_LOCATION }}", "{{ EVENT_DAEMON_LOCATION }}", "{{ EVENT_DAEMON_POLL_LOCATION }}",
['ticket-{{ ticket.id }}'], last_msg, function (message) { ['ticket-{{ ticket.id }}'], last_msg, function (message) {
console.log(message);
switch (message.type) { switch (message.type) {
case 'ticket-status': case 'ticket-status':
ticket_status(message); ticket_status(message);