fix: загрузка демо-данных при первом запуске
This commit is contained in:
parent
6408533791
commit
5e5b620ed4
236
script.js
236
script.js
@ -1,124 +1,135 @@
|
||||
// Mock data for initial development
|
||||
let equipment = [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Огнетушитель ОП-5',
|
||||
category: 'Огнетушитель',
|
||||
inventoryNumber: 'ИН-001',
|
||||
location: 'Кабинет 101',
|
||||
responsible: 'Иванов И.И.',
|
||||
lastCheck: '2025-09-15',
|
||||
period: 12,
|
||||
nextCheck: '2026-09-15',
|
||||
note: 'Порошковый огнетушитель',
|
||||
status: 'warning'
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'Аптечка медицинская',
|
||||
category: 'Аптечка',
|
||||
inventoryNumber: 'ИН-002',
|
||||
location: 'Кабинет 205',
|
||||
responsible: 'Петрова А.С.',
|
||||
lastCheck: '2025-03-10',
|
||||
period: 12,
|
||||
nextCheck: '2026-03-10',
|
||||
note: '',
|
||||
status: 'expired'
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: 'Дрель аккумуляторная',
|
||||
category: 'Электроинструмент',
|
||||
inventoryNumber: 'ИН-003',
|
||||
location: 'Склад №3',
|
||||
responsible: 'Сидоров П.К.',
|
||||
lastCheck: '2026-08-01',
|
||||
period: 6,
|
||||
nextCheck: '2027-02-01',
|
||||
note: 'Bosch GSR 12V',
|
||||
status: 'ok'
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
name: 'Каска защитная',
|
||||
category: 'СИЗ',
|
||||
inventoryNumber: 'ИН-004',
|
||||
location: 'Участок №2',
|
||||
responsible: 'Козлов М.М.',
|
||||
lastCheck: '2026-06-15',
|
||||
period: 24,
|
||||
nextCheck: '2028-06-15',
|
||||
note: '',
|
||||
status: 'ok'
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
name: 'Мультиметр цифровой',
|
||||
category: 'Измерительный прибор',
|
||||
inventoryNumber: 'ИН-005',
|
||||
location: 'Лаборатория',
|
||||
responsible: 'Николаев В.В.',
|
||||
lastCheck: '2026-07-20',
|
||||
period: 12,
|
||||
nextCheck: '2027-07-20',
|
||||
note: 'Fluke 117',
|
||||
status: 'ok'
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
name: 'Лестница алюминиевая',
|
||||
category: 'Лестница',
|
||||
inventoryNumber: 'ИН-006',
|
||||
location: 'Хозблок',
|
||||
responsible: 'Морозов А.А.',
|
||||
lastCheck: '2025-12-01',
|
||||
period: 12,
|
||||
nextCheck: '2026-12-01',
|
||||
note: '3 метра',
|
||||
status: 'ok'
|
||||
},
|
||||
{
|
||||
id: 7,
|
||||
name: 'Огнетушитель ОУ-3',
|
||||
category: 'Огнетушитель',
|
||||
inventoryNumber: 'ИН-007',
|
||||
location: 'Серверная',
|
||||
responsible: 'Иванов И.И.',
|
||||
lastCheck: '2026-08-25',
|
||||
period: 60,
|
||||
nextCheck: '2031-08-25',
|
||||
note: 'Углекислотный',
|
||||
status: 'ok'
|
||||
},
|
||||
{
|
||||
id: 8,
|
||||
name: 'Перчатки диэлектрические',
|
||||
category: 'СИЗ',
|
||||
inventoryNumber: 'ИН-008',
|
||||
location: 'Электрощитовая',
|
||||
responsible: 'Соколов Д.Д.',
|
||||
lastCheck: '2026-03-01',
|
||||
period: 6,
|
||||
nextCheck: '2026-09-01',
|
||||
note: '',
|
||||
status: 'expired'
|
||||
}
|
||||
];
|
||||
// Equipment data
|
||||
let equipment = [];
|
||||
|
||||
// Load from API on production
|
||||
// Load from API
|
||||
async function loadEquipment() {
|
||||
try {
|
||||
const response = await fetch('api/items');
|
||||
if (response.ok) {
|
||||
equipment = await response.json();
|
||||
if (equipment.length === 0) {
|
||||
// Initialize with demo data if empty
|
||||
equipment = getDemoData();
|
||||
saveEquipment();
|
||||
}
|
||||
} else {
|
||||
equipment = getDemoData();
|
||||
}
|
||||
} catch (e) {
|
||||
// Using mock data
|
||||
equipment = getDemoData();
|
||||
}
|
||||
updateAll();
|
||||
}
|
||||
|
||||
function getDemoData() {
|
||||
return [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Огнетушитель ОП-5',
|
||||
category: 'Огнетушитель',
|
||||
inventoryNumber: 'ИН-001',
|
||||
location: 'Кабинет 101',
|
||||
responsible: 'Иванов И.И.',
|
||||
lastCheck: '2025-09-15',
|
||||
period: 12,
|
||||
nextCheck: '2026-09-15',
|
||||
note: 'Порошковый огнетушитель',
|
||||
status: 'warning'
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'Аптечка медицинская',
|
||||
category: 'Аптечка',
|
||||
inventoryNumber: 'ИН-002',
|
||||
location: 'Кабинет 205',
|
||||
responsible: 'Петрова А.С.',
|
||||
lastCheck: '2025-03-10',
|
||||
period: 12,
|
||||
nextCheck: '2026-03-10',
|
||||
note: '',
|
||||
status: 'expired'
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: 'Дрель аккумуляторная',
|
||||
category: 'Электроинструмент',
|
||||
inventoryNumber: 'ИН-003',
|
||||
location: 'Склад №3',
|
||||
responsible: 'Сидоров П.К.',
|
||||
lastCheck: '2026-08-01',
|
||||
period: 6,
|
||||
nextCheck: '2027-02-01',
|
||||
note: 'Bosch GSR 12V',
|
||||
status: 'ok'
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
name: 'Каска защитная',
|
||||
category: 'СИЗ',
|
||||
inventoryNumber: 'ИН-004',
|
||||
location: 'Участок №2',
|
||||
responsible: 'Козлов М.М.',
|
||||
lastCheck: '2026-06-15',
|
||||
period: 24,
|
||||
nextCheck: '2028-06-15',
|
||||
note: '',
|
||||
status: 'ok'
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
name: 'Мультиметр цифровой',
|
||||
category: 'Измерительный прибор',
|
||||
inventoryNumber: 'ИН-005',
|
||||
location: 'Лаборатория',
|
||||
responsible: 'Николаев В.В.',
|
||||
lastCheck: '2026-07-20',
|
||||
period: 12,
|
||||
nextCheck: '2027-07-20',
|
||||
note: 'Fluke 117',
|
||||
status: 'ok'
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
name: 'Лестница алюминиевая',
|
||||
category: 'Лестница',
|
||||
inventoryNumber: 'ИН-006',
|
||||
location: 'Хозблок',
|
||||
responsible: 'Морозов А.А.',
|
||||
lastCheck: '2025-12-01',
|
||||
period: 12,
|
||||
nextCheck: '2026-12-01',
|
||||
note: '3 метра',
|
||||
status: 'ok'
|
||||
},
|
||||
{
|
||||
id: 7,
|
||||
name: 'Огнетушитель ОУ-3',
|
||||
category: 'Огнетушитель',
|
||||
inventoryNumber: 'ИН-007',
|
||||
location: 'Серверная',
|
||||
responsible: 'Иванов И.И.',
|
||||
lastCheck: '2026-08-25',
|
||||
period: 60,
|
||||
nextCheck: '2031-08-25',
|
||||
note: 'Углекислотный',
|
||||
status: 'ok'
|
||||
},
|
||||
{
|
||||
id: 8,
|
||||
name: 'Перчатки диэлектрические',
|
||||
category: 'СИЗ',
|
||||
inventoryNumber: 'ИН-008',
|
||||
location: 'Электрощитовая',
|
||||
responsible: 'Соколов Д.Д.',
|
||||
lastCheck: '2026-03-01',
|
||||
period: 6,
|
||||
nextCheck: '2026-09-01',
|
||||
note: '',
|
||||
status: 'expired'
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
function updateAll() {
|
||||
calculateStatuses();
|
||||
updateKPIs();
|
||||
@ -637,16 +648,15 @@ function escapeHtml(text) {
|
||||
.replace(/"/g, '"');
|
||||
}
|
||||
|
||||
function saveEquipment() {
|
||||
// In production, this will POST to API
|
||||
async function saveEquipment() {
|
||||
try {
|
||||
fetch('api/items', {
|
||||
await fetch('api/items', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(equipment)
|
||||
});
|
||||
} catch (e) {
|
||||
// Silent fail for mock
|
||||
console.error('Failed to save equipment:', e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user