Add problem volunteer

This commit is contained in:
cuom1999 2022-05-02 21:44:14 -05:00
parent e51129d36f
commit e70618ed19
15 changed files with 396 additions and 5 deletions

View file

@ -260,6 +260,9 @@
{% if request.user.is_staff or request.user.is_superuser %}
<li><a href="{{ url('admin:index') }}">{{ _('Admin') }}</a></li>
{% endif %}
{% if request.user.is_superuser %}
<li><a href="{{ url('internal_problem') }}">{{ _('Internal') }}</a></li>
{% endif %}
<li><a href="{{ url('user_edit_profile') }}">{{ _('Edit profile') }}</a></li>
{% if request.user.is_impersonate %}
<li><a href="{{ url('impersonate-stop') }}">Stop impersonating</a></li>

View file

@ -214,7 +214,6 @@
{% block body %}
<div class="content-description">
<form id="filter-form">
<input id="search-contest" type="text" name="contest" value="{{ contest_query or '' }}"
placeholder="{{ _('Search contests...') }}">

View file

@ -0,0 +1,92 @@
{% extends "three-column-content.html" %}
{% block three_col_media %}
<style>
.middle-content {
max-width: 50%;
}
ol {
padding-left: 1em;
}
</style>
{% endblock %}
{% block three_col_js %}
<script type="text/javascript">
$(function () {
$('.vote-detail').each(function() {
$(this).on('click', function() {
var pid = $(this).attr('pid');
$('.detail').hide();
$('#detail-'+pid).show();
})
})
});
</script>
{% endblock %}
{% block left_sidebar %}
<div class="left-sidebar">
{{ make_tab_item('problem', 'fa fa-list', url('internal_problem'), _('Problem')) }}
</div>
{% endblock %}
{% block middle_content %}
<table class="table">
<thead>
<tr>
<th>{{_('Problem')}}</th>
<th>{{_('Code')}}</th>
<th>{{_('Vote count')}}</th>
</tr>
</thead>
<tbody>
{% for problem in problems %}
<tr>
<td><a href="{{url('problem_detail', problem.code)}}">{{problem.name}}</a></td>
<td><a href="{{url('admin:judge_problem_change', problem.id)}}">{{problem.code}}</a></td>
<td><a href="#" class="vote-detail" pid="{{problem.id}}">{{problem.vote_count}}</a></td>
</tr>
{% endfor %}
</tbody>
</table>
{% if page_obj.num_pages > 1 %}
<div style="margin-top:10px;">{% include "list-pages.html" %}</div>
{% endif %}
{% endblock %}
{% block right_sidebar %}
<div style="display: block; width: 100%">
<div><a href="{{url('admin:judge_volunteerproblemvote_changelist')}}">{{_('Admin')}}</a></div>
{% for problem in problems %}
<div class="detail" id="detail-{{problem.id}}" style="display: none;">
<h3>{{_('Votes for problem') }} {{problem.name}}</h3>
<ol>
{% for vote in problem.volunteer_user_votes.order_by('id') %}
<li>
<h4> {{link_user(vote.voter)}} </h4>
<table class="table">
<tbody>
<tr>
<td style="width:10%">{{_('Knowledge')}}</td>
<td>{{vote.knowledge_points}}</td>
</tr>
<tr>
<td>{{_('Thinking')}}</td>
<td>{{vote.thinking_points}}</td>
</tr>
<tr>
<td>{{_('Types')}}</td>
<td>{{vote.types.all() | join(', ')}}</td>
</tr>
<tr>
<td>{{_('Feedback')}}</td>
<td>{{vote.feedback}}</td>
</tr>
</tbody>
</table>
</li>
{% endfor %}
</ol>
</div>
{% endfor %}
{% endblock %}

View file

@ -31,5 +31,68 @@
{% cache 86400 'problem_html' problem.id MATH_ENGINE LANGUAGE_CODE %}
{{ problem.description|markdown("problem", MATH_ENGINE)|reference|str|safe }}
{% endcache %}
{% if feed_type=='volunteer' and request.user.has_perm('judge.suggest_problem_changes') %}
<hr>
<center><h3>{{_('Volunteer form')}}</h3></center>
<br>
<button class="edit-btn" id="edit-{{problem.id}}" pid="{{problem.id}}" style="float: right">{{_('Edit')}}</button>
<form class="volunteer-form" id="form-{{problem.id}}" pid="{{problem.id}}" style="display: none;" method="POST">
<input type="submit" class="volunteer-submit-btn" id="submit-{{problem.id}}" pid="{{problem.id}}" pcode="{{problem.code}}" style="float: right" value="{{_('Submit')}}">
<table class="table">
<thead>
<tr>
<th>
{{_('Field')}}
</th>
<th>
{{_('Value')}}
</th>
</tr>
</thead>
<tbody>
<tr>
<td width="30%">
<label for="knowledge_point-{{problem.id}}"><i>{{ _('Knowledge point') }}</i></label>
</td>
<td>
<input id="knowledge_point-{{problem.id}}" type="number" class="point-input" required>
</td>
</tr>
<tr>
<td width="30%">
<label for="thinking_point-{{problem.id}}"><i>{{ _('Thinking point') }}</i></label>
</td>
<td>
<input id="thinking_point-{{problem.id}}" type="number" class="point-input" required>
</td>
</tr>
<tr>
<td width="30%">
<label for="types"><i>{{ _('Problem types') }}</i></label>
</td>
<td>
<select id="volunteer-types-{{problem.id}}" name="types" multiple>
{% for type in problem_types %}
<option value="{{ type.id }}"{% if type in problem.types.all() %} selected{% endif %}>
{{ type.full_name }}
</option>
{% endfor %}
</select>
</td>
</tr>
<tr>
<td width="30%">
<label for="feedback"><i>{{ _('Feedback') }}</i></label>
</td>
<td>
<textarea id="feedback-{{problem.id}}" rows="2" style="width: 100%" placeholder="{{_('Any additional note here')}}"></textarea>
</td>
</tr>
</tbody>
</table>
</form>
<center id="thank-{{problem.id}}" style="display: none; margin-top: 3em"></center>
{% endif %}
</div>
</div>

View file

@ -36,7 +36,15 @@
#content {
width: 99%;
margin-left: 0;
}
}
.volunteer-types {
width: 100%;
}
.point-input {
height: 2em;
padding-top: 4px;
}
</style>
{% endif %}
{% endblock %}
@ -151,6 +159,59 @@
$end.prop('disabled', end === point_values.max).val(end);
});
}
{% if feed_type=='volunteer' and request.user.has_perm('judge.suggest_problem_changes') %}
$(".edit-btn").on('click', function() {
var pid = $(this).attr('pid');
$('#volunteer-types-' + pid).css({'width': '100%'});
$('#volunteer-types-' + pid).select2({multiple: 1, placeholder: '{{ _('Add types...') }}'})
.css({'visibility': 'visible'});
$('#form-' + pid).show();
$('#submit-' + pid).show();
$(this).hide();
});
let isChecking = false;
$(".volunteer-submit-btn").on('click', function(e) {
var pid = $(this).attr('pid');
var pcode = $(this).attr('pcode');
var $form = $('#form-' + pid);
if (!$form[0].checkValidity()) {
if (isChecking) return;
isChecking = true;
// The form won't actually submit;
$(this).click();
}
else {
isChecking = false;
}
if (isChecking) return;
e.preventDefault();
$('#volunteer-types-' + pid).select2({multiple: 1, placeholder: '{{ _('Add types...') }}'})
.css({'visibility': 'visible'});
$('#form-' + pid).hide();
$('#edit-' + pid).show();
$('#thank-' + pid).show();
$(this).hide();
var data = {
problem: pcode,
types: $('#volunteer-types-' + pid).val(),
knowledge_points: $('#knowledge_point-' + pid).val(),
thinking_points: $('#thinking_point-' + pid).val(),
feedback: $('#feedback-' + pid).val(),
};
$.post("{{url('volunteer_problem_vote')}}", data)
.fail(function() {
$('#thank-' + pid).html("{{_('Fail to vote!')}}");
})
.done(function() {
$('#thank-' + pid).html("{{_('Successful vote! Thank you!')}}");
});
});
{% endif %}
});
</script>
{% endcompress %}
@ -381,6 +442,11 @@
<a href="{{url('problem_feed_new')}}" class="problem-feed-option-item {{'active' if feed_type=='new'}}">
{{_('NEW')}}
</a>
{% if request.user.has_perm('judge.suggest_problem_changes') %}
<a href="{{url('problem_feed_volunteer')}}" class="problem-feed-option-item {{'active' if feed_type=='volunteer'}}">
{{_('VOLUNTEER')}}
</a>
{% endif %}
</div>
{% for problem in problems %}
{% include "problem/feed.html" %}