New top-level nav section showing all source images in a list view with checkboxes to edit the uses array (grid, bin) per image. Allows correcting wrongly-tagged images without code changes. Server PUT /api/source-images/:id was already in place; re-added the frontend API wrapper that was prematurely removed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
90 lines
4.3 KiB
JavaScript
90 lines
4.3 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 update_source_image_uses = (id, uses) => req('PUT', `/api/source-images/${id}`, { uses });
|
|
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}`);
|
|
|
|
// PDF files
|
|
export const get_pdfs = () => req('GET', '/api/pdfs');
|
|
export const rename_pdf = (id, display_name, filename) => req('PUT', `/api/pdfs/${id}`, { display_name, filename });
|
|
export const delete_pdf = (id) => req('DELETE', `/api/pdfs/${id}`);
|
|
|
|
export async function upload_pdf(file, display_name, filename) {
|
|
const form = new FormData();
|
|
form.append('file', file);
|
|
if (display_name) form.append('display_name', display_name);
|
|
if (filename) form.append('filename', filename);
|
|
const res = await fetch('/api/pdfs', { method: 'POST', body: form });
|
|
const data = await res.json();
|
|
if (!data.ok) throw new Error(data.error ?? 'Upload failed');
|
|
return data;
|
|
}
|
|
|
|
// Bins
|
|
export const get_bins = () => req('GET', '/api/bins');
|
|
export const create_bin_from_source = (source_id, name) => req('POST', '/api/bins/from-source', { source_id, name });
|
|
export const get_bin = (id) => req('GET', `/api/bins/${id}`);
|
|
export const rename_bin = (id, name) => req('PUT', `/api/bins/${id}`, { name });
|
|
export const update_bin_corners = (id, corners) => req('PUT', `/api/bins/${id}/corners`, { corners });
|
|
export const delete_bin = (id) => req('DELETE', `/api/bins/${id}`);
|
|
|
|
export async function upload_bin(file, name) {
|
|
const form = new FormData();
|
|
form.append('image', file);
|
|
if (name) form.append('name', name);
|
|
const res = await fetch('/api/bins', { method: 'POST', body: form });
|
|
const data = await res.json();
|
|
if (!data.ok) throw new Error(data.error ?? 'Upload failed');
|
|
return data;
|
|
}
|
|
|
|
// Maintenance
|
|
export const maintenance_pdf_thumbs = () => req('POST', '/api/maintenance/pdf-thumbs');
|
|
|
|
// 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);
|