Dashboard cards: rebuild deployable dists
This commit is contained in:
@@ -871,3 +871,36 @@ def get_shopfloor_notifications():
|
||||
'upcoming': upcoming_data,
|
||||
'configversion': _config_version(),
|
||||
})
|
||||
|
||||
|
||||
@notifications_bp.route('/dashboard/active', methods=['GET'])
|
||||
@jwt_required()
|
||||
def dashboard_active():
|
||||
"""Notifications currently showing on the floor.
|
||||
|
||||
The items, not a count. "4 active notifications" tells an admin nothing;
|
||||
knowing WHICH message the shop is looking at right now is the point,
|
||||
particularly when one is stale and nobody has taken it down.
|
||||
|
||||
A null start or end means open-ended, matching how the boards read them.
|
||||
"""
|
||||
now = datetime.now(timezone.utc).replace(tzinfo=None)
|
||||
|
||||
rows = (Notification.query
|
||||
.filter(db.or_(Notification.starttime.is_(None),
|
||||
Notification.starttime <= now),
|
||||
db.or_(Notification.endtime.is_(None),
|
||||
Notification.endtime >= now))
|
||||
.order_by(Notification.starttime.desc())
|
||||
.limit(25).all())
|
||||
|
||||
out = []
|
||||
for row in rows:
|
||||
notificationtype = getattr(row, 'notificationtype', None)
|
||||
out.append({
|
||||
'notificationid': row.notificationid,
|
||||
'message': (row.notification or '').strip()[:120],
|
||||
'typename': notificationtype.typename if notificationtype else None,
|
||||
'endtime': row.endtime.isoformat() + 'Z' if row.endtime else None,
|
||||
})
|
||||
return success_response(out)
|
||||
|
||||
@@ -193,14 +193,30 @@ class NotificationsPlugin(BasePlugin):
|
||||
return [notifications_cli]
|
||||
|
||||
def get_dashboard_widgets(self) -> List[Dict]:
|
||||
"""Return dashboard widget definitions."""
|
||||
"""Dashboard card: what the floor is being shown right now.
|
||||
|
||||
The items, not a count. "4 active notifications" tells an admin
|
||||
nothing; knowing WHICH message is on the boards is the point, and it is
|
||||
how a stale one gets noticed and taken down.
|
||||
|
||||
Replaces a declaration naming a component nobody wrote.
|
||||
"""
|
||||
return [
|
||||
{
|
||||
'name': 'Active Notifications',
|
||||
'component': 'NotificationsWidget',
|
||||
'endpoint': '/api/notifications/dashboard/summary',
|
||||
'size': 'small',
|
||||
'position': 1,
|
||||
'id': 'notifications-active',
|
||||
'title': 'Active notifications',
|
||||
'endpoint': '/api/notifications/dashboard/active',
|
||||
'render': 'list',
|
||||
'severity': 'info',
|
||||
'empty': 'hide',
|
||||
'position': 60,
|
||||
'map': {
|
||||
'title': 'typename',
|
||||
'detail': 'message',
|
||||
'meta': [{'key': 'endtime', 'label': 'until',
|
||||
'format': 'date'}],
|
||||
'link': '/notifications/{notificationid}',
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user