Обновление страницы ученика, сервера и добавление очистки фото

This commit is contained in:
dev
2026-11-05 17:12:37 +03:00
parent 45ec4b80a8
commit cdb364b34b
4 changed files with 205 additions and 1 deletions
+67 -1
View File
@@ -6,6 +6,8 @@
let activeTab = 'entries';
let facesLoaded = false;
let facesData = null;
let brokenFaces = null;
let brokenFacesLoaded = false;
let achTypes = [];
let achTypesLoaded = false;
let achEditId = null;
@@ -229,6 +231,16 @@
return `<figure class="sp-face">${photoTile(f.path, 'sp-photo', f.photo_original_path)}<figcaption class="sp-face-cap">${esc(f.group_name || '')}${cap ? ` · <b>${esc(cap)}</b>` : ''}</figcaption></figure>`;
}).join('')}</div>`;
}
const broken = (brokenFaces && brokenFaces.broken) || [];
if (broken.length) {
const admin = typeof isAdmin === 'function' && isAdmin();
html += `<div class="sp-block-label" style="margin-top:20px;color:var(--danger)">Битые ссылки на фото (${broken.length}) — файл не найден</div><div class="sp-photos">${broken.map(f => {
return `<figure class="sp-face sp-face-broken"><div class="sp-broken-tile" data-img="${esc(photoFull(f.photo_path))}"><div class="sp-broken-icon"><i data-lucide="image-off"></i></div><div class="sp-broken-name">${esc(f.photo_path)}</div></div><figcaption class="sp-face-cap">${esc(f.group_name || '')} · ${f.table === 'student_face_refs' ? 'эталон лица' : 'найденное лицо'}${admin ? ` <button type="button" class="icon-btn danger" data-broken-del="${f.table}:${f.id}" title="Удалить битую ссылку"><i data-lucide="trash-2"></i></button>` : ''}</figcaption></figure>`;
}).join('')}</div>`;
if (admin) {
html += `<div style="margin-top:10px"><button type="button" class="btn-danger" id="spBrokenClearBtn">Удалить все битые ссылки этого ученика (${broken.length})</button></div>`;
}
}
if (!html) html = emptyHtml('Фото с распознанным лицом не найдены');
return html;
}
@@ -243,6 +255,9 @@
loadFaces();
return;
}
if (!brokenFacesLoaded) {
loadBrokenFaces();
}
pane.innerHTML = facesHtml();
} else if (activeTab === 'entries') {
pane.innerHTML = entriesHtml();
@@ -271,6 +286,17 @@
if (activeTab === 'faces') renderPane();
}
async function loadBrokenFaces() {
try {
const res = await fetch(`${API}/api/students/${studentId}/faces/broken`, { headers: hdr() });
brokenFaces = res.ok ? await res.json() : { broken: [], total: 0 };
} catch {
brokenFaces = { broken: [], total: 0 };
}
brokenFacesLoaded = true;
if (activeTab === 'faces') renderPane();
}
function achItemHtml(a) {
return `<div class="sp-ach-item" data-ach-id="${a.id}">
<div class="sp-ach-top">
@@ -494,7 +520,7 @@
<div class="sp-tabs" id="spTabs"></div>
<div id="spPane"></div>
</div>`;
page.addEventListener('click', e => {
page.addEventListener('click', async e => {
const g = e.target.closest('[data-tab],[data-goto]');
if (!g) return;
const tab = g.dataset.tab || g.dataset.goto;
@@ -504,6 +530,46 @@
renderPane();
}
});
page.addEventListener('click', async e => {
const del = e.target.closest('[data-broken-del]');
if (del) {
const parts = del.dataset.brokenDel.split(':');
const table = parts[0];
const id = parseInt(parts[1], 10);
if (!confirm(`Удалить битую ссылку на фото «${table}:${id}»?`)) return;
try {
const url = table === 'student_face_refs'
? `${API}/api/students/${studentId}/face-refs/${id}/broken`
: `${API}/api/photo-faces/${id}/broken`;
const res = await fetch(url, { method: 'DELETE', headers: hdr() });
if (!res.ok) throw new Error('delete failed');
showToast('Битую ссылку удалено');
brokenFacesLoaded = false;
if (activeTab === 'faces') renderPane();
} catch {
showToast('Не удалось удалить битую ссылку', true);
}
return;
}
const clear = e.target.closest('#spBrokenClearBtn');
if (clear) {
if (!confirm(`Удалить все битые ссылки на фото этого ученика (${brokenFaces.total})?`)) return;
try {
const res = await fetch(`${API}/api/faces/cleanup`, {
method: 'POST',
headers: { ...hdr(), 'Content-Type': 'application/json' },
body: JSON.stringify({ student_id: studentId, limit: 5000 }),
});
const d = await res.json().catch(() => ({}));
if (!res.ok) throw new Error(d.error || 'cleanup failed');
showToast(`Удалено битых ссылок: ${d.deleted || 0}`);
brokenFacesLoaded = false;
if (activeTab === 'faces') renderPane();
} catch {
showToast('Не удалось выполнить пакетную очистку', true);
}
}
});
document.getElementById('spDownloadBtn').addEventListener('click', downloadProfile);
renderTabs();
renderPane();
+4
View File
@@ -90,6 +90,10 @@
.sp-face{display:flex;flex-direction:column;gap:6px;min-width:0;margin:0}
.sp-face-cap{font-size:.75rem;color:var(--muted);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.sp-face-cap b{color:var(--accent);font-weight:600}
.sp-face-broken{border:1px solid var(--danger);background:rgba(239,68,68,.06)}
.sp-broken-tile{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:8px;aspect-ratio:1;border-radius:13px;overflow:hidden;border:1px solid var(--border);background:var(--bg);padding:10px}
.sp-broken-icon{width:42px;height:42px;border-radius:10px;background:rgba(239,68,68,.12);color:#ef4444;display:flex;align-items:center;justify-content:center;font-size:20px}
.sp-broken-name{font-size:.68rem;color:#ef4444;text-align:center;overflow:hidden;text-overflow:ellipsis;max-width:140px}
.sp-loading{display:flex;align-items:center;justify-content:center;gap:10px;color:var(--muted);padding:60px 16px}
.sp-loading svg{width:20px;height:20px;animation:spin 1s linear infinite}
.sp-error{text-align:center;padding:60px 16px;color:#ef4444}