mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core&ui: add all enroll users status in training (#456)
Co-authored-by: undefined <i@undefined.moe>
This commit is contained in:
1 parent
d02934f766
commit
c2f5541e83
12 files changed
+312
-156
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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';
|
||||
|
||||
Reference in new issue
Block a user