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/PrrByVaccineTable.js"></script>
<script src="./js/PrrBySymptomTable.js"></script>
<script src="./js/PrrByKeyTableView.js"></script>
<script src="./js/PrrByVaccineTableView.js"></script>
<script src="./js/PrrBySymptomTableView.js"></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;
#table;
#sumPrrs;
#prrBySymptom;
constructor(tableElement) {
this.#tableElement = tableElement;
@@ -13,10 +14,23 @@ class PrrBySymptomTable {
}
display(prrBySymptom) {
this.#prrBySymptom = prrBySymptom;
const symptom_prr_pairs = Object.entries(prrBySymptom);
this.#setTableRows(symptom_prr_pairs);
}
getDisplayedTableAsCsv(heading) {
return PrrByKey2CsvConverter.convertPrrByKey2Csv(
{
heading: heading,
columns: {
keyColumn: 'Symptom',
prrColumn: 'Proportional Reporting Ratio > 1'
},
prrByKey: this.#prrBySymptom
});
}
#createEmptyTable() {
return this.#tableElement.DataTable(
{

View File

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

View File

@@ -1,41 +1,16 @@
class PrrByVaccineTableView {
#prrByVaccineTable;
#downloadPrrByVaccineTableButton;
#symptom;
#delegate;
constructor(prrByVaccineTableElement, downloadPrrByVaccineTableButton) {
this.#prrByVaccineTable = new PrrByVaccineTable(prrByVaccineTableElement);
this.#prrByVaccineTable.initialize();
this.#initializeButton(downloadPrrByVaccineTableButton);
this.#delegate = new PrrByKeyTableView(
new PrrByVaccineTable(prrByVaccineTableElement),
downloadPrrByVaccineTableButton,
'Symptom',
PrrByVaccineProvider.getPrrByVaccine);
}
displayPrrByVaccineTable4Symptom(symptom) {
UIUtils.disableButton(this.#downloadPrrByVaccineTableButton);
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
);
this.#delegate.displayPrrByKeyTable4Value(symptom);
}
}

View File

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