General rank for friends

This commit is contained in:
cuom1999 2022-01-10 23:02:12 +07:00
parent 5577484b58
commit 3ba270bd07
2 changed files with 24 additions and 2 deletions

View file

@ -661,7 +661,7 @@ def get_contest_ranking_list(request, contest, participation=None, ranking_list=
problems = list(contest.contest_problems.select_related('problem').defer('problem__description').order_by('order'))
users = ranker(ranking_list(contest, problems), key=attrgetter('points', 'cumtime', 'tiebreaker'))
if show_current_virtual:
if participation is None and request.user.is_authenticated:
participation = request.profile.current_contest

View file

@ -319,6 +319,22 @@
}
}
function get_initial_rank() {
var ranks = $('.rank-td').map(function() {return this.innerHTML}).get();
var usernames = $('.user-name .user a').map(function() {return this.text}).get();
window.user_rank = new Map();
for (var i = 0; i < ranks.length; i++) {
window.user_rank[usernames[i]] = ranks[i];
}
}
function add_initial_friend_rank() {
var usernames = $('.user-name .user a').map(function() {return this.text}).get();
$('.rank-td').each(function(i) {
this.innerHTML += ' (' + window.user_rank[usernames[i]] + ')';
});
}
function update_ranking() {
var friend = $('#show-friends-checkbox').is(':checked');
var virtual = $('#show-virtual-checkbox').is(':checked');
@ -328,8 +344,13 @@
success: function(HTML) {
$('#users-table').html(HTML);
highlightFirstSolve();
renew_filter();
$('#loading-gif').hide();
if (!virtual && !friend) {
get_initial_rank();
}
if (friend) {
add_initial_friend_rank();
}
},
fail: function() {
console.log('Fail to update ranking');
@ -394,6 +415,7 @@
highlightFirstSolve();
renew_filter();
get_initial_rank();
{% if participation_tab %}
$('#show-virtual-checkbox').hide();
$('#show-virtual-label').hide();