diff --git a/public/app.js b/public/app.js index 9975f70..497c0c9 100644 --- a/public/app.js +++ b/public/app.js @@ -557,8 +557,8 @@ async function openBaselineWorkbench() { // reset form document.getElementById('seg-description').value = ''; - document.getElementById('seg-offset-years').value = '0'; - document.getElementById('seg-offset-months').value = '0'; + document.getElementById('seg-offset-type').value = ''; + document.getElementById('seg-offset-value').value = '0'; document.getElementById('seg-filter-rows').innerHTML = ''; document.getElementById('seg-timeline').classList.add('hidden'); addFilterRow(); // start with one empty filter row @@ -727,11 +727,23 @@ function updateTimelinePreview() { const months = (to.getFullYear() - from.getFullYear()) * 12 + (to.getMonth() - from.getMonth()) + 1; const fmt = new Intl.DateTimeFormat('en-US', { month: 'short', year: 'numeric' }); - const offsetYears = parseInt(document.getElementById('seg-offset-years').value) || 0; - const offsetMonths = parseInt(document.getElementById('seg-offset-months').value) || 0; + const offsetType = document.getElementById('seg-offset-type').value; + const offsetValue = parseInt(document.getElementById('seg-offset-value').value) || 0; - const projFrom = new Date(from); projFrom.setFullYear(projFrom.getFullYear() + offsetYears); projFrom.setMonth(projFrom.getMonth() + offsetMonths); - const projTo = new Date(to); projTo.setFullYear(projTo.getFullYear() + offsetYears); projTo.setMonth(projTo.getMonth() + offsetMonths); + function applyOffset(d) { + const r = new Date(d); + if (!offsetType || !offsetValue) return r; + switch (offsetType) { + case 'year': r.setFullYear(r.getFullYear() + offsetValue); break; + case 'month': r.setMonth(r.getMonth() + offsetValue); break; + case 'week': r.setDate(r.getDate() + offsetValue * 7); break; + case 'day': r.setDate(r.getDate() + offsetValue); break; + } + return r; + } + + const projFrom = applyOffset(from); + const projTo = applyOffset(to); let html = `
@@ -746,12 +758,9 @@ function updateTimelinePreview() {
`; - if (offsetYears || offsetMonths) { - const parts = []; - if (offsetYears) parts.push(`${offsetYears} yr`); - if (offsetMonths) parts.push(`${offsetMonths} mo`); + if (offsetType && offsetValue) { html += ` -
+ ${parts.join(' ')} →
+
+ ${offsetValue} ${offsetType}${offsetValue !== 1 ? 's' : ''} →
Projected
@@ -774,12 +783,11 @@ async function submitBaselineSegment() { const filters = getFilterRows(); if (filters.length === 0) { showStatus('Add at least one filter', 'error'); return; } - const years = parseInt(document.getElementById('seg-offset-years').value) || 0; - const months = parseInt(document.getElementById('seg-offset-months').value) || 0; - const parts = []; - if (years) parts.push(`${years} year${years !== 1 ? 's' : ''}`); - if (months) parts.push(`${months} month${months !== 1 ? 's' : ''}`); - const date_offset = parts.length ? parts.join(' ') : '0 days'; + const offsetType = document.getElementById('seg-offset-type').value; + const offsetValue = parseInt(document.getElementById('seg-offset-value').value) || 0; + const date_offset = (offsetType && offsetValue) + ? `${offsetValue} ${offsetType}${offsetValue !== 1 ? 's' : ''}` + : '0 days'; const body = { filters, @@ -1278,8 +1286,8 @@ document.addEventListener('DOMContentLoaded', () => { document.getElementById('btn-add-filter-row').addEventListener('click', addFilterRow); document.getElementById('btn-load-segment').addEventListener('click', submitBaselineSegment); document.getElementById('btn-clear-baseline').addEventListener('click', clearBaseline); - document.getElementById('seg-offset-years').addEventListener('input', updateTimelinePreview); - document.getElementById('seg-offset-months').addEventListener('input', updateTimelinePreview); + document.getElementById('seg-offset-type').addEventListener('change', updateTimelinePreview); + document.getElementById('seg-offset-value').addEventListener('input', updateTimelinePreview); // undo in baseline segments list document.getElementById('baseline-segments-list').addEventListener('click', async e => { diff --git a/public/index.html b/public/index.html index a9d7e62..ee5f0e9 100644 --- a/public/index.html +++ b/public/index.html @@ -111,11 +111,17 @@
-
diff --git a/public/styles.css b/public/styles.css index 4cf566d..00fb86a 100644 --- a/public/styles.css +++ b/public/styles.css @@ -478,12 +478,14 @@ body { } .baseline-field-label input[type=text], -.baseline-field-label input[type=number] { +.baseline-field-label input[type=number], +.baseline-field-label select { border: 1px solid #dce1e7; padding: 5px 8px; border-radius: 3px; font-size: 12px; color: #333; + background: white; } .offset-row { display: flex; gap: 10px; }