fix: загрузка демо-данных при первом запуске
This commit is contained in:
parent
6408533791
commit
5e5b620ed4
46
script.js
46
script.js
@ -1,5 +1,28 @@
|
||||
// Mock data for initial development
|
||||
let equipment = [
|
||||
// Equipment data
|
||||
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,
|
||||
name: 'Огнетушитель ОП-5',
|
||||
@ -105,18 +128,6 @@ let equipment = [
|
||||
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() {
|
||||
@ -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