mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +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('title', Types.Title)
|
||||||
@param('content', Types.Content)
|
@param('content', Types.Content)
|
||||||
@param('dag', Types.Content)
|
@param('dag', Types.Content)
|
||||||
@param('pin', Types.Boolean)
|
@param('pin', Types.UnsignedInt)
|
||||||
@param('description', Types.Content)
|
@param('description', Types.Content)
|
||||||
async post(
|
async post(
|
||||||
domainId: string, tid: ObjectId,
|
domainId: string, tid: ObjectId,
|
||||||
title: string, content: string,
|
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 dag = await _parseDagJson(domainId, _dag);
|
||||||
const pids = training.getPids(dag);
|
const pids = training.getPids(dag);
|
||||||
assert(pids.length, new ValidationError('dag', null, 'Please specify at least one problem'));
|
assert(pids.length, new ValidationError('dag', null, 'Please specify at least one problem'));
|
||||||
if (!tid) {
|
if (!tid) {
|
||||||
tid = await training.add(domainId, title, content, this.user._id, dag, description);
|
tid = await training.add(domainId, title, content, this.user._id, dag, description, pin);
|
||||||
if (pin) await training.edit(domainId, tid, { pin });
|
|
||||||
} else {
|
} else {
|
||||||
await training.edit(domainId, tid, {
|
await training.edit(domainId, tid, {
|
||||||
title, content, dag, description, pin,
|
title, content, dag, description, pin,
|
||||||
|
|||||||
@@ -411,7 +411,7 @@ export interface Tdoc<docType = document['TYPE_CONTEST'] | document['TYPE_TRAINI
|
|||||||
|
|
||||||
export interface TrainingDoc extends Tdoc {
|
export interface TrainingDoc extends Tdoc {
|
||||||
description: string;
|
description: string;
|
||||||
pin?: boolean;
|
pin?: number;
|
||||||
dag: TrainingNode[];
|
dag: TrainingNode[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,13 +36,14 @@ export function setStatus(domainId: string, tid: ObjectId, uid: number, $set: an
|
|||||||
|
|
||||||
export function add(
|
export function add(
|
||||||
domainId: string, title: string, content: string,
|
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, {
|
return document.add(domainId, content, owner, document.TYPE_TRAINING, null, null, null, {
|
||||||
dag,
|
dag,
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
attend: 0,
|
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;
|
export default scripts;
|
||||||
@@ -6,18 +6,16 @@
|
|||||||
<div class="section__body">
|
<div class="section__body">
|
||||||
<form method="post">
|
<form method="post">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="medium-10 columns">
|
<div class="medium-9 columns">
|
||||||
<label>
|
<label>
|
||||||
{{ _('Title') }}
|
{{ _('Title') }}
|
||||||
<input name="title" placeholder="{{ _('title') }}" value="{{ tdoc.title|default('') }}" class="textbox" autofocus>
|
<input name="title" placeholder="{{ _('title') }}" value="{{ tdoc.title|default('') }}" class="textbox" autofocus>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="medium-2 columns">
|
<div class="medium-3 columns">
|
||||||
<label>
|
<label>
|
||||||
<br>
|
{{ _('Pin') }}
|
||||||
<label class="checkbox">
|
<input name="pin" placeholder="{{ _('Pin level') }}" value="{{ tdoc.pin|default(0) }}" class="textbox">
|
||||||
<input type="checkbox" name="pin" value="on"{% if tdoc['hidden'] %} checked{% endif %} class="checkbox">{{ _('Pin') }}
|
|
||||||
</label>
|
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in new issue
Block a user