mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
core&ui: add contest/homework group filter (#589)
This commit is contained in:
1 parent
93bf79e6ad
commit
6f6bdee077
5 files changed
+47
-12
No files matched your search
@@ -73,32 +73,37 @@ ScheduleModel.Worker.addHandler('contest', async (doc) => {
|
||||
|
||||
export class ContestListHandler extends Handler {
|
||||
@param('rule', Types.Range(contest.RULES), true)
|
||||
@param('group', Types.Name, true)
|
||||
@param('page', Types.PositiveInt, true)
|
||||
async get(domainId: string, rule = '', page = 1) {
|
||||
async get(domainId: string, rule = '', group = '', page = 1) {
|
||||
if (rule && contest.RULES[rule].hidden) throw new BadRequestError();
|
||||
const groups = (await user.listGroup(domainId, this.user._id)).map((i) => i.name);
|
||||
if (group && !groups.includes(group)) throw new NotAssignedError(group);
|
||||
const rules = Object.keys(contest.RULES).filter((i) => !contest.RULES[i].hidden);
|
||||
const q = {
|
||||
...this.user.hasPerm(PERM.PERM_VIEW_HIDDEN_CONTEST)
|
||||
...this.user.hasPerm(PERM.PERM_VIEW_HIDDEN_CONTEST) && !group
|
||||
? {}
|
||||
: {
|
||||
$or: [
|
||||
{ maintainer: this.user._id },
|
||||
{ owner: this.user._id },
|
||||
{ assign: { $in: this.user.group } },
|
||||
{ assign: { $in: groups } },
|
||||
{ assign: { $size: 0 } },
|
||||
],
|
||||
},
|
||||
...rule ? { rule } : { rule: { $in: rules } },
|
||||
...group ? { assign: { $in: [group] } } : {},
|
||||
};
|
||||
const cursor = contest.getMulti(domainId, q);
|
||||
const qs = rule ? `rule=${rule}` : '';
|
||||
let qs = rule ? `rule=${rule}` : '';
|
||||
if (group) qs += qs ? `&group=${group}` : `group=${group}`;
|
||||
const [tdocs, tpcount] = await paginate<Tdoc>(cursor, page, system.get('pagination.contest'));
|
||||
const tids = [];
|
||||
for (const tdoc of tdocs) tids.push(tdoc.docId);
|
||||
const tsdict = await contest.getListStatus(domainId, this.user._id, tids);
|
||||
this.response.template = 'contest_main.html';
|
||||
this.response.body = {
|
||||
page, tpcount, qs, rule, tdocs, tsdict,
|
||||
page, tpcount, qs, rule, tdocs, tsdict, groups, group,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,20 +21,24 @@ const validatePenaltyRules = (input: string) => yaml.load(input);
|
||||
const convertPenaltyRules = validatePenaltyRules;
|
||||
|
||||
class HomeworkMainHandler extends Handler {
|
||||
@param('group', Types.Name, true)
|
||||
@param('page', Types.PositiveInt, true)
|
||||
async get(domainId: string, page = 1) {
|
||||
async get(domainId: string, group = '', page = 1) {
|
||||
const groups = (await user.listGroup(domainId, this.user._id)).map((i) => i.name);
|
||||
if (group && !groups.includes(group)) throw new NotAssignedError(group);
|
||||
const cursor = contest.getMulti(domainId, {
|
||||
rule: 'homework',
|
||||
...this.user.hasPerm(PERM.PERM_VIEW_HIDDEN_HOMEWORK)
|
||||
...this.user.hasPerm(PERM.PERM_VIEW_HIDDEN_HOMEWORK) && !group
|
||||
? {}
|
||||
: {
|
||||
$or: [
|
||||
{ maintainer: this.user._id },
|
||||
{ owner: this.user._id },
|
||||
{ assign: { $in: this.user.group } },
|
||||
{ assign: { $in: groups } },
|
||||
{ assign: { $size: 0 } },
|
||||
],
|
||||
},
|
||||
...group ? { assign: { $in: [group] } } : {},
|
||||
});
|
||||
const [tdocs, tpcount] = await paginate<Tdoc>(cursor, page, system.get('pagination.contest'));
|
||||
const calendar = [];
|
||||
@@ -46,8 +50,9 @@ class HomeworkMainHandler extends Handler {
|
||||
} else cal.endAt = tdoc.penaltySince;
|
||||
calendar.push(cal);
|
||||
}
|
||||
const qs = group ? `group=${group}` : '';
|
||||
this.response.body = {
|
||||
tdocs, calendar, tpcount, page,
|
||||
tdocs, calendar, tpcount, page, qs, groups, group,
|
||||
};
|
||||
this.response.template = 'homework_main.html';
|
||||
}
|
||||
|
||||
@@ -11,4 +11,7 @@ $highlight-button-color = #F6DF45
|
||||
|
||||
.homework__date
|
||||
margin-right: rem(10px)
|
||||
white-space: nowrap
|
||||
white-space: nowrap
|
||||
|
||||
.filter-form
|
||||
display: inline-block
|
||||
@@ -60,10 +60,18 @@
|
||||
<div class="section__tools">
|
||||
<form method="get" name="filter-form">
|
||||
{{ _('Show') }}:
|
||||
{% if groups.length %}
|
||||
<select class="inline compact select" name="group">
|
||||
<option value=""{% if not group %} selected{% endif %}>{{ _('All') }}</option>
|
||||
{%- for g in groups -%}
|
||||
<option value="{{ g }}"{% if group == g %} selected{% endif %}>{{ g }}</option>
|
||||
{%- endfor -%}
|
||||
</select>
|
||||
{% endif %}
|
||||
<select class="inline compact select" name="rule">
|
||||
<option value=""{% if not rule %} selected{% endif %}>{{ _('All') }}</option>
|
||||
{%- for k, v in model.contest.RULES -%}
|
||||
{% if k != 'homework' %}
|
||||
{% if not k.hidden %}
|
||||
<option value="{{ k }}"{% if rule == k %} selected{% endif %}>{{ _('All {0} Contests').format(v.TEXT) }}</option>
|
||||
{% endif %}
|
||||
{%- endfor -%}
|
||||
|
||||
@@ -14,6 +14,20 @@
|
||||
<option value="list" selected>{{ _('List View') }}</option>
|
||||
</select>
|
||||
</span>
|
||||
{% if groups.length %}
|
||||
<form method="get" class="filter-form" name="filter-form">
|
||||
{{ _('Show') }}:
|
||||
<select class="inline compact select" name="group">
|
||||
<option value=""{% if not group %} selected{% endif %}>{{ _('All') }}</option>
|
||||
{%- for g in groups -%}
|
||||
<option value="{{ g }}"{% if group == g %} selected{% endif %}>{{ g }}</option>
|
||||
{%- endfor -%}
|
||||
</select>
|
||||
<button type="submit" class="compact button hasjs--hide">
|
||||
{{ _('Search') }}
|
||||
</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
{% if handler.user.hasPerm(perm.PERM_CREATE_HOMEWORK) %}
|
||||
<a class="compact button" href="{{ url('homework_create') }}">{{ _('Create Homework') }}</a>
|
||||
{% endif %}
|
||||
@@ -51,7 +65,7 @@
|
||||
</li>
|
||||
{%- endfor -%}
|
||||
</ol>
|
||||
{{ paginator.render(page, tpcount) }}
|
||||
{{ paginator.render(page, tpcount, add_qs=qs) }}
|
||||
<div name="calendar_entry"></div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user