Admin fixes

This commit is contained in:
nyan404 committed 2026-08-16 21:03:25 +03:00
1 parent 6db39f0d51
commit a7f6fc0fc8
18 files changed
+285 -59

No files matched your search

+21 -5
View File
@@ -18,7 +18,8 @@
th, td { text-align: left; vertical-align: top; padding: 10px; border-bottom: 1px solid #4a383d; }
th { color: #d59b62; }
td pre { white-space: pre-wrap; margin: 0; max-width: 560px; }
td img { width: 96px; height: 72px; object-fit: cover; margin: 2px; border-radius: 5px; }
td .photo-list { display: flex; flex-wrap: wrap; gap: 4px; max-width: 320px; }
td img { width: 96px; height: 72px; object-fit: cover; border-radius: 5px; }
.muted { color: #b9aaad; }
</style>
</head>
@@ -28,12 +29,12 @@
<p class="muted">История подтверждённых расчётов из VK-бота и веб-калькулятора.</p>
<div class="toolbar">
<label>Пароль администратора<input id="password" type="password" autocomplete="current-password"></label>
<label>Сортировать<select id="sort"><option value="kitten_id">ID котёнка</option><option value="kitten_name">Имя котёнка</option></select></label>
<label>Сортировать<select id="sort"><option value="escort_id">ID кота</option><option value="escort_name">Имя кота</option><option value="kitten_id">ID котёнка</option><option value="kitten_name">Имя котёнка</option></select></label>
<label>Порядок<select id="direction"><option value="asc">А–Я / по возрастанию</option><option value="desc" selected>Я–А / по убыванию</option></select></label>
<button id="load">Загрузить</button>
</div>
<p class="error" id="error"></p>
<div class="table-wrap"><table><thead><tr><th>ID записи</th><th>Автор</th><th>Режим</th><th>Котёнок</th><th>Фото</th><th>Дата</th><th>Сообщение</th></tr></thead><tbody id="rows"></tbody></table></div>
<div class="table-wrap"><table><thead><tr><th>ID записи</th><th>Автор</th><th>Режим</th><th>Кот</th><th>Котёнок</th><th>Фото</th><th>Дата</th><th>Сообщение</th><th>Действие</th></tr></thead><tbody id="rows"></tbody></table></div>
</main>
<script>
const password = document.querySelector('#password');
@@ -52,19 +53,34 @@
data.items.forEach(item => {
const row = document.createElement('tr');
row.append(cell(item.id)); row.append(cell(item.actor_id || '—')); row.append(cell(item.mode));
row.append(cell(`${item.input.escort_name || item.input.character_name || '—'} [${item.input.escort_id || item.input.character_id || '—'}]`));
row.append(cell(`${item.input.kitten_name || '—'} [${item.input.kitten_id || '—'}]`));
const photos = document.createElement('td');
const photoList = document.createElement('div'); photoList.className = 'photo-list';
(item.input.attachments || []).forEach(photo => {
const photoUrl = photo.mirror_url || photo.url;
if (!photoUrl) return;
const link = document.createElement('a'); link.href = photoUrl; link.target = '_blank'; link.rel = 'noopener';
const image = document.createElement('img'); image.src = photoUrl; image.alt = 'Фото'; image.loading = 'lazy';
link.append(image); photos.append(link);
link.append(image); photoList.append(link);
});
if (!photos.childNodes.length) photos.textContent = '—';
if (photoList.childNodes.length) photos.append(photoList); else photos.textContent = '—';
row.append(photos);
row.append(cell(item.created_at));
const message = document.createElement('td'); const pre = document.createElement('pre'); pre.textContent = item.message; message.append(pre); row.append(message);
const actions = document.createElement('td');
const remove = document.createElement('button'); remove.textContent = 'Удалить';
remove.addEventListener('click', async () => {
if (!window.confirm(`Удалить запись №${item.id}?`)) return;
remove.disabled = true;
try {
const response = await fetch(`/api/admin/calculations/${encodeURIComponent(item.id)}`, {method: 'DELETE', headers: {'X-Admin-Password': password.value}});
const result = await response.json();
if (!response.ok) throw new Error(result.error || 'Не удалось удалить запись');
row.remove();
} catch (err) { error.textContent = err.message; remove.disabled = false; }
});
actions.append(remove); row.append(actions);
rows.append(row);
});
} catch (err) { error.textContent = err.message; }
+31 -1
View File
@@ -25,6 +25,9 @@
.bulk textarea { min-height: 100px; margin: 8px 0; }
.bulk-status { white-space: pre-wrap; }
.identity-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.extra-kittens { display: grid; gap: 8px; }
.extra-kitten { display: grid; grid-template-columns: 1fr 140px 180px auto; gap: 8px; align-items: end; }
@media (max-width: 700px) { .extra-kitten { grid-template-columns: 1fr; } }
dialog { max-width: min(440px, calc(100% - 32px)); background: #251e20; color: inherit; border: 1px solid #80656c; border-radius: 10px; padding: 20px; }
dialog::backdrop { background: #0009; }
.result { margin-top: 20px; }
@@ -63,6 +66,11 @@
<label>Имя котёнка<input name="kitten_name" required></label>
<label>ID котёнка<input name="kitten_id" type="number" min="1" required></label>
<label>Котёнок<select name="kitten_independence"><option value="самостоятельно">самостоятельно</option><option value="несамостоятельно">несамостоятельно</option></select></label>
<div class="wide extra-kittens">
<label>Дополнительные котята <span class="muted">(общие баллы не суммируются; 2-й ×1,5, следующие ×1,15)</span></label>
<div id="extraKittens"></div>
<button type="button" id="addKitten">Добавить котёнка</button>
</div>
</div>
<div id="training" class="grid mode hidden">
@@ -78,7 +86,7 @@
<div class="wide identity-tools"><button type="button" id="resolveIdentity">Найти связку имени и ID</button><span class="muted" id="identityStatus"></span></div>
<label>Место<select name="place"><option>дупло</option><option>расщелина</option></select></label>
<label>Количество осмотров<input name="inspections" type="number" min="0" value="0"></label>
<label class="wide">Ресурсы, по одному на строку: название; количество<br><textarea name="resources" placeholder="вьюнок; -2&#10;паук; 1"></textarea></label>
<label class="wide">Ресурсы, по одному на строку: название; количество<br><textarea name="resources" placeholder="вьюнок; 2&#10;паук; 1"></textarea></label>
</div>
<div class="actions"><button class="primary" type="submit">Подготовить сообщение</button><button type="button" id="copy" disabled>Скопировать</button></div>
@@ -109,6 +117,20 @@
const identityMissingLabel = document.querySelector('#identityMissingLabel');
const identityMissingValue = document.querySelector('#identityMissingValue');
let mode = 'coaching';
const extraKittens = document.querySelector('#extraKittens');
function addExtraKitten(values = {}) {
const row = document.createElement('div'); row.className = 'extra-kitten';
row.innerHTML = `<input data-extra="name" placeholder="Имя котёнка" required>
<input data-extra="id" type="number" min="1" placeholder="ID" required>
<select data-extra="independence"><option value="самостоятельно">самостоятельно</option><option value="несамостоятельно">несамостоятельно</option></select>
<button type="button" data-remove>Удалить</button>`;
row.querySelector('[data-extra="name"]').value = values.name || '';
row.querySelector('[data-extra="id"]').value = values.id || '';
row.querySelector('[data-extra="independence"]').value = values.independence || 'самостоятельно';
row.querySelector('[data-remove]').addEventListener('click', () => row.remove());
extraKittens.append(row);
}
document.querySelector('#addKitten').addEventListener('click', () => addExtraKitten());
function selectMode(nextMode) {
mode = nextMode;
document.querySelectorAll('[data-mode]').forEach(item => item.classList.toggle('active', item.dataset.mode === mode));
@@ -134,6 +156,7 @@
setField(target, key, value);
});
if (fields.resources) setField(target, 'resources', fields.resources.map(item => `${item[0]}; ${item[1]}`).join('\n'));
(fields.extra_kittens || []).forEach(item => addExtraKitten({name: item[0], id: item[1], independence: item[2]}));
bulkStatus.textContent = data.status === 'complete'
? 'Данные распознаны. Проверьте поля и нажмите «Подготовить сообщение».'
: `Нужно уточнить:\n${(data.questions || []).join('\n')}`;
@@ -186,6 +209,13 @@
return [name, Number(amount)];
});
}
if (mode === 'coaching') {
data.extra_kittens = [...extraKittens.querySelectorAll('.extra-kitten')].map(row => ({
name: row.querySelector('[data-extra="name"]').value.trim(),
id: Number(row.querySelector('[data-extra="id"]').value),
independence: row.querySelector('[data-extra="independence"]').value,
}));
}
return data;
}
form.addEventListener('submit', async event => {