mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core&ui: allow copy/import as hidden
This commit is contained in:
6 files changed
+45
-24
No files matched your search
@@ -13,7 +13,8 @@ class ProblemImportHydroHandler extends Handler {
|
|||||||
|
|
||||||
@param('keepUser', Types.Boolean)
|
@param('keepUser', Types.Boolean)
|
||||||
@param('preferredPrefix', Types.String, true)
|
@param('preferredPrefix', Types.String, true)
|
||||||
async post(domainId: string, keepUser: boolean, preferredPrefix?: string) {
|
@param('hidden', Types.Boolean)
|
||||||
|
async post(domainId: string, keepUser: boolean, preferredPrefix?: string, hidden?: boolean) {
|
||||||
if (keepUser) this.checkPriv(PRIV.PRIV_EDIT_SYSTEM);
|
if (keepUser) this.checkPriv(PRIV.PRIV_EDIT_SYSTEM);
|
||||||
if (!this.request.files.file) throw new ValidationError('file');
|
if (!this.request.files.file) throw new ValidationError('file');
|
||||||
if (preferredPrefix && !/^[a-zA-Z]+$/.test(preferredPrefix)) throw new ValidationError('preferredPrefix');
|
if (preferredPrefix && !/^[a-zA-Z]+$/.test(preferredPrefix)) throw new ValidationError('preferredPrefix');
|
||||||
@@ -24,6 +25,7 @@ class ProblemImportHydroHandler extends Handler {
|
|||||||
progress: this.progress.bind(this),
|
progress: this.progress.bind(this),
|
||||||
operator: keepUser ? null : this.user._id,
|
operator: keepUser ? null : this.user._id,
|
||||||
delSource: true,
|
delSource: true,
|
||||||
|
hidden,
|
||||||
},
|
},
|
||||||
).catch((e) => MessageModel.send(1, this.user._id, `Import failed: ${e.message}\n${e.stack}`));
|
).catch((e) => MessageModel.send(1, this.user._id, `Import failed: ${e.message}\n${e.stack}`));
|
||||||
let resolved = false;
|
let resolved = false;
|
||||||
|
|||||||
@@ -190,7 +190,8 @@ export class ProblemMainHandler extends Handler {
|
|||||||
|
|
||||||
@param('pids', Types.NumericArray)
|
@param('pids', Types.NumericArray)
|
||||||
@param('target', Types.String)
|
@param('target', Types.String)
|
||||||
async postCopy(domainId: string, pids: number[], target: string) {
|
@param('hidden', Types.Boolean)
|
||||||
|
async postCopy(domainId: string, pids: number[], target: string, hidden?: boolean) {
|
||||||
const t = `,${this.domain.share || ''},`;
|
const t = `,${this.domain.share || ''},`;
|
||||||
if (t !== ',*,' && !t.includes(`,${target},`)) throw new PermissionError(target);
|
if (t !== ',*,' && !t.includes(`,${target},`)) throw new PermissionError(target);
|
||||||
const ddoc = await domain.get(target);
|
const ddoc = await domain.get(target);
|
||||||
@@ -205,7 +206,7 @@ export class ProblemMainHandler extends Handler {
|
|||||||
const ids = [];
|
const ids = [];
|
||||||
for (const pid of pids) {
|
for (const pid of pids) {
|
||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
ids.push(await problem.copy(domainId, pid, target));
|
ids.push(await problem.copy(domainId, pid, target, undefined, hidden));
|
||||||
}
|
}
|
||||||
this.response.body = ids;
|
this.response.body = ids;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ interface ProblemImportOptions {
|
|||||||
override?: boolean;
|
override?: boolean;
|
||||||
operator?: number;
|
operator?: number;
|
||||||
delSource?: boolean;
|
delSource?: boolean;
|
||||||
|
hidden?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ProblemCreateOptions {
|
interface ProblemCreateOptions {
|
||||||
@@ -244,7 +245,7 @@ export class ProblemModel {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static async copy(domainId: string, _id: number, target: string, pid?: string) {
|
static async copy(domainId: string, _id: number, target: string, pid?: string, hidden?: boolean) {
|
||||||
const original = await ProblemModel.get(domainId, _id);
|
const original = await ProblemModel.get(domainId, _id);
|
||||||
if (!original) throw new ProblemNotFoundError(domainId, _id);
|
if (!original) throw new ProblemNotFoundError(domainId, _id);
|
||||||
if (original.reference) throw new ValidationError('reference');
|
if (original.reference) throw new ValidationError('reference');
|
||||||
@@ -252,7 +253,7 @@ export class ProblemModel {
|
|||||||
if (!pid && original.pid && !await ProblemModel.get(target, original.pid)) pid = original.pid;
|
if (!pid && original.pid && !await ProblemModel.get(target, original.pid)) pid = original.pid;
|
||||||
return await ProblemModel.add(
|
return await ProblemModel.add(
|
||||||
target, pid, original.title, original.content,
|
target, pid, original.title, original.content,
|
||||||
original.owner, original.tag, { hidden: original.hidden, reference: { domainId, pid: _id } },
|
original.owner, original.tag, { hidden: hidden || original.hidden, reference: { domainId, pid: _id } },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -560,10 +561,11 @@ export class ProblemModel {
|
|||||||
content: overrideContent || pdoc.content?.toString() || 'No content',
|
content: overrideContent || pdoc.content?.toString() || 'No content',
|
||||||
tag,
|
tag,
|
||||||
difficulty: pdoc.difficulty,
|
difficulty: pdoc.difficulty,
|
||||||
|
...(options.hidden ? { hidden: true } : {}),
|
||||||
})).docId
|
})).docId
|
||||||
: await ProblemModel.add(
|
: await ProblemModel.add(
|
||||||
domainId, pid, title.trim(), overrideContent || pdoc.content?.toString() || 'No content',
|
domainId, pid, title.trim(), overrideContent || pdoc.content?.toString() || 'No content',
|
||||||
operator || pdoc.owner, tag, { hidden: pdoc.hidden, difficulty: pdoc.difficulty },
|
operator || pdoc.owner, tag, { hidden: options.hidden || pdoc.hidden, difficulty: pdoc.difficulty },
|
||||||
);
|
);
|
||||||
// TODO delete unused file when updating pdoc
|
// TODO delete unused file when updating pdoc
|
||||||
for (const [f, loc] of await getFiles('testdata', 'attachments', 'generators', 'include')) {
|
for (const [f, loc] of await getFiles('testdata', 'attachments', 'generators', 'include')) {
|
||||||
|
|||||||
@@ -177,7 +177,9 @@ function ensureAndGetSelectedPids() {
|
|||||||
return selectedPids;
|
return selectedPids;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleOperation(operation) {
|
let refDiv: any;
|
||||||
|
|
||||||
|
async function handleOperation(operation: string) {
|
||||||
const pids = ensureAndGetSelectedPids();
|
const pids = ensureAndGetSelectedPids();
|
||||||
if (pids === null) return;
|
if (pids === null) return;
|
||||||
const payload: any = {};
|
const payload: any = {};
|
||||||
@@ -187,9 +189,10 @@ async function handleOperation(operation) {
|
|||||||
}).open();
|
}).open();
|
||||||
if (action !== 'yes') return;
|
if (action !== 'yes') return;
|
||||||
} else if (operation === 'copy') {
|
} else if (operation === 'copy') {
|
||||||
const domainSelector: any = DomainSelectAutoComplete.getOrConstruct($('.dialog__body--problem-copy [name="target"]'));
|
const $target = $(refDiv).find('[name="target"]');
|
||||||
|
const domainSelector: any = DomainSelectAutoComplete.getOrConstruct($target);
|
||||||
const copyDialog = await new ActionDialog({
|
const copyDialog = await new ActionDialog({
|
||||||
$body: $('.dialog__body--problem-copy > div'),
|
$body: refDiv,
|
||||||
onDispatch(action) {
|
onDispatch(action) {
|
||||||
if (action === 'ok' && domainSelector.value() === null) {
|
if (action === 'ok' && domainSelector.value() === null) {
|
||||||
domainSelector.focus();
|
domainSelector.focus();
|
||||||
@@ -199,9 +202,8 @@ async function handleOperation(operation) {
|
|||||||
},
|
},
|
||||||
}).open();
|
}).open();
|
||||||
if (copyDialog !== 'ok') return;
|
if (copyDialog !== 'ok') return;
|
||||||
const target = $('[name="target"]').val();
|
payload.target = domainSelector.value()._id;
|
||||||
if (!target) return;
|
payload.hidden = $(refDiv).find('[name="hidden"]').prop('checked');
|
||||||
payload.target = target;
|
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await request.post('', { operation, pids, ...payload });
|
await request.post('', { operation, pids, ...payload });
|
||||||
@@ -412,23 +414,30 @@ const page = new NamedPage(['problem_main'], () => {
|
|||||||
const $body = $('body');
|
const $body = $('body');
|
||||||
$body.addClass('display-mode');
|
$body.addClass('display-mode');
|
||||||
$('.section.display-mode').removeClass('display-mode');
|
$('.section.display-mode').removeClass('display-mode');
|
||||||
$(tpl`
|
$(tpl(
|
||||||
<div style="display: none" class="dialog__body--problem-copy">
|
<div style={{ display: 'none' }} className="dialog__body--problem-copy">
|
||||||
<div class="row"><div class="columns">
|
<div className="row"><div className="columns">
|
||||||
<h1 name="select_user_hint">${i18n('Copy Problems')}</h1>
|
<h1>{i18n('Copy Problems')}</h1>
|
||||||
</div></div>
|
</div></div>
|
||||||
<div class="row">
|
<div className="row">
|
||||||
<div class="columns">
|
<div className="medium-8 columns">
|
||||||
<label>
|
<label>
|
||||||
${i18n('Target')}
|
{i18n('Target')}
|
||||||
<div class="textbox-container">
|
<div className="textbox-container">
|
||||||
<input name="target" type="text" class="textbox" data-autofocus>
|
<input name="target" type="text" className="textbox" data-autofocus />
|
||||||
</div>
|
</div>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="medium-4 columns">
|
||||||
|
<label className="checkbox">
|
||||||
|
{i18n('Hidden')}
|
||||||
|
<input name="hidden" type="checkbox" />
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`).appendTo(document.body);
|
</div>,
|
||||||
|
)).appendTo(document.body);
|
||||||
|
refDiv = $('.dialog__body--problem-copy > div');
|
||||||
|
|
||||||
buildSearchContainer();
|
buildSearchContainer();
|
||||||
buildLegacyCategoryFilter();
|
buildLegacyCategoryFilter();
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ const page = new NamedPage([
|
|||||||
$(document).on('click', '[name="problem-sidebar__copy"]', () => {
|
$(document).on('click', '[name="problem-sidebar__copy"]', () => {
|
||||||
$(tpl`<div style="display: none" class="dialog__body--problem-copy">
|
$(tpl`<div style="display: none" class="dialog__body--problem-copy">
|
||||||
<div class="row"><div class="columns">
|
<div class="row"><div class="columns">
|
||||||
<h1 name="select_user_hint">${i18n('Copy Problem')}</h1>
|
<h1>${i18n('Copy Problem')}</h1>
|
||||||
</div></div>
|
</div></div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="columns">
|
<div class="columns">
|
||||||
|
|||||||
@@ -20,8 +20,15 @@
|
|||||||
help_text:_('The preferred problem ID prefix.'),
|
help_text:_('The preferred problem ID prefix.'),
|
||||||
placeholder:_('Leave empty for default')
|
placeholder:_('Leave empty for default')
|
||||||
}) }}
|
}) }}
|
||||||
|
{{ form.form_checkbox({
|
||||||
|
label:'Hidden',
|
||||||
|
columns:6,
|
||||||
|
name:'hidden',
|
||||||
|
placeholder:_('Make the problem hidden.'),
|
||||||
|
row:false
|
||||||
|
}) }}
|
||||||
{% if handler.user.hasPriv(PRIV.PRIV_EDIT_SYSTEM) and not type %}
|
{% if handler.user.hasPriv(PRIV.PRIV_EDIT_SYSTEM) and not type %}
|
||||||
{{ form.form_checkbox ({
|
{{ form.form_checkbox({
|
||||||
label:'Keep original user',
|
label:'Keep original user',
|
||||||
columns:6,
|
columns:6,
|
||||||
name:'keepUser',
|
name:'keepUser',
|
||||||
|
|||||||
Reference in new issue
Block a user