сделал настройку временных слотов

This commit is contained in:
Zuev
2026-05-01 20:55:49 +03:00
parent bf02efb8b8
commit 3cb311f469
32 changed files with 2130 additions and 383 deletions

View File

@@ -37,17 +37,6 @@ export async function initSchedule() {
const rulesTbody = document.getElementById('schedule-tbody');
const refreshRulesButton = document.getElementById('schedule-refresh');
const timeSlotForm = document.getElementById('time-slot-form');
const timeSlotFormTitle = document.getElementById('time-slot-form-title');
const timeSlotIdInput = document.getElementById('time-slot-id');
const timeSlotOrderInput = document.getElementById('time-slot-order');
const timeSlotStartInput = document.getElementById('time-slot-start');
const timeSlotEndInput = document.getElementById('time-slot-end');
const timeSlotDurationInput = document.getElementById('time-slot-duration');
const timeSlotResetButton = document.getElementById('time-slot-reset');
const timeSlotsTbody = document.getElementById('time-slots-tbody');
const refreshSlotsButton = document.getElementById('time-slots-refresh');
let rules = [];
let subjects = [];
let groups = [];
@@ -70,10 +59,8 @@ export async function initSchedule() {
function bindEvents() {
refreshRulesButton?.addEventListener('click', loadRules);
refreshSlotsButton?.addEventListener('click', loadTimeSlots);
ruleResetButton?.addEventListener('click', resetRuleForm);
slotAddButton?.addEventListener('click', () => renderRuleSlots([...readRuleSlots(false), {}]));
timeSlotResetButton?.addEventListener('click', resetTimeSlotForm);
ruleSlotsContainer.addEventListener('click', (event) => {
const removeButton = event.target.closest('.schedule-slot-remove');
@@ -84,9 +71,7 @@ export async function initSchedule() {
});
ruleForm.addEventListener('submit', saveRule);
timeSlotForm.addEventListener('submit', saveTimeSlot);
rulesTbody.addEventListener('click', handleRuleTableClick);
timeSlotsTbody.addEventListener('click', handleTimeSlotTableClick);
}
async function loadBaseLists() {
@@ -293,97 +278,10 @@ export async function initSchedule() {
}
async function loadTimeSlots() {
timeSlotsTbody.innerHTML = '<tr><td colspan="5" class="loading-row">Загрузка...</td></tr>';
try {
timeSlots = await api.get('/api/admin/time-slots');
renderTimeSlots();
} catch (error) {
timeSlotsTbody.innerHTML = `<tr><td colspan="5" class="loading-row">Ошибка загрузки: ${escapeHtml(error.message)}</td></tr>`;
}
}
function renderTimeSlots() {
if (!timeSlots.length) {
timeSlotsTbody.innerHTML = '<tr><td colspan="5" class="loading-row">Сетка пар не настроена</td></tr>';
return;
}
timeSlotsTbody.innerHTML = timeSlots.map(slot => `
<tr>
<td>${slot.orderNumber}</td>
<td>${escapeHtml(trimTime(slot.startTime))}</td>
<td>${escapeHtml(trimTime(slot.endTime))}</td>
<td>${escapeHtml(String(slot.durationMinutes ?? '-'))}</td>
<td>
<button class="btn-edit-classroom btn-edit-time-slot" data-id="${slot.id}">Изменить</button>
<button class="btn-delete btn-delete-time-slot" data-id="${slot.id}">Удалить</button>
</td>
</tr>
`).join('');
}
async function saveTimeSlot(event) {
event.preventDefault();
hideAlert('time-slot-alert');
const payload = {
id: timeSlotIdInput.value ? Number(timeSlotIdInput.value) : null,
orderNumber: Number(timeSlotOrderInput.value),
startTime: timeSlotStartInput.value,
endTime: timeSlotEndInput.value,
durationMinutes: timeSlotDurationInput.value ? Number(timeSlotDurationInput.value) : null
};
try {
if (!payload.orderNumber || !payload.startTime || !payload.endTime) {
throw new Error('Заполните номер пары и время');
}
const id = timeSlotIdInput.value;
await (id
? api.put('/api/admin/time-slots/' + id, payload)
: api.post('/api/admin/time-slots', payload));
showAlert('time-slot-alert', 'Временной слот сохранён', 'success');
resetTimeSlotForm();
await loadTimeSlots();
renderRuleSlots(readRuleSlots(false).length ? readRuleSlots(false) : [{}]);
} catch (error) {
showAlert('time-slot-alert', error.message || 'Ошибка сохранения временного слота', 'error');
}
}
async function handleTimeSlotTableClick(event) {
const editButton = event.target.closest('.btn-edit-time-slot');
const deleteButton = event.target.closest('.btn-delete-time-slot');
if (editButton) {
const slot = timeSlots.find(item => item.id == editButton.dataset.id);
if (!slot) return;
timeSlotFormTitle.textContent = 'Редактирование временного слота';
timeSlotIdInput.value = slot.id;
timeSlotOrderInput.value = slot.orderNumber || '';
timeSlotStartInput.value = trimTime(slot.startTime);
timeSlotEndInput.value = trimTime(slot.endTime);
timeSlotDurationInput.value = slot.durationMinutes || '';
hideAlert('time-slot-alert');
timeSlotForm.scrollIntoView({ behavior: 'smooth', block: 'start' });
return;
}
if (deleteButton) {
if (!confirm('Удалить временной слот?')) return;
try {
await api.delete('/api/admin/time-slots/' + deleteButton.dataset.id);
showAlert('time-slot-alert', 'Временной слот удалён', 'success');
await loadTimeSlots();
renderRuleSlots(readRuleSlots(false).length ? readRuleSlots(false) : [{}]);
} catch (error) {
showAlert('time-slot-alert', error.message || 'Ошибка удаления временного слота', 'error');
}
}
}
function resetTimeSlotForm() {
timeSlotForm.reset();
timeSlotFormTitle.textContent = 'Новый временной слот';
timeSlotIdInput.value = '';
hideAlert('time-slot-alert');
const slots = await api.get('/api/admin/time-slots');
timeSlots = slots
.filter(slot => slot.scopeApplyMode === 'DEFAULT')
.sort((a, b) => (a.orderNumber || 0) - (b.orderNumber || 0));
}
function populateSubjectSelects() {