refactoring

This commit is contained in:
frankknoll
2023-10-15 15:23:10 +02:00
parent d84bc82a8c
commit fb53822fdc
6 changed files with 74 additions and 76 deletions

View File

@@ -33,6 +33,7 @@
<script src="./js/PrrByVaccineProvider.js"></script> <script src="./js/PrrByVaccineProvider.js"></script>
<script src="./js/PrrByVaccineTable.js"></script> <script src="./js/PrrByVaccineTable.js"></script>
<script src="./js/PrrBySymptomTable.js"></script> <script src="./js/PrrBySymptomTable.js"></script>
<script src="./js/PrrByKeyTableView.js"></script>
<script src="./js/PrrByVaccineTableView.js"></script> <script src="./js/PrrByVaccineTableView.js"></script>
<script src="./js/PrrBySymptomTableView.js"></script> <script src="./js/PrrBySymptomTableView.js"></script>
<script> <script>

View File

@@ -0,0 +1,44 @@
class PrrByKeyTableView {
#prrByKeyTable;
#downloadPrrByKeyTableButton;
#value;
#valueName;
#prrByKeyProvider;
constructor(prrByKeyTable, downloadPrrByKeyTableButton, valueName, prrByKeyProvider) {
this.#prrByKeyTable = prrByKeyTable;
this.#prrByKeyTable.initialize();
this.#initializeButton(downloadPrrByKeyTableButton);
this.#valueName = valueName;
this.#prrByKeyProvider = prrByKeyProvider;
}
displayPrrByKeyTable4Value(value) {
UIUtils.disableButton(this.#downloadPrrByKeyTableButton);
this.#prrByKeyProvider(value)
.then(prrByKey => {
this.#value = value;
this.#prrByKeyTable.display(prrByKey);
UIUtils.enableButton(this.#downloadPrrByKeyTableButton);
});
}
#initializeButton(downloadPrrByKeyTableButton) {
this.#downloadPrrByKeyTableButton = downloadPrrByKeyTableButton;
UIUtils.disableButton(downloadPrrByKeyTableButton);
downloadPrrByKeyTableButton.addEventListener(
'click',
() => this.#downloadPrrByKey())
}
#downloadPrrByKey() {
UIUtils.downloadUrlAsFilename(
window.URL.createObjectURL(
new Blob(
[this.#prrByKeyTable.getDisplayedTableAsCsv(`# ${this.#valueName}: ${this.#value}`)],
{ type: 'text/csv' })),
this.#value
);
}
}

View File

@@ -3,6 +3,7 @@ class PrrBySymptomTable {
#tableElement; #tableElement;
#table; #table;
#sumPrrs; #sumPrrs;
#prrBySymptom;
constructor(tableElement) { constructor(tableElement) {
this.#tableElement = tableElement; this.#tableElement = tableElement;
@@ -13,10 +14,23 @@ class PrrBySymptomTable {
} }
display(prrBySymptom) { display(prrBySymptom) {
this.#prrBySymptom = prrBySymptom;
const symptom_prr_pairs = Object.entries(prrBySymptom); const symptom_prr_pairs = Object.entries(prrBySymptom);
this.#setTableRows(symptom_prr_pairs); this.#setTableRows(symptom_prr_pairs);
} }
getDisplayedTableAsCsv(heading) {
return PrrByKey2CsvConverter.convertPrrByKey2Csv(
{
heading: heading,
columns: {
keyColumn: 'Symptom',
prrColumn: 'Proportional Reporting Ratio > 1'
},
prrByKey: this.#prrBySymptom
});
}
#createEmptyTable() { #createEmptyTable() {
return this.#tableElement.DataTable( return this.#tableElement.DataTable(
{ {

View File

@@ -1,53 +1,16 @@
class PrrBySymptomTableView { class PrrBySymptomTableView {
#prrBySymptomTable; #delegate;
#downloadPrrBySymptomTableButton;
#prrBySymptom;
#vaccine;
constructor(prrBySymptomTableElement, downloadPrrBySymptomTableButton) { constructor(prrBySymptomTableElement, downloadPrrBySymptomTableButton) {
this.#prrBySymptomTable = new PrrBySymptomTable(prrBySymptomTableElement); this.#delegate = new PrrByKeyTableView(
this.#prrBySymptomTable.initialize(); new PrrBySymptomTable(prrBySymptomTableElement),
this.#initializeButton(downloadPrrBySymptomTableButton); downloadPrrBySymptomTableButton,
'Vaccine',
PrrByVaccineProvider.getPrrBySymptom);
} }
displayPrrBySymptomTable4Vaccine(vaccine) { displayPrrBySymptomTable4Vaccine(vaccine) {
UIUtils.disableButton(this.#downloadPrrBySymptomTableButton); this.#delegate.displayPrrByKeyTable4Value(vaccine);
PrrByVaccineProvider
.getPrrBySymptom(vaccine)
.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
);
} }
} }

View File

@@ -1,41 +1,16 @@
class PrrByVaccineTableView { class PrrByVaccineTableView {
#prrByVaccineTable; #delegate;
#downloadPrrByVaccineTableButton;
#symptom;
constructor(prrByVaccineTableElement, downloadPrrByVaccineTableButton) { constructor(prrByVaccineTableElement, downloadPrrByVaccineTableButton) {
this.#prrByVaccineTable = new PrrByVaccineTable(prrByVaccineTableElement); this.#delegate = new PrrByKeyTableView(
this.#prrByVaccineTable.initialize(); new PrrByVaccineTable(prrByVaccineTableElement),
this.#initializeButton(downloadPrrByVaccineTableButton); downloadPrrByVaccineTableButton,
'Symptom',
PrrByVaccineProvider.getPrrByVaccine);
} }
displayPrrByVaccineTable4Symptom(symptom) { displayPrrByVaccineTable4Symptom(symptom) {
UIUtils.disableButton(this.#downloadPrrByVaccineTableButton); this.#delegate.displayPrrByKeyTable4Value(symptom);
PrrByVaccineProvider
.getPrrByVaccine(symptom)
.then(prrByVaccine => {
this.#symptom = symptom;
this.#prrByVaccineTable.display(prrByVaccine);
UIUtils.enableButton(this.#downloadPrrByVaccineTableButton);
});
}
#initializeButton(downloadPrrByVaccineTableButton) {
this.#downloadPrrByVaccineTableButton = downloadPrrByVaccineTableButton;
UIUtils.disableButton(downloadPrrByVaccineTableButton);
downloadPrrByVaccineTableButton.addEventListener(
'click',
() => this.#downloadPrrByVaccine())
}
#downloadPrrByVaccine() {
UIUtils.downloadUrlAsFilename(
window.URL.createObjectURL(
new Blob(
[this.#prrByVaccineTable.getDisplayedTableAsCsv('# Symptom: ' + this.#symptom)],
{ type: 'text/csv' })),
this.#symptom
);
} }
} }

View File

@@ -16,6 +16,7 @@
<script src="../../docs/SymptomsCausedByVaccines/js/PrrByVaccineProvider.js"></script> <script src="../../docs/SymptomsCausedByVaccines/js/PrrByVaccineProvider.js"></script>
<script src="../../docs/SymptomsCausedByVaccines/js/PrrByVaccineTable.js"></script> <script src="../../docs/SymptomsCausedByVaccines/js/PrrByVaccineTable.js"></script>
<script src="../../docs/SymptomsCausedByVaccines/js/PrrBySymptomTable.js"></script> <script src="../../docs/SymptomsCausedByVaccines/js/PrrBySymptomTable.js"></script>
<script src="../../docs/SymptomsCausedByVaccines/js/PrrByKeyTableView.js"></script>
<script src="../../docs/SymptomsCausedByVaccines/js/PrrByVaccineTableView.js"></script> <script src="../../docs/SymptomsCausedByVaccines/js/PrrByVaccineTableView.js"></script>
<script src="../../docs/SymptomsCausedByVaccines/js/PrrBySymptomTableView.js"></script> <script src="../../docs/SymptomsCausedByVaccines/js/PrrBySymptomTableView.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-2.17.2.css"> <link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-2.17.2.css">