refactor(web/group/assignment): use bootstrap5 and display score
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Baoshuo Ren 2022-10-17 20:42:32 +08:00
parent 62010fd9e0
commit 0568633496
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
9 changed files with 140 additions and 103 deletions

View File

@ -1,97 +0,0 @@
<?php
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
redirectToLogin();
}
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
become403Page();
}
requirePHPLib('form');
$assignment_id = $_GET['id'];
$assignment = queryAssignment($assignment_id);
if (!$assignment) {
become404Page();
}
$group = queryGroup($assignment['group_id']);
$list = queryProblemList($assignment['list_id']);
?>
<?php echoUOJPageHeader(UOJLocale::get('assignments')) ?>
<h2 style="margin-top: 24px">作业详细信息</h2>
<div class="row">
<div class="col-sm-12 mt-4">
<h5>作业信息</h5>
<ul>
<li><b>小组</b><a href="/group/<?= $group['id'] ?>"><?= $group['title'] ?></a></li>
<li><b>题单</b><a href="/problem_list/<?= $list['id'] ?>"><?= $list['title'] ?></a></li>
<li><b>创建时间</b><?= $assignment['create_time'] ?></li>
<li><b>截止时间</b><?= $assignment['deadline'] ?></li>
</ul>
</div>
</div>
<div class="row">
<div class="col-sm-12 mt-4">
<h5>完成状况</h5>
<?php
$query = DB::query("select problem_id from lists_problems where list_id = {$list['id']}");
$problem_ids = [];
while ($row = DB::fetch($query)) {
$problem_ids[] = $row['problem_id'];
}
$query = DB::query("select a.username as username, c.problem_id as problem_id from user_info a inner join groups_users b on a.username = b.username and b.group_id = {$group['id']} inner join best_ac_submissions c on a.username = c.submitter inner join lists_problems d on c.problem_id = d.problem_id and d.list_id = {$list['id']}");
$finished = [];
while ($row = DB::fetch($query)) {
$username = $row['username'];
$problem_id = $row['problem_id'];
if (!isset($finished[$username])) {
$finished[$username] = [];
}
$finished[$username][$problem_id] = 1;
}
$header_row = '';
$header_row .= '<tr>';
$header_row .= '<th style="width: 14em;">'.UOJLocale::get('username').'</th>';
foreach ($problem_ids as $problem_id) {
$header_row .= '<th style="width: 2em;">' . "<a href=\"/problem/{$problem_id}\">#{$problem_id}</a>" . '</th>';
}
$header_row .= '</tr>';
$print_row = function($row) use ($problem_ids, $finished) {
$username = $row['username'];
echo '<tr>';
echo '<td>' . getUserLink($username) . '</td>';
foreach ($problem_ids as $problem_id) {
if (!isset($finished[$username]) || !isset($finished[$username][$problem_id])) {
echo '<td class="failed"><span class="glyphicon glyphicon-remove"></span></td>';
} else {
echo '<td class="success"><span class="glyphicon glyphicon-ok"></span></td>';
}
}
echo '</tr>';
};
$from = "user_info a inner join groups_users b on (b.group_id = {$group['id']} and a.username = b.username)";
$col_names = array('a.username as username');
$cond = "1";
$tail = "order by a.username asc";
$config = array('page_len' => 100);
echoLongTable($col_names, $from, $cond, $tail, $header_row, $print_row, $config);
?>
</div>
</div>
<?php echoUOJPageFooter() ?>

View File

@ -142,7 +142,7 @@
if (isset($REQUIRE_LIB['bootstrap5'])) {
echo ' class="text-decoration-none" ';
}
echo ' href="/assignment/', $ass['id'], '">查看完成情况</a>)';
echo ' href="/group/',$group['id'],'/assignment/', $ass['list_id'], '">查看完成情况</a>)';
echo '</li>';
}

View File

@ -0,0 +1,132 @@
<?php
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
redirectToLogin();
}
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
become403Page();
}
requirePHPLib('form');
requireLib('bootstrap5');
$group_id = $_GET['id'];
if (!validateUInt($group_id)) {
become404Page();
}
$list_id = $_GET['list_id'];
if (!validateUInt($list_id)) {
become404Page();
}
$assignment = queryAssignmentByGroupListID($group_id, $list_id);
if (!$assignment) {
become404Page();
}
$group = queryGroup($assignment['group_id']);
$list = queryProblemList($assignment['list_id']);
?>
<?php echoUOJPageHeader(UOJLocale::get('assignments')) ?>
<div class="row">
<!-- left col -->
<div class="col-lg-9">
<h1 class="h2">
<small class="fs-4">作业:</small><?= $list['title'] ?>
</h1>
<ul class="mt-3">
<li>所属小组:<a class="text-decoration-none" href="<?= HTML::url('/group/'.$group['id']) ?>"><?= $group['title'] ?></a></li>
<li>开始时间:<?= $assignment['create_time'] ?></li>
<li>结束时间:<?= $assignment['deadline'] ?></li>
</ul>
<?php
$query = DB::query("select problem_id from lists_problems where list_id = {$list['id']}");
$problem_ids = [];
while ($row = DB::fetch($query)) {
$problem_ids[] = $row['problem_id'];
}
$header_row = '';
$header_row .= '<tr>';
$header_row .= '<th style="width: 10em;">'.UOJLocale::get('username').'</th>';
$header_row .= '<th style="width: 2em;">'.UOJLocale::get('contests::total score').'</th>';
foreach ($problem_ids as $problem_id) {
$header_row .= '<th style="width: 2em;">' . '<a class="text-decoration-none" href="'.HTML::url('/problem/'.$problem_id).'">#'.$problem_id.'</a>' . '</th>';
}
$header_row .= '</tr>';
$print_row = function($row) use ($problem_ids) {
$username = $row['username'];
$scores = [];
$sum = 0;
$total_score = count($problem_ids) * 100;
$query = DB::query("SELECT MAX(id), problem_id, MAX(score) FROM submissions WHERE (problem_id, score) IN (SELECT problem_id, MAX(score) FROM submissions WHERE submitter = '{$username}' AND problem_id IN (".implode(',', $problem_ids).") GROUP BY problem_id) AND submitter = '{$username}' GROUP BY problem_id");
while ($row = DB::fetch($query)) {
$scores[$row['problem_id']] = [
'submission_id' => $row['MAX(id)'],
'score' => $row['MAX(score)'],
];
$sum += $row['MAX(score)'];
}
if ($sum == $total_score) {
echo '<tr class="table-success">';
} else {
echo '<tr>';
}
echo '<td>' . getUserLink($username) . '</td>';
echo '<td>';
echo '<span class="uoj-score" data-max="', $total_score, '">', $sum, '</span>';
echo '</td>';
foreach ($problem_ids as $problem_id) {
if (!isset($scores[$problem_id])) {
echo '<td>';
} else {
if ($scores[$problem_id]['score'] == 100) {
echo '<td class="table-success">';
} else {
echo '<td>';
}
echo '<a class="text-decoration-none uoj-score" href="'.HTML::url('/submission/'.$scores[$problem_id]['submission_id']).'">'.$scores[$problem_id]['score'].'</a>';
}
echo '</td>';
}
echo '</tr>';
};
$from = "user_info a inner join groups_users b on (b.group_id = {$group['id']} and a.username = b.username)";
$col_names = array('a.username as username');
$cond = "1";
$tail = "order by a.username asc";
$config = [
'page_len' => 50,
'div_classes' => ['card', 'my-3', 'table-responsive', 'text-center'],
'table_classes' => ['table', 'uoj-table', 'mb-0'],
];
echoLongTable($col_names, $from, $cond, $tail, $header_row, $print_row, $config);
?>
<!-- end left col -->
</div>
<aside class="col mt-3 mt-lg-0">
<!-- right col -->
<?php uojIncludeView('sidebar', ['assignments_hidden' => true]); ?>
</aside>
</div>
<?php echoUOJPageFooter() ?>

View File

@ -260,7 +260,7 @@
if (isset($REQUIRE_LIB['bootstrap5'])) {
echo ' class="text-decoration-none" ';
}
echo ' href="/assignment/', $ass['id'], '">查看完成情况</a>)';
echo ' href="/group/',$group['id'],'/assignment/', $ass['list_id'], '">查看完成情况</a>)';
echo '</li>';
}

View File

@ -146,7 +146,7 @@ function queryGroupAssignments($group_id) {
return DB::selectAll("select a.id as id, a.list_id as list_id, a.create_time as create_time, a.deadline as deadline, b.title from assignments a left join lists b on a.list_id = b.id where a.group_id = $group_id order by a.deadline asc", MYSQLI_ASSOC);
}
function queryGroupActiveAssignments($group_id) {
return DB::selectAll("select a.id as id, a.list_id as list_id, a.create_time as create_time, a.deadline as deadline, b.title from assignments a left join lists b on a.list_id = b.id where a.group_id = $group_id and a.deadline > addtime(now(), '-168:00:00') order by a.deadline asc", MYSQLI_ASSOC);
return DB::selectAll("select a.id as id, a.group_id as group_id, a.list_id as list_id, a.create_time as create_time, a.deadline as deadline, b.title from assignments a left join lists b on a.list_id = b.id where a.group_id = $group_id and a.deadline > addtime(now(), '-168:00:00') order by a.deadline asc", MYSQLI_ASSOC);
}
function queryAssignment($id) {

View File

@ -15,6 +15,7 @@ return [
'pending final test' => 'pending final test',
'final testing' => 'final testing',
'ended' => 'ended',
'total score' => 'total score',
'add new contest' => 'Add new contest',
'contest dashboard' => 'Dashboard',
'contest submissions' => 'Submissions',

View File

@ -15,6 +15,7 @@ return [
'pending final test' => '等待评测',
'final testing' => '正在评测',
'ended' => '已结束',
'total score' => '总分',
'add new contest' => '添加比赛',
'contest dashboard' => '比赛主页',
'contest submissions' => '提交记录',

View File

@ -3,6 +3,7 @@
Route::pattern('username', '[a-zA-Z0-9_]{1,20}');
Route::pattern('id', '[1-9][0-9]{0,9}');
Route::pattern('contest_id', '[1-9][0-9]{0,9}');
Route::pattern('list_id', '[1-9][0-9]{0,9}');
Route::pattern('tab', '\S{1,20}');
Route::pattern('rand_str_id', '[0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]{20}');
Route::pattern('image_name', '[0-9a-z]{1,20}');
@ -49,8 +50,7 @@ Route::group([
Route::any('/groups', '/groups.php');
Route::any('/group/{id}', '/group.php');
Route::any('/group/{id}/manage', '/group_manage.php');
Route::any('/assignment/{id}', '/assignment.php');
Route::any('/group/{id}/assignment/{list_id}', '/group_assignment.php');
Route::any('/blogs', '/blogs.php');
if (UOJConfig::$data['switch']['blog-domain-mode'] != 3) {

View File

@ -57,7 +57,7 @@
$create_time = DateTime::createFromFormat('Y-m-d H:i:s', $assignment['create_time']);
$now = new DateTime();
?>
<a href="<?= HTML::url('/assignment/'.$assignment['id']) ?>" class="fw-bold text-decoration-none">
<a href="<?= HTML::url('/group/'.$assignment['group_id'].'/assignment/'.$assignment['list_id']) ?>" class="fw-bold text-decoration-none">
<?= $assignment['title'] ?>
<?php if ($deadline < $now): ?>
<sup class="fw-normal text-danger">overdue</sup>