Batman
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>{% block title %}bike-admin{% endblock %}</title>
|
||||
<link rel="stylesheet" href="/static/main.css">
|
||||
<script src="/static/htmx.min.js" defer></script>
|
||||
</head>
|
||||
<body>
|
||||
<header class="topbar">
|
||||
<a class="brand" href="/">bike-admin</a>
|
||||
<nav class="nav">
|
||||
<a href="/bikes/new" class="btn btn-primary">+ Bike</a>
|
||||
<a href="/logout"
|
||||
class="btn"
|
||||
onclick="if(!confirm('Log out?')){event.preventDefault();return false;}">Log out</a>
|
||||
</nav>
|
||||
</header>
|
||||
<main class="container">
|
||||
{% block content %}{% endblock %}
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,69 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}{{ bike.name }} - bike-admin{% endblock %}
|
||||
{% block content %}
|
||||
<div class="page-head">
|
||||
<h1>{{ bike.name }}</h1>
|
||||
<a href="/bikes/{{ bike.id }}/edit" class="btn">Edit</a>
|
||||
</div>
|
||||
|
||||
<div id="bike-body">
|
||||
{% include "components/service_card.html" with context %}
|
||||
|
||||
<section class="card list-card">
|
||||
{% include "events/list.html" with context %}
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<section class="card">
|
||||
<h2>Log a new event</h2>
|
||||
<form method="post" action="/bikes/{{ bike.id }}/events" novalidate
|
||||
hx-post="/bikes/{{ bike.id }}/events"
|
||||
hx-target="#bike-body"
|
||||
hx-swap="innerHTML"
|
||||
hx-indicator="#busy-btn"
|
||||
hx-on::after-request="this.reset()">
|
||||
<input type="hidden" name="csrf" value="{{ csrf }}">
|
||||
<div class="form-row">
|
||||
<label>
|
||||
<span>Type</span>
|
||||
<select name="type" required>
|
||||
{% for t in event_types %}
|
||||
<option value="{{ t }}">{{ t }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
<span>Date</span>
|
||||
<input type="date" name="event_date" required max="{{ today.isoformat() }}"
|
||||
value="{{ today.isoformat() }}">
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label>
|
||||
<span>Mileage (optional)</span>
|
||||
<input type="number" name="mileage" min="0" step="1"
|
||||
{% if summary.due.current_mileage is not none %}value="{{ summary.due.current_mileage }}"{% endif %}>
|
||||
<small class="muted">Odometer reading at this event{% if summary.due.current_mileage is not none %}. Prefilled with your last reading of {{ summary.due.current_mileage | money }} mi; just nudge it up{% endif %}.</small>
|
||||
</label>
|
||||
<label>
|
||||
<span>Cost (optional)</span>
|
||||
<input type="number" name="cost" min="0" step="1">
|
||||
</label>
|
||||
</div>
|
||||
<label>
|
||||
<span>Notes</span>
|
||||
<textarea name="notes" rows="2"></textarea>
|
||||
</label>
|
||||
<div class="form-actions">
|
||||
<button type="submit" class="btn btn-primary" id="busy-btn">
|
||||
<span class="btn-label">Add event</span>
|
||||
<span class="btn-busy">Adding…</span>
|
||||
</button>
|
||||
<p class="add-note">
|
||||
Tip: logging a <em>service</em> with the current mileage keeps your due
|
||||
date accurate.
|
||||
</p>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,16 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Edit bike - bike-admin{% endblock %}
|
||||
{% block content %}
|
||||
<div class="page-head"><h1>Edit {{ bike.name }}</h1></div>
|
||||
<div class="card">
|
||||
{% include "components/bike_form.html" with context %}
|
||||
</div>
|
||||
<div class="danger-zone">
|
||||
<h2 class="muted">Danger zone</h2>
|
||||
<form method="post" action="/bikes/{{ bike.id }}/delete"
|
||||
onsubmit="if(!confirm('Delete this bike and all its events? This cannot be undone.'))return false;">
|
||||
<input type="hidden" name="csrf" value="{{ csrf }}">
|
||||
<button class="btn btn-danger" type="submit">Delete bike</button>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,8 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}New bike - bike-admin{% endblock %}
|
||||
{% block content %}
|
||||
<div class="page-head"><h1>New bike</h1></div>
|
||||
<div class="card">
|
||||
{% include "components/bike_form.html" with context %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,28 @@
|
||||
{# Shared bike form. Expects: action (url), csrf, old (dict), errors (dict), is_edit, bike #}
|
||||
<form method="post" action="{{ action }}" novalidate>
|
||||
<input type="hidden" name="csrf" value="{{ csrf }}">
|
||||
{% if errors %}
|
||||
<div class="alert alert-error" role="alert">
|
||||
{% for key, val in errors.items() %}
|
||||
<div>{{ val }} {{ ' ' if not loop.last else '' }}</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<label>
|
||||
<span>Name</span>
|
||||
<input type="text" name="name" value="{{ old.get('name', bike.name if bike else '') }}" required>
|
||||
</label>
|
||||
|
||||
<label>
|
||||
<span>Service interval (miles)</span>
|
||||
<input type="number" name="service_interval_miles" min="1" step="1"
|
||||
value="{{ old.get('service_interval_miles', bike.service_interval_miles if bike else '') }}">
|
||||
<small class="muted">How often this bike needs a full service, in miles.</small>
|
||||
</label>
|
||||
|
||||
<div class="form-actions">
|
||||
<button type="submit" class="btn btn-primary">{{ 'Save changes' if is_edit else 'Add bike' }}</button>
|
||||
<a href="javascript:history.back()" class="btn">Cancel</a>
|
||||
</div>
|
||||
</form>
|
||||
@@ -0,0 +1,23 @@
|
||||
{# Service-status card. Expects: bike, summary (BikeSummary). #}
|
||||
<div class="card due-card {{ status_class(summary.due) }}">
|
||||
<div class="due-top">
|
||||
<div>
|
||||
<h2 class="due-title">Service status</h2>
|
||||
<p class="due-summary">{{ status_text(summary.due) }}</p>
|
||||
</div>
|
||||
<span class="badge {{ status_class(summary.due) }}">{{ status_text(summary.due) }}</span>
|
||||
</div>
|
||||
<dl class="due-meta">
|
||||
{% if summary.due.current_mileage is not none %}
|
||||
<dt>Odometer</dt><dd>{{ summary.due.current_mileage | money }} mi</dd>
|
||||
{% endif %}
|
||||
{% if summary.due.last_service %}
|
||||
{% set ls = summary.due.last_service %}
|
||||
<dt>Last service</dt><dd>{{ ls.event_date }} · {{ ls.mileage | money }} mi</dd>
|
||||
{% endif %}
|
||||
<dt>Interval</dt>
|
||||
<dd>{% if bike.service_interval_miles %}{{ bike.service_interval_miles | money }} mi{% else %}<span class="muted">not set</span>{% endif %}</dd>
|
||||
<dt>Records</dt><dd>{{ summary.event_count }}</dd>
|
||||
<dt>Cost to date</dt><dd>{{ summary.total_cost | money }}</dd>
|
||||
</dl>
|
||||
</div>
|
||||
@@ -0,0 +1,57 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Dashboard - bike-admin{% endblock %}
|
||||
{% block content %}
|
||||
<div class="page-head">
|
||||
<h1>Your bikes</h1>
|
||||
<a href="/bikes/new" class="btn btn-primary">+ New bike</a>
|
||||
</div>
|
||||
|
||||
{% if action %}
|
||||
<div class="callout callout-danger" role="alert">
|
||||
<strong>Book a service now:</strong>
|
||||
{% for s in action %}
|
||||
<span class="inline-item"><a href="/bikes/{{ s.bike.id }}">{{ s.bike.name }}</a> <span class="badge badge-overdue">{{ status_text(s.due) }}</span></span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if due_soon %}
|
||||
<div class="callout callout-warn" role="alert">
|
||||
<strong>Service coming up:</strong>
|
||||
{% for s in due_soon %}
|
||||
<span class="inline-item"><a href="/bikes/{{ s.bike.id }}">{{ s.bike.name }}</a> <span class="badge badge-due-soon">{{ status_text(s.due) }}</span></span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if not bikes %}
|
||||
<div class="card empty">
|
||||
<p>No bikes yet. Add your first bike to start logging services and repairs.</p>
|
||||
<a href="/bikes/new" class="btn btn-primary">Add a bike</a>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="grid">
|
||||
{% for s in bikes %}
|
||||
<a class="card bike-card {{ status_class(s.due) }}-card" href="/bikes/{{ s.bike.id }}">
|
||||
<div class="bike-head">
|
||||
<h2 class="bike-name">{{ s.bike.name }}</h2>
|
||||
<span class="badge {{ status_class(s.due) }}">{{ status_text(s.due) }}</span>
|
||||
</div>
|
||||
<dl class="bike-meta">
|
||||
{% if s.due.current_mileage is not none %}
|
||||
<dt>Odometer</dt><dd>{{ s.due.current_mileage | money }} mi</dd>
|
||||
{% endif %}
|
||||
{% if s.due.last_service %}
|
||||
<dt>Last service</dt><dd>{{ s.due.last_service.event_date }} ({{ s.due.last_service.mileage | money }} mi)</dd>
|
||||
{% endif %}
|
||||
{% if s.bike.service_interval_miles %}
|
||||
<dt>Every</dt><dd>{{ s.bike.service_interval_miles | money }} mi</dd>
|
||||
{% endif %}
|
||||
<dt>Records</dt><dd>{{ s.event_count }}</dd>
|
||||
<dt>Cost to date</dt><dd>{{ s.total_cost | money }}</dd>
|
||||
</dl>
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,33 @@
|
||||
{# Expects: events, csrf, old, errors (all optional) #}
|
||||
{% if events %}
|
||||
<table class="events-table">
|
||||
<thead>
|
||||
<tr><th>When</th><th>Type</th><th>Miles</th><th>Cost</th><th>Notes</th><th></th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for ev in events %}
|
||||
<tr>
|
||||
<td>{{ ev.event_date }}</td>
|
||||
<td><span class="tag tag-{{ ev.type }}">{{ ev.type }}</span></td>
|
||||
<td>{% if ev.mileage is not none %}{{ ev.mileage | money }}{% else %}-{% endif %}</td>
|
||||
<td>{{ ev.cost | money if ev.cost is not none else '-' }}</td>
|
||||
<td class="notes">{{ ev.notes or '' }}</td>
|
||||
<td class="row-actions">
|
||||
<form method="post" action="/events/{{ ev.id }}/delete"
|
||||
onsubmit="if(!confirm('Delete this event?'))return false;">
|
||||
<input type="hidden" name="csrf" value="{{ csrf }}">
|
||||
<button class="btn btn-link btn-danger" type="submit" aria-label="Delete event">×</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
<p class="muted">No events yet. Log your first one below.</p>
|
||||
{% endif %}
|
||||
{% if errors %}
|
||||
<div class="alert alert-error" style="margin-top:1rem">
|
||||
{% for key, val in errors.items() %}<div>{{ val }}</div>{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
@@ -0,0 +1,11 @@
|
||||
{# HTMX swap target for POST /bikes/{id}/events (swaps into #bike-body).
|
||||
Expects: bike, summary, events, old, errors, csrf, event_types. #}
|
||||
{% include "components/service_card.html" with context %}
|
||||
<section class="card list-card">
|
||||
{% include "events/list.html" with context %}
|
||||
</section>
|
||||
{% if errors %}
|
||||
<div id="form-errors" class="alert alert-error" role="alert">
|
||||
{% for key, val in errors.items() %}<div>{{ val }}</div>{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
@@ -0,0 +1,32 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Log in - bike-admin</title>
|
||||
<link rel="stylesheet" href="/static/main.css">
|
||||
</head>
|
||||
<body class="auth">
|
||||
<main class="container auth-card">
|
||||
<h1 style="margin-top:0">bike-admin</h1>
|
||||
<p class="muted">Log in to manage your bikes.</p>
|
||||
|
||||
{% if error %}
|
||||
<div class="alert alert-error" role="alert">{{ error }}</div>
|
||||
{% endif %}
|
||||
|
||||
<form method="post" action="/login" novalidate>
|
||||
<label>
|
||||
<span>Username</span>
|
||||
<input type="text" name="username" autocomplete="username" required autofocus>
|
||||
</label>
|
||||
<label>
|
||||
<span>Password</span>
|
||||
<input type="password" name="password" autocomplete="current-password" required>
|
||||
</label>
|
||||
<input type="hidden" name="next" value="/">
|
||||
<button type="submit" class="btn btn-primary btn-block">Log in</button>
|
||||
</form>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user