core&ui: add all enroll users status in training (#456)

Co-authored-by: undefined <i@undefined.moe>
This commit is contained in:
pandaandundefined authored and GitHub committed 2022-11-27 03:00:10 +08:00
1 parent d02934f766
commit c2f5541e83
12 files changed
+312 -156

No files matched your search

+1
View File
@@ -49,6 +49,7 @@ manage: System Manage
no_translation_warn: <blockquote class="warn">This part of content is under translation.</blockquote>
page.problem_detail.sidebar.show_category: Click to Show
page.training_detail.invalid_when_not_enrolled: You cannot view problem details unless enrolled.
page.training_detail.see_other_user_detail: You are viewing user {0} training details.
pager_first: « First
pager_last: Last »
pager_next: Next ›
+2
View File
@@ -482,6 +482,7 @@ My Files: 我的文件
My Profile: 我的资料
My Recent Submissions: 我的最近递交记录
My Role: 我的角色
My status: 我的状态
name: 名称
Name: 名称
Network error: 网络错误
@@ -537,6 +538,7 @@ Output Format: 输出格式
Owner: 所有者
page.problem_detail.sidebar.show_category: 点击显示
page.training_detail.invalid_when_not_enrolled: 未参加训练计划时您不能查看题目详情。
page.training_detail.see_other_user_detail: 您正在查看用户 {0} 的训练详情。
pager_first: « 第一页
pager_last: 末页 »
pager_next: 下一页 ›
+23 -6
View File
@@ -91,16 +91,30 @@ class TrainingMainHandler extends Handler {
class TrainingDetailHandler extends Handler {
@param('tid', Types.ObjectID)
async get(domainId: string, tid: ObjectID) {
@param('uid', Types.PositiveInt, true)
@param('pjax', Types.Boolean, true)
async get(domainId: string, tid: ObjectID, uid: number, pjax: boolean) {
const tdoc = await training.get(domainId, tid);
await bus.parallel('training/get', tdoc, this);
let targetUser = this.user._id;
let enrollUsers = [];
let shouldCompare = false;
const pids = training.getPids(tdoc.dag);
if (this.user.hasPriv(PRIV.PRIV_USER_PROFILE)) {
enrollUsers = (await training.getMultiStatus(domainId, { docId: tid, uid: { $gt: 1 } })
.project({ uid: 1 }).limit(500).toArray()).map((x) => +x.uid);
if (uid) {
targetUser = uid;
shouldCompare = targetUser !== this.user._id;
}
}
const canViewHidden = this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN) || this.user._id;
const [owner, pdict] = await Promise.all([
user.getById(domainId, tdoc.owner),
const [udict, pdict] = await Promise.all([
user.getList(domainId, [tdoc.owner, ...enrollUsers]),
problem.getList(domainId, pids, canViewHidden, true),
]);
const psdict = await problem.getListStatus(domainId, this.user._id, pids);
const psdict = await problem.getListStatus(domainId, targetUser, pids);
const selfPsdict = shouldCompare ? await problem.getListStatus(domainId, this.user._id, pids) : {};
const donePids = new Set<number>();
const progPids = new Set<number>();
for (const pid in psdict) {
@@ -134,10 +148,13 @@ class TrainingDetailHandler extends Handler {
donePids: Array.from(donePids),
done: doneNids.size === tdoc.dag.length,
});
this.response.template = 'training_detail.html';
this.response.body = {
tdoc, tsdoc, pids, pdict, psdict, ndict, nsdict, owner,
tdoc, tsdoc, pids, pdict, psdict, ndict, nsdict, udict, enrollUsers, selfPsdict,
};
if (pjax) {
const html = await this.renderHTML('partials/training_detail.html', this.response.body);
this.response.body = { fragments: [{ html }] };
} else this.response.template = 'training_detail.html';
}
@param('tid', Types.ObjectID)
+1 -1
View File
@@ -224,7 +224,7 @@ export function requireSudo(target: any, funcName: string, obj: any) {
method: this.request.method,
referer: this.request.headers.referer,
args: this.args,
redirect: this.request.path,
redirect: this.request.originalPath,
};
this.response.redirect = this.url('user_sudo');
return 'cleanup';