refining PdfCreator
This commit is contained in:
@@ -14315,7 +14315,6 @@
|
||||
<!-- page content -->
|
||||
<!-- footer content -->
|
||||
<footer>
|
||||
<button class="a2a_button" id="PDF">PDF</button>
|
||||
<!-- AddToAny BEGIN -->
|
||||
<div class="a2a_kit a2a_kit_size_32 a2a_default_style" data-a2a-title="EU Safety Signal (All drugs)">
|
||||
<a class="a2a_dd" href="https://www.addtoany.com/share"></a>
|
||||
@@ -14324,6 +14323,7 @@
|
||||
<a class="a2a_button_whatsapp"></a>
|
||||
<a class="a2a_button_telegram"></a>
|
||||
<a class="a2a_button_email"></a>
|
||||
<button class="btn" id="PDF">PDF</button>
|
||||
</div>
|
||||
<script>
|
||||
var a2a_config = a2a_config || {};
|
||||
|
||||
@@ -1,9 +1,20 @@
|
||||
class PageInitializer {
|
||||
|
||||
static initializePage({ symptom, vaccine, pdfButton }) {
|
||||
PageInitializer.#configureSymptom(symptom);
|
||||
PageInitializer.#configureVaccine(vaccine);
|
||||
PageInitializer.#configurePDFButton(pdfButton);
|
||||
const prrByVaccineTableView = PageInitializer.#configureSymptom(symptom);
|
||||
const prrBySymptomTableView = PageInitializer.#configureVaccine(vaccine);
|
||||
PageInitializer.#configurePDFButton(
|
||||
{
|
||||
pdfButton,
|
||||
symptom: {
|
||||
selectElement: symptom.symptomSelectElement,
|
||||
table: prrByVaccineTableView.getTable()
|
||||
},
|
||||
vaccine: {
|
||||
selectElement: vaccine.vaccineSelectElement,
|
||||
table: prrBySymptomTableView.getTable()
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static #configureSymptom({ symptomSelectElement, urlSearchParam, prrByVaccineTableElement, downloadPrrByVaccineTableButton, keyColumnName }) {
|
||||
@@ -18,6 +29,7 @@ class PageInitializer {
|
||||
urlSearchParam.set(text);
|
||||
}
|
||||
});
|
||||
return prrByVaccineTableView;
|
||||
}
|
||||
|
||||
static #configureVaccine({ vaccineSelectElement, urlSearchParam, prrBySymptomTableElement, downloadPrrBySymptomTableButton, valueName }) {
|
||||
@@ -32,11 +44,14 @@ class PageInitializer {
|
||||
},
|
||||
minimumInputLength: 0
|
||||
});
|
||||
return prrBySymptomTableView;
|
||||
}
|
||||
|
||||
static #configurePDFButton(pdfButton) {
|
||||
static #configurePDFButton({ pdfButton, symptom, vaccine }) {
|
||||
pdfButton.addEventListener(
|
||||
'click',
|
||||
() => PdfCreator.createPdf().open());
|
||||
() => PdfCreator
|
||||
.createPdf({ symptom, vaccine })
|
||||
.open());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,73 @@
|
||||
class PdfCreator {
|
||||
|
||||
static createPdf() {
|
||||
static createPdf({ symptom, vaccine }) {
|
||||
const documentDefinition = {
|
||||
content: [
|
||||
{ text: 'EU Safety Signal (All drugs)', fontSize: 16, alignment: 'center', margin: [0, 0, 0, 20], bold: true },
|
||||
{ text: 'Worst Drugs', fontSize: 12, alignment: 'left', margin: [0, 10, 0, 10], bold: true },
|
||||
{ text: 'table' },
|
||||
{ text: 'Strongest Symptoms', fontSize: 12, alignment: 'left', margin: [0, 10, 0, 10], bold: true },
|
||||
{ text: 'table' },
|
||||
{
|
||||
text: 'EU Safety Signal (All drugs)',
|
||||
fontSize: 18,
|
||||
alignment: 'center',
|
||||
margin: [0, 0, 0, 20],
|
||||
bold: true
|
||||
},
|
||||
...PdfCreator.#getWorstDrugsSection(symptom),
|
||||
...PdfCreator.#getStrongestSymptoms(vaccine)
|
||||
]
|
||||
}
|
||||
return pdfMake.createPdf(documentDefinition);
|
||||
// pdfMake.createPdf(documentDefinition).download();
|
||||
}
|
||||
|
||||
static #getWorstDrugsSection({ selectElement, table }) {
|
||||
return [
|
||||
PdfCreator.#getHeading(`Worst Drugs for ${PdfCreator.#getSelection(selectElement)}`),
|
||||
PdfCreator.#getTable(table)
|
||||
];
|
||||
}
|
||||
|
||||
static #getStrongestSymptoms({ selectElement, table }) {
|
||||
return [
|
||||
PdfCreator.#getHeading(`Strongest Symptoms for ${PdfCreator.#getSelection(selectElement)}`),
|
||||
PdfCreator.#getTable(table)
|
||||
];
|
||||
}
|
||||
|
||||
static #getHeading(text) {
|
||||
return {
|
||||
text: text,
|
||||
fontSize: 14,
|
||||
alignment: 'left',
|
||||
margin: [0, 15, 0, 15],
|
||||
bold: true
|
||||
}
|
||||
}
|
||||
|
||||
static #getSelection(selectElement) {
|
||||
return selectElement.select2('data')[0].text;
|
||||
}
|
||||
|
||||
static #getTable(table) {
|
||||
const headers = PdfCreator.#getTableHeaders(table);
|
||||
const rows = table.rows({ search: 'applied' }).data().toArray();
|
||||
return {
|
||||
layout: 'lightHorizontalLines',
|
||||
table: {
|
||||
headerRows: 1,
|
||||
body: [
|
||||
headers,
|
||||
...rows
|
||||
]
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
static #getTableHeaders(table) {
|
||||
return table
|
||||
.columns()
|
||||
.header()
|
||||
.map(header => ({
|
||||
text: header.textContent,
|
||||
bold: true
|
||||
}))
|
||||
.toArray();
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,10 @@ class PrrByKeyTable {
|
||||
});
|
||||
}
|
||||
|
||||
getTable() {
|
||||
return this.#table;
|
||||
}
|
||||
|
||||
#createEmptyTable() {
|
||||
return this.#tableElement.DataTable(
|
||||
{
|
||||
|
||||
@@ -24,6 +24,10 @@ class PrrByKeyTableView {
|
||||
});
|
||||
}
|
||||
|
||||
getTable() {
|
||||
return this.#prrByKeyTable.getTable();
|
||||
}
|
||||
|
||||
#initializeButton(downloadPrrByKeyTableButton) {
|
||||
this.#downloadPrrByKeyTableButton = downloadPrrByKeyTableButton;
|
||||
UIUtils.disableButton(downloadPrrByKeyTableButton);
|
||||
|
||||
@@ -14,6 +14,10 @@ class PrrBySymptomTableView {
|
||||
this.#delegate.displayPrrByKeyTable4Value(id, text);
|
||||
}
|
||||
|
||||
getTable() {
|
||||
return this.#delegate.getTable();
|
||||
}
|
||||
|
||||
#createPrrBySymptomTable(tableElement) {
|
||||
return new PrrByKeyTable({
|
||||
tableElement: tableElement,
|
||||
|
||||
@@ -14,6 +14,10 @@ class PrrByVaccineTableView {
|
||||
this.#delegate.displayPrrByKeyTable4Value(id, text);
|
||||
}
|
||||
|
||||
getTable() {
|
||||
return this.#delegate.getTable();
|
||||
}
|
||||
|
||||
#createPrrByVaccineTable(tableElement, keyColumnName) {
|
||||
return new PrrByKeyTable({
|
||||
tableElement: tableElement,
|
||||
|
||||
Reference in New Issue
Block a user