dashboard: numbers that agree, a map on hover, wider cards
"All assets 704" sat beside "all assets in use 737", and both were correct about different populations. The totals summed five specific asset types and subtracted dual-bay secondaries; the status counts took every asset row of any type with no collapse, so USB devices and hidden secondary bays inflated one side of a comparison the layout invites. Status is now counted over exactly the same assets the totals describe. Warranty rows fell back to asset.name when the covered asset had no hostname, and an asset's name is usually the MACHINE's descriptive name - which is how a column meant to identify a PC ended up showing a machine. Hostname, else the asset number, never the name. The machine number loses its label too: the row is hostname, machine, state, and "machine 3015" spends a word on what position already conveys. Printer names now carry the floor-plan preview on hover, the same LocationMapTooltip the printer's own page uses - a location name tells you the room, the map tells you where to walk. Declared as map.maphover on the card, so any card with coordinates gets it; a row without them shows a plain link rather than being dropped. Cards are four across rather than five. At five columns a row holding a hostname, a machine number and a state truncates on exactly the rows that matter. auto-fit, so two cards fill the width instead of leaving empty tracks. Not covered by a test: the count fix. I started one and it was interrupted, and I have not gone back for it - the assertion worth having is that in-use can never exceed the total.
This commit is contained in:
@@ -37,6 +37,32 @@ def _count_by_type(assettype):
|
||||
return query.count()
|
||||
|
||||
|
||||
COUNTEDTYPES = ('machine', 'computer', 'network_device', 'printer',
|
||||
'measuring_tool')
|
||||
|
||||
|
||||
def _countedassets():
|
||||
"""Base query for the assets the dashboard totals describe.
|
||||
|
||||
The status tiles and the type tiles MUST count the same population. They
|
||||
did not: the totals summed five specific types and subtracted dual-bay
|
||||
secondaries, while the status counts took every asset row of any type with
|
||||
no collapse. So "all assets 704" sat beside "in use 737", and both were
|
||||
correct about different things - which makes them worse than either alone.
|
||||
"""
|
||||
from shopdb.core.services.dualpath import (
|
||||
resolve_dualpath_pairs, dualpath_single_machine_enabled)
|
||||
|
||||
query = (db.session.query(Asset).join(AssetType)
|
||||
.filter(Asset.isactive == True,
|
||||
AssetType.assettype.in_(COUNTEDTYPES)))
|
||||
if dualpath_single_machine_enabled():
|
||||
secondaryassetids = resolve_dualpath_pairs().secondaryassetids
|
||||
if secondaryassetids:
|
||||
query = query.filter(Asset.assetid.notin_(secondaryassetids))
|
||||
return query
|
||||
|
||||
|
||||
@dashboard_bp.route('/summary', methods=['GET'])
|
||||
@dashboard_bp.route('', methods=['GET'])
|
||||
@jwt_required(optional=True)
|
||||
@@ -49,15 +75,12 @@ def get_dashboard():
|
||||
measuringtool_count = _count_by_type('measuring_tool')
|
||||
total = machine_count + pc_count + network_count + printer_count + measuringtool_count
|
||||
|
||||
# Count by status
|
||||
status_counts = db.session.query(
|
||||
AssetStatus.status,
|
||||
db.func.count(Asset.assetid)
|
||||
).outerjoin(
|
||||
Asset,
|
||||
db.and_(Asset.statusid == AssetStatus.statusid, Asset.isactive == True)
|
||||
).group_by(AssetStatus.status).all()
|
||||
status_dict = {status: count for status, count in status_counts}
|
||||
# Count by status over the SAME population as the totals above, so the
|
||||
# tiles can be read against each other.
|
||||
status_dict = {}
|
||||
for asset in _countedassets().all():
|
||||
name = asset.status.status if asset.status else 'Unknown'
|
||||
status_dict[name] = status_dict.get(name, 0) + 1
|
||||
|
||||
# Recent assets
|
||||
recent = Asset.query.filter_by(isactive=True).order_by(
|
||||
|
||||
Reference in New Issue
Block a user