core&ui: support file renaming (#688)

Co-authored-by: undefined <i@undefined.moe>
This commit is contained in:
Milmonandundefined authored and GitHub committed 2023-11-19 21:46:15 +08:00
1 parent 746efef9bf
commit 01cb6944b7
19 files changed
+496 -144

No files matched your search

@@ -40,6 +40,25 @@ const page = new NamedPage('problem_config', () => {
});
}
async function handleClickRename(ev: JQuery.ClickEvent<Document, undefined, any, any>) {
const file = [$(ev.currentTarget).parent().parent().attr('data-filename')];
// eslint-disable-next-line no-alert
const newName = prompt(i18n('Enter a new name for the file: '));
if (!newName) return;
try {
await request.post('./files', {
operation: 'rename_files',
files: file,
newNames: [newName],
type: 'testdata',
});
Notification.success(i18n('File have been renamed.'));
await pjax.request({ url: './files?d=testdata&sidebar=true', push: false });
} catch (error) {
Notification.error(error.message);
}
}
async function handleClickRemove(ev: JQuery.ClickEvent<Document, undefined, any, any>) {
const file = [$(ev.currentTarget).parent().parent().attr('data-filename')];
const action = await new ConfirmDialog({
@@ -132,6 +151,7 @@ const page = new NamedPage('problem_config', () => {
mountComponent();
$(document).on('click', '[name="testdata__upload"]', () => handleClickUpload());
$(document).on('click', '[name="testdata__rename"]', (ev) => handleClickRename(ev));
$(document).on('click', '[name="testdata__delete"]', (ev) => handleClickRemove(ev));
$(document).on('click', '[name="testdata__download__all"]', () => handleClickDownloadAll());
});