mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
core&ui: training: pin level
This commit is contained in:
5 files changed
+16
-13
No files matched your search
@@ -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>
|
||||
|
||||
Reference in new issue
Block a user