From 6c24bd9bf6cdd7ef747b867e98d76916e8668449 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sun, 5 Feb 2023 18:19:45 +0800 Subject: [PATCH] feat(problem/manage/data): subtasks configure --- web/app/models/UOJProblemConfigure.php | 93 ++++++++++++++-- web/js/uoj.js | 148 ++++++++++++++++++++++++- 2 files changed, 231 insertions(+), 10 deletions(-) diff --git a/web/app/models/UOJProblemConfigure.php b/web/app/models/UOJProblemConfigure.php index ca3d82b..79e1303 100644 --- a/web/app/models/UOJProblemConfigure.php +++ b/web/app/models/UOJProblemConfigure.php @@ -37,7 +37,7 @@ class UOJProblemConfigure { private static function getCardHeader($title, $body_class = 'vstack gap-3') { return << -
+
{$title}
@@ -99,10 +99,11 @@ class UOJProblemConfigure { $this->simple_form->appendHTML(static::getCardHeader('测试点分值', '')); $this->simple_form->appendHTML(<< - 展开/收起全部 -
- +
+ 展开/收起全部 +
+
+ EOD); $this->simple_form->appendHTML(static::getCardFooter()); $this->simple_form->appendHTML(<< EOD); + $this->simple_form->appendHTML(static::getCardHeader('Subtask 配置', 'p-0')); + $this->simple_form->appendHTML(<< + + +
+
+ EOD); + $this->simple_form->appendHTML(static::getCardFooter()); + $this->simple_form->appendHTML(<< + $(document).ready(function() { + $('#input-enable_subtasks').change(function() { + if (this.checked) { + $('#div-point-score-container-outer').hide(); + $('#div-point-score-unavailable').show(); + $('#div-subtasks-container').problem_configure_subtasks(problem_conf); + } else { + $('#div-point-score-container-outer').show(); + $('#div-point-score-unavailable').hide(); + $('#div-subtasks-container').empty(); + $('.uoj-problem-configure-point-score-input').val(''); + + var subtask_keys = Object.keys(problem_conf).filter(function(key) { + return /^subtask_/.test(key); + }); + + for (var i = 0; i < subtask_keys.length; ++i) { + problem_conf[subtask_keys[i]] = ''; + } + + problem_conf['n_subtasks'] = ''; + } + + $('#problem-conf-preview').problem_conf_preview(problem_conf); + }); + + if (problem_conf['n_subtasks']) { + $('#input-enable_subtasks').prop('checked', true).trigger('change'); + } + }); + + EOD); + + $this->simple_form->appendHTML(<< + $(document).on("keydown", "form", function(event) { + return event.key != "Enter"; + }); + + EOD); + $this->simple_form->succ_href = $this->href; $this->simple_form->config['form']['class'] = 'row gy-3'; $this->simple_form->config['submit_container']['class'] = 'col-12 text-center mt-3'; @@ -137,7 +190,7 @@ class UOJProblemConfigure { $form->addSelect($key, [ 'options' => $options, 'label' => $label, - 'div_class' => 'row', + 'div_class' => 'row gx-2', 'label_class' => 'col-form-label col-4', 'select_div_class' => 'col-8', 'default_value' => $this->problem_conf->getVal($key, $default_val), @@ -157,7 +210,7 @@ class UOJProblemConfigure { $form->addInput($key, [ 'type' => 'number', 'label' => $label, - 'div_class' => 'row', + 'div_class' => 'row gx-2', 'label_class' => 'col-form-label col-4', 'input_div_class' => 'col-8', 'default_value' => $this->problem_conf->getVal($key, $default_val), @@ -181,7 +234,7 @@ class UOJProblemConfigure { 'type' => 'number', 'label' => $label, 'input_attrs' => ['step' => 0.001], - 'div_class' => 'row', + 'div_class' => 'row gx-2', 'label_class' => 'col-form-label col-4', 'input_div_class' => 'col-8', 'default_value' => $this->problem_conf->getVal($key, $default_val), @@ -209,7 +262,7 @@ class UOJProblemConfigure { $this->conf_keys[$key] = true; $form->addInput($key, [ 'label' => $label, - 'div_class' => 'row', + 'div_class' => 'row gx-2', 'label_class' => 'col-form-label col-4', 'input_div_class' => 'col-8', 'default_value' => $this->problem_conf->getVal($key, $default_val), @@ -235,11 +288,33 @@ class UOJProblemConfigure { $conf = $this->problem_conf->conf; $conf_keys = $this->conf_keys; $n_tests = intval(UOJRequest::post('n_tests', 'validateUInt', $this->problem_conf->getVal('n_tests', 10))); + $n_subtasks = intval(UOJRequest::post('n_subtasks', 'validateUInt', $this->problem_conf->getVal('n_subtasks', 0))); for ($i = 1; $i <= $n_tests; $i++) { $conf_keys["point_score_$i"] = true; } + $conf_keys['n_subtasks'] = true; + for ($i = 1; $i <= $n_subtasks; $i++) { + $conf_keys["subtask_type_$i"] = true; + $conf_keys["subtask_score_$i"] = true; + $conf_keys["subtask_end_$i"] = true; + $conf_keys["subtask_used_time_type_$i"] = true; + + // $conf_keys["subtask_dependence_$i"] = true; + + // $subtask_dependence_str = UOJRequest::post("subtask_dependence_$i", 'is_string', ''); + + // if ($subtask_dependence_str == 'many') { + // $subtask_dependence_cnt = 0; + + // while (UOJRequest::post("subtask_dependence_{$i}_{$subtask_dependence_cnt}", 'is_string', '') != '') { + // $subtask_dependence_cnt++; + // $conf_keys["subtask_dependence_{$i}_{$subtask_dependence_cnt}"] = true; + // } + // } + } + foreach (array_keys($conf_keys) as $key) { $val = UOJRequest::post($key, 'is_string', ''); if ($key === 'use_builtin_judger') { diff --git a/web/js/uoj.js b/web/js/uoj.js index 7345e94..e9baaa7 100644 --- a/web/js/uoj.js +++ b/web/js/uoj.js @@ -1212,10 +1212,12 @@ $.fn.problem_configure_point_scores = function(problem_conf) { var _this = this; var n_tests = parseInt(problem_conf['n_tests']); - $(this).html(''); + $(this).empty(); if (isNaN(n_tests) || n_tests <= 0) { $(this).html('不可用。'); + + return; } for (var i = 1; i <= n_tests; i++) { @@ -1275,6 +1277,150 @@ $.fn.problem_configure_point_scores = function(problem_conf) { }); }; +// problem_configure: subtasks +$.fn.problem_configure_subtasks = function(problem_conf) { + return $(this).each(function() { + var _this = this; + var n_subtasks = parseInt(problem_conf['n_subtasks'] || '0'); + + $(this).empty(); + + if (isNaN(n_subtasks)) { + $(this).html('不可用。'); + + return; + } + + var input_n_subtasks = $(''); + var div_subtasks = $('
'); + + if (n_subtasks) { + input_n_subtasks.val(n_subtasks); + } + + $(this).append( + $('
').append( + $('
').append( + $('
').append('') + ).append( + $('
').append(input_n_subtasks) + ) + ) + ).append(div_subtasks); + + input_n_subtasks.change(function() { + div_subtasks.empty(); + + var n_subtasks = parseInt(input_n_subtasks.val() || '0'); + problem_conf['n_subtasks'] = input_n_subtasks.val(); + + for (var i = 1; i <= n_subtasks; i++) { + var input_subtask_type = $(''); + var input_subtask_score = $(''); + var input_subtask_used_time_type = $('