fix: загрузка демо-данных при первом запуске

This commit is contained in:
Nurs 2026-09-16 11:46:04 +00:00
parent 6408533791
commit 5e5b620ed4

View File

@ -1,5 +1,28 @@
// Mock data for initial development // Equipment data
let equipment = [ let equipment = [];
// 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) {
equipment = getDemoData();
}
updateAll();
}
function getDemoData() {
return [
{ {
id: 1, id: 1,
name: 'Огнетушитель ОП-5', name: 'Огнетушитель ОП-5',
@ -105,18 +128,6 @@ let equipment = [
status: 'expired' status: 'expired'
} }
]; ];
// Load from API on production
async function loadEquipment() {
try {
const response = await fetch('api/items');
if (response.ok) {
equipment = await response.json();
}
} catch (e) {
// Using mock data
}
updateAll();
} }
function updateAll() { function updateAll() {
@ -637,16 +648,15 @@ function escapeHtml(text) {
.replace(/"/g, '"'); .replace(/"/g, '"');
} }
function saveEquipment() { async function saveEquipment() {
// In production, this will POST to API
try { try {
fetch('api/items', { await fetch('api/items', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(equipment) body: JSON.stringify(equipment)
}); });
} catch (e) { } catch (e) {
// Silent fail for mock console.error('Failed to save equipment:', e);
} }
} }