feat: add sent report history lookup

This commit is contained in:
nyan404 committed 2026-10-18 18:56:23 +03:00
1 parent 546fa37fce
commit 3ebab303a5
12 files changed
+393 -18

No files matched your search

+73 -1
View File
@@ -69,6 +69,11 @@
.site-footer { margin-top: 48px; padding-top: 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: .9rem; }
.site-footer a { color: inherit; text-underline-offset: 3px; }
.site-footer a:hover { color: var(--accent); }
.report-results { display: grid; gap: 14px; margin-top: 18px; }
.saved-report { padding: 20px; border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 8px; background: var(--paper); }
.saved-report h3 { margin: 0 0 12px; font-size: 1rem; }
.saved-report pre { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; line-height: 1.55; }
.saved-report img { display: block; width: min(100%, 680px); max-height: 480px; object-fit: contain; object-position: left; margin-top: 14px; border: 1px solid var(--line); border-radius: 6px; background: #f4efe7; }
@media (prefers-reduced-motion: reduce) { *,*::before,*::after { transition-duration:.01ms!important; } }
@media (max-width: 700px) {
main { width: calc(100% - 24px); max-width: 1060px; margin: 24px auto 40px; }
@@ -102,6 +107,7 @@
<nav class="tabs section-tabs" role="tablist" aria-label="Раздел Беличьей норы">
<button class="active" id="reportsTab" type="button" role="tab" aria-selected="true" aria-controls="reportsSection" data-section="reports">Отчёты</button>
<button id="sentReportsTab" type="button" role="tab" aria-selected="false" aria-controls="sentReportsSection" data-section="sentReports">Отчёты по ID кота</button>
<button id="applicationsTab" type="button" role="tab" aria-selected="false" aria-controls="applicationsSection" data-section="applications">Заявки</button>
<button id="identityTab" type="button" role="tab" aria-selected="false" aria-controls="identitySection" data-section="identity">Имя кота</button>
</nav>
@@ -222,6 +228,19 @@
<p class="error" id="error"></p>
</section>
</section>
<section id="sentReportsSection" class="hidden" role="tabpanel" aria-labelledby="sentReportsTab">
<h2>Найти отчёты по ID кота</h2>
<p class="muted">Покажем последние 100 отправленных отчётов, где кот указан участником.</p>
<form id="sentReportsForm" class="panel">
<div class="grid">
<label>ID кота<input id="sentReportsCharacterId" name="character_id" type="text" inputmode="numeric" pattern="[0-9]+" required></label>
<div class="actions" style="align-items:end;margin-top:0"><button class="primary" id="sentReportsSubmit" type="submit">Найти отчёты</button></div>
</div>
<p id="sentReportsStatus" class="muted" role="status" aria-live="polite"></p>
<p id="sentReportsError" class="error" role="alert"></p>
</form>
<div id="sentReportsResults" class="report-results" aria-live="polite"></div>
</section>
<section id="applicationsSection" class="hidden" role="tabpanel" aria-labelledby="applicationsTab">
<div id="applicationWorkspace">
@@ -547,9 +566,16 @@
goalCopy.addEventListener('click', async () => { await navigator.clipboard.writeText(message.value); goalCopy.textContent = 'Скопировано'; setTimeout(() => goalCopy.textContent = 'Скопировать', 1500); });
const reportsSection = document.querySelector('#reportsSection');
const sentReportsSection = document.querySelector('#sentReportsSection');
const applicationsSection = document.querySelector('#applicationsSection');
const identitySection = document.querySelector('#identitySection');
const sectionTabs = [...document.querySelectorAll('[data-section]')];
const sentReportsForm = document.querySelector('#sentReportsForm');
const sentReportsCharacterId = document.querySelector('#sentReportsCharacterId');
const sentReportsSubmit = document.querySelector('#sentReportsSubmit');
const sentReportsStatus = document.querySelector('#sentReportsStatus');
const sentReportsError = document.querySelector('#sentReportsError');
const sentReportsResults = document.querySelector('#sentReportsResults');
const applicationForm = document.querySelector('#applicationForm');
const applicationError = document.querySelector('#applicationError');
const applicationSuccess = document.querySelector('#applicationSuccess');
@@ -568,8 +594,9 @@
// Changes between reports, applications, and identity management while optionally updating the URL.
function setSection(nextSection, updateUrl = true) {
const selectedSection = ['reports', 'applications', 'identity'].includes(nextSection) ? nextSection : 'reports';
const selectedSection = ['reports', 'sentReports', 'applications', 'identity'].includes(nextSection) ? nextSection : 'reports';
reportsSection.classList.toggle('hidden', selectedSection !== 'reports');
sentReportsSection.classList.toggle('hidden', selectedSection !== 'sentReports');
applicationsSection.classList.toggle('hidden', selectedSection !== 'applications');
identitySection.classList.toggle('hidden', selectedSection !== 'identity');
sectionTabs.forEach(tab => {
@@ -587,6 +614,51 @@
sectionTabs.forEach(tab => tab.addEventListener('click', () => setSection(tab.dataset.section)));
window.addEventListener('popstate', () => setSection(new URLSearchParams(window.location.search).get('section'), false));
sentReportsForm.addEventListener('submit', async event => {
event.preventDefault();
sentReportsError.textContent = '';
sentReportsResults.replaceChildren();
const characterId = sentReportsCharacterId.value.trim();
if (!/^[0-9]+$/.test(characterId) || Number(characterId) <= 0) {
sentReportsError.textContent = 'Укажите положительный ID кота.';
return;
}
sentReportsSubmit.disabled = true;
sentReportsStatus.textContent = 'Ищем отчёты…';
try {
const response = await fetch(`/api/reports?character_id=${encodeURIComponent(characterId)}`);
const data = await response.json();
if (!response.ok) throw new Error(data.error || 'Не удалось загрузить отчёты.');
const items = data.items || [];
sentReportsStatus.textContent = items.length ? `Найдено отчётов: ${items.length}${items.length === data.limit ? ' (показаны последние 100)' : ''}.` : 'Для этого ID кота отчётов пока нет.';
items.forEach(item => {
const article = document.createElement('article');
article.className = 'saved-report';
const title = document.createElement('h3');
const date = item.created_at ? new Date(item.created_at) : null;
const dateLabel = date && !Number.isNaN(date.getTime()) ? new Intl.DateTimeFormat('ru-RU', {dateStyle: 'medium', timeStyle: 'short'}).format(date) : 'Дата неизвестна';
const labels = {coaching: 'Прокачка ЛУ/ЗУ', training: 'Тренировка', inspection: 'Осмотр'};
title.textContent = `${labels[item.mode] || 'Отчёт'} · ${dateLabel}`;
const message = document.createElement('pre');
message.textContent = item.message || '';
article.append(title, message);
(item.attachments || []).forEach(photo => {
const image = document.createElement('img');
image.src = photo.url;
image.alt = `Скриншот к отчёту кота ${characterId}`;
image.loading = 'lazy';
article.append(image);
});
sentReportsResults.append(article);
});
} catch (err) {
sentReportsStatus.textContent = '';
sentReportsError.textContent = err.message;
} finally {
sentReportsSubmit.disabled = false;
}
});
async function lookupRenameIdentity() {
renameIdentityError.textContent = '';
renameIdentitySuccess.classList.add('hidden');