352 lines
12 KiB
JavaScript
352 lines
12 KiB
JavaScript
// Language dictionaries
|
||
const i18n = {
|
||
kz: {
|
||
appTitle: 'ЖС Платформасы',
|
||
subtitle: 'Қазақтелеком АҚ — Өндірістік қауіпсіздік шаралары жоспары',
|
||
totalEvents: 'Шаралар саны',
|
||
doneEvents: 'Орындалды',
|
||
inProgress: 'Жұмыста',
|
||
delayed: 'Кешігіп тұр',
|
||
allSections: 'Барлық бөлімдер',
|
||
allBranches: 'Барлық филиалдар',
|
||
allStatuses: 'Барлық статус',
|
||
statusDone: 'Орындалды',
|
||
statusInProgress: 'Жұмыста',
|
||
statusDelayed: 'Кешігіп тұр',
|
||
statusNotStarted: 'Басталмады',
|
||
addEvent: '+ Шара',
|
||
exportReport: 'Есепті шығару',
|
||
history: 'Есептер тарихы',
|
||
name: 'Атауы',
|
||
section: 'Бөлім',
|
||
branch: 'Филиал',
|
||
responsible: 'Жауаптылар',
|
||
due: 'Мерзімі',
|
||
status: 'Статус',
|
||
progress: 'Прогресс',
|
||
actions: 'Әрекеттер',
|
||
date: 'Күні',
|
||
period: 'Кезеңі',
|
||
format: 'Форматы',
|
||
who: 'Кім құраған',
|
||
statusSent: 'Жіберу статусы',
|
||
back: '← Артқа',
|
||
nameKz: 'Атауы (Қазақша)',
|
||
nameRu: 'Атауы (Рус)',
|
||
description: 'Сипаттамасы',
|
||
done: 'Аяқталу күні',
|
||
comment: 'Пікір',
|
||
cancel: 'Бәсеңсіту',
|
||
save: 'Сақтау',
|
||
year2026: '2026',
|
||
q12026: '2026 Q1',
|
||
q22026: '2026 Q2',
|
||
excel: 'Excel',
|
||
pdf: 'PDF',
|
||
html: 'HTML',
|
||
allData: 'Барлық деректер',
|
||
delayedOnly: 'Тек кешігендер',
|
||
generate: 'Қалыптастыру',
|
||
notSent: 'Жіберілмеген',
|
||
sent: 'Жіберілді'
|
||
},
|
||
ru: {
|
||
appTitle: 'Платформа ПБ',
|
||
subtitle: 'АО «Казахтелеком» — План мероприятий по производственной безопасности',
|
||
totalEvents: 'Всего мероприятий',
|
||
doneEvents: 'Выполнено',
|
||
inProgress: 'В работе',
|
||
delayed: 'Задержано',
|
||
allSections: 'Все секции',
|
||
allBranches: 'Все филиалы',
|
||
allStatuses: 'Все статусы',
|
||
statusDone: 'Выполнено',
|
||
statusInProgress: 'В работе',
|
||
statusDelayed: 'Задержано',
|
||
statusNotStarted: 'Не начато',
|
||
addEvent: '+ Мероприятие',
|
||
exportReport: 'Выгрузить отчёт',
|
||
history: 'История отчётов',
|
||
name: 'Название',
|
||
section: 'Секция',
|
||
branch: 'Филиал',
|
||
responsible: 'Ответственные',
|
||
due: 'Срок',
|
||
status: 'Статус',
|
||
progress: 'Прогресс',
|
||
actions: 'Действия',
|
||
date: 'Дата',
|
||
period: 'Период',
|
||
format: 'Формат',
|
||
who: 'Кто сформировал',
|
||
statusSent: 'Статус отправки',
|
||
back: '← Назад',
|
||
nameKz: 'Название (Қазақша)',
|
||
nameRu: 'Название (Русский)',
|
||
description: 'Описание',
|
||
done: 'Дата завершения',
|
||
comment: 'Комментарий',
|
||
cancel: 'Отмена',
|
||
save: 'Сохранить',
|
||
year2026: '2026',
|
||
q12026: 'Q1 2026',
|
||
q22026: 'Q2 2026',
|
||
excel: 'Excel',
|
||
pdf: 'PDF',
|
||
html: 'HTML',
|
||
allData: 'Все данные',
|
||
delayedOnly: 'Только задержанные',
|
||
generate: 'Сформировать',
|
||
notSent: 'Не отправлен',
|
||
sent: 'Отправлен'
|
||
}
|
||
};
|
||
|
||
let currentLang = 'kz';
|
||
let allEvents = [];
|
||
let allReports = [];
|
||
|
||
// API functions
|
||
async function api(path, method = 'GET', body) {
|
||
const opts = { method, headers: { 'Content-Type': 'application/json' } };
|
||
if (body) opts.body = JSON.stringify(body);
|
||
const res = await fetch(path, opts);
|
||
return res.json();
|
||
}
|
||
|
||
// Load data
|
||
async function loadData() {
|
||
allEvents = await api('/api/events');
|
||
allReports = await api('/api/reports');
|
||
renderDashboard();
|
||
renderHistory();
|
||
}
|
||
|
||
// Render dashboard
|
||
function renderDashboard() {
|
||
const sections = [...new Set(allEvents.map(e => e.sec))].sort();
|
||
const branches = [...new Set(allEvents.map(e => e.b))].sort();
|
||
|
||
const filterSection = document.getElementById('filter-section');
|
||
const filterBranch = document.getElementById('filter-branch');
|
||
|
||
filterSection.innerHTML = '<option value="">' + t('allSections') + '</option>';
|
||
sections.forEach(s => {
|
||
filterSection.innerHTML += `<option value="${s}">${s}</option>`;
|
||
});
|
||
|
||
filterBranch.innerHTML = '<option value="">' + t('allBranches') + '</option>';
|
||
branches.forEach(b => {
|
||
const label = b === 0 ? 'HQ' : `Ф${b}`;
|
||
filterBranch.innerHTML += `<option value="${b}">${label}</option>`;
|
||
});
|
||
|
||
// KPI
|
||
const total = allEvents.length;
|
||
const done = allEvents.filter(e => e.s === 'done').length;
|
||
const inProgress = allEvents.filter(e => e.s === 'in_progress').length;
|
||
const delayed = allEvents.filter(e => e.s === 'delayed').length;
|
||
|
||
document.getElementById('kpi-total').textContent = total;
|
||
document.getElementById('kpi-done').textContent = done;
|
||
document.getElementById('kpi-progress').textContent = inProgress;
|
||
document.getElementById('kpi-delayed').textContent = delayed;
|
||
|
||
// Filter and render table
|
||
const secVal = filterSection.value;
|
||
const bVal = filterBranch.value;
|
||
const sVal = document.getElementById('filter-status').value;
|
||
|
||
let filtered = allEvents;
|
||
if (secVal) filtered = filtered.filter(e => e.sec == secVal);
|
||
if (bVal) filtered = filtered.filter(e => e.b == bVal);
|
||
if (sVal) filtered = filtered.filter(e => e.s === sVal);
|
||
|
||
const tbody = document.getElementById('events-tbody');
|
||
tbody.innerHTML = '';
|
||
filtered.forEach(e => {
|
||
const name = currentLang === 'kz' ? e.dname.kz : e.dname.ru;
|
||
const branchLabel = e.b === 0 ? 'HQ' : `Ф${e.b}`;
|
||
tbody.innerHTML += `
|
||
<tr>
|
||
<td>${name}</td>
|
||
<td>${e.sec}</td>
|
||
<td>${branchLabel}</td>
|
||
<td>${e.r}</td>
|
||
<td>${e.due}</td>
|
||
<td><span class="status-chip status-${e.s}">${t('status' + e.s.charAt(0).toUpperCase() + e.s.slice(1))}</span></td>
|
||
<td>
|
||
<div class="progress-bar" style="width: 100px;">
|
||
<div class="progress-fill" style="width: ${e.p}%"></div>
|
||
</div>
|
||
<small>${e.p}%</small>
|
||
</td>
|
||
<td>
|
||
<button class="kt-ai-btn" data-size="sm" onclick="editEvent(${e.id})"><svg class="kt-icon"><use href="#pencil"></use></svg></button>
|
||
<button class="kt-ai-btn" data-size="sm" data-variant="danger" onclick="deleteEvent(${e.id})"><svg class="kt-icon"><use href="#trash"></use></svg></button>
|
||
</td>
|
||
</tr>
|
||
`;
|
||
});
|
||
}
|
||
|
||
// Render history
|
||
function renderHistory() {
|
||
const tbody = document.getElementById('reports-tbody');
|
||
tbody.innerHTML = '';
|
||
allReports.forEach(r => {
|
||
tbody.innerHTML += `
|
||
<tr>
|
||
<td>${new Date(r.createdAt).toLocaleDateString()}</td>
|
||
<td>${r.period}</td>
|
||
<td>${r.format}</td>
|
||
<td>${r.who}</td>
|
||
<td><span class="status-chip ${r.statusSent === 'sent' ? 'status-done' : 'status-not_started'}">${t(r.statusSent === 'sent' ? 'sent' : 'notSent')}</span></td>
|
||
<td>
|
||
<button class="kt-ai-btn" data-size="sm" onclick="downloadReport(${r.id})"><svg class="kt-icon"><use href="#download"></use></svg></button>
|
||
<button class="kt-ai-btn" data-size="sm" data-variant="danger" onclick="deleteReport(${r.id})"><svg class="kt-icon"><use href="#trash"></use></svg></button>
|
||
</td>
|
||
</tr>
|
||
`;
|
||
});
|
||
}
|
||
|
||
// Translate
|
||
function t(key) {
|
||
return i18n[currentLang][key] || key;
|
||
}
|
||
|
||
function updateI18n() {
|
||
document.querySelectorAll('[data-i18n]').forEach(el => {
|
||
const key = el.getAttribute('data-i18n');
|
||
el.textContent = t(key);
|
||
});
|
||
}
|
||
|
||
// Language toggle
|
||
document.querySelectorAll('.lang-btn').forEach(btn => {
|
||
btn.addEventListener('click', () => {
|
||
currentLang = btn.dataset.lang;
|
||
document.querySelectorAll('.lang-btn').forEach(b => b.classList.remove('active'));
|
||
btn.classList.add('active');
|
||
updateI18n();
|
||
renderDashboard();
|
||
renderHistory();
|
||
});
|
||
});
|
||
|
||
// Filters
|
||
document.getElementById('filter-section').addEventListener('change', renderDashboard);
|
||
document.getElementById('filter-branch').addEventListener('change', renderDashboard);
|
||
document.getElementById('filter-status').addEventListener('change', renderDashboard);
|
||
|
||
// Event modal
|
||
document.getElementById('btn-add-event').addEventListener('click', () => {
|
||
document.getElementById('event-form').reset();
|
||
document.getElementById('event-id').value = '';
|
||
document.getElementById('event-modal-title').textContent = t('addEvent');
|
||
document.getElementById('event-modal').classList.add('open');
|
||
});
|
||
|
||
function editEvent(id) {
|
||
const e = allEvents.find(ev => ev.id === id);
|
||
if (!e) return;
|
||
document.getElementById('event-form').reset();
|
||
document.getElementById('event-id').value = e.id;
|
||
document.getElementById('name-kz').value = e.dname.kz;
|
||
document.getElementById('name-ru').value = e.dname.ru;
|
||
document.getElementById('sec').value = e.sec;
|
||
document.getElementById('b').value = e.b;
|
||
document.getElementById('t').value = e.t;
|
||
document.getElementById('r').value = e.r;
|
||
document.getElementById('due').value = e.due;
|
||
document.getElementById('done').value = e.done || '';
|
||
document.getElementById('s').value = e.s;
|
||
document.getElementById('p').value = e.p;
|
||
document.getElementById('ai').value = e.ai;
|
||
document.getElementById('event-modal-title').textContent = e.dname[currentLang];
|
||
document.getElementById('event-modal').classList.add('open');
|
||
}
|
||
|
||
document.getElementById('event-form').addEventListener('submit', async (e) => {
|
||
e.preventDefault();
|
||
const id = document.getElementById('event-id').value;
|
||
const data = {
|
||
dname: {
|
||
kz: document.getElementById('name-kz').value,
|
||
ru: document.getElementById('name-ru').value
|
||
},
|
||
sec: parseInt(document.getElementById('sec').value),
|
||
b: parseInt(document.getElementById('b').value),
|
||
t: document.getElementById('t').value,
|
||
r: document.getElementById('r').value,
|
||
due: document.getElementById('due').value,
|
||
done: document.getElementById('done').value || null,
|
||
s: document.getElementById('s').value,
|
||
p: parseInt(document.getElementById('p').value),
|
||
ai: document.getElementById('ai').value
|
||
};
|
||
|
||
if (id) {
|
||
await api('/api/events/' + id, 'PUT', data);
|
||
} else {
|
||
await api('/api/events', 'POST', data);
|
||
}
|
||
|
||
closeModal('event-modal');
|
||
loadData();
|
||
});
|
||
|
||
function deleteEvent(id) {
|
||
if (!confirm(t('cancel'))) return;
|
||
api('/api/events/' + id, 'DELETE').then(() => loadData());
|
||
}
|
||
|
||
// Export modal
|
||
document.getElementById('btn-export').addEventListener('click', () => {
|
||
document.getElementById('export-modal').classList.add('open');
|
||
});
|
||
|
||
document.getElementById('btn-generate-report').addEventListener('click', async () => {
|
||
const data = {
|
||
period: document.getElementById('report-period').value,
|
||
format: document.getElementById('report-format').value,
|
||
scope: document.getElementById('report-scope').value,
|
||
who: 'Аналитик'
|
||
};
|
||
await api('/api/reports', 'POST', data);
|
||
closeModal('export-modal');
|
||
loadData();
|
||
});
|
||
|
||
function downloadReport(id) {
|
||
const r = allReports.find(rep => rep.id === id);
|
||
if (!r) return;
|
||
alert('Report: ' + r.period + ' (' + r.format + ')');
|
||
}
|
||
|
||
function deleteReport(id) {
|
||
if (!confirm(t('cancel'))) return;
|
||
api('/api/reports/' + id, 'DELETE').then(() => loadData());
|
||
}
|
||
|
||
// History view
|
||
document.getElementById('btn-history').addEventListener('click', () => {
|
||
document.getElementById('view-dashboard').classList.remove('active');
|
||
document.getElementById('view-history').classList.add('active');
|
||
});
|
||
|
||
document.getElementById('btn-back-dashboard').addEventListener('click', () => {
|
||
document.getElementById('view-history').classList.remove('active');
|
||
document.getElementById('view-dashboard').classList.add('active');
|
||
});
|
||
|
||
// Close modal
|
||
function closeModal(id) {
|
||
document.getElementById(id).classList.remove('open');
|
||
}
|
||
|
||
// Init
|
||
loadData();
|
||
updateI18n();
|