From 0c64a4679f7c1f494139b6eb5f08ab9c0320f584 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 25 Jul 2026 09:49:43 +0000 Subject: [PATCH] feat: add template selector to batch detail for CV generation --- __pycache__/database.cpython-312.pyc | Bin 12415 -> 12491 bytes __pycache__/main.cpython-312.pyc | Bin 61525 -> 61600 bytes database.py | 2 ++ main.py | 6 ++-- static/batches.js | 49 +++++++++++++++++++++++++++ static/index.html | 2 +- 6 files changed, 55 insertions(+), 4 deletions(-) diff --git a/__pycache__/database.cpython-312.pyc b/__pycache__/database.cpython-312.pyc index 051e771c9769ac8c5e14ea71f5143869fecb973d..ad6d588b6423e8d155d4c6c57b34d1eeef2df659 100644 GIT binary patch delta 145 zcmeyLa5|CiG%qg~0}w20OUbg*-pHrI$YiU!*@UrL&N(9=!%ejtpi#mIkg5VUt}9tO1oeFvkD@ delta 77 zcmX?|_&$ zI&91h6Nt}DnQVB~crxb^F~*~lrH^DX7EM0rFEM%U5fy%y?H(IFcEnyb@jel8fg^14 e(IZAYwv5vl9j#fWJE}U`PM&BSw>k0X7cBr=Rztr4 delta 139 zcmV;60CfML;RDs+0}aa!4GI7N000|=WNKTn4UNK+T!{$+-T;%)J1LXS!f*osW&@L9 z!x@w3XAYBy!x#xvtpj%fDF=EUlc~cU1TIc`YLh|F7L)129g`TuLX%&_WdUcC!A}^I tj@Ap4=)@TWNYDs9lfl*#lOx3+3@rhc0YNJSmq8UlEt8QmUbC#l^eSShHQ@jN 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