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
+50 -15

No files matched your search

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