add autofill testcases

This commit is contained in:
Dinh 2020-01-21 23:27:18 -06:00
parent 3885f6f071
commit 5562db7ecd

View file

@ -205,6 +205,47 @@
return false;
});
$('a#fill-testcases').click(function () {
var inFiles = [], outFiles = [];
for (var i = 0; i < window.valid_files.length; i++) {
if (window.valid_files[i].endsWith(".in")) {
inFiles.push(window.valid_files[i]);
}
if (window.valid_files[i].endsWith(".out")) {
outFiles.push(window.valid_files[i]);
}
}
if (inFiles.length == 0) {
alert("No input/output files. Make sure your files' suffices are .in/.out");
return false;
}
if (inFiles.length != outFiles.length) {
alert("The input files do not match the output files!");
return false;
}
// add boxes
while ($total.val() < inFiles.length) {
$('a#add-case-row').click();
}
// fill cases
for (var i = 0; i < inFiles.length; i++) {
$("#id_cases-" + i + "-input_file").val(inFiles[i]).change();
}
// add points
if ($('#problem-type').val() == "ICPC") {
for (i = 0; i + 1 < inFiles.length; i++) {
$("#id_cases-" + i + "-points").val("0").change();
}
$("#id_cases-" + (inFiles.length - 1) + "-points").val("100").change();
}
else {
for (i = 0; i < inFiles.length; i++) {
$("#id_cases-" + i + "-points").val("1").change();
}
}
return false;
});
var oldIndex;
$table.sortable({
containerSelector: 'table',
@ -324,7 +365,7 @@
height: 8em;
}
.generator-args-editor .button {
.generator-args-editor #submit-button {
display: block;
float: right;
}
@ -364,7 +405,23 @@
<form action="" method="POST" enctype="multipart/form-data">
{% csrf_token %}
{{ cases_formset.management_form }}
<table class="table">{{ data_form.as_table() }}</table>
<table class="table">
{{ data_form.as_table() }}
<th>
<label>Autofill testcases:</label>
</th>
<td>
Problem type:
<select id="problem-type">
<option value="ICPC">ICPC</option>
<option value="OI">OI</option>
</select>
<a id="fill-testcases" href="#">
<i class="fa fa-circle"></i>
Fill testcases
</a>
</td>
</table>
<div id="column-visible" data-problem="{{ problem.code }}">
<strong>{{ _('Show columns:') }}</strong>
<label>
@ -444,7 +501,7 @@
{% endfor %}
</tbody>
</table>
<input type="submit" value="{{ _('Submit!') }}" class="button">
<input type="submit" value="{{ _('Submit!') }}" class="button" id="submit-button">
<a id="add-case-row" href="#"><i class="fa fa-plus"></i> {{ _('Add new case') }}</a>
</form>
<div style="display: none" class="generator-args-editor"><textarea></textarea><a class="button">Save</a></div>