Printer card chips

This commit is contained in:
2026-08-11 15:46:21 -04:00
parent 34cb9a5e3e
commit 793dfab5c8
5 changed files with 119 additions and 16 deletions

View File

@@ -1407,6 +1407,24 @@ def _shortsupplyname(name):
return text or 'supply'
def _reordertip(supply):
"""What to order, for the chip's tooltip.
A percentage says a cartridge is nearly out; the part number says what to
buy, which is the next thing someone needs and today means opening the
printer's page to find it. Every capacity tier is listed, because the
report has always shown all reorder options.
"""
parts = supply.get('partnumbers') or []
if not parts:
return 'No part number on file for this model'
return ', '.join(
'{}{}'.format(part['partnumber'],
' ({})'.format(part['capacitytier'])
if part.get('capacitytier') else '')
for part in parts)
@printers_asset_bp.route('/dashboard/supplies', methods=['GET'])
@jwt_required()
@require_permission('printers.view')
@@ -1429,22 +1447,21 @@ def dashboard_supplies():
lows = [s for s in printer['supplies'] if s['status'] == 'low']
if not criticals and not lows:
continue
# Every depleted supply, criticals first. Listing only the worst class
# would hide a low cartridge behind a critical one on the same printer,
# and whoever walks out there wants to carry both.
worst = criticals + lows
# Criticals first. Every depleted supply is listed, not just the worst
# class - whoever walks out there wants to carry both cartridges.
rows.append({
'printerid': printer['printerid'],
'printername': printer['printername'] or printer['assetnumber'],
'location': printer['location'],
'status': 'critical' if criticals else 'low',
# 'remaining' is the percent left. There is no 'percent' key -
# reading one rendered every cartridge as "None%" on the board.
'supplies': ', '.join(
'{} {}%'.format(_shortsupplyname(s.get('name')),
s.get('remaining'))
for s in worst),
'location': printer['location'] or 'No location set',
'iscritical': bool(criticals),
# One chip per depleted supply: what is low, and on hover what to
# order to fix it.
'supplies': [{
'text': '{} {}%'.format(_shortsupplyname(supply.get('name')),
supply.get('remaining')),
'title': _reordertip(supply),
'level': supply.get('status'),
} for supply in criticals + lows],
})
rows.sort(key=lambda r: (not r['iscritical'], r['printername']))

View File

@@ -306,8 +306,11 @@ class PrintersPlugin(BasePlugin):
'position': 40,
'map': {
'title': 'printername',
'detail': 'supplies',
'meta': [{'key': 'location'}, {'key': 'status'}],
# Location on hover rather than on the line: it is context
# for "where do I walk", not part of the finding, and it
# was the text pushing rows past the card edge.
'titletooltip': 'location',
'chips': 'supplies',
'link': '/printers/{printerid}',
},
},