feat(groups): быстрые фильтры и права тьюторов, права на отчёты о занятии
- фильтры групп по филиалу, тьютору и дню, сохранение в localStorage и сброс - тьютор может редактировать только свои группы; филиал и тьютора меняет админ - редактирование отчётов о занятии доступно только автору или админу
This commit is contained in:
+22
-3
@@ -862,6 +862,22 @@ function showLessonDuplicate(modal, existingId) {
|
||||
row.hidden = !existingId;
|
||||
}
|
||||
|
||||
function canManageLessonReport(r) {
|
||||
if (isAdmin()) return true;
|
||||
if (!currentUser || !r || r.author_id == null) return false;
|
||||
return Number(r.author_id) === Number(currentUser.id);
|
||||
}
|
||||
|
||||
function setLessonModalReadonly(modal, readonly) {
|
||||
modal.querySelectorAll('#lessonGroup, #lessonDate, #lessonTime, #lessonTopic, #lessonText').forEach(el => { el.disabled = readonly; });
|
||||
const aiRow = modal.querySelector('#lessonAiRow');
|
||||
if (aiRow) aiRow.hidden = readonly;
|
||||
const submit = modal.querySelector('#lessonSubmit');
|
||||
if (submit) { submit.hidden = readonly; submit.textContent = 'Обновить'; }
|
||||
const title = modal.querySelector('#lessonModalTitle');
|
||||
if (title) title.textContent = readonly ? 'Просмотр отчёта о занятии' : 'Редактирование отчёта';
|
||||
}
|
||||
|
||||
function fillLessonModalFromReport(modal, r) {
|
||||
modal.querySelector('#lessonId').value = r.id;
|
||||
if (r.lesson_time && !modal.querySelector('#lessonTime').value) {
|
||||
@@ -878,8 +894,7 @@ function fillLessonModalFromReport(modal, r) {
|
||||
const aiCheck = modal.querySelector('#lessonAiCheck');
|
||||
if (aiCheck) aiCheck.checked = false;
|
||||
updateLessonAiRow(modal, r);
|
||||
modal.querySelector('#lessonModalTitle').textContent = 'Редактирование отчёта';
|
||||
modal.querySelector('#lessonSubmit').textContent = 'Обновить';
|
||||
setLessonModalReadonly(modal, !canManageLessonReport(r));
|
||||
}
|
||||
|
||||
function lessonAiStatusText(r) {
|
||||
@@ -911,6 +926,7 @@ function resetLessonModalFields(modal) {
|
||||
lessonDupSeq++;
|
||||
lessonGroupTouched = false;
|
||||
modal.querySelector('#lessonId').value = '';
|
||||
setLessonModalReadonly(modal, false);
|
||||
showLessonDuplicate(modal, null);
|
||||
modal.querySelector('#lessonDate').value = lessonTodayIso();
|
||||
modal.querySelector('#lessonTime').value = lessonNowTime();
|
||||
@@ -932,6 +948,7 @@ const LESSON_VERSION_LABELS = {
|
||||
};
|
||||
|
||||
let currentLessonVersionId = '';
|
||||
let currentLessonVersionManaged = false;
|
||||
|
||||
function ensureLessonVersionsModal() {
|
||||
let modal = document.getElementById('lessonVersionsModal');
|
||||
@@ -971,13 +988,14 @@ function lessonVersionItemHtml(v, index) {
|
||||
<div class="lesson-version-foot">
|
||||
${who ? `<span class="lesson-version-author">${esc(who)}</span>` : ''}
|
||||
${index === 0 ? '<span class="lesson-badge">текущая</span>' : ''}
|
||||
${index === 0 ? '' : `<button type="button" class="btn-link" data-restore="${v.id}" data-report="${v.lesson_report_id || currentLessonVersionId || ''}">Восстановить</button>`}
|
||||
${index === 0 ? '' : (currentLessonVersionManaged ? `<button type="button" class="btn-link" data-restore="${v.id}" data-report="${v.lesson_report_id || currentLessonVersionId || ''}">Восстановить</button>` : '')}
|
||||
</div>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
async function openLessonVersions(id) {
|
||||
currentLessonVersionId = String(id || '');
|
||||
currentLessonVersionManaged = false;
|
||||
const modal = ensureLessonVersionsModal();
|
||||
const list = modal.querySelector('#lessonVersionsList');
|
||||
list.innerHTML = '<div class="empty">Загрузка…</div>';
|
||||
@@ -987,6 +1005,7 @@ async function openLessonVersions(id) {
|
||||
const res = await fetch(`${API}/api/lesson-reports/${id}/versions`, { headers: hdr() });
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (!res.ok) { list.innerHTML = `<div class="empty">${esc(data.error || 'Не удалось загрузить историю')}</div>`; return; }
|
||||
currentLessonVersionManaged = canManageLessonReport({ author_id: data.author_id });
|
||||
const items = data.items || [];
|
||||
if (!items.length) { list.innerHTML = '<div class="empty">Версий пока нет</div>'; return; }
|
||||
list.innerHTML = items.map(lessonVersionItemHtml).join('');
|
||||
|
||||
@@ -48,6 +48,12 @@
|
||||
<div class="sidebar" id="sidebar"></div>
|
||||
<div class="main">
|
||||
<h2>Группы</h2>
|
||||
<div class="filters">
|
||||
<div><label>Филиал</label><select id="groupBranchFilter"><option value="">Все филиалы</option></select></div>
|
||||
<div><label>Тьютор</label><select id="groupTutorFilter"><option value="">Все тьюторы</option></select></div>
|
||||
<div><label>День</label><select id="groupDayFilter"><option value="">Все дни</option></select></div>
|
||||
<div><label> </label><button type="button" id="groupFiltersReset" style="background:var(--card);border:1px solid var(--border);color:var(--text);border-radius:8px;padding:8px 16px;font-size:.85rem;cursor:pointer;white-space:nowrap">Сбросить</button></div>
|
||||
</div>
|
||||
<div class="add-row" style="align-items:center;gap:8px">
|
||||
<input type="text" id="newGroup" placeholder="Название группы" style="flex:1;max-width:300px">
|
||||
<select id="newGroupBranch" style="background:var(--bg);border:1px solid var(--border);color:var(--text);border-radius:8px;padding:8px 12px;font-size:.85rem;min-width:180px"><option value="">— без филиала —</option></select>
|
||||
|
||||
+107
-18
@@ -6,6 +6,73 @@ let branchesCache = [];
|
||||
let tutorsCache = [];
|
||||
let allGroups = [];
|
||||
let currentCover = null;
|
||||
const GROUPS_FILTER_KEY = 'groupsFilters';
|
||||
let groupFilters = loadGroupFilters();
|
||||
|
||||
function loadGroupFilters() {
|
||||
try {
|
||||
const d = JSON.parse(localStorage.getItem(GROUPS_FILTER_KEY) || 'null');
|
||||
if (d && typeof d === 'object') return { branch: String(d.branch ?? ''), tutor: String(d.tutor ?? ''), day: String(d.day ?? '') };
|
||||
} catch (e) {}
|
||||
return { branch: '', tutor: '', day: '' };
|
||||
}
|
||||
|
||||
function saveGroupFilters() {
|
||||
try { localStorage.setItem(GROUPS_FILTER_KEY, JSON.stringify(groupFilters)); } catch (e) {}
|
||||
}
|
||||
|
||||
function pickFilterValue(el, value) {
|
||||
el.value = value;
|
||||
if (el.value !== value) el.value = '';
|
||||
return el.value;
|
||||
}
|
||||
|
||||
function renderGroupFilters() {
|
||||
const branchSel = document.getElementById('groupBranchFilter');
|
||||
const tutorSel = document.getElementById('groupTutorFilter');
|
||||
const daySel = document.getElementById('groupDayFilter');
|
||||
if (!branchSel || !tutorSel || !daySel) return;
|
||||
branchSel.innerHTML = '<option value="">Все филиалы</option><option value="none">Без филиала</option>' + branchesCache.map(b => `<option value="${b.id}">${esc(b.name)}</option>`).join('');
|
||||
tutorSel.innerHTML = '<option value="">Все тьюторы</option><option value="none">Без тьютора</option>' + tutorsCache.map(t => `<option value="${t.id}">${esc(t.name || t.username)}</option>`).join('');
|
||||
daySel.innerHTML = '<option value="">Все дни</option>' + [1, 2, 3, 4, 5, 6, 0].map(i => `<option value="${i}">${DAYS[i]}</option>`).join('') + '<option value="none">Без расписания</option>';
|
||||
const before = JSON.stringify(groupFilters);
|
||||
groupFilters.branch = pickFilterValue(branchSel, groupFilters.branch);
|
||||
groupFilters.tutor = pickFilterValue(tutorSel, groupFilters.tutor);
|
||||
groupFilters.day = pickFilterValue(daySel, groupFilters.day);
|
||||
if (before !== JSON.stringify(groupFilters)) saveGroupFilters();
|
||||
}
|
||||
|
||||
function groupMatchesFilters(g) {
|
||||
if (groupFilters.branch === 'none') {
|
||||
if (g.branch_id != null) return false;
|
||||
} else if (groupFilters.branch && String(g.branch_id ?? '') !== groupFilters.branch) return false;
|
||||
if (groupFilters.tutor === 'none') {
|
||||
if (g.tutor_id != null) return false;
|
||||
} else if (groupFilters.tutor && String(g.tutor_id ?? '') !== groupFilters.tutor) return false;
|
||||
if (groupFilters.day === 'none') {
|
||||
if (g.day_of_week != null) return false;
|
||||
} else if (groupFilters.day && String(g.day_of_week ?? '') !== groupFilters.day) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
function initGroupFilters() {
|
||||
[['groupBranchFilter', 'branch'], ['groupTutorFilter', 'tutor'], ['groupDayFilter', 'day']].forEach(([id, key]) => {
|
||||
const el = document.getElementById(id);
|
||||
if (!el) return;
|
||||
el.addEventListener('change', () => {
|
||||
groupFilters[key] = el.value;
|
||||
saveGroupFilters();
|
||||
renderGroups();
|
||||
});
|
||||
});
|
||||
const reset = document.getElementById('groupFiltersReset');
|
||||
if (reset) reset.addEventListener('click', () => {
|
||||
groupFilters = { branch: '', tutor: '', day: '' };
|
||||
saveGroupFilters();
|
||||
renderGroupFilters();
|
||||
renderGroups();
|
||||
});
|
||||
}
|
||||
|
||||
async function loadBranchesCache() {
|
||||
const res = await fetch(`${API}/api/branches`, { headers: hdr() });
|
||||
@@ -17,25 +84,36 @@ async function loadTutorsCache() {
|
||||
if (res.ok) tutorsCache = await res.json();
|
||||
}
|
||||
|
||||
function tutorSelectHTML(selectedId) {
|
||||
function tutorSelectHTML(selectedId, disabled = false) {
|
||||
const opts = tutorsCache.map(t => `<option value="${t.id}" ${t.id === selectedId ? 'selected' : ''}>${esc(t.name || t.username)}</option>`).join('');
|
||||
return `<div><label>Тутор</label><select class="tutor-select" style="background:var(--bg);border:1px solid var(--border);color:var(--text);border-radius:6px;padding:6px 8px;font-size:.8rem"><option value="">— не назначен —</option>${opts}</select></div>`;
|
||||
return `<div><label>Тутор</label><select class="tutor-select" ${disabled ? 'disabled' : ''} style="background:var(--bg);border:1px solid var(--border);color:var(--text);border-radius:6px;padding:6px 8px;font-size:.8rem"><option value="">— не назначен —</option>${opts}</select></div>`;
|
||||
}
|
||||
|
||||
function branchSelectHTML(selectedId) {
|
||||
function branchSelectHTML(selectedId, disabled = false) {
|
||||
const opts = branchesCache.map(b => `<option value="${b.id}" ${b.id === selectedId ? 'selected' : ''}>${esc(b.name)}</option>`).join('');
|
||||
return `<div><label>Филиал</label><select class="branch-select" style="background:var(--bg);border:1px solid var(--border);color:var(--text);border-radius:6px;padding:6px 8px;font-size:.8rem"><option value="">— без филиала —</option>${opts}</select></div>`;
|
||||
return `<div><label>Филиал</label><select class="branch-select" ${disabled ? 'disabled' : ''} style="background:var(--bg);border:1px solid var(--border);color:var(--text);border-radius:6px;padding:6px 8px;font-size:.8rem"><option value="">— без филиала —</option>${opts}</select></div>`;
|
||||
}
|
||||
|
||||
async function loadGroups() {
|
||||
await loadBranchesCache();
|
||||
await loadTutorsCache();
|
||||
const res = await fetch(`${API}/api/groups`, { headers: hdr() });
|
||||
const groups = await res.json();
|
||||
allGroups = groups;
|
||||
allGroups = await res.json();
|
||||
renderGroupFilters();
|
||||
renderGroups();
|
||||
}
|
||||
|
||||
function renderGroups() {
|
||||
const list = document.getElementById('groupList');
|
||||
if (!groups.length) { list.innerHTML = '<div style="color:var(--muted);text-align:center;padding:32px">Нет групп</div>'; return; }
|
||||
const groups = allGroups.filter(groupMatchesFilters);
|
||||
if (!groups.length) {
|
||||
list.innerHTML = `<div style="color:var(--muted);text-align:center;padding:32px">${allGroups.length ? 'Нет групп по выбранным фильтрам' : 'Нет групп'}</div>`;
|
||||
return;
|
||||
}
|
||||
list.innerHTML = `<div class="group-grid">` + groups.map(g => {
|
||||
const admin = isAdmin();
|
||||
const canEdit = admin || !!currentUser;
|
||||
const canDelete = admin || (currentUser && Number(g.tutor_id) === Number(currentUser.id));
|
||||
const schedSet = g.day_of_week != null && g.time_start && g.time_end;
|
||||
return `
|
||||
<div class="group-card" data-group-id="${g.id}">
|
||||
@@ -43,28 +121,28 @@ async function loadGroups() {
|
||||
? `<img class="group-cover" src="${thumbSrc(g.cover_path)}" data-img="${API}${g.cover_path}" loading="lazy" decoding="async" alt="">`
|
||||
: `<div class="group-cover empty-cover">📷</div>`}
|
||||
<div class="group-head">
|
||||
<input class="name-input" id="name-${g.id}" value="${esc(g.name)}">
|
||||
<button class="del" data-del-group="${g.id}" title="Удалить">×</button>
|
||||
<input class="name-input" id="name-${g.id}" value="${esc(g.name)}" ${canEdit ? '' : 'disabled'}>
|
||||
${canDelete ? `<button class="del" data-del-group="${g.id}" title="Удалить">×</button>` : ''}
|
||||
</div>
|
||||
<div class="group-schedule">
|
||||
${branchSelectHTML(g.branch_id)}
|
||||
${tutorSelectHTML(g.tutor_id)}
|
||||
${branchSelectHTML(g.branch_id, !admin)}
|
||||
${tutorSelectHTML(g.tutor_id, !admin)}
|
||||
<div><label>День</label>
|
||||
<select id="dow-${g.id}">
|
||||
<select id="dow-${g.id}" ${canEdit ? '' : 'disabled'}>
|
||||
<option value="">—</option>
|
||||
${DAYS.map((d, i) => `<option value="${i}" ${g.day_of_week === i ? 'selected' : ''}>${d}</option>`).join('')}
|
||||
</select>
|
||||
</div>
|
||||
<div><label>С</label>
|
||||
<input type="time" id="ts-${g.id}" value="${g.time_start ? g.time_start.slice(0,5) : ''}">
|
||||
<input type="time" id="ts-${g.id}" value="${g.time_start ? g.time_start.slice(0,5) : ''}" ${canEdit ? '' : 'disabled'}>
|
||||
</div>
|
||||
<div><label>По</label>
|
||||
<input type="time" id="te-${g.id}" value="${g.time_end ? g.time_end.slice(0,5) : ''}">
|
||||
<input type="time" id="te-${g.id}" value="${g.time_end ? g.time_end.slice(0,5) : ''}" ${canEdit ? '' : 'disabled'}>
|
||||
</div>
|
||||
</div>
|
||||
<div class="group-foot">
|
||||
<div style="display:flex;gap:8px">
|
||||
<button class="save-sched" data-save-group="${g.id}">Сохранить</button>
|
||||
${canEdit ? `<button class="save-sched" data-save-group="${g.id}">Сохранить</button>` : ''}
|
||||
<button class="photo-btn" data-group-id="${g.id}" data-group-name="${esc(g.name)}" title="Фото группы (хронология)">Фото</button>
|
||||
<button class="btn-link" data-export-group="${g.id}" data-group-name="${esc(g.name)}" title="Экспортировать записи группы">CSV</button>
|
||||
<button class="btn-link" data-export-urls="${g.id}" data-group-name="${esc(g.name)}" title="Скачать .url файлы учеников группы">URL</button>
|
||||
@@ -88,10 +166,15 @@ async function saveGroup(id) {
|
||||
const dow = document.getElementById(`dow-${id}`).value;
|
||||
const ts = document.getElementById(`ts-${id}`).value;
|
||||
const te = document.getElementById(`te-${id}`).value;
|
||||
const payload = { name, day_of_week: dow !== '' ? parseInt(dow) : null, time_start: ts || null, time_end: te || null };
|
||||
if (isAdmin()) {
|
||||
payload.branch_id = branch_id || null;
|
||||
payload.tutor_id = tutor_id;
|
||||
}
|
||||
const res = await fetch(`${API}/api/groups/${id}`, {
|
||||
method: 'PUT',
|
||||
headers: hdrJson(),
|
||||
body: JSON.stringify({ name, branch_id: branch_id || null, tutor_id, day_of_week: dow !== '' ? parseInt(dow) : null, time_start: ts || null, time_end: te || null })
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
if (res.ok) {
|
||||
loadGroups();
|
||||
@@ -111,7 +194,9 @@ async function addGroup() {
|
||||
const branch_id = branchSelect ? branchSelect.value : '';
|
||||
const tutorSelect = document.getElementById('newGroupTutor');
|
||||
const tutor_id = tutorSelect && tutorSelect.value ? tutorSelect.value : null;
|
||||
const res = await fetch(`${API}/api/groups`, { method: 'POST', headers: hdrJson(), body: JSON.stringify({ name, branch_id: branch_id || null, tutor_id }) });
|
||||
const payload = { name, branch_id: branch_id || null };
|
||||
if (isAdmin()) payload.tutor_id = tutor_id;
|
||||
const res = await fetch(`${API}/api/groups`, { method: 'POST', headers: hdrJson(), body: JSON.stringify(payload) });
|
||||
if (res.ok) { input.value = ''; loadGroups(); }
|
||||
else { const e = await res.json(); alert(e.error); }
|
||||
}
|
||||
@@ -891,11 +976,14 @@ async function populateNewGroupBranch() {
|
||||
const branches = await res.json();
|
||||
const sel = document.getElementById('newGroupBranch');
|
||||
sel.innerHTML = '<option value="">— без филиала —</option>' + branches.map(b => `<option value="${b.id}">${esc(b.name)}</option>`).join('');
|
||||
if (!isAdmin() && branches.length) sel.value = String(branches[0].id);
|
||||
}
|
||||
const tSel = document.getElementById('newGroupTutor');
|
||||
if (tSel) tSel.hidden = !isAdmin();
|
||||
if (!isAdmin()) return;
|
||||
const tRes = await fetch(`${API}/api/users/tutors`, { headers: hdr() });
|
||||
if (tRes.ok) {
|
||||
const tutors = await tRes.json();
|
||||
const tSel = document.getElementById('newGroupTutor');
|
||||
tSel.innerHTML = '<option value="">— не назначен —</option>' + tutors.map(t => `<option value="${t.id}">${esc(t.name || t.username)}</option>`).join('');
|
||||
}
|
||||
}
|
||||
@@ -904,6 +992,7 @@ async function populateNewGroupBranch() {
|
||||
if (await checkAuth()) {
|
||||
buildSidebar(document.body.dataset.page);
|
||||
await populateNewGroupBranch();
|
||||
initGroupFilters();
|
||||
loadGroups();
|
||||
connectFaceScanLive();
|
||||
}
|
||||
|
||||
+10
-3
@@ -23,6 +23,12 @@ function lessonAuthorText(r) {
|
||||
return upd ? `${name} · изменён ${notifyTime(r.updated_at)}` : name;
|
||||
}
|
||||
|
||||
function canManageLesson(r) {
|
||||
if (isAdmin()) return true;
|
||||
if (!currentUser || r.author_id == null) return false;
|
||||
return Number(r.author_id) === Number(currentUser.id);
|
||||
}
|
||||
|
||||
function lessonAiBadgeHtml(r) {
|
||||
const st = r.ai_status;
|
||||
if (!st || st === 'none') return '';
|
||||
@@ -38,6 +44,7 @@ function lessonItemHtml(r) {
|
||||
const isToday = String(r.lesson_date).slice(0, 10) === lessonTodayIso();
|
||||
const author = lessonAuthorText(r);
|
||||
const canRevert = !!r.text_original && r.text_original !== r.text;
|
||||
const canManage = canManageLesson(r);
|
||||
return `
|
||||
<div class="lesson-item" data-lesson="${r.id}">
|
||||
<div class="lesson-item-head">
|
||||
@@ -47,9 +54,9 @@ function lessonItemHtml(r) {
|
||||
${lessonAiBadgeHtml(r)}
|
||||
<div class="lesson-actions">
|
||||
<button type="button" class="btn-link" data-versions="${r.id}">История</button>
|
||||
${canRevert ? `<button type="button" class="btn-link" data-revert="${r.id}" title="Вернуть исходный текст тьютора">↩ Оригинал</button>` : ''}
|
||||
<button type="button" class="btn-link" data-edit="${r.id}">Редактировать</button>
|
||||
${isAdmin() ? `<button type="button" class="btn-link danger" data-del="${r.id}">Удалить</button>` : ''}
|
||||
${canRevert && canManage ? `<button type="button" class="btn-link" data-revert="${r.id}" title="Вернуть исходный текст тьютора">↩ Оригинал</button>` : ''}
|
||||
${canManage ? `<button type="button" class="btn-link" data-edit="${r.id}">Редактировать</button>` : ''}
|
||||
${canManage ? `<button type="button" class="btn-link danger" data-del="${r.id}">Удалить</button>` : ''}
|
||||
</div>
|
||||
</div>
|
||||
${r.topic ? `<div class="lesson-topic">${esc(r.topic)}</div>` : ''}
|
||||
|
||||
Reference in New Issue
Block a user