refactor: hack detail page with bs5
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Baoshuo Ren 2022-09-25 10:44:33 +08:00
parent 29a1b26762
commit 7aa51e889a
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
3 changed files with 117 additions and 15 deletions

View File

@ -12,6 +12,11 @@
if (!validateUInt($_GET['id']) || !($hack = queryHack($_GET['id']))) { if (!validateUInt($_GET['id']) || !($hack = queryHack($_GET['id']))) {
become404Page(); become404Page();
} }
if (!isset($_COOKIE['bootstrap4'])) {
$REQUIRE_LIB['bootstrap5'] = '';
}
$submission = querySubmission($hack['submission_id']); $submission = querySubmission($hack['submission_id']);
$problem = queryProblemBrief($submission['problem_id']); $problem = queryProblemBrief($submission['problem_id']);
$problem_extra_config = getProblemExtraConfig($problem); $problem_extra_config = getProblemExtraConfig($problem);
@ -62,17 +67,27 @@
} }
?> ?>
<?php <?php
$REQUIRE_LIB['shjs'] = ""; if (isset($REQUIRE_LIB['bootstrap5'])) {
$REQUIRE_LIB['hljs'] = '';
} else {
$REQUIRE_LIB['shjs'] = '';
}
?> ?>
<?php echoUOJPageHeader(UOJLocale::get('problems::hack').' #'.$hack['id']) ?> <?php echoUOJPageHeader(UOJLocale::get('problems::hack').' #'.$hack['id']) ?>
<?php echoHackListOnlyOne($hack, array(), $myUser) ?> <h1 class="h3">
<?= UOJLocale::get('problems::hack').' #'.$hack['id'] ?>
</h1>
<?php echoHackListOnlyOne($hack, array('id_hidden' => ''), $myUser) ?>
<?php if ($should_show_all_details): ?> <?php if ($should_show_all_details): ?>
<div class="card border-info"> <div class="card border-info mb-3">
<div class="card-header bg-info"> <div class="card-header bg-info">
<h4 class="card-title"><?= UOJLocale::get('details') ?></h4> <h4 class="card-title"><?= UOJLocale::get('details') ?></h4>
</div> </div>
<?php if (!isset($REQUIRE_LIB['bootstrap5'])): ?>
<div class="card-body"> <div class="card-body">
<?php endif ?>
<?php echoJudgementDetails($hack['details'], $styler, 'details') ?> <?php echoJudgementDetails($hack['details'], $styler, 'details') ?>
<?php if ($should_show_details_to_me): ?> <?php if ($should_show_details_to_me): ?>
<?php if ($styler->fade_all_details): ?> <?php if ($styler->fade_all_details): ?>
@ -80,9 +95,16 @@
<?php echoHackDetails($hack['details'], 'final_details') ?> <?php echoHackDetails($hack['details'], 'final_details') ?>
<?php endif ?> <?php endif ?>
<?php endif ?> <?php endif ?>
</div> <?php if (!isset($REQUIRE_LIB['bootstrap5'])): ?>
</div> </div>
<?php endif ?> <?php endif ?>
</div>
<?php endif ?>
<h2 class="h3">
<?= UOJLocale::get('problems::submission').' #'.$submission['id'] ?>
</h2>
<?php echoSubmissionsListOnlyOne($submission, array(), $myUser) ?> <?php echoSubmissionsListOnlyOne($submission, array(), $myUser) ?>
<?php if ($should_show_content): ?> <?php if ($should_show_content): ?>
<?php echoSubmissionContent($submission, getProblemSubmissionRequirement($problem)) ?> <?php echoSubmissionContent($submission, getProblemSubmissionRequirement($problem)) ?>

View File

@ -154,7 +154,7 @@
<?= UOJLocale::get('problems::submission').' #'.$submission['id'] ?> <?= UOJLocale::get('problems::submission').' #'.$submission['id'] ?>
</h1> </h1>
<?php echoSubmissionsListOnlyOne($submission, array(), $myUser) ?> <?php echoSubmissionsListOnlyOne($submission, array('id_hidden' => ''), $myUser) ?>
<?php if ($should_show_content): ?> <?php if ($should_show_content): ?>
<?php echoSubmissionContent($submission, getProblemSubmissionRequirement($problem)) ?> <?php echoSubmissionContent($submission, getProblemSubmissionRequirement($problem)) ?>

View File

@ -299,12 +299,28 @@ function echoSubmission($submission, $config, $user) {
echo '<td>'; echo '<td>';
if ($status == 'Judged') { if ($status == 'Judged') {
if ($submission['score'] == null) { if ($submission['score'] == null) {
echo '<a href="/submission/', $submission['id'], '" class="small">', $submission['result_error'], '</a>'; echo '<a ';
if (isset($REQUIRE_LIB['bootstrap5'])) {
echo ' class="text-decoration-none small" ';
} else {
echo ' class="small" ';
}
echo ' href="/submission/', $submission['id'], '">', $submission['result_error'], '</a>';
} else { } else {
echo '<a href="/submission/', $submission['id'], '" class="uoj-score">', $submission['score'], '</a>'; echo '<a href="/submission/', $submission['id'], '" class="uoj-score">', $submission['score'], '</a>';
} }
} else { } else {
echo '<a href="/submission/', $submission['id'], '" class="small">', $status, '</a>'; echo '<a ';
if (isset($REQUIRE_LIB['bootstrap5'])) {
echo ' class="text-decoration-none small" ';
} else {
echo ' class="small" ';
}
echo ' href="/submission/', $submission['id'], '">', $status, '</a>';
} }
echo '</td>'; echo '</td>';
} }
@ -756,8 +772,14 @@ class JudgementDetailsPrinter {
} }
echo htmlspecialchars($test_info); echo htmlspecialchars($test_info);
echo '</div>'; echo '</div>';
} else {
if (isset($REQUIRE_LIB['bootstrap5'])) {
echo '<div class="col-sm-4 uoj-status-text">';
echo $this->styler->getTestInfoIcon($test_info);
} else { } else {
echo '<div class="col-sm-4">'; echo '<div class="col-sm-4">';
}
echo htmlspecialchars($test_info); echo htmlspecialchars($test_info);
echo '</div>'; echo '</div>';
} }
@ -994,6 +1016,19 @@ class HackDetailsStyler {
return 'card-uoj-wrong'; return 'card-uoj-wrong';
} }
} }
public function getTestInfoIcon($test_info) {
if ($test_info == 'Accepted' || $test_info == 'Extra Test Passed') {
return '<i class="bi bi-check-lg"></i> ';
} elseif ($test_info == 'Time Limit Exceeded') {
return '<i class="bi bi-clock"></i> ';
} elseif ($test_info == 'Acceptable Answer') {
return '<i class="bi bi-dash-square"></i> ';
} elseif ($test_info == 'Wrong Answer') {
return '<i class="bi bi-x-lg"></i> ';
} else {
return '<i class="bi bi-slash-circle"></i> ';
}
}
public function shouldFadeDetails($info) { public function shouldFadeDetails($info) {
return $this->fade_all_details; return $this->fade_all_details;
} }
@ -1008,6 +1043,8 @@ function echoCustomTestSubmissionDetails($submission_details, $name) {
echoJudgementDetails($submission_details, new CustomTestSubmissionDetailsStyler(), $name); echoJudgementDetails($submission_details, new CustomTestSubmissionDetailsStyler(), $name);
} }
function echoHackDetails($hack_details, $name) { function echoHackDetails($hack_details, $name) {
global $REQUIRE_LIB;
echoJudgementDetails($hack_details, new HackDetailsStyler(), $name); echoJudgementDetails($hack_details, new HackDetailsStyler(), $name);
} }
@ -1015,10 +1052,22 @@ function echoHack($hack, $config, $user) {
$problem = queryProblemBrief($hack['problem_id']); $problem = queryProblemBrief($hack['problem_id']);
echo '<tr>'; echo '<tr>';
if (!isset($config['id_hidden'])) { if (!isset($config['id_hidden'])) {
echo '<td><a href="/hack/', $hack['id'], '">#', $hack['id'], '</a></td>'; echo '<td><a ';
if (isset($REQUIRE_LIB['bootstrap5'])) {
echo ' class="text-decoration-none" ';
}
echo ' href="/hack/', $hack['id'], '">#', $hack['id'], '</a></td>';
} }
if (!isset($config['submission_hidden'])) { if (!isset($config['submission_hidden'])) {
echo '<td><a href="/submission/', $hack['submission_id'], '">#', $hack['submission_id'], '</a></td>'; echo '<td><a ';
if (isset($REQUIRE_LIB['bootstrap5'])) {
echo ' class="text-decoration-none" ';
}
echo ' href="/submission/', $hack['submission_id'], '">#', $hack['submission_id'], '</a></td>';
} }
if (!isset($config['problem_hidden'])) { if (!isset($config['problem_hidden'])) {
if ($hack['contest_id']) { if ($hack['contest_id']) {
@ -1035,13 +1084,37 @@ function echoHack($hack, $config, $user) {
} }
if (!isset($config['result_hidden'])) { if (!isset($config['result_hidden'])) {
if ($hack['judge_time'] == null) { if ($hack['judge_time'] == null) {
echo '<td><a href="/hack/', $hack['id'], '">Waiting</a></td>'; echo '<td><a ';
if (isset($REQUIRE_LIB['bootstrap5'])) {
echo ' class="text-decoration-none" ';
}
echo ' href="/hack/', $hack['id'], '">Waiting</a></td>';
} elseif ($hack['success'] == null) { } elseif ($hack['success'] == null) {
echo '<td><a href="/hack/', $hack['id'], '">Judging</a></td>'; echo '<td><a ';
if (isset($REQUIRE_LIB['bootstrap5'])) {
echo ' class="text-decoration-none" ';
}
echo ' href="/hack/', $hack['id'], '">Judging</a></td>';
} elseif ($hack['success']) { } elseif ($hack['success']) {
echo '<td><a href="/hack/', $hack['id'], '" class="uoj-status" data-success="1"><strong>Success!</strong></a></td>'; echo '<td><a href="/hack/', $hack['id'], '" class="uoj-status ';
if (isset($REQUIRE_LIB['bootstrap5'])) {
echo ' text-decoration-none ';
}
echo ' " data-success="1"><strong>Success!</strong></a></td>';
} else { } else {
echo '<td><a href="/hack/', $hack['id'], '" class="uoj-status" data-success="0"><strong>Failed.</strong></a></td>'; echo '<td><a href="/hack/', $hack['id'], '" class="uoj-status ';
if (isset($REQUIRE_LIB['bootstrap5'])) {
echo ' text-decoration-none ';
}
echo ' " data-success="0"><strong>Failed.</strong></a></td>';
} }
} else { } else {
echo '<td>Hidden</td>'; echo '<td>Hidden</td>';
@ -1055,8 +1128,15 @@ function echoHack($hack, $config, $user) {
echo '</tr>'; echo '</tr>';
} }
function echoHackListOnlyOne($hack, $config, $user) { function echoHackListOnlyOne($hack, $config, $user) {
global $REQUIRE_LIB;
if (isset($REQUIRE_LIB['bootstrap5'])) {
echo '<div class="card mb-3">';
echo '<table class="table text-center uoj-table mb-0">';
} else {
echo '<div class="table-responsive">'; echo '<div class="table-responsive">';
echo '<table class="table table-bordered table-text-center">'; echo '<table class="table table-bordered table-text-center">';
}
echo '<thead>'; echo '<thead>';
echo '<tr>'; echo '<tr>';
if (!isset($config['id_hidden'])) { if (!isset($config['id_hidden'])) {