admin: dashboard instead of the invoice list
/admin redirected to the invoice list, which stopped making sense once the admin also ran the bingo. Make it a dashboard with one tile per area: invoice totals, outstanding amount per currency, overdue count and the five latest invoices; the bingo score, reserve size, latest incident and card cells still missing a photo. A shared nav links the sections. Tiles are per area so they can follow user permissions later. Assisted-by: Claude:opus-5
This commit is contained in:
parent
e5bd1c1ac7
commit
c2020bf903
8 changed files with 134 additions and 5 deletions
|
|
@ -78,7 +78,7 @@ If a form is ever reinstated, note that Traefik's access log (`/opt/traefik/logs
|
|||
|
||||
Admin (HTTP Basic via `ADMIN_USER`/`ADMIN_PASSWORD`):
|
||||
|
||||
- `GET /admin` → redirects to `/admin/invoices`.
|
||||
- `GET /admin` → dashboard (`views/admin/dashboard.erb`): invoice counts/outstanding/overdue + recent five, bingo score/reserve/latest incident/missing photos. Shared admin nav in `views/admin/_nav.erb`.
|
||||
- `GET /admin/invoices` — list, newest first.
|
||||
- `GET /admin/invoices/new` — create form. Dynamic line items via `public/admin-invoice-form.js`.
|
||||
- `POST /admin/invoices` — validate → allocate number → render PDF → upload to MinIO → persist row.
|
||||
|
|
|
|||
22
asxpio.rb
22
asxpio.rb
|
|
@ -130,8 +130,28 @@ class AsxpioWeb < Sinatra::Base
|
|||
halt 503, 'Invoicing not configured (DATABASE_URL missing).' unless defined?(Invoice)
|
||||
end
|
||||
|
||||
# Overview of every admin area; each tile links into its section.
|
||||
get '/admin' do
|
||||
redirect '/admin/invoices'
|
||||
@page_title = 'Dashboard · admin'
|
||||
@noindex = true
|
||||
unpaid = Invoice.where(paid_at: nil).all
|
||||
@inv = {
|
||||
count: Invoice.count,
|
||||
unpaid: unpaid,
|
||||
overdue: unpaid.count { |i| i.due_on < Date.today },
|
||||
unpaid_totals: unpaid.group_by(&:currency).transform_values { |l| l.sum(&:total) },
|
||||
recent: Invoice.order(Sequel.desc(:created_at)).limit(5).all
|
||||
}
|
||||
board = Bingo::Board.load
|
||||
@bingo = {
|
||||
cells: board.cells.size,
|
||||
hit: board.hit.count(true),
|
||||
lines: board.wins.size,
|
||||
reserve: [Bingo::Datacenter.count - board.cells.size, 0].max,
|
||||
last_incident: board.incidents.first,
|
||||
no_photo: board.cells.reject(&:photo_key)
|
||||
}
|
||||
erb :'admin/dashboard'
|
||||
end
|
||||
|
||||
get '/admin/invoices' do
|
||||
|
|
|
|||
|
|
@ -346,6 +346,36 @@ a:hover {
|
|||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
/* Admin nav + dashboard */
|
||||
.admin-nav {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
justify-content: center;
|
||||
margin-bottom: 24px;
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
.admin-nav a { color: var(--text-dim); text-decoration: none; }
|
||||
.admin-nav a.active,
|
||||
.admin-nav a:hover { color: var(--text-bright); }
|
||||
.dash { display: grid; gap: 24px; }
|
||||
.dash-tile h2 a { color: inherit; text-decoration: none; }
|
||||
.stats {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: 12px;
|
||||
margin: 12px 0 16px;
|
||||
}
|
||||
.stats div {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 4px;
|
||||
padding: 12px;
|
||||
text-align: center;
|
||||
}
|
||||
.stats b { display: block; font-size: 1.4rem; color: var(--text-bright); font-variant-numeric: tabular-nums; }
|
||||
.stats span { font-size: 0.75rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.06em; }
|
||||
|
||||
/* Invoices */
|
||||
.invoice-list {
|
||||
width: 100%;
|
||||
|
|
|
|||
|
|
@ -253,6 +253,30 @@ class BingoTest < Minitest::Test
|
|||
assert_equal 401, last_response.status
|
||||
end
|
||||
|
||||
def test_admin_dashboard
|
||||
@app = AsxpioWeb
|
||||
hit!(2)
|
||||
DB.connection[:invoices].delete
|
||||
inv = Invoice.build(client_name: 'ACME', client_email: 'b@example.com', currency: 'EUR', gel_rate: '3.05',
|
||||
due_on: (Date.today - 1).to_s,
|
||||
items: [{ 'description' => 'work', 'qty' => '2', 'unit_price' => '50' }])
|
||||
inv.pdf_key = "invoices/#{inv.number}-#{inv.uuid}.pdf"
|
||||
inv.save_changes
|
||||
get '/admin', {}, admin_env
|
||||
assert last_response.ok?, last_response.status.to_s
|
||||
body = last_response.body
|
||||
assert_includes body, '<h1>Dashboard</h1>'
|
||||
assert_includes body, '1/25' # crossed out
|
||||
assert_includes body, 'Авария 2' # latest incident
|
||||
assert_includes body, 'href="/admin/invoices/new"'
|
||||
assert_includes body, 'class="active">dashboard'
|
||||
assert_includes body, inv.number
|
||||
assert_includes body, 'EUR 100.00' # outstanding total
|
||||
assert_match %r{<b>1</b><span>overdue</span>}, body
|
||||
ensure
|
||||
DB.connection[:invoices].delete
|
||||
end
|
||||
|
||||
def test_admin_records_and_deletes_incident
|
||||
@app = AsxpioWeb
|
||||
get '/admin/bingo', {}, admin_env
|
||||
|
|
|
|||
5
views/admin/_nav.erb
Normal file
5
views/admin/_nav.erb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<nav class="admin-nav">
|
||||
<% [['/admin', 'dashboard'], ['/admin/invoices', 'invoices'], ['/admin/bingo', 'bingo']].each do |href, label| %>
|
||||
<a href="<%= href %>" class="<%= 'active' if href == '/admin' ? request.path == '/admin' : request.path.start_with?(href) %>"><%= label %></a>
|
||||
<% end %>
|
||||
</nav>
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
<%== erb :'admin/_nav', layout: false %>
|
||||
<div class="header">
|
||||
<h1>Bingo</h1>
|
||||
<p class="tagline">
|
||||
<a href="/admin/invoices">invoices</a>
|
||||
<% if bingo_public_url %> · <a href="<%= bingo_public_url %>" target="_blank" rel="noopener">public card ↗</a><% end %>
|
||||
<% if bingo_public_url %><a href="<%= bingo_public_url %>" target="_blank" rel="noopener">public card ↗</a><% end %>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
49
views/admin/dashboard.erb
Normal file
49
views/admin/dashboard.erb
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
<%== erb :'admin/_nav', layout: false %>
|
||||
<div class="header">
|
||||
<h1>Dashboard</h1>
|
||||
</div>
|
||||
|
||||
<div class="dash">
|
||||
<section class="section dash-tile">
|
||||
<h2><a href="/admin/invoices">Invoices</a></h2>
|
||||
<div class="stats">
|
||||
<div><b><%= @inv[:count] %></b><span>total</span></div>
|
||||
<div><b><%= @inv[:unpaid].size %></b><span>unpaid</span></div>
|
||||
<div><b><%= @inv[:overdue] %></b><span>overdue</span></div>
|
||||
</div>
|
||||
<% if @inv[:unpaid_totals].any? %>
|
||||
<p class="optional">Outstanding: <span class="mono"><%= @inv[:unpaid_totals].map { |cur, sum| "#{cur} #{'%.2f' % sum}" }.join(' · ') %></span></p>
|
||||
<% end %>
|
||||
<% if @inv[:recent].any? %>
|
||||
<table class="invoice-list">
|
||||
<tbody>
|
||||
<% @inv[:recent].each do |inv| %>
|
||||
<tr>
|
||||
<td class="mono"><a href="/admin/invoices/<%= inv.uuid %>"><%= inv.number %></a></td>
|
||||
<td><%= inv.client_name %></td>
|
||||
<td class="num mono"><%= inv.currency %> <%= '%.2f' % inv.total %></td>
|
||||
<td><span class="badge badge-<%= inv.status %>"><%= inv.status %></span></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% end %>
|
||||
<p><a href="/admin/invoices/new">+ New invoice</a> · <a href="/admin/invoices">all invoices</a></p>
|
||||
</section>
|
||||
|
||||
<section class="section dash-tile">
|
||||
<h2><a href="/admin/bingo">Bingo</a></h2>
|
||||
<div class="stats">
|
||||
<div><b><%= @bingo[:hit] %>/<%= @bingo[:cells] %></b><span>crossed out</span></div>
|
||||
<div><b><%= @bingo[:lines] %></b><span>lines</span></div>
|
||||
<div><b><%= @bingo[:reserve] %></b><span>in reserve</span></div>
|
||||
</div>
|
||||
<% if (last = @bingo[:last_incident]) %>
|
||||
<p>Latest: <span class="mono"><%= last.occurred_on %></span> <%= Bingo::ICONS[last.kind] %> <%= last.datacenter.name_ru %> — <%= last.title_ru %></p>
|
||||
<% end %>
|
||||
<% if @bingo[:no_photo].any? %>
|
||||
<p class="optional">No photo on the card: <%= @bingo[:no_photo].map(&:name_ru).join(', ') %></p>
|
||||
<% end %>
|
||||
<p><a href="/admin/bingo">manage</a><% if bingo_public_url %> · <a href="<%= bingo_public_url %>" target="_blank" rel="noopener">public card ↗</a><% end %></p>
|
||||
</section>
|
||||
</div>
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
<%== erb :'admin/_nav', layout: false %>
|
||||
<div class="header">
|
||||
<h1>Invoices</h1>
|
||||
<p class="tagline"><a href="/admin/invoices/new">+ New invoice</a> · <a href="/admin/bingo">bingo</a></p>
|
||||
<p class="tagline"><a href="/admin/invoices/new">+ New invoice</a></p>
|
||||
</div>
|
||||
|
||||
<% if @invoices.empty? %>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue