Files
o2o-castad-backend/app/backoffice/frontend/templates/sqladmin/traffic_macros.html
T

86 lines
3.3 KiB
HTML

{# 사이트 트래픽 화면 공통 조각 #}
{% macro num(value) -%}{{ '{:,}'.format(value or 0) }}{%- endmacro %}
{% macro when(value) -%}{{ value.strftime('%m-%d %H:%M') if value else '-' }}{%- endmacro %}
{% macro stat_card(label, value, cls='') %}
<div class="col-sm-6 col-lg-3">
<div class="card">
<div class="card-body">
<div class="subheader">{{ label }}</div>
<div class="h1 mb-1 traffic-num {{ cls }}">{{ value }}</div>
</div>
</div>
</div>
{% endmacro %}
{# 차트 + "표로 보기"(색 대비가 낮은 계열이 있어 표를 항상 함께 둔다) #}
{% macro chart_card(title, chart_id, daily, columns, col='col-12') %}
<div class="{{ col }}">
<div class="card">
<div class="card-header"><h3 class="card-title">{{ title }}</h3></div>
<div class="card-body">
<div class="traffic-chart"><canvas id="{{ chart_id }}" role="img" aria-label="{{ title }}"></canvas></div>
<details class="mt-3">
<summary class="text-muted">표로 보기</summary>
<div class="table-responsive mt-2">
<table class="table table-sm table-vcenter card-table traffic-num">
<thead><tr><th>날짜</th>{% for key, label in columns %}<th class="text-end">{{ label }}</th>{% endfor %}</tr></thead>
<tbody>
{% for d in daily | reverse %}
<tr>
<td>{{ d.date.strftime('%Y-%m-%d') }}</td>
{% for key, label in columns %}<td class="text-end">{{ num(d[key]) }}</td>{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
</details>
</div>
</div>
</div>
{% endmacro %}
{# rows: dict 목록, columns: [(키, 제목, 숫자여부)] #}
{% macro table_card(title, rows, columns, col='col-12 col-lg-6', empty='기록 없음') %}
<div class="{{ col }}">
<div class="card">
<div class="card-header"><h3 class="card-title">{{ title }}</h3></div>
<div class="table-responsive">
<table class="table table-sm table-vcenter card-table">
<thead>
<tr>{% for key, label, numeric in columns %}<th class="{{ 'text-end' if numeric }}">{{ label }}</th>{% endfor %}</tr>
</thead>
<tbody>
{% for row in rows %}
<tr>
{% for key, label, numeric in columns %}
{% if numeric %}
<td class="text-end traffic-num">{{ num(row[key]) }}</td>
{% elif key in ('last_seen', 'at') %}
<td class="text-nowrap traffic-num">{{ when(row[key]) }}</td>
{% else %}
<td class="text-break" style="max-width: 420px;">{{ row[key] if row[key] is not none else '-' }}</td>
{% endif %}
{% endfor %}
</tr>
{% else %}
<tr><td colspan="{{ columns | length }}" class="text-center text-muted">{{ empty }}</td></tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
{% endmacro %}
{% macro content_path(content_type, content_id) -%}
{%- if content_type == 'video' -%}/video/{{ content_id }}
{%- elif content_type == 'ssul' -%}/ssul/{{ content_id }}
{%- elif content_type == 'p2v_f1' -%}/p2v/f1/{{ content_id }}
{%- elif content_type == 'p2v_playreel' -%}/p2v/playreel/{{ content_id }}
{%- else -%}{{ content_type }}/{{ content_id }}{%- endif -%}
{%- endmacro %}