mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core&ui: add training search support
This commit is contained in:
2 files changed
+14
-4
No files matched your search
@@ -1,5 +1,5 @@
|
|||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import { pick } from 'lodash';
|
import { escapeRegExp, pick } from 'lodash';
|
||||||
import { Filter, ObjectId } from 'mongodb';
|
import { Filter, ObjectId } from 'mongodb';
|
||||||
import { sortFiles } from '@hydrooj/utils/lib/utils';
|
import { sortFiles } from '@hydrooj/utils/lib/utils';
|
||||||
import {
|
import {
|
||||||
@@ -59,11 +59,13 @@ async function _parseDagJson(domainId: string, _dag: string): Promise<Tdoc['dag'
|
|||||||
|
|
||||||
class TrainingMainHandler extends Handler {
|
class TrainingMainHandler extends Handler {
|
||||||
@param('page', Types.PositiveInt, true)
|
@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> = {};
|
const query: Filter<TrainingDoc> = {};
|
||||||
|
if (q) query.title = { $regex: new RegExp(escapeRegExp(q), 'i') };
|
||||||
await this.ctx.parallel('training/list', query, this);
|
await this.ctx.parallel('training/list', query, this);
|
||||||
const [tdocs, tpcount] = await this.paginate(
|
const [tdocs, tpcount] = await this.paginate(
|
||||||
training.getMulti(domainId),
|
training.getMulti(domainId, query),
|
||||||
page,
|
page,
|
||||||
'training',
|
'training',
|
||||||
);
|
);
|
||||||
@@ -89,7 +91,7 @@ class TrainingMainHandler extends Handler {
|
|||||||
for (const tdoc of tdocs) tdict[tdoc.docId.toHexString()] = tdoc;
|
for (const tdoc of tdocs) tdict[tdoc.docId.toHexString()] = tdoc;
|
||||||
this.response.template = 'training_main.html';
|
this.response.template = 'training_main.html';
|
||||||
this.response.body = {
|
this.response.body = {
|
||||||
tdocs, page, tpcount, tsdict, tdict,
|
tdocs, page, tpcount, tsdict, tdict, q,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,14 @@
|
|||||||
<div class="section">
|
<div class="section">
|
||||||
<div class="section__header">
|
<div class="section__header">
|
||||||
<h1 class="section__title">{{ _('All Training Plans') }}</h1>
|
<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>
|
</div>
|
||||||
{% if not tdocs.length %}
|
{% if not tdocs.length %}
|
||||||
{{ nothing.render('Sorry, there are no training plans.') }}
|
{{ nothing.render('Sorry, there are no training plans.') }}
|
||||||
|
|||||||
Reference in new issue
Block a user