mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: support response.pjax
This commit is contained in:
1 parent
89fb04bfb3
commit
f08ac664da
6 files changed
+27
-48
No files matched your search
@@ -451,27 +451,17 @@ export class ContestCodeHandler extends Handler {
|
||||
|
||||
export class ContestFilesHandler extends ContestDetailBaseHandler {
|
||||
@param('tid', Types.ObjectID)
|
||||
@param('pjax', Types.Boolean)
|
||||
async get(domainId: string, tid: ObjectID, pjax = false) {
|
||||
async get(domainId: string, tid: ObjectID) {
|
||||
if (!this.user.own(this.tdoc)) this.checkPerm(PERM.PERM_EDIT_CONTEST);
|
||||
const body = {
|
||||
this.response.body = {
|
||||
tdoc: this.tdoc,
|
||||
tsdoc: this.tsdoc,
|
||||
owner_udoc: await user.getById(domainId, this.tdoc.owner),
|
||||
files: sortFiles(this.tdoc.files || []),
|
||||
urlForFile: (filename: string) => this.url('contest_file_download', { tid, filename }),
|
||||
};
|
||||
if (pjax) {
|
||||
this.response.body = {
|
||||
fragments: (await Promise.all([
|
||||
this.renderHTML('partials/files.html', body),
|
||||
])).map((i) => ({ html: i })),
|
||||
};
|
||||
this.response.template = '';
|
||||
} else {
|
||||
this.response.template = 'contest_files.html';
|
||||
this.response.body = body;
|
||||
}
|
||||
this.response.pjax = 'partials/files.html';
|
||||
this.response.template = 'contest_files.html';
|
||||
}
|
||||
|
||||
@param('tid', Types.ObjectID)
|
||||
|
||||
@@ -284,7 +284,7 @@ const allPriv = Math.sum(Object.values(Priv));
|
||||
|
||||
class SystemUserPrivHandler extends SystemHandler {
|
||||
@requireSudo
|
||||
async get({ pjax }) {
|
||||
async get() {
|
||||
const defaultPriv = system.get('default.priv');
|
||||
const udocs = await user.getMulti({ _id: { $gte: -1000, $ne: 1 }, priv: { $nin: [0, defaultPriv] } }).limit(1000).sort({ _id: 1 }).toArray();
|
||||
const banudocs = await user.getMulti({ _id: { $gte: -1000, $ne: 1 }, priv: 0 }).limit(1000).sort({ _id: 1 }).toArray();
|
||||
@@ -293,10 +293,8 @@ class SystemUserPrivHandler extends SystemHandler {
|
||||
defaultPriv,
|
||||
Priv,
|
||||
};
|
||||
if (pjax) {
|
||||
const html = await this.renderHTML('partials/manage_user_priv.html', this.response.body);
|
||||
this.response.body = { fragments: [{ html }] };
|
||||
} else this.response.template = 'manage_user_priv.html';
|
||||
this.response.pjax = 'partials/manage_user_priv.html';
|
||||
this.response.template = 'manage_user_priv.html';
|
||||
}
|
||||
|
||||
@requireSudo
|
||||
|
||||
@@ -34,24 +34,14 @@ class SwitchLanguageHandler extends Handler {
|
||||
export class FilesHandler extends Handler {
|
||||
noCheckPermView = true;
|
||||
|
||||
@param('pjax', Types.Boolean)
|
||||
async get(domainId: string, pjax = false) {
|
||||
async get() {
|
||||
if (!this.user._files?.length) this.checkPriv(PRIV.PRIV_CREATE_FILE);
|
||||
const body = {
|
||||
this.response.body = {
|
||||
files: sortFiles(this.user._files),
|
||||
urlForFile: (filename: string) => this.url('fs_download', { uid: this.user._id, filename }),
|
||||
};
|
||||
if (pjax) {
|
||||
this.response.body = {
|
||||
fragments: (await Promise.all([
|
||||
this.renderHTML('partials/files.html', body),
|
||||
])).map((i) => ({ html: i })),
|
||||
};
|
||||
this.response.template = '';
|
||||
} else {
|
||||
this.response.template = 'home_files.html';
|
||||
this.response.body = body;
|
||||
}
|
||||
this.response.pjax = 'partials/files.html';
|
||||
this.response.template = 'home_files.html';
|
||||
}
|
||||
|
||||
@post('filename', Types.Name, true)
|
||||
|
||||
@@ -92,8 +92,7 @@ class TrainingMainHandler extends Handler {
|
||||
class TrainingDetailHandler extends Handler {
|
||||
@param('tid', Types.ObjectID)
|
||||
@param('uid', Types.PositiveInt, true)
|
||||
@param('pjax', Types.Boolean, true)
|
||||
async get(domainId: string, tid: ObjectID, uid: number, pjax: boolean) {
|
||||
async get(domainId: string, tid: ObjectID, uid: number) {
|
||||
const tdoc = await training.get(domainId, tid);
|
||||
await bus.parallel('training/get', tdoc, this);
|
||||
let targetUser = this.user._id;
|
||||
@@ -154,10 +153,8 @@ class TrainingDetailHandler extends Handler {
|
||||
this.response.body = {
|
||||
tdoc, tsdoc, pids, pdict, psdict, ndict, nsdict, udoc, udocs, dudict, 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';
|
||||
this.response.pjax = 'partials/training_detail.html';
|
||||
this.response.template = 'training_detail.html';
|
||||
}
|
||||
|
||||
@param('tid', Types.ObjectID)
|
||||
|
||||
Reference in new issue
Block a user