core: bulk copy

This commit is contained in:
undefined committed 2021-10-25 18:35:03 +08:00
1 parent 090b651d84
commit f33e2b932a
6 files changed
+51 -16

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "3.1.3",
"version": "3.1.4",
"bin": "bin/hydrooj.js",
"main": "src/loader",
"module": "src/loader",
+16 -1
View File
@@ -155,6 +155,21 @@ export class ProblemMainHandler extends ProblemHandler {
this.back({ star: false });
}
@param('pids', Types.NumericArray)
@param('target', Types.String)
async postCopy(domainId: string, pids: number[], target: string) {
const ddoc = await domain.get(target);
if (!ddoc) throw new NotFoundError(target);
const dudoc = await user.getById(target, this.user._id);
if (!dudoc.hasPerm(PERM.PERM_CREATE_PROBLEM)) throw new PermissionError(PERM.PERM_CREATE_PROBLEM);
const ids = [];
for (const pid of pids) {
// eslint-disable-next-line no-await-in-loop
ids.push(await problem.copy(domainId, pid, target));
}
this.response.body = ids;
}
@param('pids', Types.NumericArray)
async postDelete(domainId: string, pids: number[]) {
for (const pid of pids) {
@@ -297,7 +312,7 @@ export class ProblemDetailHandler extends ProblemHandler {
if (!ddoc) throw new NotFoundError(target);
const dudoc = await user.getById(target, this.user._id);
if (!dudoc.hasPerm(PERM.PERM_CREATE_PROBLEM)) throw new PermissionError(PERM.PERM_CREATE_PROBLEM);
const docId = await problem.copy(domainId, this.user.docId, target, this.pdoc.pid);
const docId = await problem.copy(domainId, this.pdoc.docId, target);
this.response.redirect = this.url('problem_detail', { domainId: target, pid: docId });
}
+1
View File
@@ -158,6 +158,7 @@ Contributions: 贡献
Copy Email: 复制电子邮件
Copy from: 复制自
Copy QQ Number: 复制QQ号
Copy Selected: 复制选中
Copy WeChat Account: 复制微信号
Copy: 复制
Copyright Complaint: 版权申诉
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@hydrooj/ui-default",
"version": "4.26.2",
"version": "4.26.3",
"author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0",
"main": "hydro.js",
+24 -9
View File
@@ -2,7 +2,7 @@ import _ from 'lodash';
import $ from 'jquery';
import { NamedPage } from 'vj/misc/Page';
import Notification from 'vj/components/notification';
import { ConfirmDialog } from 'vj/components/dialog';
import { ActionDialog, ConfirmDialog } from 'vj/components/dialog';
import Dropdown from 'vj/components/dropdown/Dropdown';
import createHint from 'vj/components/hint';
import { downloadProblemSet } from 'vj/components/zipDownloader';
@@ -174,17 +174,32 @@ function ensureAndGetSelectedPids() {
async function handleOperation(operation) {
const pids = ensureAndGetSelectedPids();
if (pids === null) return;
const payload = {};
if (operation === 'delete') {
const action = await new ConfirmDialog({
$body: tpl`
<div class="typo">
<p>${i18n('Confirm to delete the selected problems?')}</p>
</div>`,
$body: tpl.typoMsg(i18n('Confirm to delete the selected problems?')),
}).open();
if (action !== 'yes') return;
} else if (operation === 'copy') {
const action = await new ActionDialog({
$body: tpl`
<div class="typo">
<label>
${i18n('Target')}
<div class="textbox-container">
<input name="target" type="text" class="textbox" data-autofocus>
</div>
</label>
</div>
`,
}).open();
if (action !== 'ok') return;
const target = $('[name="target"]').val();
if (!target) return;
payload.target = target;
}
try {
await request.post('', { operation, pids });
await request.post('', { operation, pids, ...payload });
Notification.success(i18n(`Selected problems have been ${operation}d.`));
await delay(2000);
window.location.reload();
@@ -213,9 +228,9 @@ const page = new NamedPage(['problem_main', 'problem_category'], () => {
$('[name="enter-edit-mode"]').on('click', () => {
doc.className = doc.className.replace(' display-mode', ' edit-mode');
});
$('[name="remove_selected_problems"]').on('click', () => handleOperation('delete'));
$('[name="hide_selected_problems"]').on('click', () => handleOperation('hide'));
$('[name="unhide_selected_problems"]').on('click', () => handleOperation('unhide'));
['delete', 'hide', 'unhide', 'copy'].forEach((op) => {
$(`[name="${op}_selected_problems"]`).on('click', () => handleOperation(op));
});
$('[name="download_selected_problems"]').on('click', handleDownload);
$('#hideTags').on('click', () => $('.problem__tags').hide());
$('#search').on('click', (ev) => {
@@ -24,8 +24,8 @@
</div>
</div>
</div>
<div class="medium-3 columns">
{% if handler.user.hasPerm(perm.PERM_EDIT_PROBLEM) %}
{% if handler.user.hasPriv(PRIV.PRIV_USER_PROFILE) %}
<div class="medium-3 columns">
<div class="section side nojs--hide">
<ol class="menu">
<a href="javascript:;" class="menu__link edit-mode-hide" name="enter-edit-mode">
@@ -36,7 +36,7 @@
<span class="icon icon-edit"></span>
{{ _('Leave Edit Mode') }}
</a>
{% if pdocs.length %}
{% if handler.user.hasPerm(perm.PERM_EDIT_PROBLEM) %}
<a href="javascript:;" class="menu__link display-mode-hide" name="hide_selected_problems">
<span class="icon icon-close"></span>
{{ _('Hide Selected') }}
@@ -49,11 +49,15 @@
<span class="icon icon-download"></span>
{{ _('Download Selected') }}
</a>
<a href="javascript:;" class="menu__link display-mode-hide" name="remove_selected_problems">
<a href="javascript:;" class="menu__link display-mode-hide" name="delete_selected_problems">
<span class="icon icon-delete"></span>
{{ _('Remove Selected') }}
</a>
{% endif %}
<a href="javascript:;" class="menu__link display-mode-hide" name="copy_selected_problems">
<span class="icon icon-copy"></span>
{{ _('Copy Selected') }}
</a>
</ol>
</div>
{% endif %}