From 3d14ff4a85cbad88794390aeecf41cdcbb44d6c6 Mon Sep 17 00:00:00 2001 From: king Date: Mon, 26 Oct 2026 12:29:09 +0900 Subject: [PATCH] =?UTF-8?q?feat(performance):=20=EA=B8=B0=EA=B0=84=20?= =?UTF-8?q?=EB=B9=A0=EB=A5=B8=20=EC=84=A0=ED=83=9D=20=EC=9D=B4=EB=B2=88?= =?UTF-8?q?=EB=8B=AC=C2=B7=EC=98=AC=ED=95=B4=EB=A7=8C(=EA=B8=B0=EB=B3=B8?= =?UTF-8?q?=20=EC=9D=B4=EB=B2=88=EB=8B=AC)=20=C2=B7=20=EC=9D=BC=EC=9E=90?= =?UTF-8?q?=EB=B3=84=20=ED=91=9C=20=EC=A0=9C=EB=AA=A9=C2=B7=EA=B8=B0?= =?UTF-8?q?=EA=B0=84=20=ED=95=A9=EA=B3=84=20=ED=96=89=20=EC=8A=A4=ED=81=AC?= =?UTF-8?q?=EB=A1=A4=20=EA=B3=A0=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 매출 실적·광고비 탭 오늘·이번주 버튼 삭제, 매출 실적 기본 기간 = 이번달 - 일자별 표 상자(.perf-main-wrap)를 화면 높이로 묶어 상자 안 세로 스크롤 — 제목 행 + 맨 위 기간 합계 행 sticky (합계 행 top = 제목 행 높이 --perf-head-h, stickyHead 가 ResizeObserver 로 잼), 날짜 열 가로 고정은 그대로 - 테스트: perf_sticky.browser.test.js(실제 브라우저), test_ad_spend 빠른 선택 순서 Co-Authored-By: Claude Opus 5.5 --- app/modules/performance/CLAUDE.md | 5 ++ app/modules/performance/ad_spend.py | 3 +- app/modules/performance/dashboard.py | 5 +- app/modules/performance/router.py | 2 +- .../templates/performance/ads.html | 7 +- .../templates/performance/index.html | 7 +- .../templates/performance/settings.html | 4 +- .../performance/tests/test_ad_spend.py | 2 +- app/static/performance.css | 9 ++ app/static/performance.js | 15 +++- tests/js/perf_sticky.browser.test.js | 86 +++++++++++++++++++ tests/js/render_performance.py | 8 +- 12 files changed, 135 insertions(+), 18 deletions(-) create mode 100644 tests/js/perf_sticky.browser.test.js diff --git a/app/modules/performance/CLAUDE.md b/app/modules/performance/CLAUDE.md index a2c2f7c..8713c5e 100644 --- a/app/modules/performance/CLAUDE.md +++ b/app/modules/performance/CLAUDE.md @@ -44,6 +44,11 @@ 서버가 계산(원 반올림)해 금액으로, 식은 `formula` 열에 저장 → 칸 `is-formula` 파랑 굵은 숫자, 다시 누르면 식. 숫자 입력·업로드·광고 API 로 덮으면 식 지움(`db._set_formulas`, 008 미적용이면 조용히 건너뜀). 광고비 탭 직접 입력값은 파랑 **보통 굵기**(굵게는 계산식만), 매출 탭 수동 입력값은 예전처럼 파랑 굵게. - 일자별 표 **기간 합계 행은 맨 위**(제목 행 바로 아래, 2026-10-21 `calc.main_table`) — 매출·광고비 공통, 연간 보기 "연간 합계"는 그대로 맨 아래. +- **기간 빠른 선택 = 이번달·올해·직접선택**(2026-10-26 — 오늘·이번주 버튼 삭제, `dashboard.build_dashboard`·`ad_spend.build_ad_dashboard` 의 `nav.quick`), + 매출 실적 기본 기간도 **이번달**(`router.dashboard_page` `period="month"`, 광고비는 원래 이번달). day·week 주소(`?period=week`)는 그대로 열린다. +- **일자별 표 스크롤 고정**(2026-10-26, `.perf-main-wrap`) — 표 상자를 화면 높이(`100vh − 상단 바 − 24px`)로 묶어 상자 안에서 세로 스크롤, + 제목 행 + 맨 위 기간 합계 행(`tbody tr.perf-row-total:first-child`)이 sticky. 합계 행 top = 제목 행 높이(`--perf-head-h`, `performance.js stickyHead` + 가 ResizeObserver 로 잼). 상자가 가로 스크롤이라 페이지 스크롤 기준 sticky 는 안 먹어서 상자 안 스크롤로 했다. 테스트 `tests/js/perf_sticky.browser.test.js`. - 열 순서 카페24·네이버·쿠팡(윙)·쿠팡(로켓)·오늘의집·G마켓·카카오·GS샵·11번가·롯데ON·토스·애터미아자몰(마이그레이션 003). - 쿠팡(로켓)·애터미아자몰은 **수동 입력 전용**(`adapters/manual.py`, `manual_only` — 매출 업데이트에서 빠지고 인증 설정·연결 테스트 없음, 수동 입력 늘 켜짐). - **직접 추가 쇼핑몰·그룹·순서 드래그**(2026-10-22, 마이그레이션 009 `is_custom`·`is_group`·`parent_code`) — 설정 [+ 쇼핑몰 추가(수동 입력)] diff --git a/app/modules/performance/ad_spend.py b/app/modules/performance/ad_spend.py index a57785f..22b984d 100644 --- a/app/modules/performance/ad_spend.py +++ b/app/modules/performance/ad_spend.py @@ -553,9 +553,8 @@ def build_ad_dashboard(store: Any, *, kind: str, anchor: date, today: date, next_url = url("custom", start=period.end + timedelta(days=1), end=period.end + length) else: prev_url, next_url = url(period.kind, period.prev_anchor), url(period.kind, period.next_anchor) + # 빠른 선택은 이번달·올해만(2026-10-26 — 오늘·이번주 버튼 삭제, 매출 실적과 같게) nav = {"prev": prev_url, "next": next_url, "quick": [ - {"label": "오늘", "url": url("day", today), "active": period.kind == "day" and period.start == today}, - {"label": "이번주", "url": url("week", today), "active": period.kind == "week" and period.start <= today <= period.end}, {"label": "이번달", "url": url("month", today), "active": period.kind == "month" and period.start <= today <= period.end}, {"label": "올해", "url": url("year", today), "active": period.kind == "year" and period.start <= today <= period.end}, ]} diff --git a/app/modules/performance/dashboard.py b/app/modules/performance/dashboard.py index 418cb38..ed06300 100644 --- a/app/modules/performance/dashboard.py +++ b/app/modules/performance/dashboard.py @@ -249,11 +249,8 @@ def build_dashboard(store: Any, *, kind: str, anchor: date, today: date, next_url = url(period.kind, period.next_anchor) nav = { "prev": prev_url, "next": next_url, + # 빠른 선택은 이번달·올해만(2026-10-26 — 오늘·이번주 버튼 삭제, 기본 = 이번달) "quick": [ - {"key": "day", "label": "오늘", "url": url("day", today), - "active": period.kind == "day" and period.start == today}, - {"key": "week", "label": "이번주", "url": url("week", today), - "active": period.kind == "week" and period.start <= today <= period.end}, {"key": "month", "label": "이번달", "url": url("month", today), "active": period.kind == "month" and period.start <= today <= period.end}, {"key": "year", "label": "올해", "url": url("year", today), diff --git a/app/modules/performance/router.py b/app/modules/performance/router.py index 60aa8d9..dab4a4c 100644 --- a/app/modules/performance/router.py +++ b/app/modules/performance/router.py @@ -121,7 +121,7 @@ def health(request: Request) -> JSONResponse: @router.get("/", response_class=HTMLResponse) def dashboard_page( request: Request, - period: str = "week", + period: str = "month", d: str | None = None, from_: str | None = Query(None, alias="from"), to: str | None = None, diff --git a/app/modules/performance/templates/performance/ads.html b/app/modules/performance/templates/performance/ads.html index 4a06b66..0d5a683 100644 --- a/app/modules/performance/templates/performance/ads.html +++ b/app/modules/performance/templates/performance/ads.html @@ -1,6 +1,6 @@ {% extends "erp_base.html" %} -{% block head_extra %}{% endblock %} +{% block head_extra %}{% endblock %} {#- ROAS 덧붙임 — "광고비(ROAS%)". 광고비가 없으면 아무것도 안 붙는다. -#} {%- macro roas(p) -%}{%- if p is not none -%}({{ "{:,}".format(p) }}%){%- endif -%}{%- endmacro -%} @@ -96,7 +96,8 @@ {% endif %} -
+
+ {#- perf-main-wrap(2026-10-26) = 표 안에서 세로 스크롤 — 제목 행·기간 합계 행 고정 -#} {#- perf-autofit(2026-10-22) = 열 너비는 내용 길이만큼, 날짜 열은 가로 스크롤해도 고정(매출 실적 표와 같음) -#} @@ -240,4 +241,4 @@ } | tojson }} {% endblock %} -{% block scripts %}{% endblock %} +{% block scripts %}{% endblock %} diff --git a/app/modules/performance/templates/performance/index.html b/app/modules/performance/templates/performance/index.html index c243a41..ff75f70 100644 --- a/app/modules/performance/templates/performance/index.html +++ b/app/modules/performance/templates/performance/index.html @@ -1,6 +1,6 @@ {% extends "erp_base.html" %} -{% block head_extra %}{% endblock %} +{% block head_extra %}{% endblock %} {%- macro won(v) -%} {%- if v is none -%} @@ -134,7 +134,8 @@ -
+
+ {#- perf-main-wrap(2026-10-26) = 표 안에서 세로 스크롤 — 제목 행·기간 합계 행 고정 -#} {#- perf-autofit(2026-10-22) = 열 너비는 내용 길이만큼, 날짜 열은 가로 스크롤해도 고정 -#}
@@ -291,4 +292,4 @@ } | tojson }} {% endblock %} -{% block scripts %}{% endblock %} +{% block scripts %}{% endblock %} diff --git a/app/modules/performance/templates/performance/settings.html b/app/modules/performance/templates/performance/settings.html index 3dc75c4..a426db6 100644 --- a/app/modules/performance/templates/performance/settings.html +++ b/app/modules/performance/templates/performance/settings.html @@ -1,6 +1,6 @@ {% extends "erp_base.html" %} -{% block head_extra %}{% endblock %} +{% block head_extra %}{% endblock %} {%- macro when(v) -%}{{ (v or '')[:16] | replace('T', ' ') or '—' }}{%- endmacro -%} @@ -259,4 +259,4 @@ {% endblock %} -{% block scripts %}{% endblock %} +{% block scripts %}{% endblock %} diff --git a/app/modules/performance/tests/test_ad_spend.py b/app/modules/performance/tests/test_ad_spend.py index 6416f01..2c2c38f 100644 --- a/app/modules/performance/tests/test_ad_spend.py +++ b/app/modules/performance/tests/test_ad_spend.py @@ -146,7 +146,7 @@ def test_ad_dashboard_month(): assert ctx["roas_basis"]["google"] == "" and ctx["roas_basis"]["coupang_wing"] == "쿠팡(윙)" assert {r["code"]: r for r in ctx["month"]["rows"]}["google"]["roas"] is None assert ads.roas(1, 3) == 33 and ads.roas(1, 200) == 1 and ads.roas(5, 0) is None # 0.5% 반올림 → 1 - assert ctx["nav"]["quick"][2]["active"] # 이번달 + assert ctx["nav"]["quick"][0]["active"] # 이번달 def test_ad_dashboard_year_and_missing_table(): diff --git a/app/static/performance.css b/app/static/performance.css index 74fcd95..82afe40 100644 --- a/app/static/performance.css +++ b/app/static/performance.css @@ -457,3 +457,12 @@ body.perf-dragging, body.perf-dragging * { cursor: grabbing !important; user-sel .perf-memo-input { width: 100%; box-sizing: border-box; min-height: 110px; padding: 10px; border: 1px solid #d8dce2; border-radius: 8px; font: inherit; font-size: 13.5px; line-height: 1.5; resize: vertical; } .perf-memo-input:focus { outline: none; border-color: #1a56db; box-shadow: 0 0 0 3px rgba(26, 86, 219, .12); } + +/* ── 일자별 표 스크롤 고정(2026-10-26): 표 상자 안에서 세로 스크롤 → 제목 행 + 맨 위 기간 합계 행 고정 ── + (상자가 가로 스크롤(overflow-x)이라 페이지 스크롤 기준 sticky 는 안 먹는다 — 상자 높이를 화면 높이로 묶고 상자 안에서 스크롤) + --perf-head-h = 제목 행 높이(performance.js stickyHead 가 잼, 기본 31px). 연간 보기 "연간 합계"는 맨 아래 그대로. */ +.perf-main-wrap { overflow: auto; max-height: calc(100vh - var(--erp-topbar-h, 56px) - 24px); overscroll-behavior: contain; } +.perf-main-wrap .perf-main thead th { z-index: 3; } +.perf-main-wrap .perf-main thead th.perf-th-label { z-index: 5; } +.perf-main-wrap .perf-main tbody tr.perf-row-total:first-child > * { position: sticky; top: var(--perf-head-h, 31px); z-index: 1; } +.perf-main-wrap .perf-main tbody tr.perf-row-total:first-child > .perf-td-label { left: 0; z-index: 4; } diff --git a/app/static/performance.js b/app/static/performance.js index 3dc3ba5..affc537 100644 --- a/app/static/performance.js +++ b/app/static/performance.js @@ -1434,9 +1434,22 @@ }); } + // 일자별 표 스크롤 고정(2026-10-26) — 기간 합계 행이 제목 행 바로 밑에 붙도록 제목 행 높이를 CSS 변수로. + // 그룹 접기·화면 크기·글꼴에 따라 높이가 바뀌므로 ResizeObserver 로 다시 잰다. + function stickyHead(root) { + root.querySelectorAll(".perf-main-wrap").forEach(function (wrap) { + const head = wrap.querySelector("thead"); + if (!head) return; + const measure = function () { wrap.style.setProperty("--perf-head-h", head.getBoundingClientRect().height + "px"); }; + measure(); + if (window.ResizeObserver) new ResizeObserver(measure).observe(head); + else window.addEventListener("resize", measure); + }); + } + document.addEventListener("DOMContentLoaded", function () { const dash = document.getElementById("perf-dash"); - if (dash) initDashboard(dash); + if (dash) { initDashboard(dash); stickyHead(dash); } const set = document.getElementById("perf-settings"); if (set) initSettings(set); }); diff --git a/tests/js/perf_sticky.browser.test.js b/tests/js/perf_sticky.browser.test.js new file mode 100644 index 0000000..9a27696 --- /dev/null +++ b/tests/js/perf_sticky.browser.test.js @@ -0,0 +1,86 @@ +// 실적 — 기간 빠른 선택(이번달·올해만, 기본 이번달) · 일자별 표 스크롤 고정(2026-10-26) — 실제 브라우저(Chromium). +// python tests/js/render_performance.py +// NODE_PATH= PJ_TEST_BROWSER= node tests/js/perf_sticky.browser.test.js +// 매출 실적(이번달)·광고비(이번달): 표 상자 안에서 세로 스크롤하면 제목 행은 상자 맨 위, 기간 합계 행은 제목 행 바로 아래에 붙어 있고 +// 날짜 칸은 가로 스크롤해도 왼쪽 고정(예전 그대로). 오늘·이번주 버튼은 없다. +const fs = require("fs"), path = require("path"); +const { chromium } = require("playwright"); +const ROOT = path.join(__dirname, "..", ".."); +const fails = []; +function check(name, cond, extra) { + if (cond) console.log("PASS " + name); + else { console.log("FAIL " + name + (extra !== undefined ? " → " + JSON.stringify(extra) : "")); fails.push(name); } +} +function page(file) { + const css = fs.readFileSync(path.join(ROOT, "app", "static", "performance.css"), "utf8"); + const js = fs.readFileSync(path.join(ROOT, "app", "static", "performance.js"), "utf8"); + return fs.readFileSync(path.join(__dirname, ".out", file), "utf8") + .replace(//, function () { return ""; }) + .replace(/"; }); +} + +async function stickyFlow(browser, file, label) { + const ctx = await browser.newContext({ viewport: { width: 900, height: 600 } }); + const p = await ctx.newPage(); + await p.route("**/*", function (r) { + const url = new URL(r.request().url()).pathname; + if (url.startsWith("/performance/api/")) { r.fulfill({ status: 200, contentType: "application/json", body: "{}" }); return; } + r.fulfill({ status: 200, contentType: "text/html; charset=utf-8", body: page(file) }); + }); + await p.goto("http://perf.test/performance/"); + const quick = await p.evaluate(function () { + return Array.from(document.querySelectorAll(".perf-quick .perf-seg")).map(function (n) { return n.textContent.trim(); }); + }); + check(label + " 빠른 선택 = 이번달·올해·직접선택(오늘·이번주 없음)", JSON.stringify(quick) === '["이번달","올해","직접선택"]', quick); + const geo = async function () { + return p.evaluate(function () { + const wrap = document.querySelector(".perf-main-wrap"); + const head = wrap.querySelector("thead th:nth-child(2)"); + const total = wrap.querySelector("tbody tr.perf-row-total:first-child"); + const totalCell = total.querySelector("td"); + const label = total.querySelector(".perf-td-label"); + const w = wrap.getBoundingClientRect(); + return { wrapTop: w.top, wrapLeft: w.left, scrollH: wrap.scrollHeight, clientH: wrap.clientHeight, + headTop: head.getBoundingClientRect().top, headBottom: head.getBoundingClientRect().bottom, + totalTop: totalCell.getBoundingClientRect().top, labelLeft: label.getBoundingClientRect().left, + totalText: label.textContent.trim(), + // 기간 합계 행 위에 다른 줄이 겹쳐 보이지 않는가 — 합계 칸 가운데를 찍으면 합계 행 칸이 나와야 한다 + hit: (function () { + const r = totalCell.getBoundingClientRect(); + const el = document.elementFromPoint(r.left + r.width / 2, r.top + r.height / 2); + return !!el && !!el.closest("tr.perf-row-total"); + })(), + labelHit: (function () { + const r = label.getBoundingClientRect(); + const el = document.elementFromPoint(r.left + r.width / 2, r.top + r.height / 2); + return !!el && !!el.closest("tr.perf-row-total"); + })() }; + }); + }; + const g0 = await geo(); + check(label + " 표 상자가 세로로 스크롤된다(화면 높이로 묶음)", g0.scrollH > g0.clientH + 100, g0); + check(label + " 맨 위 행 = 기간 합계", g0.totalText === "기간 합계", g0.totalText); + await p.evaluate(function () { document.querySelector(".perf-main-wrap").scrollTop = 400; }); + await p.waitForTimeout(50); + const g1 = await geo(); + check(label + " 세로 스크롤 뒤 제목 행 = 상자 맨 위", Math.abs(g1.headTop - g1.wrapTop) <= 1.5, g1); + check(label + " 세로 스크롤 뒤 기간 합계 행 = 제목 행 바로 아래", Math.abs(g1.totalTop - g1.headBottom) <= 1.5 && g1.hit, g1); + await p.evaluate(function () { document.querySelector(".perf-main-wrap").scrollLeft = 300; }); + await p.waitForTimeout(50); + const g2 = await geo(); + check(label + " 가로 스크롤해도 기간 합계 날짜 칸은 왼쪽 고정", Math.abs(g2.labelLeft - g2.wrapLeft) <= 1.5 && g2.labelHit, g2); + await ctx.close(); +} + +(async function () { + const exe = process.env.PJ_TEST_BROWSER; + const browser = await chromium.launch(exe ? { executablePath: exe } : {}); + try { + await stickyFlow(browser, "perf_dash_month.html", "[매출 실적]"); + await stickyFlow(browser, "perf_ads.html", "[광고비]"); + } finally { + await browser.close(); + } + if (fails.length) { console.log("\n" + fails.length + " FAILED"); process.exit(1); } + console.log("\nALL PASS"); +})().catch(function (e) { console.error(e); process.exit(1); }); diff --git a/tests/js/render_performance.py b/tests/js/render_performance.py index dc5a4b7..2393e6b 100644 --- a/tests/js/render_performance.py +++ b/tests/js/render_performance.py @@ -94,7 +94,13 @@ def main() -> None: html = e.get_template("performance/index.html").render(**base, active_tab="dashboard", metric="net", **ctx) with open(os.path.join(OUT_DIR, "perf_dash.html"), "w", encoding="utf-8") as f: f.write(html) - actx = build_ad_dashboard(FakeStore(), kind="month", anchor=date(2026, 10, 7), today=date(2026, 10, 7), + # 이번달 보기(기본, 2026-10-26) — 맨 위 기간 합계 행이 있는 표(제목·합계 행 스크롤 고정 확인용) + mctx = build_dashboard(FakeStore(), kind="month", anchor=date(2026, 10, 7), today=date(2026, 10, 7)) + mctx["auto_sync"] = ctx["auto_sync"] + html = e.get_template("performance/index.html").render(**base, active_tab="dashboard", metric="net", **mctx) + with open(os.path.join(OUT_DIR, "perf_dash_month.html"), "w", encoding="utf-8") as f: + f.write(html) + actx =build_ad_dashboard(FakeStore(), kind="month", anchor=date(2026, 10, 7), today=date(2026, 10, 7), sales_codes=["cafe24", "coupang"]) actx["ad_sync_sources"] = [{"code": "google", "name": "구글 광고"}] # [구글 광고 불러오기] actx["auto_sync"] = ctx["auto_sync"] # 광고비 탭도 다음 업데이트 카운트다운(router._auto_sync_ctx)