Templates section: - Define JS formatter functions per template (e.g. resistor, capacitor) - First non-null result from any formatter is used as display name - Live preview in template editor against first component - Display names applied in component list, detail view, and inventory rows Grid navigation: - Grid-type inventory entries in component detail view show a '⊞' button to navigate directly to that grid's viewer Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
52 lines
2.6 KiB
JavaScript
52 lines
2.6 KiB
JavaScript
async function req(method, path, body) {
|
|
const opts = { method, headers: {} };
|
|
if (body !== undefined) {
|
|
opts.headers['Content-Type'] = 'application/json';
|
|
opts.body = JSON.stringify(body);
|
|
}
|
|
const res = await fetch(path, opts);
|
|
const data = await res.json();
|
|
if (!data.ok) throw new Error(data.error ?? 'Request failed');
|
|
return data;
|
|
}
|
|
|
|
// Fields
|
|
export const get_fields = () => req('GET', '/api/fields');
|
|
export const create_field = (body) => req('POST', '/api/fields', body);
|
|
export const update_field = (id, body) => req('PUT', `/api/fields/${id}`, body);
|
|
export const delete_field = (id) => req('DELETE', `/api/fields/${id}`);
|
|
|
|
// Components
|
|
export const get_components = () => req('GET', '/api/components');
|
|
export const create_component = (body) => req('POST', '/api/components', body);
|
|
export const update_component = (id, body) => req('PUT', `/api/components/${id}`, body);
|
|
export const delete_component = (id) => req('DELETE', `/api/components/${id}`);
|
|
|
|
// Inventory
|
|
export const get_inventory = () => req('GET', '/api/inventory');
|
|
export const create_inventory = (body) => req('POST', '/api/inventory', body);
|
|
export const update_inventory = (id, body) => req('PUT', `/api/inventory/${id}`, body);
|
|
export const delete_inventory = (id) => req('DELETE', `/api/inventory/${id}`);
|
|
|
|
// Grid drafts
|
|
export const get_grid_drafts = () => req('GET', '/api/grid-drafts');
|
|
export const create_grid_draft = (body) => req('POST', '/api/grid-drafts', body);
|
|
export const update_grid_draft = (id, body) => req('PUT', `/api/grid-drafts/${id}`, body);
|
|
export const delete_grid_draft = (id) => req('DELETE', `/api/grid-drafts/${id}`);
|
|
|
|
// Source images
|
|
export const get_source_images = () => req('GET', '/api/source-images');
|
|
export const delete_source_image = (id) => req('DELETE', `/api/source-images/${id}`);
|
|
|
|
// Component templates
|
|
export const get_component_templates = () => req('GET', '/api/component-templates');
|
|
export const create_component_template = (body) => req('POST', '/api/component-templates', body);
|
|
export const update_component_template = (id, body) => req('PUT', `/api/component-templates/${id}`, body);
|
|
export const delete_component_template = (id) => req('DELETE', `/api/component-templates/${id}`);
|
|
|
|
// Grid images
|
|
export const get_grids = () => req('GET', '/api/grid-images');
|
|
export const get_grid = (id) => req('GET', `/api/grid-images/${id}`);
|
|
export const delete_grid = (id) => req('DELETE', `/api/grid-images/${id}`);
|
|
export const update_grid_panel = (id, pi, body) => req('PUT', `/api/grid-images/${id}/panels/${pi}`, body);
|