mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-23 11:51:05 -05:00
Refactor service name code to reduce duplication
This makes the code shareable between: - the broadcast tour pages - the broadcast settings platform admin page - the regular service navigation On the training mode tour pages we don’t want to confuse people with the organisation name or _Switch service_ links, so those are omitted and the code is therefore slightly different.
This commit is contained in:
@@ -1,3 +1,37 @@
|
||||
{% macro navigation_service_name(service) %}
|
||||
<div class="navigation-service-name govuk-!-font-weight-bold">
|
||||
{{ service.name }}
|
||||
{% if not service.active %}
|
||||
<span class="navigation-service-type navigation-service-type--suspended">Suspended</span>
|
||||
{% elif service.has_permission('broadcast') %}
|
||||
{{ broadcast_service_name_tag(
|
||||
service.trial_mode,
|
||||
service.broadcast_channel,
|
||||
service.allowed_broadcast_provider,
|
||||
) }}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
{% macro broadcast_service_name_tag(trial_mode, broadcast_channel, allowed_broadcast_provider, left_margin=True) %}
|
||||
{% set margin_class = "" if left_margin else "govuk-!-margin-left-0" %}
|
||||
{% if trial_mode %}
|
||||
<span class="navigation-service-type navigation-service-type--training {{margin_class}}">Training
|
||||
{% elif broadcast_channel == 'severe' %}
|
||||
<span class="navigation-service-type navigation-service-type--live {{margin_class}}">Live
|
||||
{% elif broadcast_channel == 'test' %}
|
||||
<span class="navigation-service-type navigation-service-type--live {{margin_class}}">{{ broadcast_channel|title }}
|
||||
{% if allowed_broadcast_provider == "all" %}
|
||||
(all networks)
|
||||
{% else %}
|
||||
({{ allowed_broadcast_provider|format_mobile_network }})
|
||||
{% endif %}
|
||||
{% elif broadcast_channel == 'government' %}
|
||||
<span class="navigation-service-type navigation-service-type--government {{margin_class}}">Government
|
||||
{% endif %}
|
||||
</span>
|
||||
{% endmacro %}
|
||||
|
||||
<div class="navigation-service">
|
||||
{% if current_service.organisation_id %}
|
||||
{% if current_user.platform_admin or
|
||||
@@ -5,27 +39,6 @@
|
||||
<a href="{{ url_for('.organisation_dashboard', org_id=current_service.organisation_id) }}" class="govuk-link govuk-link--no-visited-state navigation-organisation-link">{{ current_service.organisation_name }}</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
<div class="navigation-service-name govuk-!-font-weight-bold">
|
||||
{{ current_service.name }}
|
||||
{% if not current_service.active %}
|
||||
<span class="navigation-service-type navigation-service-type--suspended">Suspended</span>
|
||||
{% elif current_service.has_permission('broadcast') %}
|
||||
{% if current_service.trial_mode %}
|
||||
<span class="navigation-service-type navigation-service-type--training">Training
|
||||
{% elif current_service.broadcast_channel == 'severe' %}
|
||||
<span class="navigation-service-type navigation-service-type--live">Live
|
||||
{% elif current_service.broadcast_channel == 'test' %}
|
||||
<span class="navigation-service-type navigation-service-type--live">{{ current_service.broadcast_channel|title }}
|
||||
{% if current_service.allowed_broadcast_provider == "all" %}
|
||||
(all networks)
|
||||
{% else %}
|
||||
({{ current_service.allowed_broadcast_provider }})
|
||||
{% endif %}
|
||||
{% elif current_service.broadcast_channel == 'government' %}
|
||||
<span class="navigation-service-type navigation-service-type--government">Government
|
||||
{% endif %}
|
||||
</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
{{ navigation_service_name(current_service) }}
|
||||
<a href="{{ url_for('main.choose_account') }}" class="govuk-link govuk-link--no-visited-state navigation-service-switch">Switch service</a>
|
||||
</div>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{% from "components/banner.html" import banner_wrapper %}
|
||||
{% from "service_navigation.html" import navigation_service_name %}
|
||||
|
||||
{% extends "admin_template.html" %}
|
||||
|
||||
@@ -11,9 +12,7 @@
|
||||
{% block content %}
|
||||
|
||||
<div class="navigation-service">
|
||||
<div class="navigation-service-name govuk-!-font-weight-bold">
|
||||
{{ current_service.name }} <span class="navigation-service-type navigation-service-type--training">Training</span>
|
||||
</div>
|
||||
{{ navigation_service_name(current_service) }}
|
||||
</div>
|
||||
|
||||
<div class="banner-tour banner-tour-no-fixed-height banner-tour-with-service-name">
|
||||
|
||||
@@ -10,11 +10,7 @@
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="navigation-service">
|
||||
<div class="navigation-service-name govuk-!-font-weight-bold">
|
||||
{{ current_service.name }} <span class="navigation-service-type navigation-service-type--training">Training</span>
|
||||
</div>
|
||||
</div>
|
||||
{% include "service_navigation.html" %}
|
||||
|
||||
<div class="banner-tour banner-tour-no-fixed-height banner-tour-with-service-name">
|
||||
<div class="govuk-grid-row">
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{% extends "withnav_template.html" %}
|
||||
{% from "service_navigation.html" import broadcast_service_name_tag %}
|
||||
{% from "components/page-header.html" import page_header %}
|
||||
{% from "components/page-footer.html" import page_footer %}
|
||||
{% from "components/form.html" import form_wrapper %}
|
||||
@@ -15,30 +16,19 @@
|
||||
'Confirm emergency alert settings',
|
||||
back_link=url_for('.service_set_broadcast_channel', service_id=current_service.id)
|
||||
) }}
|
||||
<p class="govuk-body">
|
||||
{{ broadcast_service_name_tag(
|
||||
form.account_type.service_mode == 'training',
|
||||
form.account_type.broadcast_channel,
|
||||
form.account_type.provider_restriction,
|
||||
left_margin=False,
|
||||
) }}
|
||||
</p>
|
||||
{% if form.account_type.service_mode == 'training' %}
|
||||
<p class="govuk-body">
|
||||
<span class="navigation-service-type navigation-service-type--training govuk-!-margin-left-0">Training</span>
|
||||
</p>
|
||||
<p class="govuk-body">
|
||||
No phones will receive alerts sent from this service.
|
||||
</p>
|
||||
{% else %}
|
||||
<p class="govuk-body">
|
||||
{% if form.account_type.broadcast_channel == 'severe' %}
|
||||
<span class="navigation-service-type navigation-service-type--live govuk-!-margin-left-0">Live
|
||||
{% elif form.account_type.broadcast_channel == 'government' %}
|
||||
<span class="navigation-service-type navigation-service-type--government govuk-!-margin-left-0">Government
|
||||
{% else %}
|
||||
<span class="navigation-service-type navigation-service-type--live govuk-!-margin-left-0">{{ form.account_type.broadcast_channel|title }}
|
||||
{% endif %}
|
||||
{% if form.account_type.provider_restriction != 'all' %}
|
||||
({{ form.account_type.provider_restriction|format_mobile_network }})
|
||||
{% endif %}
|
||||
{% if form.account_type.broadcast_channel == 'test' and form.account_type.provider_restriction == 'all'%}
|
||||
(all networks)
|
||||
{% endif %}
|
||||
</span>
|
||||
</p>
|
||||
<p class="govuk-body">
|
||||
Members of the public
|
||||
{% if form.account_type.broadcast_channel == 'test' %}
|
||||
|
||||
@@ -284,7 +284,9 @@ def test_broadcast_tour_page_4_shows_service_name(
|
||||
service_id=SERVICE_ONE_ID,
|
||||
step_index=step_index,
|
||||
)
|
||||
assert normalize_spaces(page.select_one('.navigation-service').text) == (
|
||||
assert normalize_spaces(
|
||||
page.select_one('.navigation-service').text
|
||||
).startswith(
|
||||
'service one Training'
|
||||
)
|
||||
|
||||
@@ -301,6 +303,7 @@ def test_live_broadcast_tour_shows_service_name_and_switch(
|
||||
service_one['permissions'] += ['broadcast']
|
||||
service_one['restricted'] = False
|
||||
service_one['allowed_broadcast_provider'] = 'all'
|
||||
service_one['broadcast_channel'] = 'severe'
|
||||
page = client_request.get(
|
||||
'.broadcast_tour_live',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
@@ -351,8 +354,8 @@ def test_live_broadcast_tour_shows_service_name_and_switch(
|
||||
'test',
|
||||
'vodafone',
|
||||
'.navigation-service-type.navigation-service-type--live',
|
||||
'service one Test (vodafone) Switch service',
|
||||
'Test (vodafone)',
|
||||
'service one Test (Vodafone) Switch service',
|
||||
'Test (Vodafone)',
|
||||
),
|
||||
(
|
||||
False,
|
||||
|
||||
Reference in New Issue
Block a user