diff --git a/backend/src/controller/scans/mod.rs b/backend/src/controller/scans/mod.rs index d32c409..c93fdfd 100644 --- a/backend/src/controller/scans/mod.rs +++ b/backend/src/controller/scans/mod.rs @@ -344,11 +344,12 @@ fn convert_to_pdf(image_path: &PathBuf, output_path: &PathBuf) -> Result<(), Str }; // Rotate image 45 degrees clockwise - let img = img.rotate270(); + // let img = img.rotate270(); // Generate PDF let (doc, page1, layer1) = - PdfDocument::new("Certificado - EEGSAC", Mm(297.0), Mm(210.0), "Layer 1"); + // PdfDocument::new("Certificado - EEGSAC", Mm(297.0), Mm(210.0), "Layer 1"); + PdfDocument::new("Certificado - EEGSAC", Mm(210.0), Mm(297.0), "Layer 1"); let current_layer = doc.get_page(page1).get_layer(layer1); @@ -369,6 +370,7 @@ fn convert_to_pdf(image_path: &PathBuf, output_path: &PathBuf) -> Result<(), Str let result = doc.save(&mut BufWriter::new(File::create(output_path).unwrap())); + // TODO: Delete image match result { Ok(_) => Ok(()), Err(reason) => { diff --git a/frontend/src/Scans/ScansList.tsx b/frontend/src/Scans/ScansList.tsx new file mode 100644 index 0000000..63c20ce --- /dev/null +++ b/frontend/src/Scans/ScansList.tsx @@ -0,0 +1,116 @@ +import { For, createMemo } from "solid-js"; +import { ScanData, ScanResult } from "."; +import { FilledButton } from "../components/FilledButton"; +import { FilledCard } from "../components/FilledCard"; +import { LoadingIcon } from "../icons/LoadingIcon"; +import { PDFIcon } from "../icons/PDFIcon"; +import { LoadingStatus, useLoading } from "../utils/functions"; + +export function ScansList(props: {scanData: ScanData | null}) { + const {status, setStatus, error, setError} = useLoading(); + + const loading = createMemo(() => status() === LoadingStatus.Loading); + + const convertScans = () => { + setStatus(LoadingStatus.Loading); + + if (props.scanData === null) { + setError("No se detectaron escaneos"); + setStatus(LoadingStatus.Error); + return; + } + + + fetch( + `${import.meta.env.VITE_BACKEND_URL}/api/scans/convert`, + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(props.scanData), + }, + ) + .then((res) => res.json()) + .then((res) => { + setStatus(LoadingStatus.Ok); + console.log(res); + }) + .catch((err) => { + setStatus(LoadingStatus.Error); + console.error(err); + }); + }; + + return ( + +

+ Escaneos detectados +

+ +
+ + {([path, result]) => ( +

+ + {path.substring(path.lastIndexOf("/") + 1)} + +
+ {dataFromScanResult(result)} +

+ )} +
+
+ +

+ - Al convertir los escaneos a PDF se eliminan los archivos JPG. +
+ - Solo se convertiran los escaneos mostrados en esta lista. +
+ - En la lista se muestran los nombres originales de los archivos. + Sin embargo, en el disco se cambiaron de nombre para asegurarse de + que solo 1 persona pueda transformarlos a la vez. +

+ +
+ + + + + + + + + + Convertir escaneos + + +
+
+ ); +} + + +function dataFromScanResult(result: ScanResult) { + if ("Full" in result) { + return `DNI: ${result.Full[0]}, iid: ${result.Full[1]}`; + } else if ("Partial" in result) { + return `DNI: ${result.Partial[0]}`; + } else if ("Error" in result) { + return `Error: ${result.Error}`; + } +} diff --git a/frontend/src/Scans/index.tsx b/frontend/src/Scans/index.tsx index 9631e0d..2b463f3 100644 --- a/frontend/src/Scans/index.tsx +++ b/frontend/src/Scans/index.tsx @@ -1,33 +1,25 @@ -import { For, createMemo, createSignal } from "solid-js"; +import { createMemo, createSignal } from "solid-js"; import { FilledButton } from "../components/FilledButton"; import { FilledCard } from "../components/FilledCard"; import { LoadingIcon } from "../icons/LoadingIcon"; import { MagnifyingGlassIcon } from "../icons/MagnifyingGlassIcon"; import { LoadingStatus, useLoading } from "../utils/functions"; -import { PDFIcon } from "../icons/PDFIcon"; +import { ScansList } from "./ScansList"; /** * Represents the data about the scans that were detected. * Serialization & Deserialization is done by the backend. */ -interface ScanData { +export interface ScanData { Ok: Array<[string, ScanResult]>, } -type ScanResult = +export type ScanResult = | {Full: [string, number, string]} | {Partial: [string, string]} | {Error: string}; -function dataFromScanResult(result: ScanResult) { - if ("Full" in result) { - return `DNI: ${result.Full[0]}, iid: ${result.Full[1]}`; - } else if ("Partial" in result) { - return `DNI: ${result.Partial[0]}`; - } else if ("Error" in result) { - return `Error: ${result.Error}`; - } -} + export function Scans() { const {status, setStatus, error, setError} = useLoading(); @@ -51,36 +43,6 @@ export function Scans() { }); }; - const convertScans = () => { - setStatus(LoadingStatus.Loading); - - if (scanData() === null) { - setError("No se detectaron escaneos"); - setStatus(LoadingStatus.Error); - return; - } - - - fetch( - `${import.meta.env.VITE_BACKEND_URL}/api/scans/convert`, - { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify(scanData()), - }, - ) - .then((res) => res.json()) - .then((res) => { - setStatus(LoadingStatus.Ok); - console.log(res); - }) - .catch((err) => { - setStatus(LoadingStatus.Error); - console.error(err); - }); - }; return (
@@ -147,13 +109,6 @@ export function Scans() { que cumplen con los parámetros de detección en la carpeta ESCANEOS, y los mostrará en una lista.

-

- La detección demora aprox. 1 segundo por cada archivo que - cumple con los parámetros. -

-

- Si la detección demora más de 90 segundos, se cancelará. -

@@ -188,64 +143,7 @@ export function Scans() {
- -

- Escaneos detectados -

- -
- - {([path, result]) => ( -

- - {path.substring(path.lastIndexOf("/") + 1)} - -
- {dataFromScanResult(result)} -

- )} -
-
- -

- - Al convertir los escaneos a PDF se eliminan los archivos JPG. -
- - Solo se convertiran los escaneos mostrados en esta lista. -
- - Si ejecutas la detección de escaneos nuevamente los nombres de - los archivos cambiarán. Esto es normal. El contenido de los JPG - es el mismo. -

- -
- - - - - - - - - - Convertir escaneos - - -
-
+
);