feat(web/problems): difficulty filter
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Baoshuo Ren 2022-12-05 11:54:58 +08:00
parent 248a924df7
commit dfb47c4b32
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
3 changed files with 37 additions and 43 deletions

View File

@ -626,6 +626,7 @@ CREATE TABLE `problems` (
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `assigned_to_judger` (`assigned_to_judger`), KEY `assigned_to_judger` (`assigned_to_judger`),
KEY `uploader` (`uploader`), KEY `uploader` (`uploader`),
KEY `difficulty` (`difficulty`),
KEY `is_hidden` (`is_hidden`) KEY `is_hidden` (`is_hidden`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci TABLESPACE `innodb_system`; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci TABLESPACE `innodb_system`;
/*!40101 SET character_set_client = @saved_cs_client */; /*!40101 SET character_set_client = @saved_cs_client */;

View File

@ -128,9 +128,7 @@ function getProblemTR($info) {
) )
); );
} }
if (isset($_COOKIE['show_difficulty'])) {
$html .= HTML::tag('td', [], UOJProblem::getDifficultyHTML($problem->info['difficulty'])); $html .= HTML::tag('td', [], UOJProblem::getDifficultyHTML($problem->info['difficulty']));
}
$html .= HTML::tag('td', [], ClickZans::getCntBlock($problem->info['zan'])); $html .= HTML::tag('td', [], ClickZans::getCntBlock($problem->info['zan']));
$html .= HTML::tag_end('tr'); $html .= HTML::tag_end('tr');
return $html; return $html;
@ -179,6 +177,10 @@ if (Auth::check() && isset($_GET['my'])) {
$cond['problems.uploader'] = Auth::id(); $cond['problems.uploader'] = Auth::id();
} }
if (isset($_GET['difficulty']) && $_GET['difficulty']) {
$cond['problems.difficulty'] = $_GET['difficulty'];
}
if (empty($cond)) { if (empty($cond)) {
$cond = '1'; $cond = '1';
} }
@ -189,9 +191,7 @@ $header .= '<th>' . UOJLocale::get('problems::problem') . '</th>';
if (isset($_COOKIE['show_submit_mode'])) { if (isset($_COOKIE['show_submit_mode'])) {
$header .= '<th class="text-center" style="width:125px;">' . UOJLocale::get('problems::ac ratio') . '</th>'; $header .= '<th class="text-center" style="width:125px;">' . UOJLocale::get('problems::ac ratio') . '</th>';
} }
if (isset($_COOKIE['show_difficulty'])) {
$header .= '<th class="text-center" style="width:8em;">' . UOJLocale::get('problems::difficulty') . '</th>'; $header .= '<th class="text-center" style="width:8em;">' . UOJLocale::get('problems::difficulty') . '</th>';
}
$header .= '<th class="text-center" style="width:50px;">' . UOJLocale::get('appraisal') . '</th>'; $header .= '<th class="text-center" style="width:50px;">' . UOJLocale::get('appraisal') . '</th>';
$header .= '</tr>'; $header .= '</tr>';
@ -246,7 +246,6 @@ $pag = new Paginator([
<?php echoUOJPageHeader(UOJLocale::get('problems')) ?> <?php echoUOJPageHeader(UOJLocale::get('problems')) ?>
<div class="row"> <div class="row">
<!-- left col --> <!-- left col -->
<div class="col-lg-9"> <div class="col-lg-9">
@ -283,13 +282,6 @@ $pag = new Paginator([
<?= UOJLocale::get('problems::show statistics') ?> <?= UOJLocale::get('problems::show statistics') ?>
</label> </label>
</div> </div>
<div class="form-check d-inline-block">
<input type="checkbox" id="input-show_difficulty" class="form-check-input" <?= isset($_COOKIE['show_difficulty']) ? 'checked="checked" ' : '' ?> />
<label class="form-check-label" for="input-show_difficulty">
<?= UOJLocale::get('problems::show difficulty') ?>
</label>
</div>
</div> </div>
</div> </div>
@ -322,19 +314,6 @@ $pag = new Paginator([
} }
location.reload(); location.reload();
}); });
$('#input-show_difficulty').click(function() {
if (this.checked) {
$.cookie('show_difficulty', '', {
path: '/problems',
expires: 365,
});
} else {
$.removeCookie('show_difficulty', {
path: '/problems'
});
}
location.reload();
});
</script> </script>
<div class="card my-3"> <div class="card my-3">
@ -366,6 +345,7 @@ $pag = new Paginator([
<i class="bi bi-search"></i> <i class="bi bi-search"></i>
</button> </button>
</div> </div>
<div>
<?php if (Auth::check()) : ?> <?php if (Auth::check()) : ?>
<div class="form-check d-inline-block"> <div class="form-check d-inline-block">
<input type="checkbox" name="my" <?= isset($_GET['my']) ? 'checked="checked"' : '' ?> class="form-check-input" id="input-my"> <input type="checkbox" name="my" <?= isset($_GET['my']) ? 'checked="checked"' : '' ?> class="form-check-input" id="input-my">
@ -382,10 +362,22 @@ $pag = new Paginator([
</label> </label>
</div> </div>
<?php endif ?> <?php endif ?>
</div>
<div class="row mt-3">
<label class="col-sm-3 col-form-label" for="input-difficulty">难度</label>
<div class="col-sm-9">
<select id="input-difficulty" name="difficulty" class="form-select">
<option value="">全部</option>
<?php foreach (UOJProblem::$difficulty as $opt_name => $opt_value) : ?>
<?= HTML::option($opt_name, $opt_value, $opt_name == $_GET['difficulty']) ?>
<?php endforeach ?>
</select>
</div>
</div>
</form> </form>
<script> <script>
$('#search-input').val(new URLSearchParams(location.search).get('search')); $('#search-input').val(new URLSearchParams(location.search).get('search'));
$('#input-my, #input-is_hidden').click(function() { $('#input-my, #input-is_hidden, #input-difficulty').change(function() {
$('#form-problem_search').submit(); $('#form-problem_search').submit();
}); });
</script> </script>

View File

@ -1,2 +1,3 @@
ALTER TABLE `problems` ADD `difficulty` int NOT NULL DEFAULT '-1' AFTER `submit_num`; ALTER TABLE `problems` ADD `difficulty` int NOT NULL DEFAULT '-1' AFTER `submit_num`;
ALTER TABLE `problems` MODIFY `extra_config` json NOT NULL; ALTER TABLE `problems` MODIFY `extra_config` json NOT NULL;
ALTER TABLE `problems` ADD KEY `difficulty` (`difficulty`);