Skip to content

Commit

Permalink
feat: add link to status page in user icons, with indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
alycejenni committed Jun 21, 2024
1 parent ea1d8f2 commit 444adba
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
24 changes: 24 additions & 0 deletions ckanext/nhm/lib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
17 changes: 17 additions & 0 deletions ckanext/nhm/theme/assets/less/nhm.less
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
16 changes: 16 additions & 0 deletions ckanext/nhm/theme/templates/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,22 @@
</div>
{% endif %}

{# Status page #}
{% set status_indicator = h.get_status_indicator() %}
<div>
<a href="{{ h.url_for('status.index') }}"
title="{{ _('System status') }}">
<span class="sr-only">{{ _('System status') }}</span>
{% if status_indicator %}
<span class="status-indicator status-indicator-{{ status_indicator }}">
<span class="sr-only">{{ _('Status alert') }}</span>
<i class="fas fa-exclamation fa-xs"></i>
</span>
{% endif %}
<i class="fas fa-heartbeat fa-lg"></i>
</a>
</div>

{# Logout #}
{% block header_account_log_out_link %}
<a href="{{ h.url_for('user.logout') }}" title="{{ _('Log out') }}">
Expand Down

0 comments on commit 444adba

Please sign in to comment.