From 26649f83873d9e01d23f2927f64155453918aec7 Mon Sep 17 00:00:00 2001 From: Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> Date: Thu, 6 Apr 2023 18:40:24 +0530 Subject: Improved the functionality of the Download PDF button and reduced bundle size manyfold. --- src/scripts.json | 2 +- src/scripts/functionality/view-khatian.ts | 53 ------- src/scripts/functionality/view-khatian/index.ts | 63 ++++++++ .../view-khatian/khatian-download-document.ts | 160 +++++++++++++++++++++ src/shared/download-pdf.ts | 41 +++--- 5 files changed, 245 insertions(+), 74 deletions(-) delete mode 100644 src/scripts/functionality/view-khatian.ts create mode 100644 src/scripts/functionality/view-khatian/index.ts create mode 100644 src/scripts/functionality/view-khatian/khatian-download-document.ts (limited to 'src') diff --git a/src/scripts.json b/src/scripts.json index a2e48fd..75228c4 100644 --- a/src/scripts.json +++ b/src/scripts.json @@ -9,7 +9,7 @@ "login.ts": "*", "otps/grievance-application.ts": "GrievAppViewAction.action", "otps/mutation-application.ts": "MuteApplication.action", - "functionality/view-khatian.ts": "KnowYourProperty.action" + "functionality/view-khatian/index.ts": "KnowYourProperty.action" }, "loaded": { "captcha.ts": "*", diff --git a/src/scripts/functionality/view-khatian.ts b/src/scripts/functionality/view-khatian.ts deleted file mode 100644 index e81613b..0000000 --- a/src/scripts/functionality/view-khatian.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { downloadPDF } from "@/shared/download-pdf"; - -declare function loadKhatian(): void; - -document.addEventListener("DOMContentLoaded", () => { - const proxiedPost = $.post; - - const submitButtonElement = document.querySelector("#khbutton") as HTMLButtonElement; - const separatorElement = document.querySelector("#bodycover > div > form > hr:nth-child(2)") as HTMLElement; - const formElement = document.querySelector("#bodycover > div > form") as HTMLElement; - let downloadPDFButton: HTMLButtonElement | null = null; - - const submitButtonElementComputedStyles = window.getComputedStyle(submitButtonElement); - const styles = Array.from(submitButtonElementComputedStyles) - .reduce( - (str, property) => `${str}${property}:${submitButtonElementComputedStyles.getPropertyValue(property)};`, - "" - ); - - const downloadKhatianInformationPDF = () => { - downloadPDF(document.querySelector("html") as HTMLElement, "khatian-details.pdf"); - }; - - $.post = function() { - if (arguments[0].startsWith("khDetailsAction_LandInfo.action")) { - const callback = arguments[2]; - arguments[2] = (data: any) => { - callback(data); - const tableElement = document.querySelector("#khdetails > table > tbody > tr > td:nth-child(1) > div:nth-child(5) > table > tbody") as HTMLElement | null; - - if (tableElement) { - tableElement.style.height = "auto"; - tableElement.style.width = "100%"; - - if (!downloadPDFButton) { - downloadPDFButton = document.createElement("button"); - downloadPDFButton.innerHTML = "Download PDF"; - downloadPDFButton.style.cssText = styles; - downloadPDFButton.style.width = "auto"; - downloadPDFButton.addEventListener("click", downloadKhatianInformationPDF); - formElement.insertBefore(downloadPDFButton, separatorElement); - } - } else if (downloadPDFButton) { - downloadPDFButton.removeEventListener("click", downloadKhatianInformationPDF); - formElement.removeChild(downloadPDFButton); - downloadPDFButton = null; - } - } - } - - return proxiedPost.apply(this, Array.from(arguments) as any); - } -}); diff --git a/src/scripts/functionality/view-khatian/index.ts b/src/scripts/functionality/view-khatian/index.ts new file mode 100644 index 0000000..baf6d8e --- /dev/null +++ b/src/scripts/functionality/view-khatian/index.ts @@ -0,0 +1,63 @@ +import { downloadPDF } from "@/shared/download-pdf"; +import getKhatinDetailsPDFPageData from "@/scripts/functionality/view-khatian/khatian-download-document"; + +declare function loadKhatian(): void; + +document.addEventListener("DOMContentLoaded", () => { + const proxiedPost = $.post; + + const submitButtonElement = document.querySelector("#khbutton") as HTMLButtonElement; + const separatorElement = document.querySelector("#bodycover > div > form > hr:nth-child(2)") as HTMLElement; + const formElement = document.querySelector("#bodycover > div > form") as HTMLElement; + let downloadPDFButton: HTMLButtonElement | null = null; + + const submitButtonElementComputedStyles = window.getComputedStyle(submitButtonElement); + const styles = Array.from(submitButtonElementComputedStyles) + .reduce( + (str, property) => `${str}${property}:${submitButtonElementComputedStyles.getPropertyValue(property)};`, + "" + ); + + const getValueOfSelectElement = (selector: string) => { + const element = document.querySelector(selector) as HTMLSelectElement; + return element.options[element.selectedIndex].text; + }; + + const downloadKhatianInformationPDF = () => { + const documentStringContent = getKhatinDetailsPDFPageData(document.querySelector("#khdetails")!.innerHTML, { + district: getValueOfSelectElement("#lstDistrictCode1"), + block: getValueOfSelectElement("#lstBlockCode1"), + mouza: getValueOfSelectElement("#lstMouzaList") + }); + downloadPDF(`
+