mirror of
https://github.com/renbaoshuo/S2OJ.git
synced 2024-11-10 05:18:42 +00:00
refactor(contest/manage): uoj_form_v2
This commit is contained in:
parent
3b1def5754
commit
87013054c4
@ -37,13 +37,13 @@ if (!isset($tabs_info[$cur_tab])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($cur_tab == 'profile') {
|
if ($cur_tab == 'profile') {
|
||||||
$profile_form = new UOJBs4Form('time');
|
$profile_form = new UOJForm('time');
|
||||||
$profile_form->addVInput(
|
$profile_form->addInput(
|
||||||
'name',
|
'name',
|
||||||
'text',
|
[
|
||||||
'比赛标题',
|
'label' => '比赛标题',
|
||||||
$contest['name'],
|
'default_value' => UOJContest::info('name'),
|
||||||
function ($name, &$vdata) {
|
'validator_php' => function ($name, &$vdata) {
|
||||||
if ($name == '') {
|
if ($name == '') {
|
||||||
return '标题不能为空';
|
return '标题不能为空';
|
||||||
}
|
}
|
||||||
@ -62,47 +62,48 @@ if ($cur_tab == 'profile') {
|
|||||||
|
|
||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
null
|
],
|
||||||
);
|
);
|
||||||
$profile_form->addVInput(
|
$profile_form->addInput(
|
||||||
'start_time',
|
'start_time',
|
||||||
'text',
|
[
|
||||||
'开始时间',
|
'div_class' => 'mt-3',
|
||||||
$contest['start_time_str'],
|
'label' => '开始时间',
|
||||||
function ($str, &$vdata) {
|
'default_value' => UOJContest::info('start_time_str'),
|
||||||
|
'validator_php' => function ($start_time, &$vdata) {
|
||||||
try {
|
try {
|
||||||
$vdata['start_time'] = new DateTime($str);
|
$vdata['start_time'] = new DateTime($start_time);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return '无效时间格式';
|
return '无效时间格式';
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
null
|
]
|
||||||
);
|
);
|
||||||
$profile_form->addVInput(
|
$profile_form->addInput(
|
||||||
'last_min',
|
'last_min',
|
||||||
'text',
|
[
|
||||||
'时长(单位:分钟)',
|
'div_class' => 'mt-3',
|
||||||
$contest['last_min'],
|
'label' => '时长',
|
||||||
function ($str, &$vdata) {
|
'help' => '单位为分钟。',
|
||||||
if (!validateUInt($str)) {
|
'default_value' => UOJContest::info('last_min'),
|
||||||
|
'validator_php' => function ($last_min, &$vdata) {
|
||||||
|
if (!validateUInt($last_min)) {
|
||||||
return '必须为一个整数';
|
return '必须为一个整数';
|
||||||
}
|
}
|
||||||
|
$vdata['last_min'] = $last_min;
|
||||||
$vdata['last_min'] = $str;
|
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
null
|
]
|
||||||
);
|
);
|
||||||
$profile_form->handle = function (&$vdata) use ($contest) {
|
$profile_form->handle = function (&$vdata) {
|
||||||
DB::update([
|
DB::update([
|
||||||
"update contests",
|
"update contests",
|
||||||
"set", [
|
"set", [
|
||||||
"name" => $vdata['name'],
|
"name" => $vdata['name'],
|
||||||
"start_time" => $vdata['start_time']->format('Y-m-d H:i:s'),
|
"start_time" => UOJTime::time2str($vdata['start_time']),
|
||||||
"last_min" => $vdata['last_min'],
|
"last_min" => $vdata['last_min'],
|
||||||
], "where", ["id" => $contest['id']]
|
], "where", ["id" => UOJContest::info('id')]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
dieWithJsonData(['status' => 'success', 'message' => '修改成功']);
|
dieWithJsonData(['status' => 'success', 'message' => '修改成功']);
|
||||||
@ -162,13 +163,12 @@ EOD);
|
|||||||
dieWithAlert('移除成功!');
|
dieWithAlert('移除成功!');
|
||||||
}
|
}
|
||||||
|
|
||||||
$add_problem_form = new UOJBs4Form('add_problem');
|
$add_problem_form = new UOJForm('add_problem');
|
||||||
$add_problem_form->addVInput(
|
$add_problem_form->addInput(
|
||||||
'problem_id',
|
'problem_id',
|
||||||
'text',
|
[
|
||||||
'题目 ID',
|
'label' => '题目 ID',
|
||||||
'',
|
'validator_php' => function ($problem_id, &$vdata) {
|
||||||
function ($problem_id, &$vdata) {
|
|
||||||
$problem = UOJProblem::query($problem_id);
|
$problem = UOJProblem::query($problem_id);
|
||||||
if (!$problem) {
|
if (!$problem) {
|
||||||
return '题目不存在。';
|
return '题目不存在。';
|
||||||
@ -186,27 +186,35 @@ EOD);
|
|||||||
|
|
||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
null
|
]
|
||||||
);
|
);
|
||||||
$add_problem_form->addVSelect('judge_config', [
|
$add_problem_form->addSelect('judge_config', [
|
||||||
|
'div_class' => 'mt-3',
|
||||||
|
'label' => '评测设置',
|
||||||
|
'options' => [
|
||||||
'default' => '默认',
|
'default' => '默认',
|
||||||
'sample' => '只测样例',
|
'sample' => '只测样例',
|
||||||
'no-details' => '测试全部数据,对于每个测试点显示得分但不显示详情',
|
'no-details' => '测试全部数据,对于每个测试点显示得分但不显示详情',
|
||||||
'full' => '测试全部数据',
|
'full' => '测试全部数据',
|
||||||
], '评测设置', 'default');
|
],
|
||||||
$add_problem_form->addVCheckboxes('bonus', ['0' => '否', '1' => '是'], '是否为 bonus 题(ACM 赛制)', '0');
|
'default_value' => 'default',
|
||||||
|
]);
|
||||||
|
$add_problem_form->addCheckbox('bonus', [
|
||||||
|
'div_class' => 'form-check mt-3',
|
||||||
|
'label' => '是否为 bonus 题(针对 ACM 赛制)',
|
||||||
|
]);
|
||||||
$add_problem_form->handle = function (&$vdata) use ($contest) {
|
$add_problem_form->handle = function (&$vdata) use ($contest) {
|
||||||
$level = DB::selectFirst([
|
$level = DB::selectSingle([
|
||||||
"select", "max(level)",
|
"select", "max(level)",
|
||||||
"from", "contests_problems",
|
"from", "contests_problems",
|
||||||
"where", [
|
"where", [
|
||||||
"contest_id" => $contest['id'],
|
"contest_id" => UOJContest::info('id'),
|
||||||
]
|
]
|
||||||
])["max(level)"];
|
]);
|
||||||
DB::insert([
|
DB::insert([
|
||||||
"insert ignore into contests_problems",
|
"insert ignore into contests_problems",
|
||||||
"(contest_id, problem_id, level)",
|
"(contest_id, problem_id, level)",
|
||||||
"values", DB::tuple([$contest['id'], $vdata['problem_id'], $level + 1])
|
"values", DB::tuple([UOJContest::info('id'), $vdata['problem_id'], $level + 1])
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$judge_type = $_POST['judge_config'];
|
$judge_type = $_POST['judge_config'];
|
||||||
@ -220,13 +228,13 @@ EOD);
|
|||||||
DB::update([
|
DB::update([
|
||||||
"update contests",
|
"update contests",
|
||||||
"set", ["extra_config" => $esc_extra_config],
|
"set", ["extra_config" => $esc_extra_config],
|
||||||
"where", ["id" => $contest['id']]
|
"where", ["id" => UOJContest::info('id')]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
dieWithJsonData(['status' => 'success', 'message' => "题目 #{$vdata['problem_id']} 添加成功!"]);
|
dieWithJsonData(['status' => 'success', 'message' => "题目 #{$vdata['problem_id']} 添加成功!"]);
|
||||||
};
|
};
|
||||||
$add_problem_form->submit_button_config['text'] = '添加';
|
$add_problem_form->config['submit_button']['text'] = '添加';
|
||||||
$add_problem_form->submit_button_config['class_str'] = 'btn btn-secondary mt-3';
|
$add_problem_form->config['submit_button']['class'] = 'btn btn-secondary mt-3';
|
||||||
$add_problem_form->setAjaxSubmit(<<<EOD
|
$add_problem_form->setAjaxSubmit(<<<EOD
|
||||||
function(res) {
|
function(res) {
|
||||||
if (res.status === 'success') {
|
if (res.status === 'success') {
|
||||||
@ -260,7 +268,6 @@ EOD);
|
|||||||
dieWithAlert('用户不是这场比赛的管理员。');
|
dieWithAlert('用户不是这场比赛的管理员。');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DB::delete([
|
DB::delete([
|
||||||
"delete from contests_permissions",
|
"delete from contests_permissions",
|
||||||
"where", [
|
"where", [
|
||||||
@ -271,13 +278,12 @@ EOD);
|
|||||||
dieWithAlert('移除成功!');
|
dieWithAlert('移除成功!');
|
||||||
}
|
}
|
||||||
|
|
||||||
$add_manager_form = new UOJBs4Form('add_manager');
|
$add_manager_form = new UOJForm('add_manager');
|
||||||
$add_manager_form->addVInput(
|
$add_manager_form->addInput(
|
||||||
'username',
|
'username',
|
||||||
'text',
|
[
|
||||||
'用户名',
|
'label' => '用户名',
|
||||||
'',
|
'validator_php' => function ($username, &$vdata) {
|
||||||
function ($username, &$vdata) use ($contest) {
|
|
||||||
$user = UOJUser::query($username);
|
$user = UOJUser::query($username);
|
||||||
|
|
||||||
if (!$user) {
|
if (!$user) {
|
||||||
@ -292,19 +298,20 @@ EOD);
|
|||||||
|
|
||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
null
|
]
|
||||||
);
|
);
|
||||||
$add_manager_form->handle = function (&$vdata) use ($contest) {
|
$add_manager_form->handle = function (&$vdata) {
|
||||||
DB::insert([
|
DB::insert([
|
||||||
"insert into contests_permissions",
|
"insert into contests_permissions",
|
||||||
"(contest_id, username)",
|
DB::bracketed_fields(["contest_id", "username"]),
|
||||||
"values", DB::tuple([$contest['id'], $vdata['username']])
|
"values",
|
||||||
|
DB::tuple([UOJContest::info('id'), $vdata['username']])
|
||||||
]);
|
]);
|
||||||
|
|
||||||
dieWithJsonData(['status' => 'success', 'message' => '已将用户名为 ' . $vdata['username'] . ' 的用户设置为本场比赛的管理者。']);
|
dieWithJsonData(['status' => 'success', 'message' => '已将用户名为 ' . $vdata['username'] . ' 的用户设置为本场比赛的管理者。']);
|
||||||
};
|
};
|
||||||
$add_manager_form->submit_button_config['text'] = '添加';
|
$add_manager_form->config['submit_button']['text'] = '添加';
|
||||||
$add_manager_form->submit_button_config['class_str'] = 'btn btn-secondary mt-3';
|
$add_manager_form->config['submit_button']['class'] = 'btn btn-secondary mt-3';
|
||||||
$add_manager_form->setAjaxSubmit(<<<EOD
|
$add_manager_form->setAjaxSubmit(<<<EOD
|
||||||
function(res) {
|
function(res) {
|
||||||
if (res.status === 'success') {
|
if (res.status === 'success') {
|
||||||
@ -326,83 +333,68 @@ function(res) {
|
|||||||
EOD);
|
EOD);
|
||||||
$add_manager_form->runAtServer();
|
$add_manager_form->runAtServer();
|
||||||
} elseif ($cur_tab == 'others') {
|
} elseif ($cur_tab == 'others') {
|
||||||
$version_form = new UOJBs4Form('version');
|
$rule_form = new UOJForm('basic_rule');
|
||||||
$version_form->addVSelect('standings_version', [
|
$rule_form->addSelect('basic_rule', [
|
||||||
'1' => '1',
|
'label' => '比赛类型',
|
||||||
'2' => '2',
|
'options' => [
|
||||||
], '比赛排名版本', $contest['extra_config']['standings_version']);
|
|
||||||
$version_form->handle = function () use ($contest) {
|
|
||||||
$contest['extra_config']['standings_version'] = $_POST['standings_version'];
|
|
||||||
$esc_extra_config = json_encode($contest['extra_config']);
|
|
||||||
DB::update([
|
|
||||||
"update contests",
|
|
||||||
"set", ["extra_config" => $esc_extra_config],
|
|
||||||
"where", ["id" => $contest['id']],
|
|
||||||
]);
|
|
||||||
|
|
||||||
dieWithJsonData(['status' => 'success', 'message' => '修改成功']);
|
|
||||||
};
|
|
||||||
$version_form->setAjaxSubmit(<<<EOD
|
|
||||||
function(res) {
|
|
||||||
if (res.status === 'success') {
|
|
||||||
$('#version-result-alert')
|
|
||||||
.html('修改成功!')
|
|
||||||
.addClass('alert-success')
|
|
||||||
.removeClass('alert-danger')
|
|
||||||
.show();
|
|
||||||
} else {
|
|
||||||
$('#version-result-alert')
|
|
||||||
.html('修改失败。' + (res.message || ''))
|
|
||||||
.removeClass('alert-success')
|
|
||||||
.addClass('alert-danger')
|
|
||||||
.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
$(window).scrollTop(0);
|
|
||||||
}
|
|
||||||
EOD);
|
|
||||||
$version_form->runAtServer();
|
|
||||||
|
|
||||||
$rule_form = new UOJBs4Form('basic_rule');
|
|
||||||
$rule_form->addVSelect('basic_rule', [
|
|
||||||
'OI' => 'OI',
|
'OI' => 'OI',
|
||||||
'IOI' => 'IOI',
|
'IOI' => 'IOI',
|
||||||
'ACM' => 'ACM',
|
'ACM' => 'ACM',
|
||||||
], '比赛类型', $contest['extra_config']['basic_rule']);
|
],
|
||||||
$rule_form->addVSelect('free_registration', [
|
'default_value' => $contest['extra_config']['basic_rule'],
|
||||||
|
]);
|
||||||
|
$rule_form->addSelect('free_registration', [
|
||||||
|
'div_class' => 'mt-3',
|
||||||
|
'label' => '报名方式',
|
||||||
|
'options' => [
|
||||||
1 => '所有人都可以自由报名',
|
1 => '所有人都可以自由报名',
|
||||||
0 => '只能由管理员帮选手报名'
|
0 => '只能由管理员帮选手报名'
|
||||||
], "报名方式", $contest['extra_config']['free_registration']);
|
],
|
||||||
$rule_form->addVCheckboxes('extra_registration', [
|
'default_value' => $contest['extra_config']['free_registration'],
|
||||||
'0' => '禁止',
|
]);
|
||||||
'1' => '允许'
|
$rule_form->addCheckbox('extra_registration', [
|
||||||
], '是否允许额外报名', isset($contest['extra_config']['extra_registration']) ? $contest['extra_config']['extra_registration'] : '1');
|
'div_class' => 'form-check mt-3',
|
||||||
$rule_form->addVSelect('individual_or_team', [
|
'label' => '允许额外报名',
|
||||||
|
'checked' => $contest['extra_config']['extra_registration'] ?: true,
|
||||||
|
]);
|
||||||
|
$rule_form->addSelect('individual_or_team', [
|
||||||
|
'div_class' => 'mt-3',
|
||||||
|
'label' => '个人赛/团体赛',
|
||||||
|
'options' => [
|
||||||
'individual' => '个人赛',
|
'individual' => '个人赛',
|
||||||
'team' => '团体赛'
|
'team' => '团体赛',
|
||||||
], "个人赛/团体赛", $contest['extra_config']['individual_or_team']);
|
],
|
||||||
$rule_form->addVInput(
|
'default_value' => $contest['extra_config']['individual_or_team'],
|
||||||
'max_n_submissions_per_problem',
|
]);
|
||||||
'text',
|
$rule_form->addInput('max_n_submissions_per_problem', [
|
||||||
'每题最高提交次数(-1 表示不限制)',
|
'div_class' => 'mt-3',
|
||||||
$contest['extra_config']['max_n_submissions_per_problem'],
|
'label' => '每题最高提交次数',
|
||||||
function ($str) {
|
'type' => 'number',
|
||||||
|
'default_value' => $contest['extra_config']['max_n_submissions_per_problem'],
|
||||||
|
'help' => '设为 -1 表示无限制(系统默认频率限制仍有效)。',
|
||||||
|
'validator_php' => function ($str) {
|
||||||
return !validateUInt($str) && $str !== '-1' ? '必须为一个非负整数或 -1' : '';
|
return !validateUInt($str) && $str !== '-1' ? '必须为一个非负整数或 -1' : '';
|
||||||
},
|
},
|
||||||
null
|
]);
|
||||||
);
|
$rule_form->addSelect('standings_version', [
|
||||||
|
'div_class' => 'mt-3',
|
||||||
|
'label' => '比赛排名版本',
|
||||||
|
'options' => [1 => 1, 2 => 2],
|
||||||
|
'default_value' => $contest['extra_config']['standings_version'],
|
||||||
|
]);
|
||||||
$rule_form->handle = function () use ($contest) {
|
$rule_form->handle = function () use ($contest) {
|
||||||
$contest['extra_config']['basic_rule'] = $_POST['basic_rule'];
|
$contest['extra_config']['basic_rule'] = $_POST['basic_rule'];
|
||||||
$contest['extra_config']['free_registration'] = (int)$_POST['free_registration'];
|
$contest['extra_config']['free_registration'] = (int)$_POST['free_registration'];
|
||||||
$contest['extra_config']['individual_or_team'] = $_POST['individual_or_team'];
|
$contest['extra_config']['individual_or_team'] = $_POST['individual_or_team'];
|
||||||
$contest['extra_config']['max_n_submissions_per_problem'] = (int)$_POST['max_n_submissions_per_problem'];
|
$contest['extra_config']['max_n_submissions_per_problem'] = (int)$_POST['max_n_submissions_per_problem'];
|
||||||
$contest['extra_config']['extra_registration'] = (int)$_POST['extra_registration'];
|
$contest['extra_config']['extra_registration'] = (int)$_POST['extra_registration'];
|
||||||
|
$contest['extra_config']['standings_version'] = (int)$_POST['standings_version'];
|
||||||
|
|
||||||
$esc_extra_config = json_encode($contest['extra_config']);
|
$esc_extra_config = json_encode($contest['extra_config']);
|
||||||
DB::update([
|
DB::update([
|
||||||
"update contests",
|
"update contests",
|
||||||
"set", ["extra_config" => $esc_extra_config],
|
"set", ["extra_config" => $esc_extra_config],
|
||||||
"where", ["id" => $contest['id']]
|
"where", ["id" => UOJContest::info('id')]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
dieWithJsonData(['status' => 'success', 'message' => '修改成功']);
|
dieWithJsonData(['status' => 'success', 'message' => '修改成功']);
|
||||||
@ -722,9 +714,6 @@ EOD);
|
|||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link active" href="#type" data-bs-toggle="tab" data-bs-target="#type">规则</a>
|
<a class="nav-link active" href="#type" data-bs-toggle="tab" data-bs-target="#type">规则</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link" href="#standings-version" data-bs-toggle="tab" data-bs-target="#standings-version">排名版本</a>
|
|
||||||
</li>
|
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" href="#blogs" data-bs-toggle="tab" data-bs-target="#blogs">比赛资料</a>
|
<a class="nav-link" href="#blogs" data-bs-toggle="tab" data-bs-target="#blogs">比赛资料</a>
|
||||||
</li>
|
</li>
|
||||||
@ -751,20 +740,6 @@ EOD);
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="tab-pane" id="standings-version">
|
|
||||||
<div id="version-result-alert" class="alert" role="alert" style="display: none"></div>
|
|
||||||
<div class="row row-cols-1 row-cols-md-2">
|
|
||||||
<div class="col">
|
|
||||||
<?php $version_form->printHTML(); ?>
|
|
||||||
</div>
|
|
||||||
<div class="col mt-3 mt-md-0">
|
|
||||||
<h5>注意事项</h5>
|
|
||||||
<ul class="mb-0">
|
|
||||||
<li>正常情况下无需调整此项设置。</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="tab-pane" id="blogs">
|
<div class="tab-pane" id="blogs">
|
||||||
<div id="blogs-result-alert" class="alert" role="alert" style="display: none"></div>
|
<div id="blogs-result-alert" class="alert" role="alert" style="display: none"></div>
|
||||||
<div class="row row-cols-1 row-cols-md-2">
|
<div class="row row-cols-1 row-cols-md-2">
|
||||||
|
@ -130,7 +130,7 @@ class UOJForm {
|
|||||||
'label_class' => 'form-label',
|
'label_class' => 'form-label',
|
||||||
'placeholder' => '',
|
'placeholder' => '',
|
||||||
'help' => '',
|
'help' => '',
|
||||||
'help_class' => '',
|
'help_class' => 'form-text',
|
||||||
'validator_php' => function ($x) {
|
'validator_php' => function ($x) {
|
||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user