From 88e8f1de62b7a67842053489f43a6872a4b581bf Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Wed, 1 Feb 2023 19:36:27 +0800 Subject: [PATCH] refactor(problem/manage/data): uoj_form_v2 --- web/app/controllers/problem_data_manage.php | 210 +++++++++----------- web/app/models/UOJProblem.php | 4 +- web/app/models/UOJProblemConf.php | 20 +- web/app/route.php | 1 + 4 files changed, 121 insertions(+), 114 deletions(-) diff --git a/web/app/controllers/problem_data_manage.php b/web/app/controllers/problem_data_manage.php index 91112c7..65746cd 100644 --- a/web/app/controllers/problem_data_manage.php +++ b/web/app/controllers/problem_data_manage.php @@ -126,11 +126,9 @@ if ($_POST['problem_settings_file_submit'] == 'submit') { } -$info_form = new UOJBs4Form('info'); -$http_host = HTML::escape(UOJContext::httpHost()); +$info_form = new UOJForm('info'); $attachment_url = UOJProblem::cur()->getAttachmentUri(); -$info_form->appendHTML( - <<appendHTML(<<
@@ -139,11 +137,9 @@ $info_form->appendHTML(
-EOD -); +EOD); $download_url = UOJProblem::cur()->getMainDataUri(); -$info_form->appendHTML( - <<appendHTML(<<
@@ -152,92 +148,80 @@ $info_form->appendHTML(
-EOD -); -$info_form->appendHTML( - <<appendHTML(<< -EOD -); +EOD); $esc_submission_requirement = HTML::escape(json_encode(json_decode($problem['submission_requirement']), JSON_PRETTY_PRINT)); -$info_form->appendHTML( - <<appendHTML(<<
-
+		
 $esc_submission_requirement
 
-
-EOD -); +EOD); $esc_extra_config = HTML::escape(json_encode(json_decode($problem['extra_config']), JSON_PRETTY_PRINT)); -$info_form->appendHTML( - <<appendHTML(<<
-
+		
 $esc_extra_config
 
-
-EOD -); +EOD); if (isSuperUser(Auth::user())) { - $info_form->addVInput( - 'submission_requirement', - 'text', - '提交文件配置', - $problem['submission_requirement'], - function ($submission_requirement, &$vdata) { + $info_form->addTextArea('submission_requirement', [ + 'label' => '提交文件配置', + 'input_class' => 'form-control font-monospace', + 'default_value' => $problem['submission_requirement'], + 'validator_php' => function ($submission_requirement, &$vdata) { $submission_requirement = json_decode($submission_requirement, true); if ($submission_requirement === null) { return '不是合法的JSON'; } $vdata['submission_requirement'] = json_encode($submission_requirement); }, - null - ); - $info_form->addVInput( - 'extra_config', - 'text', - '其它配置', - $problem['extra_config'], - function ($extra_config, &$vdata) { + ]); + $info_form->addTextArea('extra_config', [ + 'label' => '其他配置', + 'input_class' => 'form-control font-monospace', + 'default_value' => $problem['extra_config'], + 'validator_php' => function ($extra_config, &$vdata) { $extra_config = json_decode($extra_config, true); if ($extra_config === null) { return '不是合法的JSON'; } $vdata['extra_config'] = json_encode($extra_config); }, - null - ); + ]); $info_form->handle = function (&$vdata) use ($problem) { DB::update([ "update problems", "set", [ "submission_requirement" => $vdata['submission_requirement'], - "extra_config" => $vdata['extra_config'] - ], "where", ["id" => $problem['id']] + "extra_config" => $vdata['extra_config'], + ], "where", [ + "id" => $problem['id'], + ] ]); }; } else { - $info_form->no_submit = true; + $info_form->config['no_submit'] = true; } - -$problem_conf = getUOJConf("$data_dir/problem.conf"); +$info_form->runAtServer(); function displayProblemConf(UOJProblemDataDisplayer $self) { global $info_form; @@ -250,8 +234,8 @@ function displayProblemConf(UOJProblemDataDisplayer $self) { $self->echoFilePre('problem.conf'); } -function addTestsTab(UOJProblemDataDisplayer $disp, array $problem_conf) { - $n_tests = getUOJConfVal($problem_conf, 'n_tests', 10); +function addTestsTab(UOJProblemDataDisplayer $disp, UOJProblemConf $problem_conf) { + $n_tests = $problem_conf->getVal('n_tests', 10); if (!validateUInt($n_tests)) { $disp->setProblemConfRowStatus('n_tests', 'danger'); return false; @@ -260,8 +244,8 @@ function addTestsTab(UOJProblemDataDisplayer $disp, array $problem_conf) { $inputs = []; $outputs = []; for ($num = 1; $num <= $n_tests; $num++) { - $inputs[$num] = getUOJProblemInputFileName($problem_conf, $num); - $outputs[$num] = getUOJProblemOutputFileName($problem_conf, $num); + $inputs[$num] = $problem_conf->getInputFileName($num); + $outputs[$num] = $problem_conf->getOutputFileName($num); unset($disp->rest_data_files[$inputs[$num]]); unset($disp->rest_data_files[$outputs[$num]]); } @@ -281,14 +265,14 @@ function addTestsTab(UOJProblemDataDisplayer $disp, array $problem_conf) { return true; } -function addExTestsTab(UOJProblemDataDisplayer $disp, array $problem_conf) { - $has_extra_tests = !(isset($problem_conf['submit_answer']) && $problem_conf['submit_answer'] == 'on'); +function addExTestsTab(UOJProblemDataDisplayer $disp, UOJProblemConf $problem_conf) { + $has_extra_tests = $problem_conf->getNonTraditionalJudgeType() != 'submit_answer'; if (!$has_extra_tests) { return false; } - $n_ex_tests = getUOJConfVal($problem_conf, 'n_ex_tests', 0); + $n_ex_tests = $problem_conf->getVal('n_ex_tests', 0); if (!validateUInt($n_ex_tests)) { $disp->setProblemConfRowStatus('n_ex_tests', 'danger'); return false; @@ -301,8 +285,8 @@ function addExTestsTab(UOJProblemDataDisplayer $disp, array $problem_conf) { $inputs = []; $outputs = []; for ($num = 1; $num <= $n_ex_tests; $num++) { - $inputs[$num] = getUOJProblemExtraInputFileName($problem_conf, $num); - $outputs[$num] = getUOJProblemExtraOutputFileName($problem_conf, $num); + $inputs[$num] = $problem_conf->getExtraInputFileName($num); + $outputs[$num] = $problem_conf->getExtraOutputFileName($num); unset($disp->rest_data_files[$inputs[$num]]); unset($disp->rest_data_files[$outputs[$num]]); } @@ -341,7 +325,7 @@ function addSrcTab(UOJProblemDataDisplayer $disp, $tab_name, string $name) { function getDataDisplayer() { $disp = new UOJProblemDataDisplayer(UOJProblem::cur()); - $problem_conf = UOJProblem::cur()->getProblemConfArray(); + $problem_conf = UOJProblem::cur()->getProblemConf(); if ($problem_conf === -1) { return $disp->addTab('problem.conf', function ($self) { global $info_form; @@ -365,18 +349,18 @@ function getDataDisplayer() { }); } - $disp->setProblemConf($problem_conf); + $disp->setProblemConf($problem_conf->conf); unset($disp->rest_data_files['problem.conf']); unset($disp->rest_data_files['download.zip']); $disp->addTab('problem.conf', 'displayProblemConf'); addTestsTab($disp, $problem_conf); addExTestsTab($disp, $problem_conf); - $judger_name = getUOJConfVal($problem_conf, 'use_builtin_judger', null); + $judger_name = $problem_conf->getVal('use_builtin_judger', null); if ($judger_name === null) { return $disp; } elseif ($judger_name === 'on') { - if (!isset($problem_conf['interaction_mode'])) { + if ($problem_conf->isOn('interaction_mode')) { if (isset($problem_conf['use_builtin_checker'])) { $disp->addTab('checker', function ($self) { echo '

use builtin checker : ', $self->problem_conf['use_builtin_checker']['val'], '

'; @@ -389,7 +373,7 @@ function getDataDisplayer() { addSrcTab($disp, 'standard', 'std'); addSrcTab($disp, 'validator', 'val'); } - if (isset($problem_conf['interaction_mode'])) { + if (isset($problem_conf->conf['interaction_mode'])) { addSrcTab($disp, 'interactor', 'interactor'); } return $disp; @@ -409,7 +393,7 @@ if (isset($_GET['display_file'])) { die(); } -$hackable_form = new UOJBs4Form('hackable'); +$hackable_form = new UOJForm('hackable'); $hackable_form->handle = function () use ($problem) { $problem['hackable'] = !$problem['hackable']; $ret = dataSyncProblemData($problem); @@ -424,11 +408,13 @@ $hackable_form->handle = function () use ($problem) { "where", ["id" => $problem['id']] ]); }; -$hackable_form->submit_button_config['class_str'] = 'btn btn-warning d-block w-100'; -$hackable_form->submit_button_config['text'] = $problem['hackable'] ? '禁用 Hack 功能' : '启用 Hack 功能'; -$hackable_form->submit_button_config['smart_confirm'] = ''; +$hackable_form->config['submit_container']['class'] = ''; +$hackable_form->config['submit_button']['class'] = 'btn btn-warning d-block w-100'; +$hackable_form->config['submit_button']['text'] = $problem['hackable'] ? '禁用 Hack 功能' : '启用 Hack 功能'; +$hackable_form->config['confirm']['smart'] = true; +$hackable_form->runAtServer(); -$data_form = new UOJBs4Form('data'); +$data_form = new UOJForm('data'); $data_form->handle = function () use ($problem) { set_time_limit(60 * 5); $ret = dataSyncProblemData($problem, Auth::user()); @@ -436,39 +422,46 @@ $data_form->handle = function () use ($problem) { becomeMsgPage('
' . $ret . '
返回'); } }; -$data_form->submit_button_config['class_str'] = 'btn btn-danger d-block w-100'; -$data_form->submit_button_config['text'] = '检验配置并同步数据'; -$data_form->submit_button_config['smart_confirm'] = ''; +$data_form->config['submit_container']['class'] = ''; +$data_form->config['submit_button']['class'] = 'btn btn-danger d-block w-100'; +$data_form->config['submit_button']['text'] = '检验配置并同步数据'; +$data_form->config['confirm']['smart'] = true; +$data_form->runAtServer(); -$clear_data_form = new UOJBs4Form('clear_data'); -$clear_data_form->handle = function () { - global $problem; +$clear_data_form = new UOJForm('clear_data'); +$clear_data_form->handle = function () use ($problem) { dataClearProblemData($problem); }; -$clear_data_form->submit_button_config['class_str'] = 'btn btn-danger d-block w-100'; -$clear_data_form->submit_button_config['text'] = '清空题目数据'; -$clear_data_form->submit_button_config['smart_confirm'] = ''; +$clear_data_form->config['submit_container']['class'] = ''; +$clear_data_form->config['submit_button']['class'] = 'btn btn-danger d-block w-100'; +$clear_data_form->config['submit_button']['text'] = '清空题目数据'; +$clear_data_form->config['confirm']['smart'] = true; +$clear_data_form->runAtServer(); -$rejudge_form = new UOJBs4Form('rejudge'); +$rejudge_form = new UOJForm('rejudge'); $rejudge_form->handle = function () { UOJSubmission::rejudgeProblem(UOJProblem::cur()); }; $rejudge_form->succ_href = "/submissions?problem_id={$problem['id']}"; -$rejudge_form->submit_button_config['class_str'] = 'btn btn-danger d-block w-100'; -$rejudge_form->submit_button_config['text'] = '重测该题'; -$rejudge_form->submit_button_config['smart_confirm'] = ''; +$rejudge_form->config['submit_container']['class'] = ''; +$rejudge_form->config['submit_button']['class'] = 'btn btn-danger d-block w-100'; +$rejudge_form->config['submit_button']['text'] = '重测该题'; +$rejudge_form->config['confirm']['smart'] = true; +$rejudge_form->runAtServer(); -$rejudgege97_form = new UOJBs4Form('rejudgege97'); +$rejudgege97_form = new UOJForm('rejudgege97'); $rejudgege97_form->handle = function () { UOJSubmission::rejudgeProblemGe97(UOJProblem::cur()); }; $rejudgege97_form->succ_href = "/submissions?problem_id={$problem['id']}"; -$rejudgege97_form->submit_button_config['class_str'] = 'btn btn-danger d-block w-100'; -$rejudgege97_form->submit_button_config['text'] = '重测 >=97 的程序'; -$rejudgege97_form->submit_button_config['smart_confirm'] = ''; +$rejudgege97_form->config['submit_container']['class'] = ''; +$rejudgege97_form->config['submit_button']['class'] = 'btn btn-danger d-block w-100'; +$rejudgege97_form->config['submit_button']['text'] = '重测 >=97 的程序'; +$rejudgege97_form->config['confirm']['smart'] = true; +$rejudgege97_form->runAtServer(); if ($problem['hackable']) { - $test_std_form = new UOJBs4Form('test_std'); + $test_std_form = new UOJForm('test_std'); $test_std_form->handle = function () use ($problem, $data_disp) { $user_std = UOJUser::query('std'); if (!$user_std) { @@ -480,7 +473,7 @@ if ($problem['hackable']) { $src_std = UOJLang::findSourceCode('std', '', [$data_disp, 'isFile']); if ($src_std === false) { - UOJResponse::message('未找到std!'); + UOJResponse::message('未找到 std!'); } $zip_file_name = FS::randomAvailableSubmissionFileName(); @@ -526,41 +519,35 @@ if ($problem['hackable']) { ]); }; $test_std_form->succ_href = "/submissions?problem_id={$problem['id']}"; - $test_std_form->submit_button_config['class_str'] = 'btn btn-danger d-block w-100'; - $test_std_form->submit_button_config['text'] = '检验数据正确性'; + $test_std_form->config['submit_container']['class'] = ''; + $test_std_form->config['submit_button']['class'] = 'btn btn-warning d-block w-100'; + $test_std_form->config['submit_button']['text'] = '检验数据正确性'; $test_std_form->runAtServer(); } - -$hackable_form->runAtServer(); -$data_form->runAtServer(); -$clear_data_form->runAtServer(); -$rejudge_form->runAtServer(); -$rejudgege97_form->runAtServer(); -$info_form->runAtServer(); ?> - +getTitle(['with' => 'id'])) ?>

- #. 管理 + getTitle(['with' => 'id']) ?> 管理

+getProblemConf() ?> +