diff --git a/packages/hydrooj/src/handler/training.ts b/packages/hydrooj/src/handler/training.ts index 754c43d14..8b1a9c106 100644 --- a/packages/hydrooj/src/handler/training.ts +++ b/packages/hydrooj/src/handler/training.ts @@ -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 = {}; + 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, }; } } diff --git a/packages/ui-default/templates/training_main.html b/packages/ui-default/templates/training_main.html index 2b3762d2e..18331674b 100644 --- a/packages/ui-default/templates/training_main.html +++ b/packages/ui-default/templates/training_main.html @@ -5,6 +5,14 @@

{{ _('All Training Plans') }}

+
+
+ + +
+
{% if not tdocs.length %} {{ nothing.render('Sorry, there are no training plans.') }}