mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-07 20:28:25 -04:00
Refactor choose service page into macros
This makes it easier to see the logic controlling which services are shown where because the repetitive loops have been factored out.
This commit is contained in:
@@ -1,5 +1,29 @@
|
|||||||
{% extends "withoutnav_template.html" %}
|
{% extends "withoutnav_template.html" %}
|
||||||
|
|
||||||
|
{% macro service_list(heading, show_heading, organisations=[], services=[]) %}
|
||||||
|
{% if show_heading %}
|
||||||
|
<h2 class="heading-small">
|
||||||
|
{{ heading }}
|
||||||
|
</h2>
|
||||||
|
{% endif %}
|
||||||
|
<ul>
|
||||||
|
{% for org in organisations %}
|
||||||
|
<li class="browse-list-item">
|
||||||
|
<a href="{{ url_for('.organisation_dashboard', org_id=org.id) }}" class="browse-list-link">{{ org.name }}</a>
|
||||||
|
<p class="browse-list-hint">
|
||||||
|
{{ org.live_services|length }}
|
||||||
|
live service{% if org.live_services|length != 1 %}s{% endif %}
|
||||||
|
</p>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
{% for service in services %}
|
||||||
|
<li class="browse-list-item">
|
||||||
|
<a href="{{ url_for('.service_dashboard', service_id=service.id) }}" class="browse-list-link">{{ service.name }}</a>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% endmacro %}
|
||||||
|
|
||||||
{% block per_page_title %}
|
{% block per_page_title %}
|
||||||
Choose service
|
Choose service
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -10,58 +34,40 @@
|
|||||||
Choose service
|
Choose service
|
||||||
</h1>
|
</h1>
|
||||||
<nav class="browse-list">
|
<nav class="browse-list">
|
||||||
<ul>
|
|
||||||
{% if current_user.platform_admin %}
|
{% if current_user.platform_admin %}
|
||||||
|
<h2>Platform admin</h2>
|
||||||
|
<ul>
|
||||||
<li class="browse-list-item">
|
<li class="browse-list-item">
|
||||||
<a href="{{ url_for('.organisations') }}" class="browse-list-link">All organisations</a>
|
<a href="{{ url_for('.organisations') }}" class="browse-list-link">All organisations</a>
|
||||||
</li>
|
</li>
|
||||||
<div class ="keyline-block"></div>
|
<ul>
|
||||||
{% endif %}
|
<div class ="keyline-block"></div>
|
||||||
{% if current_user.organisations %}
|
{% endif %}
|
||||||
{% for org in current_user.organisations %}
|
|
||||||
<li class="browse-list-item">
|
{% if current_user.organisations %}
|
||||||
<a href="{{ url_for('.organisation_dashboard', org_id=org.id) }}" class="browse-list-link">{{ org.name }}</a>
|
{{ service_list(
|
||||||
<p class="browse-list-hint">
|
heading='Live services',
|
||||||
{{ org.live_services|length }}
|
show_heading=current_user.trial_mode_services,
|
||||||
live service{% if org.live_services|length != 1 %}s{% endif %}
|
organisations=current_user.organisations,
|
||||||
</p>
|
services=current_user.live_services_not_belonging_to_users_organisations
|
||||||
</li>
|
) }}
|
||||||
<div class ="keyline-block"></div>
|
{% else %}
|
||||||
{% endfor %}
|
{{ service_list(
|
||||||
{% for item in current_user.live_services_not_belonging_to_users_organisations %}
|
heading='Live services',
|
||||||
<li class="browse-list-item">
|
show_heading=(current_user.trial_mode_services and current_user.live_services),
|
||||||
<a href="{{ url_for('.service_dashboard', service_id=item.id) }}" class="browse-list-link">{{ item.name }}</a>
|
services=current_user.live_services
|
||||||
</li>
|
) }}
|
||||||
{% endfor %}
|
{% endif %}
|
||||||
{% else %}
|
|
||||||
{% if current_user.trial_mode_services and current_user.live_services %}
|
{% if current_user.trial_mode_services %}
|
||||||
</ul>
|
{{ service_list(
|
||||||
<h2 class="heading-small">
|
heading='Trial mode services',
|
||||||
Live services
|
show_heading=(current_user.organisations or current_user.live_services),
|
||||||
</h2>
|
services=current_user.trial_mode_services
|
||||||
<ul>
|
) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% for service in current_user.live_services %}
|
|
||||||
<li class="browse-list-item">
|
|
||||||
<a href="{{ url_for('.service_dashboard', service_id=service.id) }}" class="browse-list-link">{{ service.name }}</a>
|
|
||||||
</li>
|
|
||||||
{% endfor %}
|
|
||||||
{% endif %}
|
|
||||||
{% if current_user.trial_mode_services %}
|
|
||||||
{% if organisations or current_user.live_services %}
|
|
||||||
</ul>
|
|
||||||
<h2 class="heading-small">
|
|
||||||
Trial mode services
|
|
||||||
</h2>
|
|
||||||
<ul>
|
|
||||||
{% endif %}
|
|
||||||
{% for service in current_user.trial_mode_services %}
|
|
||||||
<li class="browse-list-item">
|
|
||||||
<a href="{{ url_for('.service_dashboard', service_id=service.id) }}" class="browse-list-link">{{ service.name }}</a>
|
|
||||||
</li>
|
|
||||||
{% endfor %}
|
|
||||||
{% endif %}
|
|
||||||
</ul>
|
|
||||||
</nav>
|
</nav>
|
||||||
{% if can_add_service %}
|
{% if can_add_service %}
|
||||||
<div class="js-stick-at-bottom-when-scrolling">
|
<div class="js-stick-at-bottom-when-scrolling">
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ def test_choose_account_should_show_choose_accounts_page(
|
|||||||
assert outer_list_items[4].a.text == 'service_2'
|
assert outer_list_items[4].a.text == 'service_2'
|
||||||
assert outer_list_items[4].a['href'] == url_for('.service_dashboard', service_id='s2')
|
assert outer_list_items[4].a['href'] == url_for('.service_dashboard', service_id='s2')
|
||||||
|
|
||||||
# orphaned live services
|
# orphaned trial services
|
||||||
trial_services_list_items = page.select('nav ul')[1].select('li')
|
trial_services_list_items = page.select('nav ul')[1].select('li')
|
||||||
assert len(trial_services_list_items) == 2
|
assert len(trial_services_list_items) == 2
|
||||||
assert trial_services_list_items[0].a.text == 'org_service_3'
|
assert trial_services_list_items[0].a.text == 'org_service_3'
|
||||||
|
|||||||
Reference in New Issue
Block a user