Refactor 3-col-content
This commit is contained in:
parent
326b3d5dd3
commit
a711fb9768
37 changed files with 453 additions and 384 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
{% set has_hidden_subtasks = request.in_contest_mode and request.participation.contest.format.has_hidden_subtasks %}
|
||||
|
||||
{% block three_col_js %}
|
||||
{% block js_media %}
|
||||
<script type="text/javascript">
|
||||
{% if dynamic_update and last_msg %}
|
||||
{% if request.in_contest_mode %}
|
||||
|
@ -91,170 +91,164 @@
|
|||
|
||||
// Draw the statistics graph.
|
||||
{% if results_json %}
|
||||
var chart = null;
|
||||
function stats_graph(raw_data) {
|
||||
var colors = {{ results_colors_json }};
|
||||
|
||||
var ctx = $('#status-graph').find('canvas')[0].getContext('2d');
|
||||
var font = $('body').css('font-family');
|
||||
if (chart !== null) {
|
||||
chart.destroy();
|
||||
}
|
||||
chart = new Chart(ctx, {
|
||||
type: 'pie',
|
||||
data: {
|
||||
datasets: [{
|
||||
data: raw_data.categories.map(function(entry) {
|
||||
return entry.count;
|
||||
}),
|
||||
backgroundColor: raw_data.categories.map(function(entry) {
|
||||
return colors[entry.code];
|
||||
}),
|
||||
}],
|
||||
labels: raw_data.categories.map(function(entry) {
|
||||
return entry.name;
|
||||
}),
|
||||
},
|
||||
options: {
|
||||
animation: false,
|
||||
scaleFontFamily: font,
|
||||
tooltips: {
|
||||
titleFontFamily: font,
|
||||
bodyFontFamily: font,
|
||||
},
|
||||
legend: {
|
||||
display: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
$('#total-submission-count').text(raw_data.total);
|
||||
}
|
||||
|
||||
$(function () {
|
||||
var chart = null;
|
||||
function stats_graph(raw_data) {
|
||||
var colors = {{ results_colors_json }};
|
||||
|
||||
var ctx = $('#status-graph').find('canvas')[0].getContext('2d');
|
||||
var font = $('body').css('font-family');
|
||||
if (chart !== null) {
|
||||
chart.destroy();
|
||||
}
|
||||
chart = new Chart(ctx, {
|
||||
type: 'pie',
|
||||
data: {
|
||||
datasets: [{
|
||||
data: raw_data.categories.map(function(entry) {
|
||||
return entry.count;
|
||||
}),
|
||||
backgroundColor: raw_data.categories.map(function(entry) {
|
||||
return colors[entry.code];
|
||||
}),
|
||||
}],
|
||||
labels: raw_data.categories.map(function(entry) {
|
||||
return entry.name;
|
||||
}),
|
||||
},
|
||||
options: {
|
||||
animation: false,
|
||||
scaleFontFamily: font,
|
||||
tooltips: {
|
||||
titleFontFamily: font,
|
||||
bodyFontFamily: font,
|
||||
},
|
||||
legend: {
|
||||
display: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
$('#total-submission-count').text(raw_data.total);
|
||||
}
|
||||
stats_graph(window.results_json);
|
||||
});
|
||||
{% endif %}
|
||||
|
||||
function load_dynamic_update(last_msg) {
|
||||
var _collect = function (e) {
|
||||
return e.value;
|
||||
};
|
||||
var language_filter = $.map($('select#language option[selected]'), _collect);
|
||||
var status_filter = $.map($('select#status option[selected]'), _collect);
|
||||
|
||||
var table = $('#submissions-table');
|
||||
var statistics = $("#statistics-table");
|
||||
var doing_ajax = false;
|
||||
var first = parseInt(table.find('>div:first-child').attr('id'));
|
||||
|
||||
var update_submission = function (message, force) {
|
||||
if (language_filter.length && 'language' in message &&
|
||||
language_filter.indexOf(message.language) == -1)
|
||||
return;
|
||||
if (status_filter.length && 'status' in message &&
|
||||
status_filter.indexOf(message.status) == -1)
|
||||
return;
|
||||
var id = message.id;
|
||||
var row = table.find('div#' + id);
|
||||
if (row.length < 1) {
|
||||
if (id < first)
|
||||
return;
|
||||
first = id;
|
||||
row = $('<div>', {id: id, 'class': 'submission-row'}).hide().prependTo(table);
|
||||
if (table.find('>div').length >= {{ paginator.per_page }})
|
||||
table.find('>div:last-child').hide('slow', function () {
|
||||
$(this).remove();
|
||||
});
|
||||
}
|
||||
if (force || !doing_ajax) {
|
||||
if (!force) doing_ajax = true;
|
||||
$.ajax({
|
||||
url: '{{ url('submission_single_query') }}',
|
||||
data: {id: id, show_problem: show_problem}
|
||||
}).done(function (data) {
|
||||
var was_shown = row.is(':visible');
|
||||
row.html(data);
|
||||
register_time(row.find('.time-with-rel'));
|
||||
if (!was_shown) {
|
||||
row.slideDown('slow');
|
||||
}
|
||||
if (!force)
|
||||
setTimeout(function () {
|
||||
doing_ajax = false;
|
||||
}, 1000);
|
||||
}).fail(function () {
|
||||
console.log('Failed to update submission: ' + id);
|
||||
if (!force) doing_ajax = false;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
var stats_outdated = false;
|
||||
var last_stat_update = Date.now();
|
||||
var stats_update_interval = {{ stats_update_interval|default(0) * 1000 }};
|
||||
|
||||
function update_stats() {
|
||||
if (Date.now() - last_stat_update < stats_update_interval)
|
||||
return;
|
||||
$.ajax({
|
||||
url: '?results'
|
||||
}).done(function (data) {
|
||||
last_stat_update = Date.now();
|
||||
stats_graph(data);
|
||||
}).fail(function () {
|
||||
console.log('Failed to update statistics table!' + id);
|
||||
}).always(function () {
|
||||
stats_outdated = false;
|
||||
});
|
||||
}
|
||||
|
||||
$(window).on('dmoj:window-visible', function () {
|
||||
if (stats_outdated)
|
||||
update_stats();
|
||||
});
|
||||
|
||||
var $body = $(document.body);
|
||||
var receiver = new EventReceiver(
|
||||
"{{ EVENT_DAEMON_LOCATION }}", "{{ EVENT_DAEMON_POLL_LOCATION }}",
|
||||
['submissions'], last_msg, function (message) {
|
||||
if (current_contest && message.contest != current_contest)
|
||||
return;
|
||||
if (dynamic_user_id && message.user != dynamic_user_id ||
|
||||
dynamic_problem_id && message.problem != dynamic_problem_id)
|
||||
return;
|
||||
if (message.type == 'update-submission') {
|
||||
if (message.state == 'test-case' && $body.hasClass('window-hidden'))
|
||||
return;
|
||||
update_submission(message);
|
||||
} else if (message.type == 'done-submission') {
|
||||
update_submission(message, true);
|
||||
|
||||
if (!statistics.length) return;
|
||||
if ($('body').hasClass('window-hidden'))
|
||||
return stats_outdated = true;
|
||||
update_stats();
|
||||
}
|
||||
}
|
||||
);
|
||||
receiver.onwsclose = function (event) {
|
||||
if (event.code == 1001) {
|
||||
console.log('Navigated away');
|
||||
return;
|
||||
}
|
||||
console.log('You probably should refresh?');
|
||||
// $('.ws-closed').show().find('a').click(function () {
|
||||
// window.location.reload();
|
||||
// });
|
||||
};
|
||||
return receiver;
|
||||
}
|
||||
</script>
|
||||
{% endcompress %}
|
||||
|
||||
{% if dynamic_update and last_msg and not has_hidden_subtasks %}
|
||||
<script type="text/javascript">
|
||||
$(function () {
|
||||
function load_dynamic_update(last_msg) {
|
||||
var _collect = function (e) {
|
||||
return e.value;
|
||||
};
|
||||
var language_filter = $.map($('select#language option[selected]'), _collect);
|
||||
var status_filter = $.map($('select#status option[selected]'), _collect);
|
||||
|
||||
var table = $('#submissions-table');
|
||||
var statistics = $("#statistics-table");
|
||||
var doing_ajax = false;
|
||||
var first = parseInt(table.find('>div:first-child').attr('id'));
|
||||
|
||||
var update_submission = function (message, force) {
|
||||
if (language_filter.length && 'language' in message &&
|
||||
language_filter.indexOf(message.language) == -1)
|
||||
return;
|
||||
if (status_filter.length && 'status' in message &&
|
||||
status_filter.indexOf(message.status) == -1)
|
||||
return;
|
||||
var id = message.id;
|
||||
var row = table.find('div#' + id);
|
||||
if (row.length < 1) {
|
||||
if (id < first)
|
||||
return;
|
||||
first = id;
|
||||
row = $('<div>', {id: id, 'class': 'submission-row'}).hide().prependTo(table);
|
||||
if (table.find('>div').length >= {{ paginator.per_page }})
|
||||
table.find('>div:last-child').hide('slow', function () {
|
||||
$(this).remove();
|
||||
});
|
||||
}
|
||||
if (force || !doing_ajax) {
|
||||
if (!force) doing_ajax = true;
|
||||
$.ajax({
|
||||
url: '{{ url('submission_single_query') }}',
|
||||
data: {id: id, show_problem: show_problem}
|
||||
}).done(function (data) {
|
||||
var was_shown = row.is(':visible');
|
||||
row.html(data);
|
||||
register_time(row.find('.time-with-rel'));
|
||||
if (!was_shown) {
|
||||
row.slideDown('slow');
|
||||
}
|
||||
if (!force)
|
||||
setTimeout(function () {
|
||||
doing_ajax = false;
|
||||
}, 1000);
|
||||
}).fail(function () {
|
||||
console.log('Failed to update submission: ' + id);
|
||||
if (!force) doing_ajax = false;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
var stats_outdated = false;
|
||||
var last_stat_update = Date.now();
|
||||
var stats_update_interval = {{ stats_update_interval|default(0) * 1000 }};
|
||||
|
||||
function update_stats() {
|
||||
if (Date.now() - last_stat_update < stats_update_interval)
|
||||
return;
|
||||
$.ajax({
|
||||
url: '?results'
|
||||
}).done(function (data) {
|
||||
last_stat_update = Date.now();
|
||||
stats_graph(data);
|
||||
}).fail(function () {
|
||||
console.log('Failed to update statistics table!' + id);
|
||||
}).always(function () {
|
||||
stats_outdated = false;
|
||||
});
|
||||
}
|
||||
|
||||
$(window).on('dmoj:window-visible', function () {
|
||||
if (stats_outdated)
|
||||
update_stats();
|
||||
});
|
||||
|
||||
var $body = $(document.body);
|
||||
var receiver = new EventReceiver(
|
||||
"{{ EVENT_DAEMON_LOCATION }}", "{{ EVENT_DAEMON_POLL_LOCATION }}",
|
||||
['submissions'], last_msg, function (message) {
|
||||
if (current_contest && message.contest != current_contest)
|
||||
return;
|
||||
if (dynamic_user_id && message.user != dynamic_user_id ||
|
||||
dynamic_problem_id && message.problem != dynamic_problem_id)
|
||||
return;
|
||||
if (message.type == 'update-submission') {
|
||||
if (message.state == 'test-case' && $body.hasClass('window-hidden'))
|
||||
return;
|
||||
update_submission(message);
|
||||
} else if (message.type == 'done-submission') {
|
||||
update_submission(message, true);
|
||||
|
||||
if (!statistics.length) return;
|
||||
if ($('body').hasClass('window-hidden'))
|
||||
return stats_outdated = true;
|
||||
update_stats();
|
||||
}
|
||||
}
|
||||
);
|
||||
receiver.onwsclose = function (event) {
|
||||
if (event.code == 1001) {
|
||||
console.log('Navigated away');
|
||||
return;
|
||||
}
|
||||
};
|
||||
return receiver;
|
||||
}
|
||||
load_dynamic_update({{last_msg}});
|
||||
});
|
||||
</script>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue