core&ui: training: pin level

pull/564/head
undefined 1 year ago
parent 234b3e970b
commit 672b0b32a6
No known key found for this signature in database

@ -202,20 +202,19 @@ class TrainingEditHandler extends Handler {
@param('title', Types.Title)
@param('content', Types.Content)
@param('dag', Types.Content)
@param('pin', Types.Boolean)
@param('pin', Types.UnsignedInt)
@param('description', Types.Content)
async post(
domainId: string, tid: ObjectId,
title: string, content: string,
_dag: string, pin = false, description: string,
_dag: string, pin = 0, description: string,
) {
if ((!!this.tdoc?.pin) !== pin) this.checkPerm(PERM.PERM_PIN_TRAINING);
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', null, 'Please specify at least one problem'));
if (!tid) {
tid = await training.add(domainId, title, content, this.user._id, dag, description);
if (pin) await training.edit(domainId, tid, { pin });
tid = await training.add(domainId, title, content, this.user._id, dag, description, pin);
} else {
await training.edit(domainId, tid, {
title, content, dag, description, pin,

@ -411,7 +411,7 @@ export interface Tdoc<docType = document['TYPE_CONTEST'] | document['TYPE_TRAINI
export interface TrainingDoc extends Tdoc {
description: string;
pin?: boolean;
pin?: number;
dag: TrainingNode[];
}

@ -36,13 +36,14 @@ export function setStatus(domainId: string, tid: ObjectId, uid: number, $set: an
export function add(
domainId: string, title: string, content: string,
owner: number, dag: TrainingNode[] = [], description = '',
owner: number, dag: TrainingNode[] = [], description = '', pin = 0,
) {
return document.add(domainId, content, owner, document.TYPE_TRAINING, null, null, null, {
dag,
title,
description,
attend: 0,
pin,
});
}

@ -582,6 +582,11 @@ const scripts: UpgradeScript[] = [
}
});
},
async function _80_81() {
await document.coll.updateMany({ docType: document.TYPE_TRAINING, pin: false }, { $set: { pin: 0 } });
await document.coll.updateMany({ docType: document.TYPE_TRAINING, pin: true }, { $set: { pin: 1 } });
return true;
},
];
export default scripts;

@ -6,18 +6,16 @@
<div class="section__body">
<form method="post">
<div class="row">
<div class="medium-10 columns">
<div class="medium-9 columns">
<label>
{{ _('Title') }}
<input name="title" placeholder="{{ _('title') }}" value="{{ tdoc.title|default('') }}" class="textbox" autofocus>
</label>
</div>
<div class="medium-2 columns">
<div class="medium-3 columns">
<label>
<br>
<label class="checkbox">
<input type="checkbox" name="pin" value="on"{% if tdoc['hidden'] %} checked{% endif %} class="checkbox">{{ _('Pin') }}
</label>
{{ _('Pin') }}
<input name="pin" placeholder="{{ _('Pin level') }}" value="{{ tdoc.pin|default(0) }}" class="textbox">
</label>
</div>
</div>

Loading…
Cancel
Save