From 444adba8b38bcadbb720e934c540e87b165a2ca4 Mon Sep 17 00:00:00 2001 From: Alice Butcher Date: Fri, 21 Jun 2024 17:16:55 +0100 Subject: [PATCH] feat: add link to status page in user icons, with indicator --- ckanext/nhm/lib/helpers.py | 24 ++++++++++++++++++++++++ ckanext/nhm/theme/assets/less/nhm.less | 17 +++++++++++++++++ ckanext/nhm/theme/templates/header.html | 16 ++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/ckanext/nhm/lib/helpers.py b/ckanext/nhm/lib/helpers.py index 0188c10f..0bc2baa7 100644 --- a/ckanext/nhm/lib/helpers.py +++ b/ckanext/nhm/lib/helpers.py @@ -1599,3 +1599,27 @@ def get_record_iiif_manifest_url(resource_id: str, record_id: int) -> str: {'builder_id': 'record', 'resource_id': resource_id, 'record_id': record_id}, ) return toolkit.url_for('iiif.resource', identifier=manifest_id, _external=True) + + +def get_status_indicator(): + """ + Check if we need to display a status indicator, and if so what type. + + :return: 'red', 'amber', or None (if no alerts) + """ + # is there a status message? + status_message = toolkit.config.get('ckanext.status.message', None) + if status_message: + return 'red' + + status_reports = toolkit.get_action('status_list')({}, {}) + + # are there any 'bad' items? + red_status = [r for r in status_reports if r['state'] == 'bad'] + if len(red_status) > 0: + return 'red' + + # are there any reports with small issues? + amber_status = [r for r in status_reports if r['state'] == 'ok'] + if len(amber_status) > 0: + return 'amber' diff --git a/ckanext/nhm/theme/assets/less/nhm.less b/ckanext/nhm/theme/assets/less/nhm.less index ef4c14eb..9cc1682a 100644 --- a/ckanext/nhm/theme/assets/less/nhm.less +++ b/ckanext/nhm/theme/assets/less/nhm.less @@ -236,6 +236,23 @@ body { & .notifications { padding-right: 10px; } + + & .status-indicator { + font-size: @font-size-body-s; + position: absolute; + top: 0; + margin-left: 1.3em; + padding: 0 2px; + border-radius: @rounding; + + &.status-indicator-red { + background: @warning2; + } + + &.status-indicator-amber { + background: orange; + } + } } .icon-pad() { diff --git a/ckanext/nhm/theme/templates/header.html b/ckanext/nhm/theme/templates/header.html index 29853d0b..d0ab1079 100755 --- a/ckanext/nhm/theme/templates/header.html +++ b/ckanext/nhm/theme/templates/header.html @@ -71,6 +71,22 @@ {% endif %} + {# Status page #} + {% set status_indicator = h.get_status_indicator() %} +
+ + {{ _('System status') }} + {% if status_indicator %} + + {{ _('Status alert') }} + + + {% endif %} + + +
+ {# Logout #} {% block header_account_log_out_link %}