core: allow pin training

This commit is contained in:
undefined committed 2021-06-18 19:04:48 +08:00
1 parent 6607a36856
commit a7f364e651
10 files changed
+51 -25

No files matched your search

+9 -4
View File
@@ -181,11 +181,13 @@ class TrainingCreateHandler extends Handler {
@param('title', Types.Title)
@param('content', Types.Content)
@param('dag', Types.String, isContent)
@param('pin', Types.Boolean)
@param('description', Types.String, isDescription)
async post(
domainId: string, title: string, content: string,
_dag: string, description: string,
_dag: string, pin = false, description: string,
) {
if (pin) this.checkPerm(PERM.PERM_PIN_TRAINING);
const dag = await _parseDagJson(domainId, _dag);
const pids = training.getPids(dag);
assert(pids.length, new ValidationError('dag'));
@@ -194,13 +196,14 @@ class TrainingCreateHandler extends Handler {
if (pdoc.hidden) this.checkPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN);
}
const tid = await training.add(domainId, title, content, this.user._id, dag, description);
if (pin) await training.edit(domainId, tid, { pin });
this.response.body = { tid };
this.response.redirect = this.url('training_detail', { tid });
}
}
class TrainingEditHandler extends Handler {
tdoc: Tdoc;
tdoc: TrainingDoc;
@param('tid', Types.ObjectID)
async prepare(domainId: string, tid: ObjectID) {
@@ -227,12 +230,14 @@ class TrainingEditHandler extends Handler {
@param('title', Types.Title)
@param('content', Types.Content)
@param('dag', Types.Content)
@param('pin', Types.Boolean)
@param('description', Types.String, isDescription)
async post(
domainId: string, tid: ObjectID,
title: string, content: string,
_dag: string, description: string,
_dag: string, pin = false, description: string,
) {
if (this.tdoc.pin !== pin) this.checkPerm(PERM.PERM_PIN_TRAINING);
const dag = await _parseDagJson(domainId, _dag);
const pids = training.getPids(dag);
assert(pids.length, new ValidationError('dag'));
@@ -257,7 +262,7 @@ class TrainingEditHandler extends Handler {
if (pdoc.hidden) this.checkPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN);
}
await training.edit(domainId, tid, {
title, content, dag, description,
title, content, dag, description, pin,
});
this.response.body = { tid };
this.response.redirect = this.url('training_detail', { tid });
+3 -2
View File
@@ -326,8 +326,9 @@ export interface Tdoc<docType = document['TYPE_CONTEST'] | document['TYPE_HOMEWO
}
export interface TrainingDoc extends Tdoc {
description: string,
dag: TrainingNode[],
description: string;
pin?: boolean;
dag: TrainingNode[];
}
export interface DomainDoc extends Record<string, any> {
+1
View File
@@ -85,6 +85,7 @@ export const PERM = {
PERM_VIEW_TRAINING: 1n << 46n,
PERM_CREATE_TRAINING: 1n << 47n,
PERM_EDIT_TRAINING: 1n << 48n,
PERM_PIN_TRAINING: 1n << 63n,
PERM_EDIT_TRAINING_SELF: 1n << 49n,
// Ranking
+1 -1
View File
@@ -114,7 +114,7 @@ export async function getList(domainId: string, tids: ObjectID[]) {
}
export const getMulti = (domainId: string, query: FilterQuery<TrainingDoc> = {}) =>
document.getMulti(domainId, document.TYPE_TRAINING, query).sort('_id', 1);
document.getMulti(domainId, document.TYPE_TRAINING, query).sort({ pin: -1, _id: -1 });
global.Hydro.model.training = {
getPids,
+9 -7
View File
@@ -84,13 +84,15 @@ export async function updateJudge(args) {
if (cluster.isMaster) {
bus.on('app/started', async () => {
sysinfo.get().then((info) => coll.updateOne(
{ mid: info.mid, type: 'server' },
{ $set: { ...info, updateAt: new Date(), type: 'server' } },
{ upsert: true },
));
feedback();
setInterval(update, 60 * 1000);
sysinfo.get().then((info) => {
coll.updateOne(
{ mid: info.mid, type: 'server' },
{ $set: { ...info, updateAt: new Date(), type: 'server' } },
{ upsert: true },
);
feedback();
setInterval(update, 60 * 1000);
});
});
}