Skip to content

Commit

Permalink
feat(csv): Adds spinner and error handling to de_list template
Browse files Browse the repository at this point in the history
  • Loading branch information
ERosendo committed Aug 28, 2024
1 parent 1325344 commit 71a66fc
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 6 deletions.
13 changes: 13 additions & 0 deletions cl/assets/static-global/css/override.css
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,14 @@ input.court-checkbox, input.status-checkbox {
padding: 0px;
}

#export-csv-spinner{
padding: 7px 0px;
}

#export-csv-error {
padding: 5px 0px;
}

@media (min-width: 767px) {
.export-csv {
padding: 5px 10px;
Expand Down Expand Up @@ -1690,3 +1698,8 @@ rect.series-segment {
.ml-1 {
margin-left: 0.25rem !important;
}

.htmx-indicator {
opacity: 0;
transition: opacity 200ms ease-in;
}
55 changes: 55 additions & 0 deletions cl/assets/static-global/js/export-csv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
document.addEventListener('htmx:beforeRequest', function () {
// If the mobile error message is currently visible, adds the 'hidden' class
// to hide it.
let mobileErrorMessage = document.getElementById('mobile-export-csv-error');
if (!mobileErrorMessage.classList.contains('hidden')) {
mobileErrorMessage.classList.add('hidden');
}

// If the desktop error message is currently visible, adds the 'hidden' class
// to hide it.
let desktopErrorMessage = document.getElementById('export-csv-error');
if (!desktopErrorMessage.classList.contains('hidden')) {
desktopErrorMessage.classList.add('hidden');
}
});

document.addEventListener('htmx:beforeOnLoad', function (event) {
// Get the XMLHttpRequest object from the event details
const xhr = event.detail.xhr;
if (xhr.status == 200) {
const response = xhr.response;
// Extract the filename from the Content-Disposition header and get
//the MIME type from the Content-Type header
const filename = xhr.getResponseHeader('Content-Disposition').split('=')[1];
const mimetype = xhr.getResponseHeader('Content-Type');

// Prepare a link element for a file download
// Create a hidden link element for download
const link = document.createElement('a');
link.style.display = 'none';

// Create a Blob object containing the response data with the correct
// MIME type and generate a temporary URL for it
const blob = new Blob([response], { type: mimetype });
const url = window.URL.createObjectURL(blob);

// Set the link's attributes for download
link.href = url;
link.download = filename.replaceAll('"', '');

// It needs to be added to the DOM so it can be clicked
document.body.appendChild(link);
link.click();

// Release the temporary URL after download (for memory management)
window.URL.revokeObjectURL(url);
} else {
// If the request failed, show the error messages
let mobileErrorMessage = document.getElementById('mobile-export-csv-error');
mobileErrorMessage.classList.remove('hidden');

let desktopErrorMessage = document.getElementById('export-csv-error');
desktopErrorMessage.classList.remove('hidden');
}
});
8 changes: 8 additions & 0 deletions cl/opinion_page/templates/docket_tabs.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
<script src="{% static "js/jquery.bootstrap-growl.min.js" %}"></script>
<script defer type="text/javascript"
src="{% static "js/save-notes.js" %}"></script>
{% if DEBUG %}
<script src="{% static "js/htmx.js" %}"></script>
<script src="{% static "js/fix-toolbar-for-htmx.js" %}"></script>
{% else %}
<script src="{% static "js/htmx.min.js" %}"></script>
{% endif %}

{% if request.user.is_authenticated %}
<script defer type="text/javascript"
src="{% static "js/toggle_settings.js" %}"></script>
Expand Down Expand Up @@ -47,6 +54,7 @@
<script type="text/javascript"
src="{% static "js/react/vendor.js" %}"></script>

<script type="text/javascript" src="{% static "js/export-csv.js" %}"></script>
{% endblock %}

{% block nav %}
Expand Down
33 changes: 27 additions & 6 deletions cl/opinion_page/templates/includes/de_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,42 @@
<p class="hidden-xs">Document Number</p>
</div>
<div class="col-xs-3 col-sm-2">Date&nbsp;Filed</div>
<div class="col-xs-8 col-sm-6">
<div class="col-xs-9 description-header">
<div class="col-xs-8 col-sm-4">
<div class="col-xs-3 description-header">
Description
</div>
<div class="col-xs-3">
<a href="{% url 'view_download_docket' docket.id %}" class="btn export-csv visible-xs">
<div class="col-xs-6 description-header">
<span id="mobile-export-csv-error" class="hidden visible-xs text-danger">
<i class="fa fa-info-circle"></i> There was a problem. Try again later.
</span>
</div>
<div class="col-xs-3 flex">
<a hx-get="{% url 'view_download_docket' docket.id %}"
hx-swap="none" hx-indicator="#mobile-spinner"
hx-trigger="click" class="btn export-csv visible-xs">
<div class="flex align-items-center">
<i class="fa fa-download gray"></i>&nbsp;
<span>CSV</span>
</div>
</a>
&nbsp;
<span>
<i id="mobile-spinner" class="htmx-indicator fa fa-spinner fa-spin fa-lg"></i>
</span>
</div>
</div>
<div class="flex justify-content-end col-xs-3">
<a href="{% url 'view_download_docket' docket.id %}" class="btn btn-default hidden-xs export-csv">
<div class="flex justify-content-end col-xs-5">
<span id="export-csv-error" class="text-danger hidden">
<i class="fa fa-info-circle"></i> There was a problem. Try again later.
</span>
<span id="export-csv-spinner" class="htmx-indicator" >
<i class="fa fa-spinner fa-spin hidden-lg"></i>
<i class="fa fa-spinner fa-spin fa-lg visible-lg"></i>
</span>
&nbsp;
<a hx-get="{% url 'view_download_docket' docket.id %}"
hx-swap="none" hx-indicator="#export-csv-spinner" hx-trigger="click"
class="btn btn-default hidden-xs export-csv">
<div class="flex align-items-center">
<i class="fa fa-download gray hidden-lg"></i>
<i class="fa fa-download fa-lg gray visible-lg"></i>&nbsp;
Expand Down

0 comments on commit 71a66fc

Please sign in to comment.