Files
scenar-creator/app/static/js/api.js
Daneel 25fd578543
Some checks failed
Build & Push Docker / build (push) Has been cancelled
feat: v3.0 - canvas editor, JSON-only, no Excel, new UI
- Remove all Excel code (import, export, template, pandas, openpyxl)
- New canvas-based schedule editor with drag & drop (interact.js)
- Modern 3-panel UI: sidebar, canvas, documentation tab
- New data model: Block with id/date/start/end, ProgramType with id/name/color
- Clean API: GET /api/health, POST /api/validate, GET /api/sample, POST /api/generate-pdf
- Rewritten PDF generator using ScenarioDocument directly (no DataFrame)
- Professional PDF output: dark header, colored blocks, merged cells, legend, footer
- Sample JSON: "Zimní výjezd oddílu" with 11 blocks, 3 program types
- 30 tests passing (API, core models, PDF generation)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 17:02:51 +01:00

58 lines
1.6 KiB
JavaScript

/**
* API fetch wrapper for Scenar Creator v3.
*/
const API = {
async post(url, body, isJson = true) {
const opts = { method: 'POST' };
if (isJson) {
opts.headers = { 'Content-Type': 'application/json' };
opts.body = JSON.stringify(body);
} else {
opts.body = body;
}
return fetch(url, opts);
},
async postJson(url, body) {
const res = await this.post(url, body, true);
if (!res.ok) {
const err = await res.json().catch(() => ({ detail: res.statusText }));
throw new Error(err.detail || 'API error');
}
return res.json();
},
async postBlob(url, body) {
const res = await this.post(url, body, true);
if (!res.ok) {
const err = await res.json().catch(() => ({ detail: res.statusText }));
throw new Error(err.detail || 'API error');
}
return res.blob();
},
async get(url) {
const res = await fetch(url);
if (!res.ok) throw new Error(res.statusText);
return res.json();
},
async getBlob(url) {
const res = await fetch(url);
if (!res.ok) throw new Error(res.statusText);
return res.blob();
},
downloadBlob(blob, filename) {
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
};