feat(audit & reports): stabilize live presence, day intervals and reports logic before topics feature
This commit is contained in:
@@ -92,6 +92,7 @@ function switchRegistrySubTab(subTab) {
|
||||
else if (subTab === 'remote') loadRemoteWorkersView();
|
||||
else if (subTab === 'local_trip') loadManualAbsencesView('LOCAL_TRIP');
|
||||
else if (subTab === 'other') loadManualAbsencesView('OTHER');
|
||||
else if (subTab === 'schedules') loadSchedulesView();
|
||||
}
|
||||
|
||||
async function loadExceptionsView() {
|
||||
@@ -417,4 +418,253 @@ async function deleteManualAbsenceRecord(id, type) {
|
||||
} catch (e) {
|
||||
alert('Ошибка сети');
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// ВКЛАДКА "ГРАФИКИ РАБОТЫ СОТРУДНИКОВ"
|
||||
// ============================================================================
|
||||
|
||||
let schedulesTemplatesCache = [];
|
||||
let allEmployeesSchedulesCache = [];
|
||||
|
||||
async function loadSchedulesTemplates() {
|
||||
if (schedulesTemplatesCache.length > 0) return schedulesTemplatesCache;
|
||||
try {
|
||||
const res = await fetch('/api/v1/schedules/templates', { headers: AuthManager.getAuthHeaders() });
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
schedulesTemplatesCache = data.templates || [];
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Ошибка загрузки шаблонов графиков:", e);
|
||||
}
|
||||
return schedulesTemplatesCache;
|
||||
}
|
||||
|
||||
async function loadSchedulesView() {
|
||||
const container = document.getElementById('registry-content-container');
|
||||
if (!container) return;
|
||||
|
||||
container.innerHTML = '<div class="text-center py-10 text-slate-400 text-xs"><i class="fa-solid fa-spinner fa-spin mr-1"></i> Загрузка графиков...</div>';
|
||||
|
||||
await loadSchedulesTemplates();
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/v1/schedules/employees', { headers: AuthManager.getAuthHeaders() });
|
||||
if (!res.ok) throw new Error('Ошибка сети');
|
||||
const data = await res.json();
|
||||
allEmployeesSchedulesCache = data.items || [];
|
||||
renderSchedulesList(allEmployeesSchedulesCache);
|
||||
} catch (e) {
|
||||
container.innerHTML = '<div class="text-center py-8 text-rose-500 text-xs">Не удалось загрузить графики сотрудников</div>';
|
||||
}
|
||||
}
|
||||
|
||||
function renderSchedulesList(items) {
|
||||
const container = document.getElementById('registry-content-container');
|
||||
if (!container) return;
|
||||
|
||||
const depts = Array.from(new Set(allEmployeesSchedulesCache.map(i => i.department).filter(Boolean))).sort();
|
||||
|
||||
const deptsOptions = depts.map(d => `<option value="${escapeHtml(d)}">${escapeHtml(d)}</option>`).join('');
|
||||
|
||||
const templateOptions = (currentTemplateId) => {
|
||||
return schedulesTemplatesCache.map(t => {
|
||||
const isSel = (t.id === currentTemplateId) ? 'selected' : '';
|
||||
return `<option value="${t.id}" ${isSel}>${escapeHtml(t.name)}</option>`;
|
||||
}).join('');
|
||||
};
|
||||
|
||||
let listHtml = '';
|
||||
if (items.length === 0) {
|
||||
listHtml = '<div class="text-center py-8 text-xs text-slate-400 bg-white border border-slate-200 rounded-xl p-4">Сотрудники не найдены</div>';
|
||||
} else {
|
||||
listHtml = items.map(item => {
|
||||
const id = item.id;
|
||||
const fio = escapeHtml(item.fio);
|
||||
const dept = escapeHtml(item.department || '—');
|
||||
const pos = escapeHtml(item.position || '—');
|
||||
const schedName = escapeHtml(item.schedule_name || 'Стандарт');
|
||||
const basis = escapeHtml(item.doc_basis || '');
|
||||
const comment = escapeHtml(item.comment || '');
|
||||
|
||||
let badgeColor = 'bg-slate-100 text-slate-700 border-slate-200';
|
||||
if (item.work_mode === 'REMOTE') badgeColor = 'bg-blue-50 text-blue-700 border-blue-200';
|
||||
else if (item.work_mode === 'HYBRID') badgeColor = 'bg-amber-50 text-amber-700 border-amber-200';
|
||||
else if (item.work_mode === 'MATERNITY') badgeColor = 'bg-purple-50 text-purple-700 border-purple-200';
|
||||
else if (item.norm_hours < 8) badgeColor = 'bg-emerald-50 text-emerald-700 border-emerald-200';
|
||||
|
||||
return `
|
||||
<div class="p-3 bg-white border border-slate-200 rounded-xl shadow-xs text-xs flex flex-col gap-2 hover:border-slate-300 transition" id="sched-card-${id}">
|
||||
<div class="flex items-start justify-between gap-2">
|
||||
<div class="min-w-0">
|
||||
<span class="font-bold text-slate-800 truncate block" title="${fio}">${fio}</span>
|
||||
<span class="text-[10px] text-slate-400 truncate block">${dept} · ${pos}</span>
|
||||
</div>
|
||||
<span class="text-[10px] font-semibold px-2 py-0.5 rounded-md border shrink-0 ${badgeColor}">
|
||||
${schedName}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<!-- Выпадающий список прямого переключения графика -->
|
||||
<div class="flex items-center gap-1.5 pt-1 border-t border-slate-100">
|
||||
<label class="text-[10px] text-slate-400 shrink-0">Режим:</label>
|
||||
<select onchange="quickChangeEmployeeSchedule(${id}, this.value)"
|
||||
class="text-[11px] py-1 px-1.5 bg-slate-50 border border-slate-200 rounded-lg text-slate-700 flex-1 focus:outline-none focus:border-indigo-500 font-mono">
|
||||
${templateOptions(item.template_id)}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
${basis || comment ? `
|
||||
<div class="text-[10px] text-slate-500 bg-slate-50 p-1.5 rounded-lg border border-slate-100">
|
||||
${basis ? `<span class="font-semibold text-slate-600">Основание:</span> ${basis}` : ''}
|
||||
${comment ? `<span class="block text-slate-400 mt-0.5">${comment}</span>` : ''}
|
||||
</div>
|
||||
` : ''}
|
||||
</div>
|
||||
`;
|
||||
}).join('');
|
||||
}
|
||||
|
||||
container.innerHTML = `
|
||||
<div class="space-y-2">
|
||||
<!-- Поиск и фильтры по графикам -->
|
||||
<div class="p-2.5 bg-white border border-slate-200 rounded-xl shadow-xs space-y-2">
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="text-xs font-bold text-slate-700">Графики сотрудников: ${allEmployeesSchedulesCache.length}</span>
|
||||
<button onclick="loadSchedulesView()" class="text-xs text-slate-400 hover:text-indigo-600 transition" title="Обновить">
|
||||
<i class="fa-solid fa-rotate-right"></i>
|
||||
</button>
|
||||
</div>
|
||||
<input type="text" id="schedules-search-input" oninput="filterSchedulesView()"
|
||||
placeholder="Поиск по фамилии..."
|
||||
class="w-full text-xs px-2.5 py-1.5 bg-slate-50 border border-slate-200 rounded-lg focus:outline-none focus:border-indigo-500">
|
||||
<div class="grid grid-cols-2 gap-1.5">
|
||||
<select id="schedules-dept-filter" onchange="filterSchedulesView()"
|
||||
class="text-xs px-2 py-1 bg-slate-50 border border-slate-200 rounded-lg text-slate-600">
|
||||
<option value="ALL">Все отделы</option>
|
||||
${deptsOptions}
|
||||
</select>
|
||||
<select id="schedules-mode-filter" onchange="filterSchedulesView()"
|
||||
class="text-xs px-2 py-1 bg-slate-50 border border-slate-200 rounded-lg text-slate-600">
|
||||
<option value="ALL">Все режимы</option>
|
||||
<option value="OFFICE">Офис</option>
|
||||
<option value="REMOTE">Удаленка</option>
|
||||
<option value="HYBRID">Гибрид</option>
|
||||
<option value="MATERNITY">Декрет</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Список сотрудников -->
|
||||
<div class="space-y-2 max-h-[60vh] overflow-y-auto" id="schedules-items-box">
|
||||
${listHtml}
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
function filterSchedulesView() {
|
||||
const q = (document.getElementById('schedules-search-input')?.value || '').toLowerCase().trim();
|
||||
const dept = document.getElementById('schedules-dept-filter')?.value || 'ALL';
|
||||
const mode = document.getElementById('schedules-mode-filter')?.value || 'ALL';
|
||||
|
||||
const filtered = allEmployeesSchedulesCache.filter(item => {
|
||||
if (dept !== 'ALL' && item.department !== dept) return false;
|
||||
if (mode !== 'ALL' && item.work_mode !== mode) return false;
|
||||
if (q && !item.fio.toLowerCase().includes(q) && !item.fio_clean.toLowerCase().includes(q)) return false;
|
||||
return true;
|
||||
});
|
||||
|
||||
const box = document.getElementById('schedules-items-box');
|
||||
if (!box) return;
|
||||
|
||||
if (filtered.length === 0) {
|
||||
box.innerHTML = '<div class="text-center py-8 text-xs text-slate-400 bg-white border border-slate-200 rounded-xl p-4">Нет сотрудников под выбранный фильтр</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
const templateOptions = (currentTemplateId) => {
|
||||
return schedulesTemplatesCache.map(t => {
|
||||
const isSel = (t.id === currentTemplateId) ? 'selected' : '';
|
||||
return `<option value="${t.id}" ${isSel}>${escapeHtml(t.name)}</option>`;
|
||||
}).join('');
|
||||
};
|
||||
|
||||
box.innerHTML = filtered.map(item => {
|
||||
const id = item.id;
|
||||
const fio = escapeHtml(item.fio);
|
||||
const dept = escapeHtml(item.department || '—');
|
||||
const pos = escapeHtml(item.position || '—');
|
||||
const schedName = escapeHtml(item.schedule_name || 'Стандарт');
|
||||
const basis = escapeHtml(item.doc_basis || '');
|
||||
const comment = escapeHtml(item.comment || '');
|
||||
|
||||
let badgeColor = 'bg-slate-100 text-slate-700 border-slate-200';
|
||||
if (item.work_mode === 'REMOTE') badgeColor = 'bg-blue-50 text-blue-700 border-blue-200';
|
||||
else if (item.work_mode === 'HYBRID') badgeColor = 'bg-amber-50 text-amber-700 border-amber-200';
|
||||
else if (item.work_mode === 'MATERNITY') badgeColor = 'bg-purple-50 text-purple-700 border-purple-200';
|
||||
else if (item.norm_hours < 8) badgeColor = 'bg-emerald-50 text-emerald-700 border-emerald-200';
|
||||
|
||||
return `
|
||||
<div class="p-3 bg-white border border-slate-200 rounded-xl shadow-xs text-xs flex flex-col gap-2 hover:border-slate-300 transition" id="sched-card-${id}">
|
||||
<div class="flex items-start justify-between gap-2">
|
||||
<div class="min-w-0">
|
||||
<span class="font-bold text-slate-800 truncate block" title="${fio}">${fio}</span>
|
||||
<span class="text-[10px] text-slate-400 truncate block">${dept} · ${pos}</span>
|
||||
</div>
|
||||
<span class="text-[10px] font-semibold px-2 py-0.5 rounded-md border shrink-0 ${badgeColor}">
|
||||
${schedName}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-1.5 pt-1 border-t border-slate-100">
|
||||
<label class="text-[10px] text-slate-400 shrink-0">Режим:</label>
|
||||
<select onchange="quickChangeEmployeeSchedule(${id}, this.value)"
|
||||
class="text-[11px] py-1 px-1.5 bg-slate-50 border border-slate-200 rounded-lg text-slate-700 flex-1 focus:outline-none focus:border-indigo-500 font-mono">
|
||||
${templateOptions(item.template_id)}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
${basis || comment ? `
|
||||
<div class="text-[10px] text-slate-500 bg-slate-50 p-1.5 rounded-lg border border-slate-100">
|
||||
${basis ? `<span class="font-semibold text-slate-600">Основание:</span> ${basis}` : ''}
|
||||
${comment ? `<span class="block text-slate-400 mt-0.5">${comment}</span>` : ''}
|
||||
</div>
|
||||
` : ''}
|
||||
</div>
|
||||
`;
|
||||
}).join('');
|
||||
}
|
||||
|
||||
async function quickChangeEmployeeSchedule(scheduleId, newTemplateId) {
|
||||
const tId = parseInt(newTemplateId, 10);
|
||||
try {
|
||||
const res = await fetch('/api/v1/schedules/assign', {
|
||||
method: 'PUT',
|
||||
headers: { ...AuthManager.getAuthHeaders(), 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
employee_schedule_id: scheduleId,
|
||||
template_id: tId
|
||||
})
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
const target = allEmployeesSchedulesCache.find(x => x.id === scheduleId);
|
||||
if (target) {
|
||||
target.template_id = tId;
|
||||
const tmpl = schedulesTemplatesCache.find(t => t.id === tId);
|
||||
if (tmpl) {
|
||||
target.schedule_name = tmpl.name;
|
||||
target.work_mode = tmpl.work_mode;
|
||||
target.norm_hours = tmpl.norm_hours;
|
||||
}
|
||||
}
|
||||
filterSchedulesView();
|
||||
} else {
|
||||
alert('Ошибка смены графика');
|
||||
}
|
||||
} catch (e) {
|
||||
alert('Сетевая ошибка при изменении графика');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user