From ae425cf72341b51aa9cf87c39cd8cc9cf51f19ac Mon Sep 17 00:00:00 2001 From: frankknoll Date: Sun, 15 Oct 2023 14:39:16 +0200 Subject: [PATCH] adding downloadPrrBySymptomTableButton --- docs/SymptomsCausedByVaccines/index.html | 4 +- .../js/PageInitializer.js | 4 +- .../js/PrrBySymptomTableView.js | 42 ++++++++++++++++++- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/docs/SymptomsCausedByVaccines/index.html b/docs/SymptomsCausedByVaccines/index.html index 7297c496f28..556ca798dd6 100644 --- a/docs/SymptomsCausedByVaccines/index.html +++ b/docs/SymptomsCausedByVaccines/index.html @@ -48,7 +48,8 @@ }, vaccine: { vaccineSelectElement: $('#vaccineSelect'), - prrBySymptomTableElement: $('#prrBySymptomTable') + prrBySymptomTableElement: $('#prrBySymptomTable'), + downloadPrrBySymptomTableButton: document.querySelector("#downloadPrrBySymptomTable") } } ); @@ -17811,6 +17812,7 @@ + diff --git a/docs/SymptomsCausedByVaccines/js/PageInitializer.js b/docs/SymptomsCausedByVaccines/js/PageInitializer.js index d503f8f433f..914e5b52283 100644 --- a/docs/SymptomsCausedByVaccines/js/PageInitializer.js +++ b/docs/SymptomsCausedByVaccines/js/PageInitializer.js @@ -15,8 +15,8 @@ class PageInitializer { }); } - static #configureVaccine({ vaccineSelectElement, prrBySymptomTableElement }) { - const prrBySymptomTableView = new PrrBySymptomTableView(prrBySymptomTableElement); + static #configureVaccine({ vaccineSelectElement, prrBySymptomTableElement, downloadPrrBySymptomTableButton }) { + const prrBySymptomTableView = new PrrBySymptomTableView(prrBySymptomTableElement, downloadPrrBySymptomTableButton); PageInitializer.#initializeSelectElement( { selectElement: vaccineSelectElement, diff --git a/docs/SymptomsCausedByVaccines/js/PrrBySymptomTableView.js b/docs/SymptomsCausedByVaccines/js/PrrBySymptomTableView.js index 663d59ac19b..995e690a877 100644 --- a/docs/SymptomsCausedByVaccines/js/PrrBySymptomTableView.js +++ b/docs/SymptomsCausedByVaccines/js/PrrBySymptomTableView.js @@ -1,15 +1,53 @@ class PrrBySymptomTableView { #prrBySymptomTable; + #downloadPrrBySymptomTableButton; + #prrBySymptom; + #vaccine; - constructor(prrBySymptomTableElement) { + constructor(prrBySymptomTableElement, downloadPrrBySymptomTableButton) { this.#prrBySymptomTable = new PrrBySymptomTable(prrBySymptomTableElement); this.#prrBySymptomTable.initialize(); + this.#initializeButton(downloadPrrBySymptomTableButton); } displayPrrBySymptomTable4Vaccine(vaccine) { + UIUtils.disableButton(this.#downloadPrrBySymptomTableButton); PrrByVaccineProvider .getPrrBySymptom(vaccine) - .then(prrBySymptom => this.#prrBySymptomTable.display(prrBySymptom)); + .then(prrBySymptom => { + this.#prrBySymptom = prrBySymptom; + this.#vaccine = vaccine; + this.#prrBySymptomTable.display(prrBySymptom); + UIUtils.enableButton(this.#downloadPrrBySymptomTableButton); + }); + } + + #initializeButton(downloadPrrBySymptomTableButton) { + this.#downloadPrrBySymptomTableButton = downloadPrrBySymptomTableButton; + UIUtils.disableButton(downloadPrrBySymptomTableButton); + downloadPrrBySymptomTableButton.addEventListener( + 'click', + () => this.#downloadPrrBySymptom()) + } + + #downloadPrrBySymptom() { + UIUtils.downloadUrlAsFilename( + window.URL.createObjectURL( + new Blob( + [ + PrrByKey2CsvConverter.convertPrrByKey2Csv( + { + heading: '# Vaccine: ' + this.#vaccine, + columns: { + keyColumn: 'Symptom', + prrColumn: 'Proportional Reporting Ratio > 1' + }, + prrByKey: this.#prrBySymptom + }) + ], + { type: 'text/csv' })), + this.#vaccine + ); } }