mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
ui: add recent_problem section
This commit is contained in:
1 parent
317fb11540
commit
7df24629dd
6 files changed
+75
-58
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "3.15.9",
|
"version": "3.15.10",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "src/loader",
|
"main": "src/loader",
|
||||||
"module": "src/loader",
|
"module": "src/loader",
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ homepage:
|
|||||||
- width: 3
|
- width: 3
|
||||||
hitokoto: true
|
hitokoto: true
|
||||||
starred_problems: 50
|
starred_problems: 50
|
||||||
|
recent_problems: 10
|
||||||
problem_search: true
|
problem_search: true
|
||||||
discussion_nodes: true
|
discussion_nodes: true
|
||||||
suggestion: true
|
suggestion: true
|
||||||
|
|||||||
@@ -38,77 +38,75 @@ export class HomeHandler extends Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getHomework(domainId: string, limit = 5) {
|
async getHomework(domainId: string, limit = 5) {
|
||||||
if (this.user.hasPerm(PERM.PERM_VIEW_HOMEWORK)) {
|
if (!this.user.hasPerm(PERM.PERM_VIEW_HOMEWORK)) return [[], {}];
|
||||||
const tdocs = await contest.getMulti(domainId, { rule: 'homework' })
|
const tdocs = await contest.getMulti(domainId, { rule: 'homework' })
|
||||||
.limit(limit).toArray();
|
.limit(limit).toArray();
|
||||||
const tsdict = await contest.getListStatus(
|
const tsdict = await contest.getListStatus(
|
||||||
domainId, this.user._id, tdocs.map((tdoc) => tdoc.docId),
|
domainId, this.user._id, tdocs.map((tdoc) => tdoc.docId),
|
||||||
);
|
);
|
||||||
return [tdocs, tsdict];
|
return [tdocs, tsdict];
|
||||||
}
|
|
||||||
return [[], {}];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getContest(domainId: string, limit = 10) {
|
async getContest(domainId: string, limit = 10) {
|
||||||
if (this.user.hasPerm(PERM.PERM_VIEW_CONTEST)) {
|
if (!this.user.hasPerm(PERM.PERM_VIEW_CONTEST)) return [[], {}];
|
||||||
const rules = Object.keys(contest.RULES).filter((i) => !contest.RULES[i].hidden);
|
const rules = Object.keys(contest.RULES).filter((i) => !contest.RULES[i].hidden);
|
||||||
const tdocs = await contest.getMulti(domainId, { rule: { $in: rules } })
|
const tdocs = await contest.getMulti(domainId, { rule: { $in: rules } })
|
||||||
.limit(limit).toArray();
|
.limit(limit).toArray();
|
||||||
const tsdict = await contest.getListStatus(
|
const tsdict = await contest.getListStatus(
|
||||||
domainId, this.user._id, tdocs.map((tdoc) => tdoc.docId),
|
domainId, this.user._id, tdocs.map((tdoc) => tdoc.docId),
|
||||||
);
|
);
|
||||||
return [tdocs, tsdict];
|
return [tdocs, tsdict];
|
||||||
}
|
|
||||||
return [[], {}];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTraining(domainId: string, limit = 10) {
|
async getTraining(domainId: string, limit = 10) {
|
||||||
if (this.user.hasPerm(PERM.PERM_VIEW_TRAINING)) {
|
if (!this.user.hasPerm(PERM.PERM_VIEW_TRAINING)) return [[], {}];
|
||||||
const tdocs = await training.getMulti(domainId)
|
const tdocs = await training.getMulti(domainId)
|
||||||
.sort({ pin: -1, _id: 1 }).limit(limit).toArray();
|
.sort({ pin: -1, _id: 1 }).limit(limit).toArray();
|
||||||
const tsdict = await training.getListStatus(
|
const tsdict = await training.getListStatus(
|
||||||
domainId, this.user._id, tdocs.map((tdoc) => tdoc.docId),
|
domainId, this.user._id, tdocs.map((tdoc) => tdoc.docId),
|
||||||
);
|
);
|
||||||
return [tdocs, tsdict];
|
return [tdocs, tsdict];
|
||||||
}
|
|
||||||
return [[], {}];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getDiscussion(domainId: string, limit = 20) {
|
async getDiscussion(domainId: string, limit = 20) {
|
||||||
if (this.user.hasPerm(PERM.PERM_VIEW_DISCUSSION)) {
|
if (!this.user.hasPerm(PERM.PERM_VIEW_DISCUSSION)) return [[], {}];
|
||||||
const ddocs = await discussion.getMulti(domainId).limit(limit).toArray();
|
const ddocs = await discussion.getMulti(domainId).limit(limit).toArray();
|
||||||
const vndict = await discussion.getListVnodes(domainId, ddocs, this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN), this.user.group);
|
const vndict = await discussion.getListVnodes(domainId, ddocs, this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN), this.user.group);
|
||||||
this.collectUser(ddocs.map((ddoc) => ddoc.owner));
|
this.collectUser(ddocs.map((ddoc) => ddoc.owner));
|
||||||
return [ddocs, vndict];
|
return [ddocs, vndict];
|
||||||
}
|
|
||||||
return [[], {}];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getRanking(domainId: string, limit = 50) {
|
async getRanking(domainId: string, limit = 50) {
|
||||||
if (this.user.hasPerm(PERM.PERM_VIEW_RANKING)) {
|
if (!this.user.hasPerm(PERM.PERM_VIEW_RANKING)) return [];
|
||||||
const dudocs = await domain.getMultiUserInDomain(domainId, { uid: { $gt: 1 } })
|
const dudocs = await domain.getMultiUserInDomain(domainId, { uid: { $gt: 1 } })
|
||||||
.sort({ rp: -1 }).project({ uid: 1 }).limit(limit).toArray();
|
.sort({ rp: -1 }).project({ uid: 1 }).limit(limit).toArray();
|
||||||
const uids = dudocs.map((dudoc) => dudoc.uid);
|
const uids = dudocs.map((dudoc) => dudoc.uid);
|
||||||
this.collectUser(uids);
|
this.collectUser(uids);
|
||||||
return uids;
|
return uids;
|
||||||
}
|
|
||||||
return [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getStarredProblems(domainId: string, limit = 50) {
|
async getStarredProblems(domainId: string, limit = 50) {
|
||||||
if (this.user.hasPerm(PERM.PERM_VIEW_PROBLEM)) {
|
if (!this.user.hasPerm(PERM.PERM_VIEW_PROBLEM)) return [[], {}];
|
||||||
const psdocs = await ProblemModel.getMultiStatus(domainId, { uid: this.user._id, star: true })
|
const psdocs = await ProblemModel.getMultiStatus(domainId, { uid: this.user._id, star: true })
|
||||||
.sort('_id', 1).limit(limit).toArray();
|
.sort('_id', 1).limit(limit).toArray();
|
||||||
const psdict = {};
|
const psdict = {};
|
||||||
for (const psdoc of psdocs) psdict[psdoc.docId] = psdoc;
|
for (const psdoc of psdocs) psdict[psdoc.docId] = psdoc;
|
||||||
const pdict = await ProblemModel.getList(
|
const pdict = await ProblemModel.getList(
|
||||||
domainId, psdocs.map((pdoc) => pdoc.docId),
|
domainId, psdocs.map((pdoc) => pdoc.docId),
|
||||||
this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN) || this.user._id, this.user.group, false,
|
this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN) || this.user._id, this.user.group, false,
|
||||||
);
|
);
|
||||||
const pdocs = Object.keys(pdict).filter((i) => +i).map((i) => pdict[i]);
|
const pdocs = Object.keys(pdict).filter((i) => +i).map((i) => pdict[i]);
|
||||||
return [pdocs, psdict];
|
return [pdocs, psdict];
|
||||||
}
|
}
|
||||||
return [[], {}];
|
|
||||||
|
async getRecentProblems(domainId: string, limit = 10) {
|
||||||
|
if (!this.user.hasPerm(PERM.PERM_VIEW_PROBLEM)) return [[], {}];
|
||||||
|
const pdocs = await ProblemModel.getMulti(domainId, { hidden: false })
|
||||||
|
.sort({ _id: -1 }).limit(limit).toArray();
|
||||||
|
const psdict = this.user.hasPriv(PRIV.PRIV_USER_PROFILE)
|
||||||
|
? await ProblemModel.getListStatus(domainId, this.user._id, pdocs.map((pdoc) => pdoc.docId))
|
||||||
|
: {};
|
||||||
|
return [pdocs, psdict];
|
||||||
}
|
}
|
||||||
|
|
||||||
getDiscussionNodes(domainId: string) {
|
getDiscussionNodes(domainId: string) {
|
||||||
|
|||||||
@@ -641,6 +641,7 @@ Ready (☆▽☆): 马上开始 (☆▽☆)
|
|||||||
Ready: 即将开始
|
Ready: 即将开始
|
||||||
Recent {0} Records: 最近 {0} 条记录
|
Recent {0} Records: 最近 {0} 条记录
|
||||||
Recent Activities: 最近活动
|
Recent Activities: 最近活动
|
||||||
|
Recent Problems: 最新题目
|
||||||
Recent Solutions: 最近编写的题解
|
Recent Solutions: 最近编写的题解
|
||||||
Recent Submissions: 最近递交
|
Recent Submissions: 最近递交
|
||||||
Recently Created Discussions: 最近创建的讨论
|
Recently Created Discussions: 最近创建的讨论
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/ui-default",
|
"name": "@hydrooj/ui-default",
|
||||||
"version": "4.39.4",
|
"version": "4.39.5",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"main": "hydro.js",
|
"main": "hydro.js",
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
{% set pdocs = payload[0] %}
|
||||||
|
{% set psdict = payload[1] %}
|
||||||
|
{% if pdocs.length %}
|
||||||
|
<div class="section side nojs--hide">
|
||||||
|
<div class="section__header">
|
||||||
|
<h1 class="section__title">{{ _('Recent Problems') }}</h1>
|
||||||
|
</div>
|
||||||
|
<div class="section__body typo no-media col--problem-name">
|
||||||
|
{%- for pdoc in pdocs -%}
|
||||||
|
<p>
|
||||||
|
{{ problem.render_problem_title(pdoc, show_tags=false, show_invisible_flag=false) }}
|
||||||
|
<span style="float: right">{{ datetimeSpan(pdoc._id)|safe }}</span>
|
||||||
|
</p>
|
||||||
|
{%- endfor -%}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
Reference in new issue
Block a user