From 18c501354cb1ae55892ab21a0c95e88c6dae7624 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Fri, 17 Feb 2023 21:46:28 +0800 Subject: [PATCH] refactor(group/manage): users_form --- web/app/controllers/group.php | 2 +- web/app/controllers/group_manage.php | 181 ++++++++------------------- 2 files changed, 55 insertions(+), 128 deletions(-) diff --git a/web/app/controllers/group.php b/web/app/controllers/group.php index d420f38..8ef5880 100644 --- a/web/app/controllers/group.php +++ b/web/app/controllers/group.php @@ -8,7 +8,7 @@ UOJGroup::init(UOJRequest::get('id')) || UOJResponse::page404(); UOJGroup::cur()->userCanView(Auth::user(), ['ensure' => true]); ?> - +
diff --git a/web/app/controllers/group_manage.php b/web/app/controllers/group_manage.php index 4a2e3f1..3e76bb8 100644 --- a/web/app/controllers/group_manage.php +++ b/web/app/controllers/group_manage.php @@ -219,82 +219,44 @@ if ($cur_tab == 'profile') { $hidden_time = new DateTime(); $hidden_time->sub(new DateInterval('P3D')); } elseif ($cur_tab == 'users') { - if (isset($_POST['submit-remove_user']) && $_POST['submit-remove_user'] == 'remove_user') { - $user = UOJUser::query(UOJRequest::post('remove_username')); - - if (!$user) { - dieWithAlert('用户不存在。'); - } - - if (!UOJGroup::cur()->hasUser($user)) { - dieWithAlert('该用户不在小组中。'); - } - - DB::delete([ - "delete from groups_users", - "where", [ - "username" => $user['username'], - "group_id" => UOJGroup::info('id'), - ], - ]); - - dieWithAlert('移除成功!'); - } - - $add_new_user_form = new UOJForm('add_new_user'); - $add_new_user_form->addInput('new_username', [ - 'label' => '用户名', - 'validator_php' => function ($username, &$vdata) { + $users_form = newAddDelCmdForm( + 'users', + function ($username) { $user = UOJUser::query($username); if (!$user) { return '用户不存在。'; } - if (UOJGroup::cur()->hasUser($user)) { - return '该用户已经在小组中'; - } - - $vdata['username'] = $user['username']; - return ''; }, - ]); - $add_new_user_form->config['submit_button']['class'] = 'btn btn-secondary'; - $add_new_user_form->config['submit_button']['text'] = '添加'; - $add_new_user_form->handle = function (&$vdata) { - DB::insert([ - "insert into groups_users", - DB::bracketed_fields(["group_id", "username"]), - "values", - DB::tuple([ - UOJGroup::info('id'), - $vdata['username'] - ]), - ]); - - dieWithJsonData(['status' => 'success', 'message' => '已将用户名为 ' . $vdata['username'] . ' 的用户添加到本小组。']); - }; - $add_new_user_form->setAjaxSubmit(<< UOJGroup::info('id'), + "username" => $username, + ], + ]); } - - $(window).scrollTop(0); - } - EOD); - $add_new_user_form->runAtServer(); + }, + null, + [ + 'help' => '命令格式:命令一行一个,+baoshuo 表示把用户名为 baoshuo 的用户加入小组,-baoshuo 表示把用户名为 baoshuo 的用户从小组中移除。', + ] + ); + $users_form->runAtServer(); } ?> @@ -429,67 +391,32 @@ if ($cur_tab == 'profile') {
-
- -
-
-
- UOJGroup::info('id')], - 'order by username asc', - << - 用户名 - 操作 - - EOD, - function ($row) { - echo HTML::tag_begin('tr'); - echo HTML::tag('td', [], UOJUser::getLink($row['username'])); - echo ''; - echo '
' - . HTML::hiddenToken() - . '' - . '' - . '
'; - echo ''; - echo HTML::tag_end('tr'); - }, - [ - 'page_len' => 10, - 'div_classes' => ['table-responsive'], - 'table_classes' => ['table', 'align-middle'], - ] - ); - ?> -
-
- -
-
- printHTML() ?> -
-
-
注意事项
-
    -
  • 添加用户前请确认用户名是否正确以免带来不必要的麻烦。
  • -
  • 用户被添加到小组后将自动被加入组内的所有作业排行中。
  • -
-
-
-
-
+ UOJGroup::info('id')], + 'order by username asc', + << + 用户名 + + EOD, + function ($row) { + echo HTML::tag_begin('tr'); + echo HTML::tag('td', [], UOJUser::getLink($row['username'])); + echo HTML::tag_end('tr'); + }, + [ + 'page_len' => 10, + 'div_classes' => ['table-responsive'], + 'table_classes' => ['table', 'align-middle'], + ] + ); + ?> + + printHTML() ?>