Add rating field to entries (1-10 scale) with UI display and module averages
This commit is contained in:
@@ -7,6 +7,7 @@ const groupInput = document.getElementById('groupInput');
|
||||
const moduleInput = document.getElementById('moduleInput');
|
||||
const moduleInputList = document.getElementById('moduleInputList');
|
||||
const moduleField = document.getElementById('moduleField');
|
||||
const ratingField = document.getElementById('ratingField');
|
||||
const moduleNames = new Map();
|
||||
const moduleAttachments = new Map();
|
||||
let moduleSearchTimer = null;
|
||||
@@ -433,6 +434,7 @@ async function applyModuleTopicAutofill() {
|
||||
if (list.length) {
|
||||
moduleInput.required = true;
|
||||
moduleField.style.display = '';
|
||||
ratingField.style.display = '';
|
||||
}
|
||||
}
|
||||
} catch (e) { /* ignore */ }
|
||||
@@ -610,6 +612,18 @@ form.addEventListener('submit', async (e) => {
|
||||
}
|
||||
}
|
||||
|
||||
let rating = '';
|
||||
if (moduleField.style.display !== 'none') {
|
||||
const checked = form.querySelector('input[name="rating"]:checked');
|
||||
if (!checked) {
|
||||
toast.textContent = 'Поставьте оценку занятия от 1 до 10';
|
||||
toast.classList.add('show', 'error');
|
||||
setTimeout(() => toast.classList.remove('show', 'error'), 3200);
|
||||
return;
|
||||
}
|
||||
rating = checked.value;
|
||||
}
|
||||
|
||||
// Проверка: если модуль требует вложений, то файлы должны быть прикреплены
|
||||
const moduleAttachmentEnabled = moduleAttachments.get((moduleInput.value || '').trim().toLowerCase()) === true;
|
||||
if (moduleAttachmentEnabled && selectedFiles.length === 0) {
|
||||
@@ -630,6 +644,7 @@ form.addEventListener('submit', async (e) => {
|
||||
fd.append('student_name', studentName || document.getElementById('nameInput').value);
|
||||
fd.append('group_id', groupInput.value);
|
||||
fd.append('module_id', moduleId || '');
|
||||
fd.append('rating', rating);
|
||||
fd.append('description', document.getElementById('descInput').value);
|
||||
fd.append('website', document.getElementById('hpWebsite').value);
|
||||
fd.append('client_id', clientId);
|
||||
|
||||
@@ -446,6 +446,22 @@ const AI_STATUS_ICONS = {
|
||||
reverted: 'undo',
|
||||
};
|
||||
|
||||
function fmtRating(v) {
|
||||
const n = Number(v);
|
||||
return Number.isFinite(n) ? n.toFixed(1).replace('.', ',') : '';
|
||||
}
|
||||
|
||||
function entryRatingHTML(e) {
|
||||
const parts = [];
|
||||
if (e.module_name && e.module_rating_avg !== null && e.module_rating_avg !== undefined) {
|
||||
parts.push(`<span class="entry-rate entry-rate-avg" title="Средний рейтинг модуля">Модуль ★ ${esc(fmtRating(e.module_rating_avg))}</span>`);
|
||||
}
|
||||
if (e.rating !== null && e.rating !== undefined && e.rating !== '') {
|
||||
parts.push(`<span class="entry-rate entry-rate-mine" title="Оценка ученика">Оценка ${esc(String(e.rating))}/10</span>`);
|
||||
}
|
||||
return parts.length ? `<div class="entry-rating">${parts.join('')}</div>` : '';
|
||||
}
|
||||
|
||||
function aiBadge(e) {
|
||||
if (!e || !e.ai_status) return '';
|
||||
const st = e.ai_status;
|
||||
@@ -485,6 +501,7 @@ function gridEntryHTML(e) {
|
||||
<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>
|
||||
${entryRatingHTML(e)}
|
||||
<div class="desc">${esc(e.description)}${aiBadge(e)}</div>
|
||||
${filesHTML(e.files)}
|
||||
<div class="time">${fmtFull(e.created_at)}</div>
|
||||
@@ -509,6 +526,7 @@ function cardEntryHTML(e) {
|
||||
${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>` : ''}
|
||||
<div class="body">
|
||||
<div class="name">${esc(e.student_name)}</div>
|
||||
${entryRatingHTML(e)}
|
||||
<div class="desc">${esc(e.description)}${aiBadge(e)}</div>
|
||||
${filesHTML(e.files)}
|
||||
</div>
|
||||
|
||||
@@ -55,7 +55,7 @@ function renderModules(total) {
|
||||
${m.photo_path ? `<img class="module-thumb" src="${thumbSrc(m.photo_path)}" alt="" data-img="${esc(API + m.photo_path)}">` : ''}
|
||||
<div class="module-info">
|
||||
<div class="module-name">${esc(m.name)}${m.has_attachments ? ' <span class="module-badge module-badge-attach">Вложения</span>' : ''}${m.is_active ? '' : ' <span class="module-badge">Отключён</span>'}</div>
|
||||
<div class="module-meta">${m.lessons_count} ${mPlural(m.lessons_count, 'занятие', 'занятия', 'занятий')} · ${m.entries_count} ${mPlural(m.entries_count, 'запись', 'записи', 'записей')}</div>
|
||||
<div class="module-meta">${m.lessons_count} ${mPlural(m.lessons_count, 'занятие', 'занятия', 'занятий')} · ${m.entries_count} ${mPlural(m.entries_count, 'запись', 'записи', 'записей')}${m.rating_avg != null ? ` · <span class="module-rating" title="Средний рейтинг модуля">★ ${Number(m.rating_avg).toFixed(1).replace('.', ',')}${m.rating_count ? ` (${m.rating_count})` : ''}</span>` : ''}</div>
|
||||
</div>
|
||||
<div class="student-actions">
|
||||
${m.is_active
|
||||
|
||||
Reference in New Issue
Block a user