Refactor export link functionality in templates to streamline CSV export and enhance title generation for inventory and worklogs

This commit is contained in:
Yaro Kasear 2025-07-17 13:13:11 -05:00
parent 7b908d7fa3
commit 912d3fe775
2 changed files with 22 additions and 10 deletions

View file

@ -41,12 +41,6 @@
{% macro export_link(id, endpoint, ids) %}
<!-- Export Link Fragment -->
<a class="link-success link-underline-opacity-0" onclick="export_{{ id }}_csv()">{{ icons.render_icon('box-arrow-up', 12) }}</a>
<script>
function export_{{ id }}_csv() {
const payload = {{ ids }};
export_csv(payload, '{{ endpoint }}', '{{ id }}_export');
}
</script>
<a class="link-success link-underline-opacity-0" onclick="export_csv({{ ids }}, '{{ endpoint }}', '{{ id }}_export');">{{ icons.render_icon('box-arrow-up', 12) }}</a>
{% endmacro %}

View file

@ -125,15 +125,33 @@
<div class="row mt-3">
{% if inventory_rows %}
<div class="col">
{% set id_list = inventory_rows | map(attribute='id') | list %}
{% set inventory_title %}
Assets
{{ links.export_link(
(user.full_name | lower | replace(' ', '_')) + '_user_inventory',
'inventory',
{'ids': id_list}
) }}
{% endset %}
<div class="row">
{{ tables.render_table(headers=inventory_headers, rows=inventory_rows, id='assets', entry_route='inventory_item', title='Assets', per_page=8) }}
{{ tables.render_table(headers=inventory_headers, rows=inventory_rows, id='assets', entry_route='inventory_item', title=inventory_title, per_page=8) }}
</div>
</div>
{% endif %}
{% if worklog_rows %}
{% set id_list = worklog_rows | map(attribute='id') | list %}
{% set worklog_title %}
Work Done
{{ links.export_link(
(user.full_name | lower | replace(' ', '_')) + '_user_worklog',
'worklog',
{'ids': id_list}
) }}
{% endset %}
<div class="col">
<div class="row">
{{ tables.render_table(headers=worklog_headers, rows=worklog_rows, id='worklog', entry_route='worklog_entry', title='Work Done', per_page=8) }}
{{ tables.render_table(headers=worklog_headers, rows=worklog_rows, id='worklog', entry_route='worklog_entry', title=worklog_title, per_page=8) }}
</div>
</div>
{% endif %}