From 8cd8670f2925c1dec506409a07e4f73dffb1fbbe Mon Sep 17 00:00:00 2001 From: paige Date: Tue, 3 Nov 2026 08:33:20 -0700 Subject: [PATCH] making launch date field editable - don't always launch on a regular cadence --- ServiceMeow-HQ.html | 88 ++++++++++++++++++++++++++++++++++++++++----- build_hub.mjs | 3 ++ smoke_test.js | 47 +++++++++++++++++------- uat_new_section.js | 85 ++++++++++++++++++++++++++++++++++++++----- 4 files changed, 194 insertions(+), 29 deletions(-) diff --git a/ServiceMeow-HQ.html b/ServiceMeow-HQ.html index 5e504be..57296f0 100644 --- a/ServiceMeow-HQ.html +++ b/ServiceMeow-HQ.html @@ -455,6 +455,9 @@ .lcard .rule { font-size:11.5px; color:var(--muted); margin-bottom:8px; } .lcard .lnext { font-size:14.5px; font-weight:700; } .lcard .lnext .fz { color:#b0721f; } + .ldate { cursor:pointer; border-bottom:1.5px dotted #98a1b8; } + .ldate:hover { color:var(--accent); border-bottom-color:var(--accent); } + .ldate.edited { color:#7a4d12; border-bottom-color:#f3c18f; } .lcard .lcount { margin-top:6px; font-size:12px; color:var(--muted); } .lcard .lcount b { color:var(--text); } .lcard .lmore { margin-top:4px; font-size:11.5px; color:var(--muted); } @@ -1742,15 +1745,84 @@ function upcomingLaunches(ordinals, count) { } return out.sort((a, b) => a.launch - b.launch).slice(0, count); } -const RDNS_LAUNCHES = upcomingLaunches([2, 4], 3); -const BT_LAUNCHES = upcomingLaunches([3], 3); const fmtD = d => d.toLocaleDateString(undefined, { weekday: "short", month: "short", day: "numeric" }); const fmtDy = d => d.toLocaleDateString(undefined, { month: "short", day: "numeric", year: "numeric" }); const daysUntil = d => Math.round((d - UAT_NOW) / 86400000); + +// ---------- Editable launch dates ---------- +// Click any launch date to type a new one. Overrides are saved in this +// browser; the freeze date, countdowns and section order all recalculate. +const LO_KEY = "sm-launch-overrides-v1"; +let launchOverrides = {}; +try { launchOverrides = JSON.parse(localStorage.getItem(LO_KEY) || "{}"); } catch { launchOverrides = {}; } +const lkey = d => d.getFullYear() + "-" + String(d.getMonth() + 1).padStart(2, "0") + "-" + String(d.getDate()).padStart(2, "0"); +function applyLaunchOverrides(list) { + for (const l of list) { + l.orig = lkey(l.launch); // scheduled date, before any override + const ov = launchOverrides[l.orig]; + if (!ov) continue; + const nd = new Date(ov + "T00:00:00"); + if (isNaN(nd) || nd < UAT_NOW) { delete launchOverrides[l.orig]; continue; } + const back = ((nd.getDay() - 5 + 7) % 7) || 7; // code freeze = Friday before the launch + l.launch = nd; + l.freeze = new Date(nd.getTime() - back * 86400000); + } + return list.sort((a, b) => a.launch - b.launch); +} +let RDNS_LAUNCHES = applyLaunchOverrides(upcomingLaunches([2, 4], 3)); +let BT_LAUNCHES = applyLaunchOverrides(upcomingLaunches([3], 3)); // global next freeze (whichever comes first) -const NEXT_FREEZE = RDNS_LAUNCHES[0].freeze < BT_LAUNCHES[0].freeze - ? { ...RDNS_LAUNCHES[0], site: "RNDSystems" } - : { ...BT_LAUNCHES[0], site: "BT" }; +let NEXT_FREEZE = null; +function recomputeLaunches() { + RDNS_LAUNCHES = applyLaunchOverrides(upcomingLaunches([2, 4], 3)); + BT_LAUNCHES = applyLaunchOverrides(upcomingLaunches([3], 3)); + NEXT_FREEZE = RDNS_LAUNCHES[0].freeze < BT_LAUNCHES[0].freeze + ? { ...RDNS_LAUNCHES[0], site: "RNDSystems" } + : { ...BT_LAUNCHES[0], site: "BT" }; +} +recomputeLaunches(); + +function launchDateSpan(l, withYear) { + const edited = l.orig !== lkey(l.launch); + return `${(withYear ? fmtDy : fmtD)(l.launch)}${edited ? " โœŽ" : ""}`; +} +function editLaunchDate(el) { + if (!el || el.querySelector("input")) return; + const orig = el.getAttribute("data-ldo"); + const cur = el.getAttribute("data-ldv"); + const inp = document.createElement("input"); + inp.type = "date"; + inp.value = cur; + inp.style.cssText = "font:inherit;font-size:13px;font-weight:700;padding:2px 8px;margin:0 2px;border:1.5px solid var(--accent);border-radius:7px;color:var(--text);background:#fff"; + el.textContent = ""; + el.appendChild(inp); + inp.focus(); + try { inp.showPicker && inp.showPicker(); } catch (e) {} + let finished = false; + const finish = save => { + if (finished) return; finished = true; + const v = inp.value; + if (save && v && v !== cur) { + if (v === orig) { + delete launchOverrides[orig]; + localStorage.setItem(LO_KEY, JSON.stringify(launchOverrides)); + recomputeLaunches(); + } else if (v >= lkey(UAT_NOW)) { + launchOverrides[orig] = v; + localStorage.setItem(LO_KEY, JSON.stringify(launchOverrides)); + recomputeLaunches(); + } else alert("That date is in the past โ€” keeping the scheduled date instead."); + } + uatRender(); + }; + inp.addEventListener("keydown", e => { + if (e.key === "Enter") finish(true); + else if (e.key === "Escape") finish(false); + e.stopPropagation(); + }); + inp.addEventListener("blur", () => finish(true)); +} +window.editLaunchDate = editLaunchDate; // ---------- Grouping (by launch cycle) ---------- function siteOf(t) { @@ -1862,9 +1934,9 @@ function uatRender() { return `

${name}

${rule}
-
๐Ÿš€ ${fmtDy(launches[0].launch)}  ยท  ๐ŸงŠ freeze ${fmtD(launches[0].freeze)} 10 AM
+
๐Ÿš€ ${launchDateSpan(launches[0], true)}  ยท  ๐ŸงŠ freeze ${fmtD(launches[0].freeze)} 10 AM
${count} open ticket${count === 1 ? "" : "s"} in queue ยท next in ${daysUntil(launches[0].launch)} days
-
then ${launches.slice(1).map(l => fmtD(l.launch)).join(" ยท ")}
+
then ${launches.slice(1).map(l => launchDateSpan(l, false)).join(" ยท ")}
`; }; const both = [ { name: "๐Ÿ–ฅ RNDSystems", rule: "launches 2nd & 4th Tuesday", launches: RDNS_LAUNCHES, count: siteCount("RNDSystems") }, @@ -1946,7 +2018,7 @@ function uatRender() { if (launch) { const n = daysUntil(launch.launch); const cls = n <= 7 ? "urgent" : (n <= 21 ? "soon" : "later"); - head += `โ†’ launch ${fmtDy(launch.launch)} + head += `โ†’ launch ${launchDateSpan(launch, true)} ๐ŸงŠ freeze ${fmtD(launch.freeze)} ยท 10 AM ${n === 0 ? "LAUNCH TODAY" : n + " day" + (n === 1 ? "" : "s") + " out"} ${siteRule[site]}`; diff --git a/build_hub.mjs b/build_hub.mjs index 65427d2..842bf19 100644 --- a/build_hub.mjs +++ b/build_hub.mjs @@ -41,6 +41,9 @@ cs += ` .lcard .rule { font-size:11.5px; color:var(--muted); margin-bottom:8px; } .lcard .lnext { font-size:14.5px; font-weight:700; } .lcard .lnext .fz { color:#b0721f; } + .ldate { cursor:pointer; border-bottom:1.5px dotted #98a1b8; } + .ldate:hover { color:var(--accent); border-bottom-color:var(--accent); } + .ldate.edited { color:#7a4d12; border-bottom-color:#f3c18f; } .lcard .lcount { margin-top:6px; font-size:12px; color:var(--muted); } .lcard .lcount b { color:var(--text); } .lcard .lmore { margin-top:4px; font-size:11.5px; color:var(--muted); } diff --git a/smoke_test.js b/smoke_test.js index dd8f741..964835b 100644 --- a/smoke_test.js +++ b/smoke_test.js @@ -25,14 +25,30 @@ setTimeout(() => { d.getElementById("tabbtn-uat").click(); ok("UAT pane activates on click", d.getElementById("tab-uat").classList.contains("active")); - // --- launch calendar (today = Wed Oct 14 2026) --- + // --- launch calendar (expected dates computed from today, so the test stays valid over time) --- + const NOW = new Date(); NOW.setHours(0, 0, 0, 0); + const nextNthTuesday = n => { + for (let i = 0; i < 24; i++) { + const dt = new Date(NOW); dt.setDate(dt.getDate() + i); + if (dt.getDay() === 2 && Math.ceil(dt.getDate() / 7) === n) return dt; + } + return null; + }; + const rnsNext = [nextNthTuesday(2), nextNthTuesday(4)].filter(Boolean).sort((a, b) => a - b)[0]; + const btNext = nextNthTuesday(3); + const friBefore = dt => { const f = new Date(dt); while (f.getDay() !== 5 || f >= dt) f.setDate(f.getDate() - 1); return f; }; + const rnsFr = friBefore(rnsNext), btFr = friBefore(btNext); + const fmtMD = dt => dt.toLocaleDateString(undefined, { month: "short", day: "numeric" }); const cards = d.getElementById("launchCards").textContent; console.log(" cards:", cards.replace(/\s+/g, " ").slice(0, 220)); - ok("RND next launch = Oct 27 (4th Tue)", cards.includes("Oct 27")); - ok("RND freeze = Oct 23 Fri", cards.includes("Oct 23")); - ok("BT next launch = Oct 20 (3rd Tue)", cards.includes("Oct 20")); - ok("BT freeze = Oct 16 Fri", cards.includes("Oct 16")); - ok("freeze banner visible (Oct 16 <= 7 days)", d.getElementById("uatBanner").style.display === "flex"); + ok(`RND next launch = ${fmtMD(rnsNext)} (2nd/4th Tue)`, cards.includes(fmtMD(rnsNext))); + ok(`RND freeze = ${fmtMD(rnsFr)} Fri`, cards.includes(fmtMD(rnsFr))); + ok(`BT next launch = ${fmtMD(btNext)} (3rd Tue)`, cards.includes(fmtMD(btNext))); + ok(`BT freeze = ${fmtMD(btFr)} Fri`, cards.includes(fmtMD(btFr))); + const nextFr = Math.min(rnsFr, btFr); + const frDays = Math.round((nextFr - NOW) / 86400000); + ok(`freeze banner ${frDays >= 0 && frDays <= 7 ? "visible" : "hidden"} (${frDays} days out)`, + d.getElementById("uatBanner").style.display === (frDays >= 0 && frDays <= 7 ? "flex" : "none")); // --- load the real weekly CSV via the app's own pipeline --- w.__csv = csv; @@ -43,17 +59,20 @@ setTimeout(() => { ok("BT section exists", /\bBT\b/.test(bodyTxt)); const rnsHead = [...d.querySelectorAll(".section")].find(s => /RNDSystem/i.test(s.querySelector(".bsec").textContent)); const btHead = [...d.querySelectorAll(".section")].find(s => s.querySelector(".bsec") && /\bBT\b/.test(s.querySelector(".bsec").textContent.split("โ†’")[0])); - ok("RND section points at Oct 27 launch + Oct 23 freeze", rnsHead && rnsHead.textContent.includes("Oct 27") && rnsHead.textContent.includes("Oct 23")); - ok("BT section points at Oct 20 launch + Oct 16 freeze", btHead && btHead.textContent.includes("Oct 20") && btHead.textContent.includes("Oct 16")); + ok(`RND section points at ${fmtMD(rnsNext)} launch + ${fmtMD(rnsFr)} freeze`, rnsHead && rnsHead.textContent.includes(fmtMD(rnsNext)) && rnsHead.textContent.includes(fmtMD(rnsFr))); + ok(`BT section points at ${fmtMD(btNext)} launch + ${fmtMD(btFr)} freeze`, btHead && btHead.textContent.includes(fmtMD(btNext)) && btHead.textContent.includes(fmtMD(btFr))); - // --- nearest launch is most prominent: BT (Oct 20) before RND (Oct 27) --- + // --- nearest launch is most prominent --- + const rnsFirst = rnsNext <= btNext; + const firstSiteRe = rnsFirst ? /RNDSystem/i : /\bBT\b/; const secNames = [...d.querySelectorAll("#list .section .bsec")].map(x => x.textContent); const btPos = secNames.findIndex(t => /\bBT\b/.test(t.split("โ†’")[0])); const rnsPos = secNames.findIndex(t => /RNDSystem/i.test(t.split("โ†’")[0])); - ok("BT section listed before RNDSystems (sooner launch first)", btPos !== -1 && rnsPos !== -1 && btPos < rnsPos); + ok((rnsFirst ? "RNDSystems" : "BT") + " section listed first (sooner launch first)", + btPos !== -1 && rnsPos !== -1 && (rnsFirst ? rnsPos < btPos : btPos < rnsPos)); const nextSec = d.querySelector("#list .section.next"); - ok("nearest section has .next highlight + NEXT UP badge", nextSec && /\bBT\b/.test(nextSec.querySelector(".bsec").textContent.split("โ†’")[0]) && nextSec.textContent.includes("NEXT UP")); - ok("launch cards sorted nearest first (BT card before RND)", d.getElementById("launchCards").children[0].textContent.includes("BT")); + ok("nearest section has .next highlight + NEXT UP badge", nextSec && firstSiteRe.test(nextSec.querySelector(".bsec").textContent.split("โ†’")[0]) && nextSec.textContent.includes("NEXT UP")); + ok("launch cards sorted nearest first", firstSiteRe.test(d.getElementById("launchCards").children[0].textContent)); const rows = d.querySelectorAll("#list .row"); ok("ticket rows rendered: " + rows.length, rows.length > 5); @@ -85,7 +104,9 @@ setTimeout(() => { ok("WA pane activates", d.getElementById("tab-wa").classList.contains("active")); const whenTxt = d.getElementById("waWhen").textContent; console.log(" wa when:", whenTxt.replace(/\s+/g, " ")); - ok("next sync = Monday Oct 19 at 9:00 AM", whenTxt.includes("October 19") && whenTxt.includes("9:00")); + const nextMon = new Date(NOW); while (nextMon.getDay() !== 1) nextMon.setDate(nextMon.getDate() + 1); + const monLong = nextMon.toLocaleDateString(undefined, { month: "long", day: "numeric" }); + ok(`next sync = next Monday (${monLong}) at 9:00 AM`, whenTxt.includes(monLong) && whenTxt.includes("9:00")); ok("badge shows โ€” when empty", d.getElementById("waBadge").textContent === "โ€”"); d.getElementById("waInput").value = "Decide staging data refresh cadence"; w.eval("addWaItem()"); diff --git a/uat_new_section.js b/uat_new_section.js index 40178ff..143f541 100644 --- a/uat_new_section.js +++ b/uat_new_section.js @@ -20,15 +20,84 @@ function upcomingLaunches(ordinals, count) { } return out.sort((a, b) => a.launch - b.launch).slice(0, count); } -const RDNS_LAUNCHES = upcomingLaunches([2, 4], 3); -const BT_LAUNCHES = upcomingLaunches([3], 3); const fmtD = d => d.toLocaleDateString(undefined, { weekday: "short", month: "short", day: "numeric" }); const fmtDy = d => d.toLocaleDateString(undefined, { month: "short", day: "numeric", year: "numeric" }); const daysUntil = d => Math.round((d - UAT_NOW) / 86400000); + +// ---------- Editable launch dates ---------- +// Click any launch date to type a new one. Overrides are saved in this +// browser; the freeze date, countdowns and section order all recalculate. +const LO_KEY = "sm-launch-overrides-v1"; +let launchOverrides = {}; +try { launchOverrides = JSON.parse(localStorage.getItem(LO_KEY) || "{}"); } catch { launchOverrides = {}; } +const lkey = d => d.getFullYear() + "-" + String(d.getMonth() + 1).padStart(2, "0") + "-" + String(d.getDate()).padStart(2, "0"); +function applyLaunchOverrides(list) { + for (const l of list) { + l.orig = lkey(l.launch); // scheduled date, before any override + const ov = launchOverrides[l.orig]; + if (!ov) continue; + const nd = new Date(ov + "T00:00:00"); + if (isNaN(nd) || nd < UAT_NOW) { delete launchOverrides[l.orig]; continue; } + const back = ((nd.getDay() - 5 + 7) % 7) || 7; // code freeze = Friday before the launch + l.launch = nd; + l.freeze = new Date(nd.getTime() - back * 86400000); + } + return list.sort((a, b) => a.launch - b.launch); +} +let RDNS_LAUNCHES = applyLaunchOverrides(upcomingLaunches([2, 4], 3)); +let BT_LAUNCHES = applyLaunchOverrides(upcomingLaunches([3], 3)); // global next freeze (whichever comes first) -const NEXT_FREEZE = RDNS_LAUNCHES[0].freeze < BT_LAUNCHES[0].freeze - ? { ...RDNS_LAUNCHES[0], site: "RNDSystems" } - : { ...BT_LAUNCHES[0], site: "BT" }; +let NEXT_FREEZE = null; +function recomputeLaunches() { + RDNS_LAUNCHES = applyLaunchOverrides(upcomingLaunches([2, 4], 3)); + BT_LAUNCHES = applyLaunchOverrides(upcomingLaunches([3], 3)); + NEXT_FREEZE = RDNS_LAUNCHES[0].freeze < BT_LAUNCHES[0].freeze + ? { ...RDNS_LAUNCHES[0], site: "RNDSystems" } + : { ...BT_LAUNCHES[0], site: "BT" }; +} +recomputeLaunches(); + +function launchDateSpan(l, withYear) { + const edited = l.orig !== lkey(l.launch); + return `${(withYear ? fmtDy : fmtD)(l.launch)}${edited ? " โœŽ" : ""}`; +} +function editLaunchDate(el) { + if (!el || el.querySelector("input")) return; + const orig = el.getAttribute("data-ldo"); + const cur = el.getAttribute("data-ldv"); + const inp = document.createElement("input"); + inp.type = "date"; + inp.value = cur; + inp.style.cssText = "font:inherit;font-size:13px;font-weight:700;padding:2px 8px;margin:0 2px;border:1.5px solid var(--accent);border-radius:7px;color:var(--text);background:#fff"; + el.textContent = ""; + el.appendChild(inp); + inp.focus(); + try { inp.showPicker && inp.showPicker(); } catch (e) {} + let finished = false; + const finish = save => { + if (finished) return; finished = true; + const v = inp.value; + if (save && v && v !== cur) { + if (v === orig) { + delete launchOverrides[orig]; + localStorage.setItem(LO_KEY, JSON.stringify(launchOverrides)); + recomputeLaunches(); + } else if (v >= lkey(UAT_NOW)) { + launchOverrides[orig] = v; + localStorage.setItem(LO_KEY, JSON.stringify(launchOverrides)); + recomputeLaunches(); + } else alert("That date is in the past โ€” keeping the scheduled date instead."); + } + uatRender(); + }; + inp.addEventListener("keydown", e => { + if (e.key === "Enter") finish(true); + else if (e.key === "Escape") finish(false); + e.stopPropagation(); + }); + inp.addEventListener("blur", () => finish(true)); +} +window.editLaunchDate = editLaunchDate; // ---------- Grouping (by launch cycle) ---------- function siteOf(t) { @@ -140,9 +209,9 @@ function uatRender() { return `

${name}

${rule}
-
๐Ÿš€ ${fmtDy(launches[0].launch)}  ยท  ๐ŸงŠ freeze ${fmtD(launches[0].freeze)} 10 AM
+
๐Ÿš€ ${launchDateSpan(launches[0], true)}  ยท  ๐ŸงŠ freeze ${fmtD(launches[0].freeze)} 10 AM
${count} open ticket${count === 1 ? "" : "s"} in queue ยท next in ${daysUntil(launches[0].launch)} days
-
then ${launches.slice(1).map(l => fmtD(l.launch)).join(" ยท ")}
+
then ${launches.slice(1).map(l => launchDateSpan(l, false)).join(" ยท ")}
`; }; const both = [ { name: "๐Ÿ–ฅ RNDSystems", rule: "launches 2nd & 4th Tuesday", launches: RDNS_LAUNCHES, count: siteCount("RNDSystems") }, @@ -224,7 +293,7 @@ function uatRender() { if (launch) { const n = daysUntil(launch.launch); const cls = n <= 7 ? "urgent" : (n <= 21 ? "soon" : "later"); - head += `โ†’ launch ${fmtDy(launch.launch)} + head += `โ†’ launch ${launchDateSpan(launch, true)} ๐ŸงŠ freeze ${fmtD(launch.freeze)} ยท 10 AM ${n === 0 ? "LAUNCH TODAY" : n + " day" + (n === 1 ? "" : "s") + " out"} ${siteRule[site]}`;