diff options
Diffstat (limited to 'src/scripts/pages')
| -rw-r--r-- | src/scripts/pages/application-receipt/captcha.ts | 6 | ||||
| -rw-r--r-- | src/scripts/pages/know-your-property/captcha.ts | 6 | ||||
| -rw-r--r-- | src/scripts/pages/mutation-application/download-button.ts | 15 | ||||
| -rw-r--r-- | src/scripts/pages/sheet-map/index.ts | 90 | ||||
| -rw-r--r-- | src/scripts/pages/view-khatian/index.ts | 28 |
5 files changed, 84 insertions, 61 deletions
diff --git a/src/scripts/pages/application-receipt/captcha.ts b/src/scripts/pages/application-receipt/captcha.ts index c5bb657..94e6b0e 100644 --- a/src/scripts/pages/application-receipt/captcha.ts +++ b/src/scripts/pages/application-receipt/captcha.ts @@ -3,7 +3,11 @@ * stubs the form validation so the user can proceed without * solving a CAPTCHA. */ +type WindowApplicationReceipt = { + validateForm?: () => boolean +} & Window; + document.addEventListener("DOMContentLoaded", () => { $("#werter > div > form > div:nth-child(4)").hide(); - (window as any).validateForm = () => true; + (window as WindowApplicationReceipt).validateForm = () => true; }); diff --git a/src/scripts/pages/know-your-property/captcha.ts b/src/scripts/pages/know-your-property/captcha.ts index 3abdf08..e304342 100644 --- a/src/scripts/pages/know-your-property/captcha.ts +++ b/src/scripts/pages/know-your-property/captcha.ts @@ -3,7 +3,11 @@ * stubs the captcha validation so the user can proceed without * solving a CAPTCHA. */ +type WindowKnowYourProperty = { + validateCaptcha?: () => boolean +} & Window; + document.addEventListener("DOMContentLoaded", () => { $("#khatianPlotDiv > div:nth-child(6) > div").hide(); - (window as any).validateCaptcha = () => true; + (window as WindowKnowYourProperty).validateCaptcha = () => true; }); diff --git a/src/scripts/pages/mutation-application/download-button.ts b/src/scripts/pages/mutation-application/download-button.ts index 9503e00..6463079 100644 --- a/src/scripts/pages/mutation-application/download-button.ts +++ b/src/scripts/pages/mutation-application/download-button.ts @@ -1,4 +1,5 @@ import { PDFDocument, StandardFonts } from "pdf-lib"; + import { observeDOM } from "@/shared/observe-dom"; const sanghaFacilitationCentreBannerUrl = "$l{ /assets/sangha-facilitation-centre-banner.jpg }l$"; @@ -17,7 +18,7 @@ observeDOM(() => { submitButtonElement.on("click", (submitButtonClickEvent) => { submitButtonClickEvent.preventDefault(); - (async () => { + void (async function(): Promise<void> { const pdfDoc = await PDFDocument.load(await fetch("/BanglarBhumi/MutationDeclarationForm.action", { method: "post", credentials: "same-origin", @@ -25,11 +26,13 @@ observeDOM(() => { "Content-Type": "application/x-www-form-urlencoded" }, body: "hdnAppNo=" - }).then(res => res.arrayBuffer())); + }).then((res) => res.arrayBuffer())); const pages = pdfDoc.getPages(); const lastPage = pages[pages.length - 1]; - const { width, height: _ } = lastPage.getSize(); - const bannerImage = await pdfDoc.embedJpg(await fetch(sanghaFacilitationCentreBannerUrl).then(res => res.arrayBuffer())); + const { width } = lastPage.getSize(); + const bannerImage + = await pdfDoc.embedJpg(await fetch(sanghaFacilitationCentreBannerUrl) + .then((res) => res.arrayBuffer())); const bannerImageHeight = width * (bannerImage.height / bannerImage.width); lastPage.drawImage(bannerImage, { @@ -39,7 +42,7 @@ observeDOM(() => { height: bannerImageHeight }); - lastPage.drawText(pdfDoc.getCreationDate()!.toLocaleString(), { + lastPage.drawText(pdfDoc.getCreationDate()?.toLocaleString() ?? "", { x: 10, y: bannerImageHeight, size: 12, @@ -47,7 +50,7 @@ observeDOM(() => { }); const link = document.createElement("a"); - link.href = window.URL.createObjectURL(new Blob([new Uint8Array(await pdfDoc.save())], {type: "application/pdf"})); + link.href = window.URL.createObjectURL(new Blob([new Uint8Array(await pdfDoc.save())], { type: "application/pdf" })); link.download = "Declaration.pdf"; link.click(); })(); diff --git a/src/scripts/pages/sheet-map/index.ts b/src/scripts/pages/sheet-map/index.ts index a4e45b0..c16a2ae 100644 --- a/src/scripts/pages/sheet-map/index.ts +++ b/src/scripts/pages/sheet-map/index.ts @@ -1,23 +1,23 @@ -import { generateWebPage } from "@/shared/generate-web-page"; import getDownloadMapPDFPageContent from "@/scripts/pages/sheet-map/download-map-pdf-page-content.html"; -import getMapPlotPolygonPathElement from "@/scripts/pages/sheet-map/map-plot-polygon-path-element.html"; import getMapPlotNumberLabelTextElement from "@/scripts/pages/sheet-map/map-plot-number-label-text-element.html"; +import getMapPlotPolygonPathElement from "@/scripts/pages/sheet-map/map-plot-polygon-path-element.html"; import getPlotInformationElement from "@/scripts/pages/sheet-map/plot-information-element.html"; +import { generateWebPage } from "@/shared/generate-web-page"; -interface PlotPolygon { +type PlotPolygon = { plotArea: number; plotno: string; - polygon: string; + polygon: string }; -interface PlotNumberLabel { +type PlotNumberLabel = { plotno: string; - point: string; -} + point: string +}; -const headerElement = document.querySelector("#headerTable > tbody > tr")!; -const plotNumberInput = document.querySelector<HTMLInputElement>("#txtPlotNo")!; -const plotInformation = document.createElement("div") as HTMLDivElement; +const headerElement = document.querySelector<HTMLTableRowElement>("#headerTable > tbody > tr"); +const plotNumberInput = document.querySelector<HTMLInputElement>("#txtPlotNo"); +const plotInformation = document.createElement("div"); let plotPolygonPathElements = ""; let plotNumberLabelTextElements = ""; @@ -30,13 +30,14 @@ document.body.appendChild(plotInformation); * @param text - The button label text. * @returns The created button element. */ -const createHeaderButton = (text: string) => { +function createHeaderButton(text: string): HTMLButtonElement { const buttonContainer = document.createElement("td"); const button = document.createElement("button"); button.innerHTML = text; button.style.display = "none"; buttonContainer.appendChild(button); - headerElement.appendChild(buttonContainer); + if (headerElement) + headerElement.appendChild(buttonContainer); return button; }; @@ -46,14 +47,16 @@ const createHeaderButton = (text: string) => { * * @param plotPolygon - The selected plot's data, or `null`/`undefined` to clear. */ -const setPlotInformation = (plotPolygon: PlotPolygon | null | undefined = null) => { - plotInformation.innerHTML = plotPolygon ? getPlotInformationElement({ - area: (plotPolygon.plotArea/1000).toFixed(3), - plotNumber: plotPolygon.plotno - }) : getPlotInformationElement({ - area: "0.000", - plotNumber: "" - }); +function setPlotInformation(plotPolygon: PlotPolygon | null | undefined = null): void { + plotInformation.innerHTML = plotPolygon + ? getPlotInformationElement({ + area: (plotPolygon.plotArea / 1000).toFixed(3), + plotNumber: plotPolygon.plotno + }) + : getPlotInformationElement({ + area: "0.000", + plotNumber: "" + }); }; /** @@ -62,11 +65,10 @@ const setPlotInformation = (plotPolygon: PlotPolygon | null | undefined = null) * * @param labelPoints - Whether to include plot number text labels. */ -const downloadPDF = (labelPoints: boolean = true) => { +function downloadPDF(labelPoints = true): void { /** Extracts a detail value (district/block/mouza) from the header table by column index. */ - const _getMapDetail = (i: number) => { - const detail = document.querySelector(`#headerTable > tbody > tr > td:nth-child(${i})`)! - .innerHTML + function _getMapDetail(i: number): string { + const detail = (document.querySelector<HTMLTableCellElement>(`#headerTable > tbody > tr > td:nth-child(${i.toString()})`)?.innerHTML ?? "") .split("[")[1] .trim(); return detail.substring(0, detail.length - 1); @@ -85,33 +87,43 @@ const downloadPDF = (labelPoints: boolean = true) => { const downloadPDFButton = createHeaderButton("SAVE PDF"); const downloadPDFNoLabelButton = createHeaderButton("SAVE PDF (NO LABEL)"); -downloadPDFButton.addEventListener("click", e => { +downloadPDFButton.addEventListener("click", (e) => { e.preventDefault(); downloadPDF(); }); -downloadPDFNoLabelButton.addEventListener("click", e => { +downloadPDFNoLabelButton.addEventListener("click", (e) => { e.preventDefault(); downloadPDF(false); }); setPlotInformation(); -(async () => { +void (async function(): Promise<void> { const searchParams = new URLSearchParams(window.location.search); - const response1 = await fetch( - "/BanglarBhumi/sheetMap_populateLayerData?lstSheetNo=" + searchParams.get("lstSheetNo"), + const sheetMapLayerDataResponse = await fetch( + `/BanglarBhumi/sheetMap_populateLayerData?lstSheetNo=${searchParams.get("lstSheetNo")?.toString() ?? ""}`, { method: "POST" }); - const plotPolygonList: PlotPolygon[] = (await response1.json()).features; - const response2 = await fetch( - "/BanglarBhumi/sheetMap_populateCentroidData?lstSheetNo=" + searchParams.get("lstSheetNo"), + type SheetMapLayerDataResponseType = { + features: PlotPolygon[] + }; + const sheetMapLayerDataResponseJson + = await sheetMapLayerDataResponse.json() as SheetMapLayerDataResponseType; + const plotPolygonList: PlotPolygon[] = sheetMapLayerDataResponseJson.features; + const sheetMapCentroidDataResponse = await fetch( + `/BanglarBhumi/sheetMap_populateCentroidData?lstSheetNo=${searchParams.get("lstSheetNo")?.toString() ?? ""}`, { method: "POST" }); - const plotNumberLabelList: PlotNumberLabel[] = (await response2.json()).features; - let plotPolygons: { [key: string]: PlotPolygon } = {}; + type SheetMapCentroidDataResponseType = { + features: PlotNumberLabel[] + }; + const sheetMapCentroidDataResponseJson + = await sheetMapCentroidDataResponse.json() as SheetMapCentroidDataResponseType; + const plotNumberLabelList: PlotNumberLabel[] = sheetMapCentroidDataResponseJson.features; + const plotPolygons: Record<string, PlotPolygon> = {}; for (const plotPolygon of plotPolygonList) { const plotPolygonPoints = plotPolygon.polygon.split("(((")[1].split(")))")[0]; @@ -132,10 +144,10 @@ setPlotInformation(); downloadPDFButton.style.display = "inherit"; downloadPDFNoLabelButton.style.display = "inherit"; - document.querySelector("#btnSearch")!.addEventListener("click", () => { + document.querySelector<HTMLButtonElement>("#btnSearch")?.addEventListener("click", () => { let plotPolygon; for (const p of plotPolygonList) { - if (p.plotno === plotNumberInput.value) { + if (p.plotno === plotNumberInput?.value) { plotPolygon = p; break; } @@ -145,7 +157,7 @@ setPlotInformation(); await new Promise<void>((resolve, _reject) => { const plotElementIdsControl = setInterval(() => { - let plotElements = document.querySelector("#OpenLayers_Layer_Vector_25_vroot")?.children || []; + const plotElements = document.querySelector("#OpenLayers_Layer_Vector_25_vroot")?.children ?? []; if (plotElements.length) { clearInterval(plotElementIdsControl); for (let i = 0; i < plotElements.length; i++) { @@ -172,8 +184,8 @@ setPlotInformation(); * * @param e - The mouse click event. */ - const handlePlotClick = (e: MouseEvent) => { - document.querySelectorAll("path").forEach(e => { + function handlePlotClick(e: MouseEvent): void { + document.querySelectorAll("path").forEach((e) => { e.setAttribute("fill", "#ffcc66"); }); diff --git a/src/scripts/pages/view-khatian/index.ts b/src/scripts/pages/view-khatian/index.ts index 0be0c52..bb44a38 100644 --- a/src/scripts/pages/view-khatian/index.ts +++ b/src/scripts/pages/view-khatian/index.ts @@ -1,6 +1,6 @@ -import { generateWebPage } from "@/shared/generate-web-page"; -import { interceptPost } from "@/shared/intercept-jquery-ajax"; import getDownloadInformationPDFPageContent from "@/scripts/pages/view-khatian/download-information-pdf-page-content.html"; +import { generateWebPage } from "@/shared/generate-web-page"; +import { addPostInterceptor, JQueryAjaxArgs } from "@/shared/intercept-jquery-ajax"; const submitButtonElement = $("#khbutton"); const separatorElement = $("#bodycover > div > form > hr:nth-child(2)"); @@ -20,9 +20,9 @@ const styles = Array.from(submitButtonElementComputedStyles) * @param selector - CSS selector for the select element. * @returns The text of the selected option. */ -const getValueOfSelectElement = (selector: string) => { - const element = document.querySelector<HTMLSelectElement>(selector)!; - return element.options[element.selectedIndex].text; +function getValueOfSelectElement(selector: string): string { + const element = document.querySelector<HTMLSelectElement>(selector); + return element?.options[element.selectedIndex].text ?? ""; }; let isPlotInformation: boolean | null = null; @@ -31,11 +31,11 @@ let isPlotInformation: boolean | null = null; * Opens a new window with a printable PDF view of the current khatian * or plot details, including district/block/mouza info. */ -const downloadInformationPDF = () => { +function downloadInformationPDF(): void { generateWebPage( getDownloadInformationPDFPageContent({ isPlotInformation: !!isPlotInformation, - details: $(isPlotInformation ? "#plotdetails" : "#khdetails").html(), + details: $(isPlotInformation ? "#plotdetails" : "#khdetails").html() || "", district: getValueOfSelectElement("#lstDistrictCode1"), block: getValueOfSelectElement("#lstBlockCode1"), mouza: getValueOfSelectElement("#lstMouzaList") @@ -53,11 +53,11 @@ const downloadInformationPDF = () => { * * @param args - The `arguments` object from the intercepted `$.post` call. */ -const showDownloadButton = (args: any) => { +function showDownloadButton(args: JQueryAjaxArgs): void { if (isPlotInformation !== null) { const callback = args[2]; - args[2] = (data: any) => { - callback(data); + args[2] = (...data) => { + callback(...data); const tableElement = $(isPlotInformation ? "#plotdetails > div:nth-child(1) > div:nth-child(4) > table > tbody" : "#khdetails > table > tbody > tr > td:nth-child(1) > div:nth-child(5) > table > tbody" @@ -77,19 +77,19 @@ const showDownloadButton = (args: any) => { formElement[0].insertBefore(downloadPDFButton[0], separatorElement[0]); } } else if (downloadPDFButton) { - ($(downloadPDFButton as any) as any).remove(); + ($(downloadPDFButton)).remove(); isPlotInformation = null; downloadPDFButton = null; } - } + }; } }; -interceptPost("plotDetailsAction_LandInfo.action", args => { +addPostInterceptor("plotDetailsAction_LandInfo.action", (args: JQueryAjaxArgs) => { isPlotInformation = true; showDownloadButton(args); }); -interceptPost("khDetailsAction_LandInfo.action", args => { +addPostInterceptor("khDetailsAction_LandInfo.action", (args: JQueryAjaxArgs) => { isPlotInformation = false; showDownloadButton(args); }); |
