refining PdfCreator
This commit is contained in:
@@ -14315,7 +14315,6 @@
|
|||||||
<!-- page content -->
|
<!-- page content -->
|
||||||
<!-- footer content -->
|
<!-- footer content -->
|
||||||
<footer>
|
<footer>
|
||||||
<button class="a2a_button" id="PDF">PDF</button>
|
|
||||||
<!-- AddToAny BEGIN -->
|
<!-- AddToAny BEGIN -->
|
||||||
<div class="a2a_kit a2a_kit_size_32 a2a_default_style" data-a2a-title="EU Safety Signal (All drugs)">
|
<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>
|
<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_whatsapp"></a>
|
||||||
<a class="a2a_button_telegram"></a>
|
<a class="a2a_button_telegram"></a>
|
||||||
<a class="a2a_button_email"></a>
|
<a class="a2a_button_email"></a>
|
||||||
|
<button class="btn" id="PDF">PDF</button>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
var a2a_config = a2a_config || {};
|
var a2a_config = a2a_config || {};
|
||||||
|
|||||||
@@ -1,9 +1,20 @@
|
|||||||
class PageInitializer {
|
class PageInitializer {
|
||||||
|
|
||||||
static initializePage({ symptom, vaccine, pdfButton }) {
|
static initializePage({ symptom, vaccine, pdfButton }) {
|
||||||
PageInitializer.#configureSymptom(symptom);
|
const prrByVaccineTableView = PageInitializer.#configureSymptom(symptom);
|
||||||
PageInitializer.#configureVaccine(vaccine);
|
const prrBySymptomTableView = PageInitializer.#configureVaccine(vaccine);
|
||||||
PageInitializer.#configurePDFButton(pdfButton);
|
PageInitializer.#configurePDFButton(
|
||||||
|
{
|
||||||
|
pdfButton,
|
||||||
|
symptom: {
|
||||||
|
selectElement: symptom.symptomSelectElement,
|
||||||
|
table: prrByVaccineTableView.getTable()
|
||||||
|
},
|
||||||
|
vaccine: {
|
||||||
|
selectElement: vaccine.vaccineSelectElement,
|
||||||
|
table: prrBySymptomTableView.getTable()
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static #configureSymptom({ symptomSelectElement, urlSearchParam, prrByVaccineTableElement, downloadPrrByVaccineTableButton, keyColumnName }) {
|
static #configureSymptom({ symptomSelectElement, urlSearchParam, prrByVaccineTableElement, downloadPrrByVaccineTableButton, keyColumnName }) {
|
||||||
@@ -18,6 +29,7 @@ class PageInitializer {
|
|||||||
urlSearchParam.set(text);
|
urlSearchParam.set(text);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
return prrByVaccineTableView;
|
||||||
}
|
}
|
||||||
|
|
||||||
static #configureVaccine({ vaccineSelectElement, urlSearchParam, prrBySymptomTableElement, downloadPrrBySymptomTableButton, valueName }) {
|
static #configureVaccine({ vaccineSelectElement, urlSearchParam, prrBySymptomTableElement, downloadPrrBySymptomTableButton, valueName }) {
|
||||||
@@ -32,11 +44,14 @@ class PageInitializer {
|
|||||||
},
|
},
|
||||||
minimumInputLength: 0
|
minimumInputLength: 0
|
||||||
});
|
});
|
||||||
|
return prrBySymptomTableView;
|
||||||
}
|
}
|
||||||
|
|
||||||
static #configurePDFButton(pdfButton) {
|
static #configurePDFButton({ pdfButton, symptom, vaccine }) {
|
||||||
pdfButton.addEventListener(
|
pdfButton.addEventListener(
|
||||||
'click',
|
'click',
|
||||||
() => PdfCreator.createPdf().open());
|
() => PdfCreator
|
||||||
|
.createPdf({ symptom, vaccine })
|
||||||
|
.open());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,73 @@
|
|||||||
class PdfCreator {
|
class PdfCreator {
|
||||||
|
|
||||||
static createPdf() {
|
static createPdf({ symptom, vaccine }) {
|
||||||
const documentDefinition = {
|
const documentDefinition = {
|
||||||
content: [
|
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: 'EU Safety Signal (All drugs)',
|
||||||
{ text: 'table' },
|
fontSize: 18,
|
||||||
{ text: 'Strongest Symptoms', fontSize: 12, alignment: 'left', margin: [0, 10, 0, 10], bold: true },
|
alignment: 'center',
|
||||||
{ text: 'table' },
|
margin: [0, 0, 0, 20],
|
||||||
|
bold: true
|
||||||
|
},
|
||||||
|
...PdfCreator.#getWorstDrugsSection(symptom),
|
||||||
|
...PdfCreator.#getStrongestSymptoms(vaccine)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
return pdfMake.createPdf(documentDefinition);
|
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() {
|
#createEmptyTable() {
|
||||||
return this.#tableElement.DataTable(
|
return this.#tableElement.DataTable(
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ class PrrByKeyTableView {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getTable() {
|
||||||
|
return this.#prrByKeyTable.getTable();
|
||||||
|
}
|
||||||
|
|
||||||
#initializeButton(downloadPrrByKeyTableButton) {
|
#initializeButton(downloadPrrByKeyTableButton) {
|
||||||
this.#downloadPrrByKeyTableButton = downloadPrrByKeyTableButton;
|
this.#downloadPrrByKeyTableButton = downloadPrrByKeyTableButton;
|
||||||
UIUtils.disableButton(downloadPrrByKeyTableButton);
|
UIUtils.disableButton(downloadPrrByKeyTableButton);
|
||||||
|
|||||||
@@ -14,6 +14,10 @@ class PrrBySymptomTableView {
|
|||||||
this.#delegate.displayPrrByKeyTable4Value(id, text);
|
this.#delegate.displayPrrByKeyTable4Value(id, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getTable() {
|
||||||
|
return this.#delegate.getTable();
|
||||||
|
}
|
||||||
|
|
||||||
#createPrrBySymptomTable(tableElement) {
|
#createPrrBySymptomTable(tableElement) {
|
||||||
return new PrrByKeyTable({
|
return new PrrByKeyTable({
|
||||||
tableElement: tableElement,
|
tableElement: tableElement,
|
||||||
|
|||||||
@@ -14,6 +14,10 @@ class PrrByVaccineTableView {
|
|||||||
this.#delegate.displayPrrByKeyTable4Value(id, text);
|
this.#delegate.displayPrrByKeyTable4Value(id, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getTable() {
|
||||||
|
return this.#delegate.getTable();
|
||||||
|
}
|
||||||
|
|
||||||
#createPrrByVaccineTable(tableElement, keyColumnName) {
|
#createPrrByVaccineTable(tableElement, keyColumnName) {
|
||||||
return new PrrByKeyTable({
|
return new PrrByKeyTable({
|
||||||
tableElement: tableElement,
|
tableElement: tableElement,
|
||||||
|
|||||||
Reference in New Issue
Block a user