mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
ui: enhance problem_list
This commit is contained in:
1 parent
8dabcc3941
commit
43a1730c5c
8 files changed
+198
-36
No files matched your search
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"mobile": 600,
|
"mobile": 600,
|
||||||
"desktop": 1000,
|
"desktop": 1000,
|
||||||
"hd": 1250
|
"hd": 1280
|
||||||
}
|
}
|
||||||
@@ -14,7 +14,9 @@ const starPage = new AutoloadPage('starPage', () => {
|
|||||||
const $button = $(ev.currentTarget);
|
const $button = $(ev.currentTarget);
|
||||||
const currentState = $button.hasClass('activated');
|
const currentState = $button.hasClass('activated');
|
||||||
const $form = $button.closest('form');
|
const $form = $button.closest('form');
|
||||||
$form.find('[name="operation"]').val(currentState ? 'unstar' : 'star');
|
const $op = $form.find('[name="operation"]');
|
||||||
|
if (!['star', 'unstar'].includes($op.val())) return;
|
||||||
|
$op.val(currentState ? 'unstar' : 'star');
|
||||||
setStarButtonState($button, !currentState);
|
setStarButtonState($button, !currentState);
|
||||||
request
|
request
|
||||||
.post($form.attr('action'), $form)
|
.post($form.attr('action'), $form)
|
||||||
@@ -25,7 +27,6 @@ const starPage = new AutoloadPage('starPage', () => {
|
|||||||
// TODO: notify failure
|
// TODO: notify failure
|
||||||
setStarButtonState($button, currentState);
|
setStarButtonState($button, currentState);
|
||||||
});
|
});
|
||||||
return false;
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/ui-default",
|
"name": "@hydrooj/ui-default",
|
||||||
"version": "4.31.14",
|
"version": "4.31.15",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"main": "hydro.js",
|
"main": "hydro.js",
|
||||||
|
|||||||
@@ -0,0 +1,174 @@
|
|||||||
|
import _ from 'lodash';
|
||||||
|
import Clipboard from 'clipboard';
|
||||||
|
import { NamedPage } from 'vj/misc/Page';
|
||||||
|
import Notification from 'vj/components/notification';
|
||||||
|
import { ConfirmDialog, Dialog } from 'vj/components/dialog/index';
|
||||||
|
import request from 'vj/utils/request';
|
||||||
|
import pjax from 'vj/utils/pjax';
|
||||||
|
import tpl from 'vj/utils/tpl';
|
||||||
|
import i18n from 'vj/utils/i18n';
|
||||||
|
|
||||||
|
function onBeforeUnload(e) {
|
||||||
|
e.returnValue = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
function ensureAndGetSelectedFiles() {
|
||||||
|
const files = _.map(
|
||||||
|
$('.home-files tbody [data-checkbox-group="user_files"]:checked'),
|
||||||
|
(ch) => $(ch).closest('tr').attr('data-filename'),
|
||||||
|
);
|
||||||
|
if (files.length === 0) {
|
||||||
|
Notification.error(i18n('Please select at least one file to perform this operation.'));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleClickUpload(files) {
|
||||||
|
if (!files) {
|
||||||
|
const input = document.createElement('input');
|
||||||
|
input.type = 'file';
|
||||||
|
input.multiple = true;
|
||||||
|
input.click();
|
||||||
|
await new Promise((resolve) => { input.onchange = resolve; });
|
||||||
|
files = input.files;
|
||||||
|
}
|
||||||
|
if (!files.length) {
|
||||||
|
Notification.warn(i18n('No file selected.'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const dialog = new Dialog({
|
||||||
|
$body: `
|
||||||
|
<div class="file-label" style="text-align: center; margin-bottom: 5px; color: gray; font-size: small;"></div>
|
||||||
|
<div class="bp3-progress-bar bp3-intent-primary bp3-no-stripes">
|
||||||
|
<div class="file-progress bp3-progress-meter" style="width: 0"></div>
|
||||||
|
</div>
|
||||||
|
<div class="upload-label" style="text-align: center; margin: 5px 0; color: gray; font-size: small;"></div>
|
||||||
|
<div class="bp3-progress-bar bp3-intent-primary bp3-no-stripes">
|
||||||
|
<div class="upload-progress bp3-progress-meter" style="width: 0"></div>
|
||||||
|
</div>`,
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
Notification.info(i18n('Uploading files...'));
|
||||||
|
window.addEventListener('beforeunload', onBeforeUnload);
|
||||||
|
dialog.open();
|
||||||
|
const $uploadLabel = dialog.$dom.find('.dialog__body .upload-label');
|
||||||
|
const $uploadProgress = dialog.$dom.find('.dialog__body .upload-progress');
|
||||||
|
const $fileLabel = dialog.$dom.find('.dialog__body .file-label');
|
||||||
|
const $fileProgress = dialog.$dom.find('.dialog__body .file-progress');
|
||||||
|
for (const i in files) {
|
||||||
|
if (Number.isNaN(+i)) continue;
|
||||||
|
const file = files[i];
|
||||||
|
const data = new FormData();
|
||||||
|
data.append('filename', file.name);
|
||||||
|
data.append('file', file);
|
||||||
|
data.append('operation', 'upload_file');
|
||||||
|
await request.postFile('', data, {
|
||||||
|
xhr() {
|
||||||
|
const xhr = new XMLHttpRequest();
|
||||||
|
xhr.upload.addEventListener('loadstart', () => {
|
||||||
|
$fileLabel.text(`[${+i + 1}/${files.length}] ${file.name}`);
|
||||||
|
$fileProgress.width(`${Math.round((+i + 1) / files.length * 100)}%`);
|
||||||
|
$uploadLabel.text(i18n('Uploading... ({0}%)', 0));
|
||||||
|
$uploadProgress.width(0);
|
||||||
|
});
|
||||||
|
xhr.upload.addEventListener('progress', (e) => {
|
||||||
|
if (e.lengthComputable) {
|
||||||
|
const percentComplete = Math.round((e.loaded / e.total) * 100);
|
||||||
|
if (percentComplete === 100) $uploadLabel.text(i18n('Processing...'));
|
||||||
|
else $uploadLabel.text(i18n('Uploading... ({0}%)', percentComplete));
|
||||||
|
$uploadProgress.width(`${percentComplete}%`);
|
||||||
|
}
|
||||||
|
}, false);
|
||||||
|
return xhr;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
window.removeEventListener('beforeunload', onBeforeUnload);
|
||||||
|
Notification.success(i18n('File uploaded successfully.'));
|
||||||
|
await pjax.request({ push: false });
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
Notification.error(i18n('File upload failed: {0}', e.toString()));
|
||||||
|
} finally {
|
||||||
|
dialog.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleClickRemoveSelected() {
|
||||||
|
const selectedFiles = ensureAndGetSelectedFiles();
|
||||||
|
if (selectedFiles === null) return;
|
||||||
|
const action = await new ConfirmDialog({
|
||||||
|
$body: tpl`
|
||||||
|
<div class="typo">
|
||||||
|
<p>${i18n('Confirm to delete the selected files?')}</p>
|
||||||
|
</div>`,
|
||||||
|
}).open();
|
||||||
|
if (action !== 'yes') return;
|
||||||
|
try {
|
||||||
|
await request.post('', {
|
||||||
|
operation: 'delete_files',
|
||||||
|
files: selectedFiles,
|
||||||
|
});
|
||||||
|
Notification.success(i18n('Selected files have been deleted.'));
|
||||||
|
await pjax.request({ push: false });
|
||||||
|
} catch (error) {
|
||||||
|
Notification.error(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {JQuery.DragOverEvent<HTMLElement, undefined, HTMLElement, HTMLElement>} ev
|
||||||
|
*/
|
||||||
|
function handleDragOver(ev) {
|
||||||
|
ev.preventDefault();
|
||||||
|
// TODO display a drag-drop allowed hint
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {JQuery.DropEvent<HTMLElement, undefined, HTMLElement, HTMLElement>} ev
|
||||||
|
*/
|
||||||
|
function handleDrop(ev) {
|
||||||
|
ev.preventDefault();
|
||||||
|
if (!$('[name="upload_file"]').length) {
|
||||||
|
Notification.error(i18n("You don't have permission to upload file."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ev = ev.originalEvent;
|
||||||
|
const files = [];
|
||||||
|
if (ev.dataTransfer.items) {
|
||||||
|
for (let i = 0; i < ev.dataTransfer.items.length; i++) {
|
||||||
|
if (ev.dataTransfer.items[i].kind === 'file') {
|
||||||
|
const file = ev.dataTransfer.items[i].getAsFile();
|
||||||
|
files.push(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (let i = 0; i < ev.dataTransfer.files.length; i++) {
|
||||||
|
files.push(ev.dataTransfer.files[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
handleClickUpload(files);
|
||||||
|
}
|
||||||
|
|
||||||
|
const page = new NamedPage('home_files', () => {
|
||||||
|
const clip = new Clipboard('.home-files .col--name', {
|
||||||
|
text: (trigger) => {
|
||||||
|
const filename = trigger.closest('[data-filename]').getAttribute('data-filename');
|
||||||
|
return new URL(`/file/${UserContext._id}/${filename}`, window.location.href).toString();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
clip.on('success', () => {
|
||||||
|
Notification.success(i18n('Download link copied to clipboard!'), 1000);
|
||||||
|
});
|
||||||
|
clip.on('error', () => {
|
||||||
|
Notification.error(i18n('Copy failed :('));
|
||||||
|
});
|
||||||
|
$(document).on('click', '.home-files .col--name', (ev) => ev.preventDefault());
|
||||||
|
$(document).on('click', '[name="upload_file"]', () => handleClickUpload());
|
||||||
|
$(document).on('click', '[name="remove_selected"]', () => handleClickRemoveSelected());
|
||||||
|
$(document).on('dragover', '.home-files', (ev) => handleDragOver(ev));
|
||||||
|
$(document).on('drop', '.home-files', (ev) => handleDrop(ev));
|
||||||
|
});
|
||||||
|
|
||||||
|
export default page;
|
||||||
@@ -9,15 +9,15 @@
|
|||||||
.col--status
|
.col--status
|
||||||
width: rem(140px)
|
width: rem(140px)
|
||||||
position: relative
|
position: relative
|
||||||
|
border-right: 1px solid $table-border-color
|
||||||
|
|
||||||
.col--tried, .col--ac, .col--difficulty
|
.col--difficulty
|
||||||
width: rem(70px)
|
width: rem(70px)
|
||||||
text-align: center
|
text-align: center
|
||||||
|
|
||||||
.col--status
|
.col--ac-tried
|
||||||
border-right: 1px solid $table-border-color
|
width: rem(100px)
|
||||||
|
text-align: center
|
||||||
.col--tried, .col--difficulty
|
|
||||||
border-left: 1px solid $table-border-color
|
border-left: 1px solid $table-border-color
|
||||||
|
|
||||||
+mobile()
|
+mobile()
|
||||||
|
|||||||
@@ -5,24 +5,16 @@
|
|||||||
{% if pdoc.domainId !== handler.domainId %}{{ set(_linkArgs, 'domainId', pdoc.domainId) }}{% endif %}
|
{% if pdoc.domainId !== handler.domainId %}{{ set(_linkArgs, 'domainId', pdoc.domainId) }}{% endif %}
|
||||||
<a href="{{ url('problem_detail', _linkArgs) }}"{% if small %} data-tooltip="{{ pdoc.title }}"{% endif %}>
|
<a href="{{ url('problem_detail', _linkArgs) }}"{% if small %} data-tooltip="{{ pdoc.title }}"{% endif %}>
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
{%- if pdoc.domainId !== handler.domainId -%}
|
{%- if pdoc.domainId !== handler.domainId -%}{{ pdoc.domainId }}#{%- endif -%}
|
||||||
{{ pdoc.domainId }}#
|
<b>{{ pdoc.pid or 'P'+pdoc.docId if pdoc.domainId === handler.domainId else pdoc.docId }}</b>
|
||||||
{%- endif -%}
|
{%- if not small -%} {{ pdoc.title }}{%- endif -%}
|
||||||
{%- if pdoc.pid -%}
|
|
||||||
{{ pdoc.pid }}
|
|
||||||
{%- else -%}
|
|
||||||
{{ 'P'+pdoc.docId if pdoc.domainId === handler.domainId else pdoc.docId }}
|
|
||||||
{%- endif -%}
|
|
||||||
{%- if not small -%}. {{ pdoc.title }}{%- endif -%}
|
|
||||||
{%- if not invalid -%}
|
{%- if not invalid -%}
|
||||||
</a>
|
</a>
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
{%- if pdoc.hidden and show_invisible_flag -%}
|
{%- if pdoc.hidden and show_invisible_flag -%}
|
||||||
<span class="text-orange">({{ _('Hidden') }})</span>
|
<span class="text-orange">({{ _('Hidden') }})</span>
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
{%- if show_tags -%}
|
{%- if show_tags -%}{{ render_problem_tags(pdoc, inline=inline) }}{%- endif -%}
|
||||||
{{ render_problem_tags(pdoc, inline=inline) }}
|
|
||||||
{%- endif -%}
|
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
{% macro render_problem_tags(pdoc, show_none_label=false, inline=false) %}
|
{% macro render_problem_tags(pdoc, show_none_label=false, inline=false) %}
|
||||||
@@ -30,11 +22,9 @@
|
|||||||
{%- if not inline %}<ul class="problem__tags">{% endif -%}
|
{%- if not inline %}<ul class="problem__tags">{% endif -%}
|
||||||
{%- for tag in pdoc['tag'] %}
|
{%- for tag in pdoc['tag'] %}
|
||||||
<li class="problem__tag"><a class="problem__tag-link" href="{{ url('problem_category', category=tag) }}">{{ tag }}</a></li>
|
<li class="problem__tag"><a class="problem__tag-link" href="{{ url('problem_category', category=tag) }}">{{ tag }}</a></li>
|
||||||
{%- endfor %}
|
{%- endfor -%}
|
||||||
{%- if not inline %}</ul>{% endif -%}
|
{%- if not inline %}</ul>{% endif -%}
|
||||||
{%- else %}
|
{%- else -%}
|
||||||
{%- if show_none_label %}
|
{%- if show_none_label -%}{{ _('(None)') }}{%- endif -%}
|
||||||
{{ _('(None)') }}
|
{%- endif -%}
|
||||||
{%- endif %}
|
|
||||||
{%- endif %}
|
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
{% macro render_status_td(rdoc, rid_key='_id', class='', allDomain = false) %}
|
{% macro render_status_td(rdoc, rid_key='_id', class='', allDomain=false, short=false) %}
|
||||||
<td class="col--status record-status--border {{ class }} {{ model.builtin.STATUS_CODES[rdoc.status] }}">
|
<td class="col--status record-status--border {{ class }} {{ model.builtin.STATUS_CODES[rdoc.status] }}">
|
||||||
<div class="col--status__text">
|
<div class="col--status__text">
|
||||||
<span class="icon record-status--icon {{ model.builtin.STATUS_CODES[rdoc.status] }}"></span>
|
<span class="icon record-status--icon {{ model.builtin.STATUS_CODES[rdoc.status] }}"></span>
|
||||||
<span style="color: {{ utils.status.getScoreColor(rdoc.score|default(0)) }}">{{ rdoc.score|default(0) }}</span>
|
|
||||||
<a
|
<a
|
||||||
href="{{ url('record_detail', rid=rdoc[rid_key], domainId=rdoc.domainId) if allDomain else url('record_detail', rid=rdoc[rid_key]) }}"
|
href="{{ url('record_detail', rid=rdoc[rid_key], domainId=rdoc.domainId) if allDomain else url('record_detail', rid=rdoc[rid_key]) }}"
|
||||||
class="record-status--text {{ model.builtin.STATUS_CODES[rdoc.status] }}"
|
class="record-status--text {{ model.builtin.STATUS_CODES[rdoc.status] }}"
|
||||||
>
|
>
|
||||||
{{ model.builtin.STATUS_TEXTS[rdoc.status] }}
|
<span style="color: {{ utils.status.getScoreColor(rdoc.score|default(0)) }}">{{ rdoc.score|default(0) }}</span>
|
||||||
|
{{ model.builtin.STATUS_SHORT_TEXTS[rdoc.status] if short else model.builtin.STATUS_TEXTS[rdoc.status] }}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
{% if rdoc.status == STATUS.STATUS_JUDGING %}
|
{% if rdoc.status == STATUS.STATUS_JUDGING %}
|
||||||
|
|||||||
@@ -15,8 +15,7 @@
|
|||||||
<col class="col--status edit-mode-hide">
|
<col class="col--status edit-mode-hide">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<col class="col--name">
|
<col class="col--name">
|
||||||
<col class="col--tried">
|
<col class="col--ac-tried">
|
||||||
<col class="col--ac">
|
|
||||||
<col class="col--difficulty">
|
<col class="col--difficulty">
|
||||||
</colgroup>
|
</colgroup>
|
||||||
<thead>
|
<thead>
|
||||||
@@ -34,8 +33,7 @@
|
|||||||
<span class="nojs--hide toggle-tag tag--hide">{{ _('Show tags') }}</span>
|
<span class="nojs--hide toggle-tag tag--hide">{{ _('Show tags') }}</span>
|
||||||
<span class="nojs--hide toggle-tag notag--hide">{{ _('Hide tags') }}</span>
|
<span class="nojs--hide toggle-tag notag--hide">{{ _('Hide tags') }}</span>
|
||||||
</th>
|
</th>
|
||||||
<th class="col--tried">{{ _('Tried') }}</th>
|
<th class="col--ac-tried">{{ _('AC') }} / {{ _('Tried') }}</th>
|
||||||
<th class="col--ac">{{ _('AC') }}</th>
|
|
||||||
<th class="col--difficulty">{{ _('Difficulty') }}</th>
|
<th class="col--difficulty">{{ _('Difficulty') }}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -69,8 +67,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{{ problem.render_problem_title(pdoc) }}
|
{{ problem.render_problem_title(pdoc) }}
|
||||||
</td>
|
</td>
|
||||||
<td class="col--tried">{{ pdoc.nSubmit }}</td>
|
<td class="col--ac-tried">{{ pdoc.nAccept }} / {{ pdoc.nSubmit }}</td>
|
||||||
<td class="col--ac">{{ pdoc.nAccept }}</td>
|
|
||||||
<td class="col--difficulty">{{ pdoc['difficulty'] or lib.difficulty(pdoc.nSubmit, pdoc.nAccept) or _('(None)') }}</td>
|
<td class="col--difficulty">{{ pdoc['difficulty'] or lib.difficulty(pdoc.nSubmit, pdoc.nAccept) or _('(None)') }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{%- endfor -%}
|
{%- endfor -%}
|
||||||
|
|||||||
Reference in new issue
Block a user