NDOJ/templates/submission/list.html

398 lines
13 KiB
HTML
Raw Permalink Normal View History

2022-06-06 16:36:35 +00:00
{% extends "three-column-content.html" %}
{% block three_col_js %}
2023-01-27 23:11:10 +00:00
<script type="text/javascript">
{% if dynamic_update and last_msg %}
{% if request.in_contest_mode %}
window.current_contest = '{{request.participation.contest.key}}';
{% else %}
window.current_contest = null;
{% endif %}
{% if dynamic_user_id %}
window.dynamic_user_id = {{dynamic_user_id}};
{% else %}
window.dynamic_user_id = null;
{% endif %}
{% if dynamic_problem_id %}
window.dynamic_problem_id = {{dynamic_problem_id}};
{% else %}
window.dynamic_problem_id = null;
{% endif %}
{% if show_problem %}
window.show_problem = 1;
{% else %}
window.show_problem = 0;
{% endif %}
{% endif %}
{% if results_json %}
window.results_json = {{ results_json }};
{% endif %}
</script>
{% compress js %}
<script type="text/javascript" src="{{ static('event.js') }}"></script>
{% if request.user.is_authenticated and perms.judge.rejudge_submission %}
<script type="text/javascript">
window.rejudge_submission = function (id, e) {
if ((typeof e !== 'undefined' && e.ctrlKey) ||
confirm('Are you sure you want to rejudge?')) {
$.ajax({
url: '{{ url('submission_rejudge') }}',
type: "POST",
data: {
id: id
2020-01-21 06:35:58 +00:00
}
2023-01-27 23:11:10 +00:00
});
}
};
</script>
{% endif %}
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
<script src="{{ static('libs/chart.js/Chart.js') }}"></script>
<script type="text/javascript">
$(function () {
var info_float = $('.info-float');
var container = $('#content-right');
if (window.bad_browser) {
container.css('float', 'right');
} else if (!featureTest('position', 'sticky')) {
fix_div(info_float, 55);
$(window).resize(function () {
info_float.width(container.width());
});
info_float.width(container.width());
}
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
function idAndTextMatcher(params, data) {
if ($.trim(params.term) === '')
return data;
var regex = new RegExp(escapeRegExp(params.term), 'i');
return data.text.search(regex) >= 0 || data.id.search(regex) >= 0 ? data : null;
}
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
$('#status').select2({
multiple: 1,
placeholder: '{{ _('Filter by status...') }}',
matcher: idAndTextMatcher,
}).css({'visibility': 'visible'});
$('#language').select2({
multiple: 1,
placeholder: '{{ _('Filter by language...') }}',
matcher: idAndTextMatcher,
}).css({'visibility': 'visible'});
});
// 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);
}
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
$(function () {
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;
});
}
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
$(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();
2020-01-21 06:35:58 +00:00
}
2023-01-27 23:11:10 +00:00
}
);
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 %}
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
{% if dynamic_update and last_msg %}
<script type="text/javascript">
$(function () {
load_dynamic_update({{last_msg}});
});
</script>
{% endif %}
2020-01-21 06:35:58 +00:00
{% endblock %}
{% block title_ruler %}{% endblock %}
2022-06-06 16:36:35 +00:00
{% block title_row %}{% endblock %}
2020-01-21 06:35:58 +00:00
2022-06-06 16:36:35 +00:00
{% block three_col_media %}
2023-01-27 23:11:10 +00:00
{% if perms.judge.change_submission and perms.judge.rejudge_submission %}
2020-01-21 06:35:58 +00:00
<style>
2023-01-27 23:11:10 +00:00
td.sub-prop, col.sub-prop {
width: 22%
}
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
col.sub-info, td.sub-info {
width: 78%
}
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
#status, #language {
visibility: hidden;
}
2020-01-21 06:35:58 +00:00
</style>
2023-01-27 23:11:10 +00:00
{% endif %}
<style>
.total {
text-align: center;
margin-bottom: 0.5em;
}
#status-graph {
padding: 1em 0em;
}
#status-graph canvas {
display: block;
margin: 0 auto;
}
</style>
2020-01-21 06:35:58 +00:00
{% endblock %}
2022-06-09 05:43:15 +00:00
{% block middle_title %}
2023-01-27 23:11:10 +00:00
<div class="page-title">
2022-06-09 05:43:15 +00:00
<div class="tabs" style="border: none;">
2023-01-27 23:11:10 +00:00
<h2>{{content_title}}</h2>
2022-06-09 05:43:15 +00:00
</div>
2023-01-27 23:11:10 +00:00
</div>
2022-06-09 05:43:15 +00:00
{% endblock %}
2020-01-21 06:35:58 +00:00
2022-06-09 05:43:15 +00:00
{% block middle_content %}
2023-01-27 23:11:10 +00:00
<div class="submission">
<div class="ws-closed">
<a href="javascript:void(0)">{{ _('You were disconnected. Refresh to show latest updates.') }}</a>
</div>
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
<div id="submissions-table">
{% set profile_id = request.profile.id if request.user.is_authenticated else 0 %}
{% for submission in submissions %}
<div class="submission-row" id="{{ submission.id }}">
{% with problem_name=show_problem and submission.problem.i18n_name %}
{% include "submission/row.html" %}
{% endwith %}
2022-06-24 13:26:04 +00:00
</div>
2023-01-27 23:11:10 +00:00
{% endfor %}
2022-06-06 16:36:35 +00:00
</div>
2023-01-27 23:11:10 +00:00
{% if page_obj.num_pages > 1 %}
<div style="margin-top:10px;">{% include "list-pages.html" %}</div>
{% endif %}
</div>
2022-06-06 16:36:35 +00:00
{% endblock %}
2020-01-21 06:35:58 +00:00
2022-06-06 16:36:35 +00:00
{% block right_sidebar %}
2023-01-27 23:11:10 +00:00
{% if results_json %}
2022-06-06 16:36:35 +00:00
<div class="right-sidebar">
2023-01-27 23:11:10 +00:00
<div class="submission">
<div class="sidebox">
<h3>{{ _('Filter submissions') }} <i class="fa fa-search"></i></h3>
<div class="sidebox-content">
<form id="filter-form" name="form" action="" method="get">
<div class="filter-form-group">
<label for="status"><i>{{ _('Status') }}</i></label>
<select id="status" name="status" multiple>
{% for id, name in all_statuses %}
<option {% if id in selected_statuses %}selected{% endif %}
value="{{ id }}">{{ name }}</option>
{% endfor %}
</select>
</div>
<div class="filter-form-group">
<label for="language"><i>{{ _('Language') }}</i></label>
<select id="language" name="language" multiple>
{% for code, name in all_languages %}
<option {% if code in selected_languages %}selected{% endif %}
value="{{ code }}">{{ name }}</option>
{% endfor %}
</select>
</div>
<div class="form-submit-group">
<a id="go" onclick="form.submit()" class="button small">{{ _('Go') }}</a>
</div>
</form>
</div>
</div>
<div class="sidebox">
<div id="statistics-table">
<h3>{{ _('Statistics') }} <i class="fa fa-pie-chart"></i></h3>
<div class="sidebox-content">
<div id="status-graph">
<canvas width="230" height="170"></canvas>
</div>
<div class="total">
{{ _('Total:') }} <span id="total-submission-count"></span>
</div>
2020-01-21 06:35:58 +00:00
</div>
2023-01-27 23:11:10 +00:00
</div>
2020-01-21 06:35:58 +00:00
</div>
2023-01-27 23:11:10 +00:00
</div>
2020-01-21 06:35:58 +00:00
</div>
2023-01-27 23:11:10 +00:00
{% endif %}
2020-01-21 06:35:58 +00:00
{% endblock %}
2022-06-06 16:36:35 +00:00
{% block left_sidebar %}
2023-01-27 23:11:10 +00:00
<div class="left-sidebar">
{{ make_tab_item('all_submissions_list', 'fa fa-list', all_submissions_link, _('All')) }}
{% if my_submissions_link or tab == 'my_submissions_tab' %}
{{ make_tab_item('my_submissions_tab', 'fa fa-user', my_submissions_link, _('Mine')) }}
{% endif %}
{% if best_submissions_link %}
{{ make_tab_item('best_submissions_list', 'fa fa-bar-chart', best_submissions_link, _('Best')) }}
{% endif %}
{% if page_type == 'user_submissions_tab' %}
{{ make_tab_item('user_submissions_tab', 'fa fa-user', None, _("%(user)s", user=tab_username)) }}
{% endif %}
2023-02-13 03:35:48 +00:00
{% if friend_submissions_link %}
{{ make_tab_item('friend_tab', 'fa fa-user', friend_submissions_link, _('Friends')) }}
{% endif %}
2023-01-27 23:11:10 +00:00
{% if perms.judge.change_submission %}
{{ make_tab_item('admin', 'fa fa-edit', url('admin:judge_submission_changelist'), _('Admin')) }}
{% endif %}
</div>
2022-06-06 16:36:35 +00:00
{% endblock %}