Enhance CSV export functionality by allowing custom filenames and adding export links for active worklogs

This commit is contained in:
Yaro Kasear 2025-07-17 09:12:35 -05:00
parent a050ff7c1e
commit 4061065430
3 changed files with 29 additions and 7 deletions

View file

@ -1,4 +1,4 @@
async function export_csv(ids, csv_route) { async function export_csv(ids, csv_route, filename=`${csv_route}_export.csv`) {
const payload = ids; const payload = ids;
try { try {
@ -20,7 +20,7 @@ async function export_csv(ids, csv_route) {
const link = document.createElement("a"); const link = document.createElement("a");
link.href = url; link.href = url;
link.download = `${csv_route}_export.csv`; link.download = `${filename}.csv`;
link.click(); link.click();
console.log(url); console.log(url);

View file

@ -7,7 +7,7 @@
<a href="{{ url_for('main.' + endpoint, **arguments) }}" <a href="{{ url_for('main.' + endpoint, **arguments) }}"
class="d-flex flex-column justify-content-center link-success link-underline-opacity-0"> class="d-flex flex-column justify-content-center link-success link-underline-opacity-0">
{% if icon_html %} {% if icon_html %}
{{ icon_html | safe }} {{ icon_html | safe }}
{% endif %} {% endif %}
{{ label }} {{ label }}
</a> </a>
@ -18,13 +18,13 @@
<!-- Navigation Link Fragment --> <!-- Navigation Link Fragment -->
{% if not active %} {% if not active %}
{% set active = request.endpoint == 'main.' + endpoint %} {% set active = request.endpoint == 'main.' + endpoint %}
{% endif %} {% endif %}
<li class="nav-item"> <li class="nav-item">
<a href="{{ url_for('main.' + endpoint, **arguments) }}" class="nav-link{% if active %} active{% endif %}"> <a href="{{ url_for('main.' + endpoint, **arguments) }}" class="nav-link{% if active %} active{% endif %}">
{% if icon_html %} {% if icon_html %}
{{ icon_html | safe }} {{ icon_html | safe }}
{% endif %} {% endif %}
{{ label }} {{ label }}
</a> </a>
@ -34,7 +34,19 @@
{% macro entry_link(endpoint, id) %} {% macro entry_link(endpoint, id) %}
<!-- Entry Link Fragment --> <!-- Entry Link Fragment -->
<a href="{{ url_for('main.' + endpoint, id=id) }}" class="link-success link-underline-opacity-0"> <a href="{{ url_for('main.' + endpoint, id=id) }}" class="link-success link-underline-opacity-0">
{{ icons.render_icon('link', 12) }} {{ icons.render_icon('link', 12) }}
</a> </a>
{% endmacro %} {% endmacro %}
{% 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>
{% endmacro %}

View file

@ -13,7 +13,17 @@
<div class="card"> <div class="card">
<div class="card-body"> <div class="card-body">
<h5 class="card-title">Active Worklogs</h5> <h5 class="card-title">Active Worklogs</h5>
<h6 class="card-subtitle mb-2 text-body-secondary">You have {{ active_count }} active worklogs.</h6> <h6 class="card-subtitle mb-2 text-body-secondary">
You have {{ active_count }} active worklogs.
{% set ids %}
{ids: [{% for row in active_worklog_rows %}{{ row['id'] }}, {% endfor %}]}
{% endset %}
{{ links.export_link(
'active_worklog',
'worklog',
ids
) }}
</h6>
{{ tables.render_table( {{ tables.render_table(
headers = active_worklog_headers, headers = active_worklog_headers,
rows = active_worklog_rows, rows = active_worklog_rows,