From 5562db7ecd561d5daf4404c27eece4f2023a7cba Mon Sep 17 00:00:00 2001 From: Dinh Date: Tue, 21 Jan 2020 23:27:18 -0600 Subject: [PATCH] add autofill testcases --- templates/problem/data.html | 63 +++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 3 deletions(-) diff --git a/templates/problem/data.html b/templates/problem/data.html index 83d16ed..b21a8ed 100644 --- a/templates/problem/data.html +++ b/templates/problem/data.html @@ -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 @@
{% csrf_token %} {{ cases_formset.management_form }} - {{ data_form.as_table() }}
+ + {{ data_form.as_table() }} + + +
+ + + Problem type: + + + + Fill testcases + +
{{ _('Show columns:') }}