groups: AI enhance for gallery photos (photo_jobs.group_photo_id, before/after compare modal)
This commit is contained in:
+113
-4
@@ -224,6 +224,43 @@ function render() {
|
||||
renderIcons();
|
||||
}
|
||||
|
||||
function photoCellHtml(r, side) {
|
||||
const rejected = r.status === 'rejected';
|
||||
if (side === 'before') {
|
||||
if (!r.before_path) {
|
||||
const title = rejected
|
||||
? 'Копия «Было» не создавалась: результат отклонён и не применялся'
|
||||
: 'Копия «Было» не создавалась для этого задания';
|
||||
return `<span class="photo-na" title="${esc(title)}">нет «было»</span>`;
|
||||
}
|
||||
return `<img class="photo-thumb" loading="lazy" src="${esc(thumbUrl(r.before_path))}" alt="было" title="Копия «Было» до обработки" data-fallback="нет файла" data-fallback-title="Файл копии «Было» не найден">`;
|
||||
}
|
||||
if (!r.after_path) {
|
||||
const title = rejected ? 'Задание отклонено до создания результата' : 'Файл результата не создавался';
|
||||
return `<span class="photo-na" title="${esc(title)}">нет «стало»</span>`;
|
||||
}
|
||||
if (rejected) {
|
||||
return '<span class="photo-na" title="Результат отклонён — файл удалён">удалён</span>';
|
||||
}
|
||||
return `<img class="photo-thumb" loading="lazy" src="${esc(thumbUrl(r.after_path))}" alt="стало" title="Результат обработки" data-fallback="нет файла" data-fallback-title="Файл результата не найден">`;
|
||||
}
|
||||
|
||||
function photoThumbFail(img) {
|
||||
if (!img.isConnected) return;
|
||||
const span = document.createElement('span');
|
||||
span.className = 'photo-na';
|
||||
span.textContent = img.dataset.fallback || 'нет файла';
|
||||
span.title = img.dataset.fallbackTitle || '';
|
||||
img.replaceWith(span);
|
||||
}
|
||||
|
||||
function bindPhotoThumbs(root) {
|
||||
root.querySelectorAll('img.photo-thumb[data-fallback]').forEach(img => {
|
||||
if (img.complete && !img.naturalWidth) { photoThumbFail(img); return; }
|
||||
img.addEventListener('error', () => photoThumbFail(img), { once: true });
|
||||
});
|
||||
}
|
||||
|
||||
function renderPhoto() {
|
||||
if (!photoState) return;
|
||||
const w = photoState.worker || {};
|
||||
@@ -254,8 +291,8 @@ function renderPhoto() {
|
||||
if (!photoTotal) { tbody.innerHTML = ''; empty.style.display = 'block'; renderPager(pager, photoPage, maxPage, p => { photoPage = p; loadPhoto(); }); return; }
|
||||
empty.style.display = 'none';
|
||||
tbody.innerHTML = rows.map(r => {
|
||||
const before = r.before_path ? `<img class="photo-thumb" loading="lazy" src="${esc(thumbUrl(r.before_path))}" alt="было">` : '<span style="color:var(--muted)">—</span>';
|
||||
const after = r.after_path ? `<img class="photo-thumb" loading="lazy" src="${esc(thumbUrl(r.after_path))}" alt="стало">` : '<span style="color:var(--muted)">—</span>';
|
||||
const before = photoCellHtml(r, 'before');
|
||||
const after = photoCellHtml(r, 'after');
|
||||
const canRollback = r.status === 'done' && r.before_path && r.action !== 'rollback';
|
||||
const badge = `<span class="ai-badge ${PHOTO_STATUS_BADGE[r.status] || ''}">${esc(PHOTO_STATUS_LABELS[r.status] || r.status)}</span>`;
|
||||
return `<tr>
|
||||
@@ -272,6 +309,7 @@ function renderPhoto() {
|
||||
</td>
|
||||
</tr>`;
|
||||
}).join('');
|
||||
bindPhotoThumbs(tbody);
|
||||
renderPager(pager, photoPage, maxPage, p => { photoPage = p; loadPhoto(); });
|
||||
renderIcons();
|
||||
}
|
||||
@@ -344,16 +382,87 @@ function renderPhotoJobMeta(r) {
|
||||
: '<span class="hint">Метаданные обработки недоступны</span>';
|
||||
}
|
||||
|
||||
function photoJobImgOk(img) {
|
||||
return !!(img.getAttribute('src') && img.complete && img.naturalWidth > 0);
|
||||
}
|
||||
|
||||
function imgSettled(img) {
|
||||
if (!img.getAttribute('src') || img.complete) return Promise.resolve();
|
||||
return new Promise(resolve => {
|
||||
img.addEventListener('load', resolve, { once: true });
|
||||
img.addEventListener('error', resolve, { once: true });
|
||||
});
|
||||
}
|
||||
|
||||
function photoJobMissingNotes(r, beforeOk, afterOk) {
|
||||
const notes = [];
|
||||
if (!beforeOk) {
|
||||
notes.push(r.status === 'rejected'
|
||||
? 'Копия «Было» не создавалась: результат отклонён и не применялся'
|
||||
: 'Копия «Было» не создавалась для этого задания');
|
||||
}
|
||||
if (!afterOk) {
|
||||
notes.push(r.status === 'rejected'
|
||||
? 'Файл «Стало» удалён после отклонения результата'
|
||||
: 'Файл «Стало» не найден');
|
||||
}
|
||||
return notes;
|
||||
}
|
||||
|
||||
function updatePhotoJobLayers(r, beforeOk, afterOk) {
|
||||
const beforeImg = document.getElementById('photoJobBefore');
|
||||
const top = document.getElementById('photoJobTop');
|
||||
const divider = document.getElementById('photoJobDivider');
|
||||
const empty = document.getElementById('photoJobEmpty');
|
||||
const note = document.getElementById('photoJobNote');
|
||||
const badgeBefore = document.getElementById('photoJobBadgeBefore');
|
||||
const badgeAfter = document.getElementById('photoJobBadgeAfter');
|
||||
const both = beforeOk && afterOk;
|
||||
const anyOk = beforeOk || afterOk;
|
||||
top.style.display = both ? '' : 'none';
|
||||
divider.style.display = both ? '' : 'none';
|
||||
badgeBefore.style.display = beforeOk ? '' : 'none';
|
||||
badgeAfter.style.display = afterOk ? '' : 'none';
|
||||
beforeImg.style.display = anyOk ? '' : 'none';
|
||||
setPhotoJobClip(both ? 50 : 100);
|
||||
const notes = photoJobMissingNotes(r, beforeOk, afterOk);
|
||||
empty.textContent = notes.join(' · ');
|
||||
empty.style.display = anyOk ? 'none' : 'flex';
|
||||
note.textContent = notes.join(' · ');
|
||||
note.style.display = anyOk && notes.length ? '' : 'none';
|
||||
}
|
||||
|
||||
async function loadPhotoJobImages(r) {
|
||||
const beforeImg = document.getElementById('photoJobBefore');
|
||||
const afterImg = document.getElementById('photoJobAfter');
|
||||
if (r.before_path) beforeImg.src = thumbUrl(r.before_path);
|
||||
else beforeImg.removeAttribute('src');
|
||||
const afterSrc = r.after_path && r.status !== 'rejected' ? `${API}${r.after_path}` : '';
|
||||
if (afterSrc) afterImg.src = afterSrc;
|
||||
else afterImg.removeAttribute('src');
|
||||
await Promise.all([imgSettled(beforeImg), imgSettled(afterImg)]);
|
||||
if (photoJobRow !== r) return;
|
||||
const beforeOk = photoJobImgOk(beforeImg);
|
||||
const afterOk = photoJobImgOk(afterImg);
|
||||
if (!beforeOk && afterOk) {
|
||||
beforeImg.src = thumbUrl(r.after_path);
|
||||
await imgSettled(beforeImg);
|
||||
if (photoJobRow !== r) return;
|
||||
}
|
||||
updatePhotoJobLayers(r, beforeOk, afterOk);
|
||||
}
|
||||
|
||||
function openPhotoJob(r) {
|
||||
photoJobRow = r;
|
||||
document.getElementById('photoJobTitle').textContent = `Обработка фото — запись #${r.entry_id} ${r.student_name || ''}`;
|
||||
document.getElementById('photoJobBefore').src = thumbUrl(r.before_path);
|
||||
document.getElementById('photoJobAfter').src = r.after_path ? `${API}${r.after_path}` : '';
|
||||
document.getElementById('photoJobNote').style.display = 'none';
|
||||
document.getElementById('photoJobEmpty').style.display = 'none';
|
||||
document.getElementById('photoJobRollbackBtn').style.display = (r.before_path && r.action !== 'rollback') ? '' : 'none';
|
||||
renderPhotoJobMeta(r);
|
||||
loadPhotoJobMeta().then(() => { if (photoJobRow === r) renderPhotoJobMeta(r); });
|
||||
setPhotoJobClip(50);
|
||||
document.getElementById('photoJobModal').classList.add('open');
|
||||
loadPhotoJobImages(r);
|
||||
}
|
||||
|
||||
async function loadPhoto() {
|
||||
|
||||
Reference in New Issue
Block a user