feat(ui): улучшения фото-модалки, отправки записей и списка модулей
- enhance-модалка: индикатор «размышления» с прогрессом, иконки Lucide вместо эмодзи, подсветка готового результата, защита от гонок опроса - index.js: лимит модулей 1000, повторные попытки загрузки списка, таймаут и ретрай отправки записи, требование вложений по флагу модуля - journal.js/groups.js: `data-img` получает полный путь (лайтбокс вместо миниатюры), thumbSrc отдаёт `/uploads/thumb/` и оригиналы из `.originals/` - shorts.js: переключение «Использовано» без полной перезагрузки списка - AGENTS.md: правила миниатюр (`thumbSrc`) и `data-img`
This commit is contained in:
+132
-25
@@ -7,6 +7,7 @@ let editGroups = [];
|
||||
let editModules = [];
|
||||
let moduleNames = new Map();
|
||||
let moduleFilterId = '';
|
||||
const MODULE_LIST_LIMIT = 1000;
|
||||
let moduleSearchTimer = null;
|
||||
let editModuleSearchTimer = null;
|
||||
let modulesLoaded = false;
|
||||
@@ -250,7 +251,7 @@ function gridEntryHTML(e) {
|
||||
const mp = mainPhotoPath(e);
|
||||
return `
|
||||
<div class="card${highlightNewIds.has(e.id) ? ' entry-appear' : ' entry-enter'}">
|
||||
${mp ? `<img src="${thumbSrc(mp)}" data-img="${esc(thumbSrc(mp))}" loading="lazy" decoding="async" alt="">` : ''}
|
||||
${mp ? `<img src="${thumbSrc(mp)}" data-img="${API}${mp}" loading="lazy" decoding="async" alt="">` : ''}
|
||||
<div class="info">
|
||||
<div class="name">${esc(e.student_name)}</div>
|
||||
<div class="group">${esc(e.group_name)}${e.module_name ? ' · ' + esc(e.module_name) : ''}</div>
|
||||
@@ -271,7 +272,7 @@ function cardEntryHTML(e) {
|
||||
return `
|
||||
<div class="journal-card${highlightNewIds.has(e.id) ? ' entry-appear' : ' entry-enter'}">
|
||||
${mp
|
||||
? `<img src="${thumbSrc(mp)}" data-img="${esc(thumbSrc(mp))}" loading="lazy" decoding="async" alt="">`
|
||||
? `<img src="${thumbSrc(mp)}" data-img="${API}${mp}" loading="lazy" decoding="async" alt="">`
|
||||
: `<div class="no-photo"><svg viewBox="0 0 240 160" preserveAspectRatio="xMidYMid meet" aria-hidden="true"><circle cx="105" cy="48" r="15"/><path d="M74 140 C74 106 88 92 105 92 C122 92 136 106 136 140 Z"/><circle cx="145" cy="58" r="18"/><path d="M108 144 C108 104 124 88 145 88 C166 88 182 104 182 144 Z"/></svg></div>`}
|
||||
${e.group_name ? `<span class="group-badge" title="${esc(e.group_name)}">${esc(e.group_name)}</span>` : ''}
|
||||
${e.module_name ? `<span class="group-badge" style="left:auto;right:8px;background:rgba(37,99,235,.8)" title="Модуль: ${esc(e.module_name)}">${esc(e.module_name)}</span>` : ''}
|
||||
@@ -385,15 +386,22 @@ function renderModuleOptions(datalistId, list) {
|
||||
});
|
||||
}
|
||||
|
||||
async function fetchModules(q, limit) {
|
||||
async function fetchModules(q, limit, attempts = 2) {
|
||||
const p = new URLSearchParams();
|
||||
if (q) p.set('search', q);
|
||||
p.set('limit', String(limit));
|
||||
p.set('active', '1');
|
||||
const res = await fetch(`${API}/api/modules?${p}`, { headers: hdr() });
|
||||
if (!res.ok) return [];
|
||||
const data = await res.json().catch(() => ({}));
|
||||
return data.modules || [];
|
||||
for (let i = 0; i < attempts; i++) {
|
||||
try {
|
||||
const res = await fetch(`${API}/api/modules?${p}`, { headers: hdr() });
|
||||
if (!res.ok) return null;
|
||||
const data = await res.json().catch(() => ({}));
|
||||
return data.modules || [];
|
||||
} catch (e) {
|
||||
if (i < attempts - 1) await new Promise(r => setTimeout(r, 600));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async function resolveModuleId(name) {
|
||||
@@ -401,14 +409,18 @@ async function resolveModuleId(name) {
|
||||
if (!n) return '';
|
||||
if (moduleNames.has(n)) return String(moduleNames.get(n));
|
||||
const list = await fetchModules(n, 10);
|
||||
if (!list) return null;
|
||||
const lower = n.toLowerCase();
|
||||
const exact = list.find(m => m.name.toLowerCase() === lower);
|
||||
return exact ? String(exact.id) : null;
|
||||
}
|
||||
|
||||
async function loadModuleOptions() {
|
||||
editModules = await fetchModules('', 50);
|
||||
modulesLoaded = true;
|
||||
const list = await fetchModules('', MODULE_LIST_LIMIT);
|
||||
if (list) {
|
||||
editModules = list;
|
||||
modulesLoaded = true;
|
||||
}
|
||||
renderModuleOptions('moduleFilterList', editModules);
|
||||
}
|
||||
|
||||
@@ -666,10 +678,53 @@ function showEnhanceResult(show) {
|
||||
document.getElementById('enhanceLoading').style.display = show ? 'none' : '';
|
||||
}
|
||||
|
||||
function flashEnhanceResult() {
|
||||
const area = document.getElementById('enhanceCompare');
|
||||
if (!area) return;
|
||||
area.classList.remove('enhance-flash');
|
||||
void area.offsetWidth;
|
||||
area.classList.add('enhance-flash');
|
||||
setTimeout(() => area.classList.remove('enhance-flash'), 1200);
|
||||
}
|
||||
|
||||
function setBtnLabel(btn, text) {
|
||||
if (!btn) return;
|
||||
const icon = btn.querySelector('svg, i[data-lucide]');
|
||||
btn.textContent = '';
|
||||
if (icon) {
|
||||
btn.appendChild(icon);
|
||||
btn.appendChild(document.createTextNode(' ' + text));
|
||||
} else {
|
||||
btn.textContent = text;
|
||||
}
|
||||
}
|
||||
|
||||
function setEnhanceLoadingText(text) {
|
||||
const el = document.getElementById('enhanceLoading');
|
||||
if (!el) return;
|
||||
el.style.display = '';
|
||||
el.textContent = text;
|
||||
const textEl = document.getElementById('enhanceThinkingText');
|
||||
if (textEl) textEl.textContent = text;
|
||||
const dots = el.querySelector('.enhance-thinking-dots');
|
||||
if (dots) dots.style.display = '';
|
||||
const progress = document.getElementById('enhanceProgress');
|
||||
if (progress) progress.style.display = 'none';
|
||||
}
|
||||
|
||||
function setEnhanceLoadingProgress(pct, text) {
|
||||
const el = document.getElementById('enhanceLoading');
|
||||
if (!el) return;
|
||||
el.style.display = '';
|
||||
const textEl = document.getElementById('enhanceThinkingText');
|
||||
if (textEl && text) textEl.textContent = text;
|
||||
const dots = el.querySelector('.enhance-thinking-dots');
|
||||
if (dots) dots.style.display = pct >= 100 ? 'none' : '';
|
||||
const progress = document.getElementById('enhanceProgress');
|
||||
const bar = document.getElementById('enhanceProgressBar');
|
||||
if (progress && bar) {
|
||||
progress.style.display = '';
|
||||
bar.style.width = Math.min(100, Math.max(0, pct)) + '%';
|
||||
}
|
||||
}
|
||||
|
||||
let enhanceZoom = 1;
|
||||
@@ -835,20 +890,45 @@ async function runPhotoAi() {
|
||||
const { jobId } = await res.json();
|
||||
enhanceAiJobId = jobId;
|
||||
showEnhanceResult(false);
|
||||
setEnhanceLoadingText(mode.face === 'off'
|
||||
? 'ИИ обрабатывает фото... (может занять до минуты)'
|
||||
setEnhanceLoadingProgress(0, mode.face === 'off'
|
||||
? 'ИИ обрабатывает фото...'
|
||||
: 'ИИ обрабатывает фото и восстанавливает лица...');
|
||||
btn.textContent = '⏳ ИИ...';
|
||||
setBtnLabel(btn, '⏳ ИИ...');
|
||||
let doneHandled = false;
|
||||
const result = await new Promise((resolve, reject) => {
|
||||
photoAiPollTimer = setInterval(async () => {
|
||||
if (doneHandled) return;
|
||||
try {
|
||||
const r = await fetch(`${API}/api/entries/${entryId}/photo/enhance-ai/${jobId}`, { headers: hdr() });
|
||||
if (!r.ok) throw new Error('Ошибка опроса статуса');
|
||||
const s = await r.json();
|
||||
if (s.status === 'done') { clearInterval(photoAiPollTimer); resolve(s); }
|
||||
else if (s.status === 'error') { clearInterval(photoAiPollTimer); reject(new Error(s.error || 'Ошибка ИИ')); }
|
||||
} catch (e) { clearInterval(photoAiPollTimer); reject(e); }
|
||||
}, 2000);
|
||||
if (doneHandled) return;
|
||||
if (s.status === 'done') {
|
||||
doneHandled = true;
|
||||
clearInterval(photoAiPollTimer);
|
||||
const loadingEl = document.getElementById('enhanceLoading');
|
||||
if (loadingEl) loadingEl.style.display = 'none';
|
||||
resolve(s);
|
||||
}
|
||||
else if (s.status === 'error') {
|
||||
doneHandled = true;
|
||||
clearInterval(photoAiPollTimer);
|
||||
showEnhanceResult(true);
|
||||
reject(new Error(s.error || 'Ошибка ИИ'));
|
||||
}
|
||||
else {
|
||||
const progress = Math.min(95, Date.now() % 10000 / 100);
|
||||
setEnhanceLoadingProgress(progress, mode.face === 'off'
|
||||
? 'ИИ обрабатывает фото...'
|
||||
: 'ИИ обрабатывает фото и восстанавливает лица...');
|
||||
}
|
||||
} catch (e) {
|
||||
doneHandled = true;
|
||||
clearInterval(photoAiPollTimer);
|
||||
showEnhanceResult(true);
|
||||
reject(e);
|
||||
}
|
||||
}, 500);
|
||||
});
|
||||
showToast('ИИ результат готов');
|
||||
enhanceAiResultPath = result.photo_path;
|
||||
@@ -864,8 +944,9 @@ async function runPhotoAi() {
|
||||
document.getElementById('enhanceDenoise').value = 0;
|
||||
document.getElementById('enhanceDenoiseVal').textContent = '0%';
|
||||
renderEnhancePreview();
|
||||
flashEnhanceResult();
|
||||
};
|
||||
aiImg.onerror = () => { showToast('Не удалось загрузить результат ИИ'); };
|
||||
aiImg.onerror = () => { showEnhanceResult(true); showToast('Не удалось загрузить результат ИИ'); };
|
||||
aiImg.src = `${API}${result.photo_path}`;
|
||||
} catch (e) {
|
||||
showEnhanceResult(true);
|
||||
@@ -873,7 +954,7 @@ async function runPhotoAi() {
|
||||
} finally {
|
||||
enhanceSaving = false;
|
||||
btn.disabled = false;
|
||||
btn.textContent = '🤖 ИИ';
|
||||
setBtnLabel(btn, 'ИИ');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -921,6 +1002,8 @@ function openEnhance(id) {
|
||||
const orig = document.getElementById('enhanceOrig');
|
||||
orig.src = `${API}${mp}`;
|
||||
document.getElementById('enhanceRestoreBtn').style.display = e.photo_original_path ? '' : 'none';
|
||||
const aiBtn = document.getElementById('enhanceAiBtn');
|
||||
if (aiBtn) { aiBtn.disabled = false; setBtnLabel(aiBtn, 'ИИ'); }
|
||||
loadEnhanceEngine().then(() => {
|
||||
const show = photoAiEnabled ? '' : 'none';
|
||||
document.getElementById('enhanceAiBtn').style.display = show;
|
||||
@@ -931,14 +1014,24 @@ function openEnhance(id) {
|
||||
setEnhanceClip(50);
|
||||
resetEnhanceZoom();
|
||||
showEnhanceResult(false);
|
||||
setEnhanceLoadingText('Загрузка...');
|
||||
setEnhanceLoadingProgress(0, 'Загрузка...');
|
||||
renderIcons();
|
||||
const img = new Image();
|
||||
img.onload = () => {
|
||||
if (enhanceAiResultPath) return;
|
||||
enhanceSourceImg = img;
|
||||
renderEnhancePreview();
|
||||
};
|
||||
img.onerror = () => {
|
||||
setEnhanceLoadingText('Не удалось загрузить фото');
|
||||
const loadingEl = document.getElementById('enhanceLoading');
|
||||
if (loadingEl) {
|
||||
const textEl = document.getElementById('enhanceThinkingText');
|
||||
if (textEl) textEl.textContent = 'Не удалось загрузить фото';
|
||||
const dots = loadingEl.querySelector('.enhance-thinking-dots');
|
||||
if (dots) dots.style.display = 'none';
|
||||
const progress = document.getElementById('enhanceProgress');
|
||||
if (progress) progress.style.display = 'none';
|
||||
}
|
||||
};
|
||||
img.src = `${API}${mp}`;
|
||||
document.getElementById('enhanceModal').classList.add('open');
|
||||
@@ -987,6 +1080,8 @@ function closeEnhance() {
|
||||
enhanceEntryId = null;
|
||||
enhanceSourceImg = null;
|
||||
enhanceAiResultPath = null;
|
||||
const loadingEl = document.getElementById('enhanceLoading');
|
||||
if (loadingEl) loadingEl.style.display = 'none';
|
||||
}
|
||||
|
||||
function photoJobThumb(p) {
|
||||
@@ -1061,13 +1156,23 @@ async function rollbackPhotoJob(jobId) {
|
||||
const mp = data.photo_path;
|
||||
document.getElementById('enhanceOrig').src = `${API}${mp}`;
|
||||
showEnhanceResult(false);
|
||||
setEnhanceLoadingText('Загрузка...');
|
||||
setEnhanceLoadingProgress(0, 'Загрузка...');
|
||||
const img = new Image();
|
||||
img.onload = () => {
|
||||
enhanceSourceImg = img;
|
||||
renderEnhancePreview();
|
||||
};
|
||||
img.onerror = () => setEnhanceLoadingText('Не удалось загрузить фото');
|
||||
img.onerror = () => {
|
||||
const loadingEl = document.getElementById('enhanceLoading');
|
||||
if (loadingEl) {
|
||||
const textEl = document.getElementById('enhanceThinkingText');
|
||||
if (textEl) textEl.textContent = 'Не удалось загрузить фото';
|
||||
const dots = loadingEl.querySelector('.enhance-thinking-dots');
|
||||
if (dots) dots.style.display = 'none';
|
||||
const progress = document.getElementById('enhanceProgress');
|
||||
if (progress) progress.style.display = 'none';
|
||||
}
|
||||
};
|
||||
img.src = `${API}${mp}`;
|
||||
refreshEntryCard(enhanceEntryId);
|
||||
} catch (e) {
|
||||
@@ -1475,14 +1580,16 @@ document.getElementById('moduleFilter').addEventListener('input', () => {
|
||||
clearTimeout(moduleSearchTimer);
|
||||
const q = document.getElementById('moduleFilter').value.trim();
|
||||
moduleSearchTimer = setTimeout(async () => {
|
||||
renderModuleOptions('moduleFilterList', await fetchModules(q, 20));
|
||||
const list = await fetchModules(q, q ? 20 : MODULE_LIST_LIMIT);
|
||||
if (list) renderModuleOptions('moduleFilterList', list);
|
||||
}, 250);
|
||||
});
|
||||
document.getElementById('editModule').addEventListener('input', () => {
|
||||
clearTimeout(editModuleSearchTimer);
|
||||
const q = document.getElementById('editModule').value.trim();
|
||||
editModuleSearchTimer = setTimeout(async () => {
|
||||
renderModuleOptions('editModuleList', await fetchModules(q, 20));
|
||||
const list = await fetchModules(q, q ? 20 : MODULE_LIST_LIMIT);
|
||||
if (list) renderModuleOptions('editModuleList', list);
|
||||
}, 250);
|
||||
});
|
||||
document.getElementById('dateFrom').addEventListener('change', () => { page = 1; loadEntries(); });
|
||||
|
||||
Reference in New Issue
Block a user