feat(groups): assign tutor to group
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
<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>
|
||||
<select id="newGroupTutor" style="background:var(--bg);border:1px solid var(--border);color:var(--text);border-radius:8px;padding:8px 12px;font-size:.85rem;min-width:160px"><option value="">— не назначен —</option></select>
|
||||
<button type="button" id="addGroupBtn">Добавить</button>
|
||||
</div>
|
||||
<div class="list" id="groupList"></div>
|
||||
|
||||
+26
-2
@@ -1,5 +1,6 @@
|
||||
const DAYS = ['Вс', 'Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб'];
|
||||
let branchesCache = [];
|
||||
let tutorsCache = [];
|
||||
let allGroups = [];
|
||||
let currentCover = null;
|
||||
|
||||
@@ -8,6 +9,16 @@ async function loadBranchesCache() {
|
||||
if (res.ok) branchesCache = await res.json();
|
||||
}
|
||||
|
||||
async function loadTutorsCache() {
|
||||
const res = await fetch(`${API}/api/users/tutors`, { headers: hdr() });
|
||||
if (res.ok) tutorsCache = await res.json();
|
||||
}
|
||||
|
||||
function tutorSelectHTML(selectedId) {
|
||||
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>`;
|
||||
}
|
||||
|
||||
function branchSelectHTML(selectedId) {
|
||||
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>`;
|
||||
@@ -15,6 +26,7 @@ function branchSelectHTML(selectedId) {
|
||||
|
||||
async function loadGroups() {
|
||||
await loadBranchesCache();
|
||||
await loadTutorsCache();
|
||||
const res = await fetch(`${API}/api/groups`, { headers: hdr() });
|
||||
const groups = await res.json();
|
||||
allGroups = groups;
|
||||
@@ -33,6 +45,7 @@ async function loadGroups() {
|
||||
</div>
|
||||
<div class="group-schedule">
|
||||
${branchSelectHTML(g.branch_id)}
|
||||
${tutorSelectHTML(g.tutor_id)}
|
||||
<div><label>День</label>
|
||||
<select id="dow-${g.id}">
|
||||
<option value="">—</option>
|
||||
@@ -66,13 +79,15 @@ async function saveGroup(id) {
|
||||
const groupCard = nameInput.closest('.group-card');
|
||||
const branchSelect = groupCard ? groupCard.querySelector('.branch-select') : null;
|
||||
const branch_id = branchSelect ? branchSelect.value : '';
|
||||
const tutorSelect = groupCard ? groupCard.querySelector('.tutor-select') : null;
|
||||
const tutor_id = tutorSelect ? (tutorSelect.value || null) : undefined;
|
||||
const dow = document.getElementById(`dow-${id}`).value;
|
||||
const ts = document.getElementById(`ts-${id}`).value;
|
||||
const te = document.getElementById(`te-${id}`).value;
|
||||
const res = await fetch(`${API}/api/groups/${id}`, {
|
||||
method: 'PUT',
|
||||
headers: hdrJson(),
|
||||
body: JSON.stringify({ name, branch_id: branch_id || null, day_of_week: dow !== '' ? parseInt(dow) : null, time_start: ts || null, time_end: te || null })
|
||||
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 })
|
||||
});
|
||||
if (res.ok) {
|
||||
loadGroups();
|
||||
@@ -87,9 +102,12 @@ async function addGroup() {
|
||||
const name = input.value.trim();
|
||||
if (!name) return;
|
||||
await loadBranchesCache();
|
||||
await loadTutorsCache();
|
||||
const branchSelect = document.getElementById('newGroupBranch');
|
||||
const branch_id = branchSelect ? branchSelect.value : '';
|
||||
const res = await fetch(`${API}/api/groups`, { method: 'POST', headers: hdrJson(), body: JSON.stringify({ name, branch_id: branch_id || null }) });
|
||||
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 }) });
|
||||
if (res.ok) { input.value = ''; loadGroups(); }
|
||||
else { const e = await res.json(); alert(e.error); }
|
||||
}
|
||||
@@ -414,6 +432,12 @@ async function populateNewGroupBranch() {
|
||||
const sel = document.getElementById('newGroupBranch');
|
||||
sel.innerHTML = '<option value="">— без филиала —</option>' + branches.map(b => `<option value="${b.id}">${esc(b.name)}</option>`).join('');
|
||||
}
|
||||
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('');
|
||||
}
|
||||
}
|
||||
|
||||
(async () => {
|
||||
|
||||
Reference in New Issue
Block a user