core&ui: add training search support

This commit is contained in:
undefined committed 2025-12-28 05:55:55 +08:00
1 parent cd94929e20
commit c26dee9a66
2 files changed
+14 -4

No files matched your search

+6 -4
View File
@@ -1,5 +1,5 @@
import assert from 'assert';
import { pick } from 'lodash';
import { escapeRegExp, pick } from 'lodash';
import { Filter, ObjectId } from 'mongodb';
import { sortFiles } from '@hydrooj/utils/lib/utils';
import {
@@ -59,11 +59,13 @@ async function _parseDagJson(domainId: string, _dag: string): Promise<Tdoc['dag'
class TrainingMainHandler extends Handler {
@param('page', Types.PositiveInt, true)
async get(domainId: string, page = 1) {
@param('q', Types.String, true)
async get(domainId: string, page = 1, q = '') {
const query: Filter<TrainingDoc> = {};
if (q) query.title = { $regex: new RegExp(escapeRegExp(q), 'i') };
await this.ctx.parallel('training/list', query, this);
const [tdocs, tpcount] = await this.paginate(
training.getMulti(domainId),
training.getMulti(domainId, query),
page,
'training',
);
@@ -89,7 +91,7 @@ class TrainingMainHandler extends Handler {
for (const tdoc of tdocs) tdict[tdoc.docId.toHexString()] = tdoc;
this.response.template = 'training_main.html';
this.response.body = {
tdocs, page, tpcount, tsdict, tdict,
tdocs, page, tpcount, tsdict, tdict, q,
};
}
}
@@ -5,6 +5,14 @@
<div class="section">
<div class="section__header">
<h1 class="section__title">{{ _('All Training Plans') }}</h1>
<div class="section__tools">
<form method="get" class="filter-form" name="filter-form">
<input type="text" class="inline compact textbox" name="q" value="{{ q }}" placeholder="{{ _('Search training...') }}">
<button type="submit" class="compact button">
{{ _('Search') }}
</button>
</form>
</div>
</div>
{% if not tdocs.length %}
{{ nothing.render('Sorry, there are no training plans.') }}