diff --git a/routes/operations.js b/routes/operations.js index 3dcdf3b..13ffe9f 100644 --- a/routes/operations.js +++ b/routes/operations.js @@ -9,6 +9,18 @@ const { fcTable } = require('../lib/utils'); module.exports = function(pool) { const router = express.Router(); + // the names an adjustment's rows carry until the next load re-reads them + // through VERSION_JOIN. The per-version overrides live on pf.version, so + // stamping the built-in constants here made every fresh adjustment show as + // '99 - Adjustments' and jump to the version's own name on refresh. + function adjustmentNames(version) { + const pick = (v, dflt) => (v || '').trim() || dflt; + return { + pf_segment: pick(version?.adjustment_segment, ADJUSTMENT_SEGMENT), + pf_bucket: pick(version?.adjustment_bucket, ADJUSTMENT_BUCKET), + }; + } + async function runSQL(sql, client) { console.log('--- SQL ---\n', sql, '\n--- END SQL ---'); return (client || pool).query(sql); @@ -850,7 +862,8 @@ module.exports = function(pool) { }); } const opLabel = (req.body.tag || '').trim() || note || null; - const rows = allRows.map(r => ({ ...r, pf_segment: ADJUSTMENT_SEGMENT, pf_bucket: ADJUSTMENT_BUCKET, pf_note: opLabel, pf_op: 'scale' })); + const names = adjustmentNames(ctx.version); + const rows = allRows.map(r => ({ ...r, ...names, pf_note: opLabel, pf_op: 'scale' })); res.json({ rows, rows_affected: rows.length, @@ -923,7 +936,8 @@ module.exports = function(pool) { }); } const opLabel = (req.body.tag || '').trim() || note || null; - const rows = allRows.map(r => ({ ...r, pf_segment: ADJUSTMENT_SEGMENT, pf_bucket: ADJUSTMENT_BUCKET, pf_note: opLabel, pf_op: 'recode' })); + const names = adjustmentNames(ctx.version); + const rows = allRows.map(r => ({ ...r, ...names, pf_note: opLabel, pf_op: 'recode' })); res.json({ rows, rows_affected: rows.length, slices_applied: units.length }); } finally { if (!committed) try { await client.query('ROLLBACK'); } catch {} @@ -1030,7 +1044,8 @@ module.exports = function(pool) { }); } const opLabel = (req.body.tag || '').trim() || note || null; - const rows = allRows.map(r => ({ ...r, pf_segment: ADJUSTMENT_SEGMENT, pf_bucket: ADJUSTMENT_BUCKET, pf_note: opLabel, pf_op: 'clone' })); + const names = adjustmentNames(ctx.version); + const rows = allRows.map(r => ({ ...r, ...names, pf_note: opLabel, pf_op: 'clone' })); res.json({ rows, rows_affected: rows.length, slices_applied: units.length }); } finally { if (!committed) try { await client.query('ROLLBACK'); } catch {}