Illustrations/web/templates/stats.html

221 lines
8.3 KiB
HTML

{% extends "base.html" %}
{% block body_class %}themed-bg{% endblock %}
{% block content %}
<div class="container">
<h1 class="page-title">Statistics</h1>
<!-- Totals -->
<div class="card" style="padding:16px; margin-bottom:16px;">
<div class="meta-grid">
<div>
<div class="meta-label">Total Illustrations</div>
<div class="subject-title" style="margin:0">{{ total }}</div>
</div>
<div>
<div class="meta-label">Added in last 30 days</div>
<div class="subject-title" style="margin:0">{{ last30 }}</div>
</div>
<div>
<div class="meta-label">Added in last 365 days</div>
<div class="subject-title" style="margin:0">{{ last365 }}</div>
</div>
</div>
</div>
<!-- Sparkline (simple bars) -->
<div class="card" style="padding:16px; margin-bottom:16px;">
<div class="meta-label">Adds by Month (last 12)</div>
<div style="display:flex; align-items:flex-end; gap:6px; height:140px; margin-top:8px;">
{% for label, value, height in heights %}
<div title="{{ label }} = {{ value }}"
style="width:22px; height:{{ height }}px; background:#cfe3f6; border:1px solid #bcd4ee; border-radius:6px;"></div>
{% endfor %}
</div>
<div class="small muted" style="margin-top:6px;">
{% for label, value in series %}{% if not forloop.last %}{{ label }} · {% else %}{{ label }}{% endif %}{% endfor %}
</div>
</div>
<!-- Top subjects (clickable) -->
<div class="card" style="padding:16px; margin-bottom:16px;">
<div class="meta-label">Top Subjects</div>
<div style="display:flex; flex-wrap:wrap; gap:8px; margin-top:8px;">
{% for s in top_subjects %}
<a
class="chip chip-muted"
href="{% url 'search' %}?q={{ s.name|urlencode }}&subject=on"
title="Search by subject: {{ s.name }}"
>
{{ s.name }} ({{ s.count }})
</a>
{% empty %}
<span class="muted">No subjects.</span>
{% endfor %}
</div>
</div>
<!-- Scripture usage -->
<div class="card" style="padding:16px; margin-bottom:16px;">
<h3 style="margin:0 0 10px;">Scripture Usage</h3>
<div class="chip" style="margin-bottom:10px;"><strong>Avg. refs per scripture-bearing entry:</strong>&nbsp;{{ avg_refs_per_entry }}</div>
<div style="display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:16px;">
<div>
<h4 style="margin:0 0 6px;">Top 10 Books</h4>
<ol class="small" style="margin:0; padding-left:18px;">
{% for book, cnt in top_books %}
<li>
<a
href="{% url 'search' %}?q={{ book|urlencode }}&scripture_raw=on"
title="Search scripture field for book: {{ book }}"
>
<strong>{{ book }}</strong>
</a>
— {{ cnt }}
</li>
{% empty %}
<li class="muted">No data yet.</li>
{% endfor %}
</ol>
</div>
<div>
<h4 style="margin:0 0 6px;">Top 10 Scriptures</h4>
<ol class="small" style="margin:0; padding-left:18px;">
{% for ref, cnt in top_refs %}
<li>
<a
href="{% url 'search' %}?q={{ ref|urlencode }}&scripture_raw=on"
title="Search scripture field for: {{ ref }}"
>
<strong>{{ ref }}</strong>
</a>
— {{ cnt }}
</li>
{% empty %}
<li class="muted">No data yet.</li>
{% endfor %}
</ol>
</div>
</div>
</div>
<!-- Maintenance tools (collapsible like the search help) -->
<div class="card" style="padding:16px; margin-bottom:24px;">
<details class="tools-details">
<summary class="tools-summary">
🛠️ Maintenance Tools
</summary>
<div class="tools-grid">
<!-- Scripture Normalizer -->
<div class="tool">
<h4>Scripture Normalizer</h4>
<p class="small muted">
Normalize scripture references (abbreviations, separators, and repeat book names where needed).
</p>
<div class="tool-actions">
<form method="get" action="{% url 'normalize_scripture' %}">
<input type="number" min="0" name="limit" placeholder="Preview limit (optional)"
class="tool-input">
<button class="btn btn-secondary">Preview (dry-run)</button>
</form>
{% if user.is_authenticated and user.is_staff %}
<form method="post" action="{% url 'normalize_scripture' %}">
{% csrf_token %}
<button class="btn btn-danger"
onclick="return confirm('Apply normalization to ALL entries? This will modify scripture_raw fields.');">
Apply to all
</button>
</form>
{% endif %}
</div>
</div>
<!-- Source Normalizer -->
<div class="tool">
<h4>Source Normalizer</h4>
<p class="small muted">
Convert Watchtower/Awake!/Yearbook/KM references into WOL short-codes (e.g., <code>w13 3/15 p.14</code>).
Non-JW sources are left unchanged.
</p>
<div class="tool-actions">
<form method="get" action="{% url 'normalize_source' %}">
<input type="number" min="0" name="limit" placeholder="Preview limit (optional)"
class="tool-input">
<button class="btn btn-secondary">Preview (dry-run)</button>
</form>
{% if user.is_authenticated and user.is_staff %}
<form method="post" action="{% url 'normalize_source' %}">
{% csrf_token %}
<button class="btn btn-danger"
onclick="return confirm('Apply normalization to all entries? This cannot be undone. Make a backup first.')">
Apply to all
</button>
</form>
{% endif %}
</div>
</div>
<!-- Subject Normalizer (NEW) -->
<div class="tool">
<h4>Subject Normalizer</h4>
<p class="small muted">
Unify delimiters (semicolons, dashes, slashes, etc.) into commas and trim spacing.
Preserves multi-word subjects. Most entries are already correct—this avoids over-splitting.
</p>
<div class="tool-actions">
<form method="get" action="{% url 'normalize_subjects' %}">
<input type="number" min="0" name="limit" placeholder="Preview limit (optional)"
class="tool-input">
<button class="btn btn-secondary">Preview (dry-run)</button>
</form>
{% if user.is_authenticated and user.is_staff %}
<form method="post" action="{% url 'normalize_subjects' %}">
{% csrf_token %}
<button class="btn btn-danger"
onclick="return confirm('Apply subject normalization to all entries? This will modify subject fields. Make a backup first.')">
Apply to all
</button>
</form>
{% endif %}
</div>
</div>
</div>
<div class="small muted" style="margin-top:10px;">
Tip: add <code>?limit=1000</code> on the preview to test against a subset before applying globally.
</div>
</details>
</div>
</div>
<!-- Minimal styles for the collapsible tools, matching your existing look -->
<style>
.tools-details { margin-top: 4px; }
.tools-summary {
display:inline-flex; align-items:center; gap:8px;
padding:8px 12px; border-radius:10px;
background: var(--btn-bg); border:1px solid var(--btn-border);
color: var(--nav-ink); cursor:pointer; user-select:none;
}
.tools-summary:hover { background: var(--btn-hover); }
.tools-details[open] .tools-summary { background:#fff; }
.tools-grid {
margin-top:12px;
display:grid; gap:16px;
grid-template-columns: repeat( auto-fit, minmax(260px, 1fr) );
}
.tool { border:1px solid var(--nav-border); border-radius:12px; padding:12px; background:#fff; }
.tool h4 { margin:0 0 6px; }
.tool-actions { display:flex; flex-wrap:wrap; gap:8px; margin-top:8px; }
.tool-input {
border:1px solid var(--nav-border);
border-radius:8px; padding:6px 8px; min-width: 190px;
}
</style>
{% endblock %}