Files
notifications-admin/app/templates/components/table.html
T

238 lines
7.6 KiB
HTML
Raw Normal View History

2023-12-29 15:47:10 -08:00
{% macro mapping_table(caption='', field_headings=[], field_headings_visible=True, caption_visible=True, equal_length=False, border_visible=False) -%}
<table class="usa-table{{' usa-table--borderless' if not border_visible}} width-full">
<caption class="font-body-lg table-heading{{ ' usa-sr-only' if not caption_visible}}">
2015-12-10 17:54:05 +00:00
{{ caption }}
</caption>
<thead class="table-field-headings{% if field_headings_visible %}-visible{% endif %}">
<tr>
{% for field_heading in field_headings %}
2024-07-11 12:59:14 -04:00
<th class="table-field-heading{% if loop.first %}-first{% endif %}" width="{% if equal_length %}{{ (100 / field_headings|length)|int }}%{% endif %}">
2015-12-10 17:54:05 +00:00
{% if field_headings_visible %}
{{ field_heading }}
{% else %}
<span>{{ field_heading }}</span>
2015-12-10 17:54:05 +00:00
{% endif %}
</th>
{% endfor %}
</tr>
</thead>
2024-01-08 16:04:23 -08:00
<tbody>
2016-01-07 12:29:56 +00:00
{{ caller() }}
2015-12-10 17:54:05 +00:00
</tbody>
</table>
{%- endmacro %}
2023-12-29 15:47:10 -08:00
{% macro list_table(items, caption='', empty_message='', field_headings=[], field_headings_visible=True, caption_visible=True, equal_length=False, border_visible=False) -%}
{% set parent_caller = caller %}
2016-02-03 14:43:16 +00:00
2023-12-29 15:47:10 -08:00
{% call mapping_table(caption, field_headings, field_headings_visible, caption_visible, equal_length, border_visible) %}
2016-02-03 14:43:16 +00:00
{% for item in items %}
{% call row(item.id) %}
2016-04-05 11:16:29 +01:00
{{ parent_caller(item, loop.index + 1) }}
2016-02-03 14:43:16 +00:00
{% endcall %}
{% endfor %}
{% if not items %}
{% call row() %}
<td class="table-empty-message" colspan="10">
{{ empty_message }}
</td>
{% endcall %}
{% endif %}
{%- endcall %}
2016-01-07 12:29:56 +00:00
{%- endmacro %}
{% macro row(id=None) -%}
<tr class="table-row" {% if id and id is string %}id="{{id}}"{% endif %}>
2016-01-07 12:29:56 +00:00
{{ caller() }}
</tr>
{%- endmacro %}
{% macro row_group(id=None) %}
<tbody class="table-row-group" {% if id %}id="{{id}}"{% endif %}>
{{ caller() }}
</tbody>
{%- endmacro %}
{% macro settings_row(if_has_permission='') -%}
{% set parent_caller = caller %}
{% if if_has_permission in current_service.permissions %}
{% call row() %}
{{ parent_caller() }}
{% endcall %}
{% endif %}
{%- endmacro %}
2021-01-13 18:48:20 +00:00
{% macro field(align='left', status='', border=True, colspan=None, wrap=False) -%}
{% set field_alignment =
'table-field-right-aligned' if align == 'right' else
'table-field-center-aligned' if align == 'center' else
'table-field-left-aligned'
%}
{% set border = '' if border else 'table-field-noborder' %}
2021-01-13 18:48:20 +00:00
{% set wrap = 'table-field-wrap-text' if wrap else '' %}
2021-01-13 18:48:20 +00:00
<td class="{{ [field_alignment, border, wrap]|join(' ') }}" {% if colspan %}colspan="{{ colspan }}"{% endif %}>
2017-02-14 15:09:54 +00:00
<div class="{{ 'table-field-status-' + status if status }}">{{ caller() }}</div>
</td>
2015-12-10 17:54:05 +00:00
{%- endmacro %}
2015-12-17 11:14:19 +00:00
2016-06-08 13:41:02 +01:00
{% macro row_heading() -%}
2024-07-11 12:59:14 -04:00
<td>
2017-02-14 15:09:54 +00:00
{{ caller() }}
2024-07-11 12:59:14 -04:00
</td>
2016-06-08 13:41:02 +01:00
{%- endmacro %}
2020-04-11 11:42:13 +01:00
{% macro index_field(text=None, rowspan=None) -%}
<td class="table-field-index" {% if rowspan %}rowspan="{{ rowspan }}"{% endif %}>
2017-05-23 14:21:59 +01:00
{{ text if text != None else caller() }}
2016-04-05 11:16:29 +01:00
</td>
{%- endmacro %}
2021-01-13 18:48:20 +00:00
{% macro text_field(text, status='', truncate=false, wrap=False) -%}
{% call field(status=status, wrap=wrap) %}
2017-03-24 11:51:47 +00:00
{% if text is iterable and text is not string %}
2019-04-23 11:26:36 +01:00
<ul>
2017-03-24 11:51:47 +00:00
{% for item in text %}
2018-03-09 15:07:47 +00:00
{% if item %}
<li>{{ item }}</li>
{% endif %}
2017-03-24 11:51:47 +00:00
{% endfor %}
</ul>
{% else %}
2018-06-07 10:55:48 +01:00
{% if truncate %}
<div class="truncate-text" title="{{ text }}">{{text}}</div>
{% else %}
{{ text }}
{% endif %}
2017-03-24 11:51:47 +00:00
{% endif %}
2016-02-19 15:02:13 +00:00
{% endcall %}
{%- endmacro %}
2021-01-13 18:48:20 +00:00
{% macro optional_text_field(text, default='Not set', truncate=false, wrap=False) -%}
2017-10-05 11:21:00 +01:00
{{ text_field(
text or default,
2018-06-07 10:55:48 +01:00
status='' if text else 'default',
2021-01-13 18:48:20 +00:00
truncate=truncate,
wrap=wrap
2017-10-05 11:21:00 +01:00
) }}
{%- endmacro %}
2016-04-12 15:05:27 +01:00
{% macro link_field(text, link) -%}
{% call field() %}
2023-06-15 10:17:07 -04:00
<a class="usa-link" href="{{ link }}">{{ text }}</a>
2016-04-12 15:05:27 +01:00
{% endcall %}
{%- endmacro %}
2020-08-25 20:01:31 +01:00
{% macro edit_field(text, link, permissions=[], suffix=None) -%}
2016-08-22 13:49:41 +01:00
{% call field(align='right') %}
{% if not permissions or current_user.has_permissions(*permissions) %}
2023-06-15 10:17:07 -04:00
<a class="usa-link" href="{{ link }}">
2020-08-25 20:01:31 +01:00
{{ text }}
2023-06-15 10:17:07 -04:00
{%- if suffix %}<span class="usa-sr-only"> {{ suffix }}</span>{% endif -%}
2020-08-25 20:01:31 +01:00
</a>
{% endif %}
2016-08-22 13:49:41 +01:00
{% endcall %}
{%- endmacro %}
2017-06-07 14:54:23 +01:00
{% macro boolean_field(value) -%}
{{ text_field('On' if value else 'Off') }}
2016-02-19 15:02:13 +00:00
{%- endmacro %}
2015-12-17 11:14:19 +00:00
{% macro right_aligned_field_heading(text) %}
<span class="table-field-heading-right-aligned">{{ text }}</span>
{%- endmacro %}
2016-01-19 09:55:13 +00:00
{% macro hidden_field_heading(text) %}
2023-06-16 14:55:24 -04:00
<span class="usa-sr-only">{{ text }}</span>
2016-01-19 09:55:13 +00:00
{%- endmacro %}
{% macro notification_status_field(notification) %}
{% set displayed_on_single_line = notification.status in ['created', 'pending', 'sending', 'delivered', 'accepted', 'received'] %}
2017-07-13 07:10:45 +01:00
{% if not notification %}
{% call field(align='right') %}{% endcall %}
{% else %}
{% set status = notification.status|format_notification_status_as_field_status(notification.notification_type) %}
{% call field(
status=status,
align='right'
) %}
{% if displayed_on_single_line %}<span class="align-with-message-body">{% endif %}
{% if notification.status|format_notification_status_as_url(notification.notification_type) %}
2023-06-15 10:17:07 -04:00
<a class="usa-link" href="{{ notification.status|format_notification_status_as_url(notification.notification_type) }}">
2017-07-13 07:10:45 +01:00
{% endif %}
{{ notification.status|format_notification_status(notification.template.template_type) }}
{% if notification.status|format_notification_status_as_url(notification.notification_type) %}
2017-07-13 07:10:45 +01:00
</a>
{% endif %}
<p class="status-hint margin-0 width-card ">
2022-12-05 15:33:44 -05:00
{{ notification.status|format_notification_status_as_time(
2024-03-18 15:10:26 -07:00
notification.created_at|format_datetime_table,
(notification.sent_at or notification.created_at)|format_datetime_table
2022-12-05 15:33:44 -05:00
) }}
</p>
{% if displayed_on_single_line %}</span>{% endif %}
2017-07-13 07:10:45 +01:00
{% endcall %}
{% endif %}
{% endmacro %}
2017-02-16 15:08:16 +00:00
{% macro notification_carrier_field(notification) %}
<!-- {% set displayed_on_single_line = notification.status in ['created', 'pending', 'sending', 'delivered', 'accepted', 'received'] %} -->
{% if not notification %}
{% call field(align='right') %}{% endcall %}
{% else %}
<!-- {% set status = notification.status|format_notification_status_as_field_status(notification.notification_type) %} -->
{% call field(
align='right'
) %}
<p class="status-hint margin-0 width-card">
{{ notification.carrier}}
</p>
{% if displayed_on_single_line %}</span>{% endif %}
{% endcall %}
{% endif %}
{% endmacro %}
{% macro notification_carrier_message_field(notification) %}
{% if not notification %}
{% call field(align='right') %}{% endcall %}
{% else %}
<!-- {% set status = notification.status|format_notification_status_as_field_status(notification.notification_type) %} -->
{% call field(
status=status,
align='right'
) %}
<p class="status-hint margin-0 width-card">
{{notification.provider_response}}
</p>
{% if displayed_on_single_line %}</span>{% endif %}
{% endcall %}
{% endif %}
{% endmacro %}
2017-02-16 15:08:16 +00:00
{% macro spark_bar_field(
count,
2017-03-20 12:00:22 +00:00
max_count,
id=None
2017-02-16 15:08:16 +00:00
) %}
{% call field(align='right') %}
2017-03-20 12:00:22 +00:00
<span {% if id %}id="{{ id }}"{% endif %} class="spark-bar">
2023-03-07 17:15:31 -05:00
<span class="spark-bar-bar">
{{ '{:,.0f}'.format(count) }}
<!-- {% if count == 1 -%}
message sent
{% else -%}
messages sent
{% endif %} -->
2017-02-16 15:08:16 +00:00
</span>
</span>
{% endcall %}
{% endmacro %}