dashboard: overflow links somewhere, tiles say what they count, rows stay inside
Some checks failed
CI / backend (push) Failing after 8s
CI / naming (push) Successful in 2s
CI / frontend (push) Successful in 9s
CI / migrations-mysql (push) Failing after 7s

Four fixes, all from looking at the real board.

"and N more" now links to a page showing them all. Telling someone 35 more PCs
are silent and leaving them to find the list is worse than not saying it. Each
card names its own destination and a test checks it against the routes that
actually exist - a viewall pointing at a route nobody wrote is the same rot the
endpoint check already guards, just failing in the browser instead of the API.

PRINTER ROWS ESCAPED THE CARD. A flex child will not shrink below its content
width unless told to, so text-overflow never engaged and a row carrying three
cartridge readings plus a location simply ran past the border. min-width:0 on
the row parts is what enables the ellipsis; meta shrinks first because it
matters least, and the card clips as a backstop.

THE STAT TILES WERE INCOHERENT. Two counted asset TYPES, two counted asset
STATUSES, and nothing said which - with the status one labelled "Active", which
reads as "not deleted" but meant status = In Use across every type. Each tile
now counts one thing and its label says so.

PCs GONE SILENT IS NARROWER, and better for it. A PC that never reported at all
is usually a hand-made or imported record rather than a bay that broke, and a
PC that is not In Use is silent ON PURPOSE - that is the status doing its job.
Both were burying the real signal: a machine that was working, is not now, and
nobody has marked as anything else.
This commit is contained in:
cproudlock
2026-08-11 15:28:29 -04:00
parent 294ddbb38e
commit c34815b87e
11 changed files with 150 additions and 76 deletions

View File

@@ -63,3 +63,21 @@ def test_every_card_links_somewhere(app):
if card['render'] == 'metric':
continue
assert (card.get('map') or {}).get('link'), card
def test_a_viewall_target_is_one_of_the_known_pages(app):
"""A card's overflow line links here. Pointing it at a route nobody wrote is
the same rot the endpoint check exists to stop - it just fails in the
browser instead of the API."""
known = {
'/pcs', '/machines', '/printers', '/network', '/notifications',
'/geenforce', '/reports/toner', '/reports/warranty',
'/reports/pc-relationships', '/reports/calibration', '/reports',
}
with app.app_context():
for pluginname, card in _declared(app):
target = card.get('viewall')
if target is None:
continue
assert target in known, '{}: {} is not a known page'.format(
pluginname, target)

View File

@@ -1,15 +1,14 @@
"""Dashboard card: PCs that stopped reporting, and PCs that never started.
"""Dashboard card: PCs that were reporting and have stopped.
Two populations, deliberately not merged. A PC that reported and went quiet is
probably off, moved or broken. A PC that has NEVER reported is worse - not
enrolled, or enrolled against the wrong pc-type, so nothing enforces anything on
it and no backup of it exists. That one hides indefinitely because nothing about
it fails loudly.
Deliberately narrow. A PC that never reported at all is usually a record made by
hand or imported, not a bay that broke, and a PC that is not In Use is silent on
purpose - that is the status doing its job. Both would bury the real signal: a
machine that was working, is not now, and nobody has marked as anything else.
"""
from datetime import datetime, timedelta, timezone
from shopdb.core.models import Asset, AssetType, Setting
from shopdb.core.models import Asset, AssetStatus, AssetType, Setting
URL = '/api/computers/dashboard/quiet'
@@ -18,6 +17,16 @@ def _now():
return datetime.now(timezone.utc).replace(tzinfo=None)
def _inuse(db):
"""The card joins on the status NAME, so a bare statusid will not do."""
status = AssetStatus.query.filter_by(status='In Use').first()
if not status:
status = AssetStatus(status='In Use', isactive=True)
db.session.add(status)
db.session.flush()
return status
def _pc(db, hostname, lastreported='now', isactive=True):
from plugins.computers.models import Computer
@@ -27,7 +36,7 @@ def _pc(db, hostname, lastreported='now', isactive=True):
db.session.add(atype)
db.session.flush()
asset = Asset(assetnumber=hostname, assettypeid=atype.assettypeid,
statusid=1, isactive=isactive)
statusid=_inuse(db).statusid, isactive=isactive)
db.session.add(asset)
db.session.flush()
comp = Computer(assetid=asset.assetid, hostname=hostname)
@@ -51,26 +60,29 @@ def test_a_pc_gone_quiet_is_listed_with_how_long(client, db, auth_headers):
_pc(db, 'QUIETPC', lastreported=72)
[row] = client.get(URL, headers=auth_headers).get_json()['data']
assert row['hostname'] == 'QUIETPC'
assert row['state'] == 'stopped reporting'
assert row['quietdays'] == 3
def test_a_pc_that_never_reported_is_called_out_separately(client, db,
auth_headers):
"""Never-reported is a different fault from gone-quiet: nothing is
enforcing anything on that PC and no backup of it exists."""
def test_a_pc_that_never_reported_is_not_listed(client, db, auth_headers):
"""Usually a hand-made or imported record rather than a bay that broke.
Listing them buries the PCs that actually changed state."""
_pc(db, 'NEVERPC', lastreported=None)
[row] = client.get(URL, headers=auth_headers).get_json()['data']
assert row['state'] == 'never reported'
assert row['lastreported'] is None
assert client.get(URL, headers=auth_headers).get_json()['data'] == []
def test_never_reported_sorts_above_the_merely_quiet(client, db, auth_headers):
"""The order someone should work down the list."""
_pc(db, 'QUIETPC', lastreported=48)
_pc(db, 'NEVERPC', lastreported=None)
rows = client.get(URL, headers=auth_headers).get_json()['data']
assert [r['hostname'] for r in rows] == ['NEVERPC', 'QUIETPC']
def test_a_pc_not_in_use_is_not_listed(client, db, auth_headers):
"""A PC in Repair or Retired is silent on purpose - that is the status
doing its job, not a fault to chase."""
from shopdb.core.models import AssetStatus
repair = AssetStatus.query.filter_by(status='In Repair').first()
if not repair:
repair = AssetStatus(status='In Repair', isactive=True)
db.session.add(repair)
db.session.flush()
comp = _pc(db, 'SHELVED', lastreported=200)
comp.asset.statusid = repair.statusid
db.session.commit()
assert client.get(URL, headers=auth_headers).get_json()['data'] == []
def test_the_longest_silence_comes_first(client, db, auth_headers):