refactor: contests list with bs5
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Baoshuo Ren 2022-09-24 12:10:30 +08:00
parent 79d4c3832c
commit 4fa402ec4b
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

View File

@ -5,14 +5,24 @@
become403Page(UOJLocale::get('need login')); become403Page(UOJLocale::get('need login'));
} }
if (!isset($_COOKIE['bootstrap4'])) {
$REQUIRE_LIB['bootstrap5'] = '';
}
$upcoming_contest_name = null; $upcoming_contest_name = null;
$upcoming_contest_href = null; $upcoming_contest_href = null;
$rest_second = 1000000; $rest_second = 1000000;
function echoContest($contest) { function echoContest($contest) {
global $myUser, $upcoming_contest_name, $upcoming_contest_href, $rest_second; global $myUser, $upcoming_contest_name, $upcoming_contest_href, $rest_second, $REQUIRE_LIB;
$a_class = ' ';
if (isset($REQUIRE_LIB['bootstrap5'])) {
$a_class = ' class="text-decoration-none" ';
}
$contest_name_link = <<<EOD $contest_name_link = <<<EOD
<a href="/contest/{$contest['id']}">{$contest['name']}</a> <a $a_class href="/contest/{$contest['id']}">{$contest['name']}</a>
EOD; EOD;
genMoreContestInfo($contest); genMoreContestInfo($contest);
if ($contest['cur_progress'] == CONTEST_NOT_STARTED) { if ($contest['cur_progress'] == CONTEST_NOT_STARTED) {
@ -23,18 +33,18 @@ EOD;
$rest_second = $cur_rest_second; $rest_second = $cur_rest_second;
} }
if ($myUser != null && hasRegistered($myUser, $contest)) { if ($myUser != null && hasRegistered($myUser, $contest)) {
$contest_name_link .= '<sup><a style="color:green">'.UOJLocale::get('contests::registered').'</a></sup>'; $contest_name_link .= '<sup><a '.$a_class.' style="color:green">'.UOJLocale::get('contests::registered').'</a></sup>';
} else { } else {
$contest_name_link .= '<sup><a style="color:red" href="/contest/'.$contest['id'].'/register">'.UOJLocale::get('contests::register').'</a></sup>'; $contest_name_link .= '<sup><a '.$a_class.' style="color:red" href="/contest/'.$contest['id'].'/register">'.UOJLocale::get('contests::register').'</a></sup>';
} }
} elseif ($contest['cur_progress'] == CONTEST_IN_PROGRESS) { } elseif ($contest['cur_progress'] == CONTEST_IN_PROGRESS) {
$contest_name_link .= '<sup><a style="color:blue" href="/contest/'.$contest['id'].'">'.UOJLocale::get('contests::in progress').'</a></sup>'; $contest_name_link .= '<sup><a '.$a_class.' style="color:blue" href="/contest/'.$contest['id'].'">'.UOJLocale::get('contests::in progress').'</a></sup>';
} elseif ($contest['cur_progress'] == CONTEST_PENDING_FINAL_TEST) { } elseif ($contest['cur_progress'] == CONTEST_PENDING_FINAL_TEST) {
$contest_name_link .= '<sup><a style="color:blue" href="/contest/'.$contest['id'].'">'.UOJLocale::get('contests::pending final test').'</a></sup>'; $contest_name_link .= '<sup><a '.$a_class.' style="color:blue" href="/contest/'.$contest['id'].'">'.UOJLocale::get('contests::pending final test').'</a></sup>';
} elseif ($contest['cur_progress'] == CONTEST_TESTING) { } elseif ($contest['cur_progress'] == CONTEST_TESTING) {
$contest_name_link .= '<sup><a style="color:blue" href="/contest/'.$contest['id'].'">'.UOJLocale::get('contests::final testing').'</a></sup>'; $contest_name_link .= '<sup><a '.$a_class.' style="color:blue" href="/contest/'.$contest['id'].'">'.UOJLocale::get('contests::final testing').'</a></sup>';
} elseif ($contest['cur_progress'] == CONTEST_FINISHED) { } elseif ($contest['cur_progress'] == CONTEST_FINISHED) {
$contest_name_link .= '<sup><a style="color:grey" href="/contest/'.$contest['id'].'/standings">'.UOJLocale::get('contests::ended').'</a></sup>'; $contest_name_link .= '<sup><a '.$a_class.'style="color:grey" href="/contest/'.$contest['id'].'/standings">'.UOJLocale::get('contests::ended').'</a></sup>';
} }
$last_hour = round($contest['last_min'] / 60, 2); $last_hour = round($contest['last_min'] / 60, 2);
@ -42,14 +52,25 @@ EOD;
$click_zan_block = getClickZanBlock('C', $contest['id'], $contest['zan']); $click_zan_block = getClickZanBlock('C', $contest['id'], $contest['zan']);
echo '<tr>'; echo '<tr>';
echo '<td>', $contest_name_link, '</td>'; echo '<td>', $contest_name_link, '</td>';
echo '<td>', '<a href="'.HTML::timeanddate_url($contest['start_time'], array('duration' => $contest['last_min'])).'">'.$contest['start_time_str'].'</a>', '</td>'; echo '<td>', '<a'.$a_class.'href="'.HTML::timeanddate_url($contest['start_time'], array('duration' => $contest['last_min'])).'">'.$contest['start_time_str'].'</a>', '</td>';
echo '<td>', UOJLocale::get('hours', $last_hour), '</td>'; echo '<td>', UOJLocale::get('hours', $last_hour), '</td>';
echo '<td>', '<a href="/contest/'.$contest['id'].'/registrants"><span class="glyphicon glyphicon-user"></span> &times;'.$contest['player_num'].'</a>', '</td>'; echo '<td>', '<a'.$a_class.'href="/contest/'.$contest['id'].'/registrants"><span class="glyphicon glyphicon-user"></span> &times;'.$contest['player_num'].'</a>', '</td>';
echo '<td>', '<div class="text-left">'.$click_zan_block.'</div>', '</td>'; echo '<td>', '<div class="text-left">'.$click_zan_block.'</div>', '</td>';
echo '</tr>'; echo '</tr>';
} }
?> ?>
<?php echoUOJPageHeader(UOJLocale::get('contests')) ?> <?php echoUOJPageHeader(UOJLocale::get('contests')) ?>
<?php
if (isSuperUser($myUser)) {
if (isset($REQUIRE_LIB['bootstrap5'])) {
echo '<div class="text-end">';
} else {
echo '<div class="text-right">';
}
echo '<a href="/contest/new" class="btn btn-primary">'.UOJLocale::get('contests::add new contest').'</a>';
echo '</div>';
}
?>
<h4><?= UOJLocale::get('contests::current or upcoming contests') ?></h4> <h4><?= UOJLocale::get('contests::current or upcoming contests') ?></h4>
<?php <?php
$table_header = ''; $table_header = '';
@ -60,16 +81,22 @@ EOD;
$table_header .= '<th style="width:100px;">'.UOJLocale::get('contests::the number of registrants').'</th>'; $table_header .= '<th style="width:100px;">'.UOJLocale::get('contests::the number of registrants').'</th>';
$table_header .= '<th style="width:180px;">'.UOJLocale::get('appraisal').'</th>'; $table_header .= '<th style="width:180px;">'.UOJLocale::get('appraisal').'</th>';
$table_header .= '</tr>'; $table_header .= '</tr>';
$table_config = array('page_len' => 40);
if (isset($REQUIRE_LIB['bootstrap5'])) {
$table_config['div_classes'] = array('card', 'mb-3');
$table_config['table_classes'] = array('table', 'uoj-table', 'mb-0');
}
echoLongTable(array('*'), 'contests', "status != 'finished'", 'order by start_time desc, id desc', $table_header, echoLongTable(array('*'), 'contests', "status != 'finished'", 'order by start_time desc, id desc', $table_header,
echoContest, echoContest,
array('page_len' => 40) $table_config
); );
if ($rest_second <= 86400) { if ($rest_second <= 86400) {
$notification = json_encode($upcoming_contest_name . " 已经开始了。是否要跳转到比赛页面?"); $notification = json_encode($upcoming_contest_name . " 已经开始了。是否要跳转到比赛页面?");
echo <<<EOD echo <<<EOD
<div class="text-center bot-buffer-lg"> <div class="text-center bot-buffer-lg">
<div class="text-warning">$upcoming_contest_name 倒计时</div> <div class="text-secondary">$upcoming_contest_name 倒计时</div>
<div id="contest-countdown"></div> <div id="contest-countdown"></div>
<script type="text/javascript"> <script type="text/javascript">
$('#contest-countdown').countdown($rest_second, function() { $('#contest-countdown').countdown($rest_second, function() {
@ -87,16 +114,7 @@ EOD;
<?php <?php
echoLongTable(array('*'), 'contests', "status = 'finished'", 'order by start_time desc, id desc', $table_header, echoLongTable(array('*'), 'contests', "status = 'finished'", 'order by start_time desc, id desc', $table_header,
echoContest, echoContest,
array('page_len' => 40, $table_config
'print_after_table' => function() {
global $myUser;
if (isSuperUser($myUser)) {
echo '<div class="text-right">';
echo '<a href="/contest/new" class="btn btn-primary">'.UOJLocale::get('contests::add new contest').'</a>';
echo '</div>';
}
}
)
); );
?> ?>
<?php echoUOJPageFooter() ?> <?php echoUOJPageFooter() ?>