feat(라이브): 달력 보기 오른쪽에 공용 달력과 말레이시아 공휴일

표 오른쪽에 erp-datepop 붙박이 달력을 두고, 날짜를 누르면 그 날이 표 맨 왼쪽에 오게 한다.
다른 달을 누르면 그 달 화면으로 이동해 같은 위치로 맞춘다. 마지막 날도 맨 왼쪽에 오도록 표 끝에 여백을 둔다.
말레이시아 공휴일·대체휴일 표(holidays.py, 쿠알라룸푸르 기준 2026·2027)를 표시한다.
공용 달력에 선택 옵션 locale 을 추가해 영문 화면도 영어로 그린다. 기존 화면 동작은 그대로.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-05 18:50:29 +09:00
parent e77f3d6a82
commit cf0e3f2139
17 changed files with 334 additions and 25 deletions
@@ -2,4 +2,4 @@
<link rel="stylesheet" href="/static/vendor/material-symbols/material-symbols.css" />
<link rel="stylesheet" href="/static/erp-datepop.css?v=20261102a" />
<script type="application/json" id="io-holidays">{{ (date_holidays or {}) | tojson }}</script>
<script src="/static/erp-datepop.js?v=20261102a" defer></script>
<script src="/static/erp-datepop.js?v=20261105a" defer></script>
+2
View File
@@ -17,6 +17,8 @@
- **달력 보기** `/live/calendar?month=`(`store.build_calendar`, 사용자가 준 화면 참고, 글자도 영어 그대로) — 줄 = 2시간 칸(06:00~24:00 늘 보임, 그보다 이른 칸은 방송이 있을 때만, 칸은 시작 시간으로 정함), 열 = 날짜, 주말 노랑, Jump to Date, 위 달 합계, 맨 아래 날짜별 TOTAL SALES·AD SPEND·HOST FEE·ROAS.
카드 머리 = **Tiktok Handle**(없으면 이름, 색 = 호스트 id 순 `HOST_COLORS`), SALES·COM·Fee. 카드 머리를 끌어 빈 칸으로 = 옮기기(`move`, 방송 길이 유지) · 다른 카드 위 = 맞바꾸기(`swap_with`, 날짜·시간 교환). 다시 그린 뒤 가로 위치 유지(sessionStorage). 빈 칸 + = 그 날짜·시간이 채워진 추가 창.
**AD SPEND** = 날짜별 광고비 `live_daily_ad_spend`(마이그레이션 002, `POST /live/ad-spend`, 빈칸 = 지우기), ROAS = 판매금액 ÷ 광고비(광고비 없으면 `-`). 002 미적용이면 0 으로 보이고 저장만 안내.
- **오른쪽 달력**(2026-11-05, 달력 보기만, 공용 `erp-datepop` `mountRange` + `locale` 옵션으로 영문) — 날짜를 누르면 그 날이 표 맨 왼쪽(마지막 날까지 — `endGap` 이 표 끝에 여백), 다른 달이면 그 달 화면으로 가서 맨 왼쪽(sessionStorage `lv_cal_jump`). 표시만 하고 요금·일수에 안 씀. 테스트 `tests/js/live_calendar.browser.test.js`(`render_live.py`).
**말레이시아 공휴일 표 = `holidays.py`**(쿠알라룸푸르 기준, 2026·2027, 대체휴일 포함) — 이슬람 명절은 달 관측으로 바뀔 수 있고, 2028 은 공고되면 손으로 추가.
- **결과 이미지** — 방송 저장과 한 트랜잭션, JPG·PNG·WebP, 한 장 8MB, 방송당 10장(`store.MAX_IMAGES`). `prepare_photo` 가 실제 이미지 확인·긴 변 2400px·EXIF(GPS 등) 제거. BYTEA 저장.
`GET /live/images/{id}`(권한 필요, 하루 private 캐시), `?thumb=1` = 160px JPEG(그때그때 만듦). 올린 뒤 내용이 안 바뀐다는 전제 — 이미지를 고치는 기능을 넣으면 캐시도 바꿀 것.
- 저장은 `live.js` 가 fetch → JSON `{ok, message}`(틀려도 창의 입력값 유지). 창 하나로 추가·고치기(`data-edit` JSON).
+59
View File
@@ -0,0 +1,59 @@
"""말레이시아 공휴일 표(쿠알라룸푸르 기준, 2026-11-05) — 달력 보기 오른쪽 달력에 표시만 한다(요금·일수 계산에 안 씀).
출처: publicholidays.com.my(KL 2026·2027), 2027 대체휴일은 총리실(JPM) 목록을 옮긴 maukerja.my 기준 — 공식 PDF 원문은 확인하지 못했다.
이슬람 명절(하리라야·이슬람 새해·예언자 탄신일 등)은 달 관측으로 며칠 바뀔 수 있고, 주마다 쉬는 날이 달라 다른 주 지사 생일 등은 넣지 않았다.
shortcut: 해마다 손으로 추가한다 — 2028 목록이 공고되면 여기에 더한다.
"""
from __future__ import annotations
_NAMES: dict[str, tuple[str, str]] = {
"new_year": ("새해", "New Year's Day"),
"thaipusam": ("타이푸삼", "Thaipusam"),
"ft_day": ("연방직할구의 날", "Federal Territory Day"),
"cny": ("음력 설", "Chinese New Year"),
"nuzul": ("코란 계시일", "Nuzul Al-Quran"),
"aidilfitri": ("하리라야 푸아사", "Hari Raya Aidilfitri"),
"labour": ("노동절", "Labour Day"),
"haji": ("하리라야 하지", "Hari Raya Haji"),
"wesak": ("웨삭", "Wesak Day"),
"agong": ("국왕 탄신일", "Agong's Birthday"),
"muharram": ("이슬람 새해", "Awal Muharram"),
"maulud": ("예언자 탄신일", "Maulidur Rasul"),
"merdeka": ("독립기념일", "Merdeka Day"),
"malaysia": ("말레이시아의 날", "Malaysia Day"),
"deepavali": ("디파발리", "Deepavali"),
"christmas": ("크리스마스", "Christmas Day"),
}
# 날짜 → 공휴일. "@" 로 시작 = 대체휴일(일요일·겹친 공휴일 다음 평일).
_DAYS: dict[str, str] = {
"2026-01-01": "new_year", "2026-02-01": "thaipusam", "2026-02-02": "@thaipusam", "2026-02-03": "@ft_day",
"2026-02-17": "cny", "2026-02-18": "cny", "2026-03-07": "nuzul",
"2026-03-20": "aidilfitri", "2026-03-21": "aidilfitri", "2026-03-22": "aidilfitri", "2026-03-23": "@aidilfitri",
"2026-05-01": "labour", "2026-05-27": "haji", "2026-05-31": "wesak", "2026-06-01": "agong", "2026-06-02": "@wesak",
"2026-06-17": "muharram", "2026-08-25": "maulud", "2026-08-31": "merdeka", "2026-09-16": "malaysia",
"2026-11-08": "deepavali", "2026-11-09": "@deepavali", "2026-12-25": "christmas",
"2027-01-01": "new_year", "2027-01-22": "thaipusam", "2027-02-01": "ft_day",
"2027-02-06": "cny", "2027-02-07": "cny", "2027-02-08": "@cny", "2027-02-24": "nuzul",
"2027-03-10": "aidilfitri", "2027-03-11": "aidilfitri", "2027-05-01": "labour", "2027-05-17": "haji", "2027-05-20": "wesak",
"2027-06-06": "muharram", "2027-06-07": "agong", "2027-06-08": "@muharram", "2027-08-15": "maulud", "2027-08-16": "@maulud",
"2027-08-31": "merdeka", "2027-09-16": "malaysia", "2027-10-28": "deepavali", "2027-12-25": "christmas",
}
# 같은 날 둘(2026-02-01 일요일 — 타이푸삼 + 연방직할구의 날)
_ALSO = {"2026-02-01": "ft_day"}
def holiday_names(lang: str = "ko") -> dict[str, str]:
"""{날짜: 이름} — 달력에 넘기는 값. 대체휴일은 한글 '… 대체'(공용 달력이 '대체휴일'로 줄임)·영문 '… (Replacement)'."""
i = 1 if lang == "en" else 0
out = {}
for day, key in _DAYS.items():
name = _NAMES[key.lstrip("@")][i]
if key.startswith("@"):
name += " (Replacement)" if lang == "en" else " 대체"
if day in _ALSO:
name += " · " + _NAMES[_ALSO[day]][i]
out[day] = name
return out
+3 -2
View File
@@ -24,7 +24,7 @@ from fastapi.responses import HTMLResponse, JSONResponse, Response
from app.modules.asset.media import MAX_PHOTO_BYTES, prepare_photo
from app.timezone import today_kst
from . import i18n, store
from . import holidays, i18n, store
router = APIRouter(prefix="/live", tags=["live"])
@@ -160,7 +160,8 @@ def calendar(request: Request, month: str = "") -> Any:
span = store.month_range(month, today, lang)
cal = store.build_calendar(span, st.list_broadcasts(span["start"], span["end"]), st.ad_spends(span["start"], span["end"]), today, lang)
return _render(request, "live/calendar.html", user, {"view": "calendar", "span": span, "cal": cal, "hosts": st.host_choices(),
"accounts": st.account_choices(), "max_images": store.MAX_IMAGES})
"accounts": st.account_choices(), "max_images": store.MAX_IMAGES,
"my_holidays": holidays.holiday_names(lang)})
@router.post("/broadcasts/{broadcast_id}/move")
@@ -1,2 +1,2 @@
<script>window.LV_T = {{ js_text | tojson }};</script>
<script src="/static/live.js?v=20261105a" defer></script>
<script src="/static/live.js?v=20261105b" defer></script>
+10 -2
View File
@@ -1,7 +1,9 @@
{% extends "erp_base.html" %}
{#- 라이브 커머스 달력 보기(2026-11-04) — 줄 = 2시간 칸, 열 = 날짜, 맨 아래 = 날짜별 합계. 카드 머리 = 호스트 간단한 이름 + 그 방송의 틱톡 계정.
카드 머리를 끌어 빈 칸으로 옮기거나 다른 카드 위에 놓아 맞바꾼다(live.js). 문구 = t()(i18n.py), 영문은 CSS 로 대문자(받은 화면과 같게). -#}
{% block head_extra %}<link rel="stylesheet" href="/static/live.css?v=20261105a" />{% endblock %}
{% block head_extra %}<link rel="stylesheet" href="/static/live.css?v=20261105b" />
<link rel="stylesheet" href="/static/vendor/material-symbols/material-symbols.css" />
<link rel="stylesheet" href="/static/erp-datepop.css?v=20261102a" />{% endblock %}
{% block content %}
<section class="lv" lang="{{ lang }}">
@@ -20,6 +22,7 @@
</nav>
<p class="lv-tip">{{ t('팁: 카드 머리를 끌어 옮기거나 맞바꿀 수 있습니다. 오른쪽으로 스크롤하면 이달 {n}일을 모두 볼 수 있습니다.').format(n=cal.days | length) }}</p>
<div class="lv-cal-row">
<div class="lv-cal-wrap" id="lv-cal-wrap">
<table class="lv-cal">
<thead>
@@ -78,9 +81,14 @@
</tfoot>
</table>
</div>
{#- 오른쪽 달력 — 날짜를 누르면 그 날이 표 맨 왼쪽(live.js), 말레이시아 공휴일(holidays.py) -#}
<aside class="lv-side-cal" id="lv-side-cal"></aside>
</div>
</section>
{% include "live/_dialog.html" %}
{% endblock %}
{% block scripts %}{% include "live/_scripts.html" %}{% endblock %}
{% block scripts %}<script type="application/json" id="lv-my-holidays">{{ my_holidays | tojson }}</script>
<script src="/static/erp-datepop.js?v=20261105a" defer></script>
{% include "live/_scripts.html" %}{% endblock %}
+1 -1
View File
@@ -1,6 +1,6 @@
{% extends "erp_base.html" %}
{#- 라이브 커머스 스케줄표(2026-11-04) — 달마다 방송 목록. 추가·고치기 창은 달력과 공용(_dialog.html, live.js). 문구 = t()(i18n.py). -#}
{% block head_extra %}<link rel="stylesheet" href="/static/live.css?v=20261105a" />{% endblock %}
{% block head_extra %}<link rel="stylesheet" href="/static/live.css?v=20261105b" />{% endblock %}
{% block content %}
<section class="lv" lang="{{ lang }}">
@@ -1,6 +1,6 @@
{% extends "erp_base.html" %}
{#- 라이브 커머스 설정(2026-11-04) — 호스트 정보. 계좌 등 개인정보·지우기는 ERP 관리자만(router.settings), 칩 권한자는 이름·상태만 보임 — `live_host` = 새 등록, `live_host_edit` = 고치기(개인정보는 빈칸으로 열림, 비워 두면 그대로). 추가·고치기는 같은 창(live.js). 문구 = t()(i18n.py). -#}
{% block head_extra %}<link rel="stylesheet" href="/static/live.css?v=20261105a" />{% endblock %}
{% block head_extra %}<link rel="stylesheet" href="/static/live.css?v=20261105b" />{% endblock %}
{% block content %}
<section class="lv" lang="{{ lang }}">
@@ -134,5 +134,5 @@
{% endblock %}
{% block scripts %}<script type="application/json" id="vac-holidays">{{ holidays | tojson }}</script>
<script src="/static/erp-datepop.js?v=20261102a" defer></script>
<script src="/static/erp-datepop.js?v=20261105a" defer></script>
<script src="/static/vacation.js?v=20261102a" defer></script>{% endblock %}
@@ -149,5 +149,5 @@
</section>
{% endblock %}
{% block scripts %}<script src="/static/erp-datepop.js?v=20261102a" defer></script>
{% block scripts %}<script src="/static/erp-datepop.js?v=20261105a" defer></script>
<script src="/static/vacation.js?v=20261102a" defer></script>{% endblock %}
+10 -8
View File
@@ -63,7 +63,8 @@
const HOLIDAY_SHORT = { "부처님오신날": "석가탄신일", "추석·개천절": "추석" };
// 요일 줄 + 6주 날짜 칸(팝업·붙박이 달력 공용). extra(iso) = 그 칸에 더할 클래스 목록
function gridHtml(viewY, viewM, holidays, today, extra) {
// locale(선택, 라이브 커머스 영문 화면): { weekdays[7], shortName(이름), title(연, 월0), prev, next } — 없으면 한글
function gridHtml(viewY, viewM, holidays, today, extra, locale) {
const first = new Date(viewY, viewM, 1);
const gridStart = new Date(viewY, viewM, 1 - first.getDay());
let days = "";
@@ -78,14 +79,14 @@
if (iso === today) cls.push("is-today");
cls.push.apply(cls, extra(iso, d));
if (holName) cls.push("has-hol");
const holShort = /\s대체$/.test(holName) ? "대체휴일" : (HOLIDAY_SHORT[holName] || holName);
const holShort = locale && locale.shortName ? locale.shortName(holName) : /\s대체$/.test(holName) ? "대체휴일" : (HOLIDAY_SHORT[holName] || holName);
days += '<button type="button" class="' + cls.join(" ") + '" data-iso="' + iso + '"' +
(holName ? ' title="' + esc(holName) + '"' : "") + ">" +
'<span class="pj-dp-num">' + d.getDate() + "</span>" +
(holName ? '<span class="pj-dp-hol">' + esc(holShort) + "</span>" : "") + "</button>";
}
return '<div class="pj-dp-grid">' +
["일", "월", "화", "수", "목", "금", "토"].map(function (w, i) {
((locale && locale.weekdays) || ["일", "월", "화", "수", "목", "금", "토"]).map(function (w, i) {
return '<span class="pj-dp-wd' + (i === 0 ? " is-sun" : i === 6 ? " is-sat" : "") + '">' + w + "</span>";
}).join("") + days + "</div>";
}
@@ -355,7 +356,7 @@
// 화면에 붙박이는 기간 달력(2026-11-02, 휴가 신청) — 팝업과 같은 달력 서식(.pj-dp-*).
// 첫 클릭 = 시작일(동그라미), 다음 클릭 = 종료일(둥근 막대), 그다음 클릭 = 새로 시작. 시작일보다 앞을 누르면 그 날이 새 시작일.
// opts: { start, end, holidays, single() — true 면 클릭마다 하루, onChange(start, end) }. 반환 { set(start, end) }
// opts: { start, end, holidays, single() — true 면 클릭마다 하루, onChange(start, end), locale }. 반환 { set(start, end) }
function mountRange(box, opts) {
const holidays = opts.holidays || {};
const today = isoToday();
@@ -373,12 +374,13 @@
return c;
}
function render() {
const loc = opts.locale || {};
box.innerHTML =
'<div class="pj-dp-nav">' +
'<button type="button" class="pj-dp-navbtn" data-nav="-1" title="이전 달"><span class="material-symbols-outlined">chevron_left</span></button>' +
'<span class="pj-dp-title">' + viewY + "년 " + (viewM + 1) + "월</span>" +
'<button type="button" class="pj-dp-navbtn" data-nav="1" title="다음 달"><span class="material-symbols-outlined">chevron_right</span></button>' +
"</div>" + gridHtml(viewY, viewM, holidays, today, bandClasses);
'<button type="button" class="pj-dp-navbtn" data-nav="-1" title="' + esc(loc.prev || "이전 달") + '"><span class="material-symbols-outlined">chevron_left</span></button>' +
'<span class="pj-dp-title">' + esc(loc.title ? loc.title(viewY, viewM) : viewY + "년 " + (viewM + 1) + "월") + "</span>" +
'<button type="button" class="pj-dp-navbtn" data-nav="1" title="' + esc(loc.next || "다음 달") + '"><span class="material-symbols-outlined">chevron_right</span></button>' +
"</div>" + gridHtml(viewY, viewM, holidays, today, bandClasses, opts.locale);
}
box.addEventListener("click", function (e) {
const nav = e.target.closest(".pj-dp-navbtn");
+7
View File
@@ -46,6 +46,13 @@
.lv-jump-day.is-today { outline: 2px solid #111; outline-offset: -2px; }
.lv-tip { margin: 0; padding: 8px 12px; border: 1px solid var(--color-subtle-ash, #e5e5e5); border-radius: 10px; background: #f6f8fb; font-size: 13px; color: #374151; }
/* 표 + 오른쪽 달력(공용 erp-datepop 서식) */
.lv-cal-row { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 14px; align-items: start; }
.lv-side-cal { box-sizing: border-box; padding: 12px; border: 1px solid #cfd4dc; border-radius: 10px; background: #fff; font-size: 13px; }
@media (max-width: 1100px) {
.lv-cal-row { grid-template-columns: minmax(0, 1fr); }
.lv-side-cal { max-width: 340px; }
}
.lv-cal-wrap { overflow: auto; max-height: calc(100vh - 150px); border: 1px solid #cfd4dc; border-radius: 10px; background: #fff; }
.lv-cal { border-collapse: separate; border-spacing: 0; min-width: max-content; }
.lv-cal th, .lv-cal td { border-right: 1px solid #e3e6eb; border-bottom: 1px solid #e3e6eb; }
+44 -6
View File
@@ -4,6 +4,7 @@
"use strict";
const calWrap = document.getElementById("lv-cal-wrap");
const CAL_POS = "lv_cal_left";
const CAL_JUMP = "lv_cal_jump";
function tr(text) { return (window.LV_T && window.LV_T[text]) || text; }
const dialogText = function () { return { okText: tr("확인"), cancelText: tr("취소") }; };
function reload() {
@@ -131,17 +132,54 @@
const time = calWrap.querySelector("thead .lv-cal-time");
if (col && time) calWrap.scrollLeft += col.getBoundingClientRect().left - time.getBoundingClientRect().right;
}
// 마지막 날들도 맨 왼쪽까지 오도록 표 끝에 여백(표 상자 너비 − 시간 열 − 날짜 열 하나)
function endGap() {
const time = calWrap.querySelector("thead .lv-cal-time");
const col = calWrap.querySelector("thead th[data-day]");
const table = calWrap.querySelector("table");
if (time && col && table) table.style.marginRight = Math.max(0, calWrap.clientWidth - time.offsetWidth - col.offsetWidth) + "px";
}
endGap();
window.addEventListener("resize", endGap);
// ── 오른쪽 달력(공용 erp-datepop, 말레이시아 공휴일): 날짜를 누르면 그 날이 표 맨 왼쪽, 다른 달이면 그 달 화면으로 가서 맨 왼쪽 ──
let pending = null;
try { pending = sessionStorage.getItem(CAL_JUMP); sessionStorage.removeItem(CAL_JUMP); } catch (_) {}
const hasDay = function (iso) { return !!iso && !!calWrap.querySelector('thead th[data-day="' + iso + '"]'); };
const todayHead = calWrap.querySelector("thead th[data-today]");
const firstHead = calWrap.querySelector("thead th[data-day]");
const shownDay = hasDay(pending) ? pending : todayHead ? todayHead.dataset.day : firstHead && firstHead.dataset.day;
const sideBox = document.getElementById("lv-side-cal");
let sideCal = null;
if (sideBox && window.ErpDatePop) {
let holidays = {};
try { holidays = JSON.parse(document.getElementById("lv-my-holidays").textContent); } catch (_) {}
const english = document.querySelector(".lv").lang === "en";
sideCal = window.ErpDatePop.mountRange(sideBox, {
start: shownDay, end: shownDay, holidays: holidays, single: function () { return true; },
locale: english ? {
weekdays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], prev: "Previous month", next: "Next month",
title: function (y, m) { return new Date(y, m, 1).toLocaleString("en", { month: "long" }) + " " + y; },
shortName: function (name) { return / \(Replacement\)$/.test(name) ? "Replacement" : name; },
} : undefined,
onChange: function (iso) {
if (hasDay(iso)) { jumpTo(iso); return; }
try { sessionStorage.setItem(CAL_JUMP, iso); } catch (_) {}
location.href = "/live/calendar?month=" + iso.slice(0, 7);
},
});
}
document.addEventListener("click", function (e) {
const b = e.target.closest("[data-jump]");
if (b) jumpTo(b.dataset.jump);
if (!b) return;
jumpTo(b.dataset.jump);
if (sideCal) sideCal.set(b.dataset.jump, b.dataset.jump);
});
let left = null;
try { left = sessionStorage.getItem(CAL_POS); sessionStorage.removeItem(CAL_POS); } catch (_) {}
if (left !== null) calWrap.scrollLeft = Number(left);
else {
const today = calWrap.querySelector("thead th[data-today]");
if (today) jumpTo(today.dataset.day);
}
if (hasDay(pending)) jumpTo(pending);
else if (left !== null) calWrap.scrollLeft = Number(left);
else if (todayHead) jumpTo(todayHead.dataset.day);
// ── 달력: 날짜별 광고비 ──
document.addEventListener("click", async function (e) {