Обновление страницы ученика, сервера и добавление очистки фото
This commit is contained in:
+67
-1
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user