diff --git a/__pycache__/database.cpython-312.pyc b/__pycache__/database.cpython-312.pyc index 051e771..ad6d588 100644 Binary files a/__pycache__/database.cpython-312.pyc and b/__pycache__/database.cpython-312.pyc differ diff --git a/__pycache__/main.cpython-312.pyc b/__pycache__/main.cpython-312.pyc index 0935591..a3a8d62 100644 Binary files a/__pycache__/main.cpython-312.pyc and b/__pycache__/main.cpython-312.pyc differ diff --git a/database.py b/database.py index a3bb733..1a813f2 100644 --- a/database.py +++ b/database.py @@ -197,6 +197,8 @@ CREATE TABLE IF NOT EXISTS cv_batches ( -- JSON array of positions extracted from the document -- [{job_title, num_positions, required_skills, required_years, required_certs, description}] positions JSONB DEFAULT '[]', + -- Selected Carbone template ID for CV generation + template_id TEXT, -- draft = still working, active = matching done, exported = CVs generated status VARCHAR(50) DEFAULT 'draft', created_at TIMESTAMPTZ DEFAULT NOW(), diff --git a/main.py b/main.py index 1da0b1a..d90e572 100644 --- a/main.py +++ b/main.py @@ -913,12 +913,12 @@ async def get_batch(batch_id: str): @app.put("/api/batches/{batch_id}") async def update_batch(batch_id: str, request: Request): - """Update batch name/description.""" + """Update batch name/description/template.""" body = await request.json() row = db.execute( - """UPDATE cv_batches SET name = %s, description = %s, updated_at = NOW() + """UPDATE cv_batches SET name = %s, description = %s, template_id = %s, updated_at = NOW() WHERE id = %s RETURNING *""", - (body.get("name"), body.get("description"), batch_id) + (body.get("name"), body.get("description"), body.get("template_id"), batch_id) ) if not row: raise HTTPException(404, "Batch not found") diff --git a/static/batches.js b/static/batches.js index c3e9af7..8d98069 100644 --- a/static/batches.js +++ b/static/batches.js @@ -143,6 +143,17 @@ async function uploadBatchDoc(file) { // BATCH DETAIL VIEW // ============================================================ let currentBatch = null; +let batchTemplates = []; + +async function loadBatchTemplates() { + try { + const resp = await fetch('http://' + location.hostname + ':8771/api/carbone/templates'); + const data = await resp.json(); + batchTemplates = data.templates || []; + } catch (e) { + batchTemplates = []; + } +} async function openBatch(batchId) { currentBatchId = batchId; @@ -151,6 +162,8 @@ async function openBatch(batchId) { detail.style.display = 'block'; detail.innerHTML = '
Loading batch...
'; + await loadBatchTemplates(); + try { const resp = await fetch('/api/batches/' + batchId); const data = await resp.json(); @@ -226,6 +239,12 @@ function renderBatchDetail(data) { positionsHtml += ''; } + // Build template selector options + const currentTemplateId = batch.template_id || ''; + const templateOptions = batchTemplates.map(t => + '' + ).join(''); + document.getElementById('batch-detail-view').innerHTML = `
@@ -239,10 +258,40 @@ function renderBatchDetail(data) {
+
+
+ +
+ + ${batchTemplates.length === 0 ? 'No templates uploaded. Go to Templates page to add one.' : ''} +
+
+
${positionsHtml} `; } +async function saveBatchTemplate() { + const templateId = document.getElementById('batch-template-select').value; + try { + await fetch('/api/batches/' + currentBatchId, { + method: 'PUT', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + name: currentBatch.batch.name, + description: currentBatch.batch.description, + template_id: templateId + }) + }); + toast('Template saved for this batch'); + } catch (e) { + toast('Error saving template: ' + e.message, 'error'); + } +} + function closeBatchDetail() { document.getElementById('batches-list-view').style.display = 'block'; document.getElementById('batch-detail-view').style.display = 'none'; diff --git a/static/index.html b/static/index.html index 104a031..5a9fd36 100644 --- a/static/index.html +++ b/static/index.html @@ -152,6 +152,6 @@ - + \ No newline at end of file