From 1aba82ce249b7916de21d783f6b82fd05a2c61be Mon Sep 17 00:00:00 2001 From: Frank Knoll Date: Sun, 14 Jul 2024 01:27:22 +0200 Subject: [PATCH] refactoring --- docs/SymptomsCausedByDrugs/index.html | 2 ++ docs/SymptomsCausedByDrugs/js/PageInitializer.js | 12 ++++-------- docs/UIUtils.js | 6 ++++++ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/docs/SymptomsCausedByDrugs/index.html b/docs/SymptomsCausedByDrugs/index.html index adbef9bff16..30ef302ac64 100644 --- a/docs/SymptomsCausedByDrugs/index.html +++ b/docs/SymptomsCausedByDrugs/index.html @@ -47,6 +47,7 @@ symptom: { symptomSelectElement: $('#symptomSelect'), selectSymptom: UIUtils.getSearchParam(urlSearchParams, 'symptom', null), + onSymptomSelected: symptom => UIUtils.setSearchParamOfCurrentUrl('symptom', symptom), prrByVaccineTableElement: $('#prrByVaccineTable'), downloadPrrByVaccineTableButton: document.querySelector("#downloadPrrByVaccineTable"), keyColumnName: name @@ -54,6 +55,7 @@ vaccine: { vaccineSelectElement: $('#vaccineSelect'), selectVaccine: UIUtils.getSearchParam(urlSearchParams, 'vaccine', null), + onVaccineSelected: vaccine => UIUtils.setSearchParamOfCurrentUrl('vaccine', vaccine), prrBySymptomTableElement: $('#prrBySymptomTable'), downloadPrrBySymptomTableButton: document.querySelector("#downloadPrrBySymptomTable"), valueName: name diff --git a/docs/SymptomsCausedByDrugs/js/PageInitializer.js b/docs/SymptomsCausedByDrugs/js/PageInitializer.js index 033e486ae19..e4a1ee846a2 100644 --- a/docs/SymptomsCausedByDrugs/js/PageInitializer.js +++ b/docs/SymptomsCausedByDrugs/js/PageInitializer.js @@ -5,7 +5,7 @@ class PageInitializer { PageInitializer.#configureVaccine(vaccine); } - static #configureSymptom({ symptomSelectElement, selectSymptom, prrByVaccineTableElement, downloadPrrByVaccineTableButton, keyColumnName }) { + static #configureSymptom({ symptomSelectElement, selectSymptom, onSymptomSelected, prrByVaccineTableElement, downloadPrrByVaccineTableButton, keyColumnName }) { const prrByVaccineTableView = new PrrByVaccineTableView(prrByVaccineTableElement, downloadPrrByVaccineTableButton, keyColumnName); Select2.initializeSelectElement( { @@ -13,15 +13,13 @@ class PageInitializer { textOfOption2Select: selectSymptom, onValueSelected: (id, text) => { prrByVaccineTableView.displayPrrByVaccineTable4Symptom(id, text); - const url = new URL(window.location.href); - url.searchParams.set('symptom', text); - window.history.replaceState(null, "", url); + onSymptomSelected(text); }, minimumInputLength: 0 }); } - static #configureVaccine({ vaccineSelectElement, selectVaccine, prrBySymptomTableElement, downloadPrrBySymptomTableButton, valueName }) { + static #configureVaccine({ vaccineSelectElement, selectVaccine, onVaccineSelected, prrBySymptomTableElement, downloadPrrBySymptomTableButton, valueName }) { const prrBySymptomTableView = new PrrBySymptomTableView(prrBySymptomTableElement, downloadPrrBySymptomTableButton, valueName); Select2.initializeSelectElement( { @@ -29,9 +27,7 @@ class PageInitializer { textOfOption2Select: selectVaccine, onValueSelected: (id, text) => { prrBySymptomTableView.displayPrrBySymptomTable4Vaccine(id, text); - const url = new URL(window.location.href); - url.searchParams.set('vaccine', text); - window.history.replaceState(null, "", url); + onVaccineSelected(text); }, minimumInputLength: 0 }); diff --git a/docs/UIUtils.js b/docs/UIUtils.js index 6aae5dc2c68..530604b8159 100644 --- a/docs/UIUtils.js +++ b/docs/UIUtils.js @@ -38,6 +38,12 @@ class UIUtils { return UIUtils.getSearchParam(urlParams, searchParam, 'NO').toUpperCase() == 'YES'; } + static setSearchParamOfCurrentUrl(nameOfSearchParam, valueOfSearchParam) { + const url = new URL(window.location.href); + url.searchParams.set(nameOfSearchParam, valueOfSearchParam); + window.history.replaceState(null, "", url); + } + static downloadUrlAsFilename(url, filename) { const a = document.createElement('a'); a.setAttribute('href', url);