- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 729
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Merge pull request #12782 from mkllnk/reports
Add fallback report loading in case websockets fail
Showing
21 changed files
with
142 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
.download.hidden | ||
= link_to t("admin.reports.download.button"), file_url, target: "_blank", class: "button icon icon-file" | ||
|
||
:javascript | ||
(function () { | ||
const tryDownload = function() { | ||
const link = document.querySelector(".download a"); | ||
|
||
// If the report was already rendered via web sockets: | ||
if (link == null) return; | ||
|
||
fetch(link.href).then((response) => { | ||
if (response.ok) { | ||
response.blob().then((blob) => blob.text()).then((text) => { | ||
const loading = document.querySelector(".loading"); | ||
|
||
if (loading == null) return; | ||
|
||
loading.remove(); | ||
document.querySelector("#report-go button").disabled = false; | ||
|
||
if (link.href.endsWith(".html")) { | ||
// This replaces the hidden download button with the report: | ||
link.parentElement.outerHTML = text; | ||
} else { | ||
// Or just show the download button when it's ready: | ||
document.querySelector(".download").classList.remove("hidden") | ||
} | ||
}); | ||
} else { | ||
setTimeout(tryDownload, 2000); | ||
} | ||
}); | ||
} | ||
|
||
/* | ||
A lot of reports are rendered within 250ms. Others take at least | ||
2.5 seconds. There's a big gap in between. Observed on: | ||
https://openfoodnetwork.org.au/admin/sidekiq/metrics/ReportJob?period=8h | ||
https://openfoodnetwork.org.uk/admin/sidekiq/metrics/ReportJob?period=8h | ||
https://coopcircuits.fr/admin/sidekiq/metrics/ReportJob?period=8h | ||
But let's leave the timed response to websockets for now and just poll | ||
as a backup mechanism. | ||
*/ | ||
setTimeout(tryDownload, 3000); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
= turbo_stream.update "report-go" do | ||
= button t(:go), "report__submit-btn", "submit", disabled: true | ||
= turbo_stream.update "report-table" do | ||
= render "admin/reports/loading" | ||
= render "admin/reports/fallback_display", file_url: @blob.expiring_service_url | ||
= turbo_stream.scroll_into_view("#report-table", behavior: "smooth") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.