From b44ba94e913d3ffc2ec473c10e452fd2b2b92b25 Mon Sep 17 00:00:00 2001 From: IvanJGG Date: Mon, 30 Sep 2024 21:57:07 -0600 Subject: [PATCH 1/7] Add dashboard --- templates/index.twig | 1 + views/dashboard/blocks/visitsbutton.html | 6 ++ views/dashboard/index.html | 78 ++++++++++++++++++++++++ views/dashboard/script.js | 0 4 files changed, 85 insertions(+) create mode 100644 views/dashboard/blocks/visitsbutton.html create mode 100644 views/dashboard/index.html create mode 100644 views/dashboard/script.js diff --git a/templates/index.twig b/templates/index.twig index a679b29..343184c 100644 --- a/templates/index.twig +++ b/templates/index.twig @@ -8,6 +8,7 @@ {{ title }} +

{{ title }}

diff --git a/views/dashboard/blocks/visitsbutton.html b/views/dashboard/blocks/visitsbutton.html new file mode 100644 index 0000000..c47d50b --- /dev/null +++ b/views/dashboard/blocks/visitsbutton.html @@ -0,0 +1,6 @@ + + \ No newline at end of file diff --git a/views/dashboard/index.html b/views/dashboard/index.html new file mode 100644 index 0000000..94e9973 --- /dev/null +++ b/views/dashboard/index.html @@ -0,0 +1,78 @@ +
+
+
+

+
+ +
+ + + + + +
+ +
+
+
+
+ + + + + + diff --git a/views/dashboard/script.js b/views/dashboard/script.js new file mode 100644 index 0000000..e69de29 From 918867be5f26ff4898f7a10ac97a8cec6f6ff8f5 Mon Sep 17 00:00:00 2001 From: IvanJGG Date: Mon, 6 Jan 2025 21:46:24 -0600 Subject: [PATCH 2/7] CAF-43 Creation of Package Control Interface and Test --- tests/cypress/e2e/dashboard.cy.js | 4 +- tests/cypress/e2e/packages.cy.js | 40 ++++++++ .../dashboard/blocks/parcelControlbutton.html | 2 +- views/packages/assets/index.js | 98 +++++++++++++++++++ views/packages/index.html | 25 +++++ 5 files changed, 166 insertions(+), 3 deletions(-) create mode 100644 tests/cypress/e2e/packages.cy.js create mode 100644 views/packages/assets/index.js create mode 100644 views/packages/index.html diff --git a/tests/cypress/e2e/dashboard.cy.js b/tests/cypress/e2e/dashboard.cy.js index 5a54380..316da4b 100644 --- a/tests/cypress/e2e/dashboard.cy.js +++ b/tests/cypress/e2e/dashboard.cy.js @@ -32,7 +32,7 @@ describe("Role-based button functionality", () => { cy.visitWithToken("/dashboard"); cy.get("#btnParcelControl").contains("Control de paquetería").click(); - cy.url().should("include", "/parcelControl"); + cy.url().should("include", "/packages"); cy.visitWithToken("/dashboard"); }); }); @@ -62,7 +62,7 @@ describe("Role-based button functionality", () => { cy.visitWithToken("/dashboard"); cy.get("#btnParcelControl").contains("Control de paquetería").click(); - cy.url().should("include", "/parcelControl"); + cy.url().should("include", "/packages"); }); }); diff --git a/tests/cypress/e2e/packages.cy.js b/tests/cypress/e2e/packages.cy.js new file mode 100644 index 0000000..cd3e10d --- /dev/null +++ b/tests/cypress/e2e/packages.cy.js @@ -0,0 +1,40 @@ +describe("Packages Table", () => { + beforeEach(() => { + cy.intercept("GET", "/packages", { + statusCode: 200, + body: { + message: "OK", + data: { + packages: [ + { + id: 1, + service: "Delivery", + received_at: "2023-12-20 14:00:00", + confirmed_at: null, + address_id: 123, + status: 1, + }, + ], + }, + }, + }).as("getPackages"); + + }); + + it("should display the packages table", () => { + cy.visitWithToken("/packages"); + + cy.wait("@getPackages"); + + cy.get("#packageTable").should("exist"); + + cy.get('[data-cy="btnConfirm"]').should("exist"); + + + cy.get("#packageTable tr").then(($rows) => { + const numRows = $rows.length; + cy.get('[data-cy="btnConfirm"]').should("have.length", numRows); + }); + }); + +}); diff --git a/views/dashboard/blocks/parcelControlbutton.html b/views/dashboard/blocks/parcelControlbutton.html index 4a4d503..5ee724f 100644 --- a/views/dashboard/blocks/parcelControlbutton.html +++ b/views/dashboard/blocks/parcelControlbutton.html @@ -4,7 +4,7 @@ id="btnParcelControl" class="btn btn-primary btn-lg me-3" style="width: 150px; height: 150px" - onclick="navigateTo('/parcelControl')" + onclick="navigateTo('/packages')" > local_shipping
Control de paquetería diff --git a/views/packages/assets/index.js b/views/packages/assets/index.js new file mode 100644 index 0000000..3af40c2 --- /dev/null +++ b/views/packages/assets/index.js @@ -0,0 +1,98 @@ +async function fetchPackages() { + try { + return await apiRequest("GET", "packages"); + } catch (error) { + console.error("Error al cargar paquetes:", error); + return null; + } +} + +function createCell(textContent) { + const cell = document.createElement("td"); + cell.textContent = textContent; + return cell; +} + +function createActionsCell(pkg) { + const actionsCell = document.createElement("td"); + + const confirmButton = createConfirmButton(pkg.id); + actionsCell.appendChild(confirmButton); + + return actionsCell; +} + +function createPackageRow(pkg) { + const row = document.createElement("tr"); + + const serviceCell = createCell(pkg.service); + const receivedCell = createCell(pkg.received_at); + const confirmationCell = createCell(pkg.confirmed_at); + const addressCell = createCell(pkg.address_id); + const statusCell = createCell(pkg.status); + const actionsCell = createActionsCell(pkg); + + row.appendChild(serviceCell); + row.appendChild(receivedCell); + row.appendChild(confirmationCell); + row.appendChild(addressCell); + row.appendChild(statusCell); + row.appendChild(actionsCell); + + return row; +} + +function createConfirmButton(packageId) { + + const confirmButton = document.createElement("button"); + confirmButton.className = "btn btn-outline-success btn-sm"; + confirmButton.title = "Confirmar Entrega"; + confirmButton.setAttribute("data-cy", "btnConfirm"); + + const confirmIcon = document.createElement("span"); + confirmIcon.className = "material-symbols-outlined"; + confirmIcon.textContent = "check_circle"; + confirmButton.appendChild(confirmIcon); + + confirmButton.onclick = async () => { + try { + const response = await apiRequest("POST", `packages/${packageId}/confirm`); + if (response.success) { + alert("Entrega confirmada."); + await loadPackagesTable(); + } else { + alert("No se pudo confirmar la entrega."); + } + } catch (error) { + console.error("Error al confirmar entrega ", error); + } + }; + + return confirmButton; +} + +async function loadPackagesTable() { + try { + const response = await fetchPackages(); + + console.log("API Response:", response); + + const packageTable = document.getElementById("packageTable"); + packageTable.innerHTML = ""; + + response.data.packages.forEach((pkg) => { + const row = createPackageRow(pkg); + packageTable.appendChild(row); + }); + } catch (error) { + console.error("Error al cargar la tabla de paquetes ", error); + } +} + +document.getElementById("registerPackage").addEventListener("click", () => { + window.location.href = "/packages/register.html"; +}); + +window.addEventListener("load", async () => { + await loadPackagesTable(); +}); diff --git a/views/packages/index.html b/views/packages/index.html new file mode 100644 index 0000000..781dd1a --- /dev/null +++ b/views/packages/index.html @@ -0,0 +1,25 @@ +
+
+
+

Lista de Entregas

+ + + + + + + + + + + + + + + +
ServicioFecha y Hora de RecibidoFecha y Hora de ConfirmadoDirecciónEstatusAcciones
+
+
+
+ + \ No newline at end of file From 477083a05321420eeea92fcb740e3721f8b33ee0 Mon Sep 17 00:00:00 2001 From: IvanJGG Date: Tue, 7 Jan 2025 17:12:29 -0600 Subject: [PATCH 3/7] CAF-43 Saving changes --- tests/cypress/e2e/packages.cy.js | 15 +++++---------- views/packages/assets/index.js | 22 ++++++++++++++++------ 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/tests/cypress/e2e/packages.cy.js b/tests/cypress/e2e/packages.cy.js index cd3e10d..6364c22 100644 --- a/tests/cypress/e2e/packages.cy.js +++ b/tests/cypress/e2e/packages.cy.js @@ -9,10 +9,10 @@ describe("Packages Table", () => { { id: 1, service: "Delivery", - received_at: "2023-12-20 14:00:00", - confirmed_at: null, - address_id: 123, - status: 1, + receivedAt: "2023-12-20 14:00:00", + confirmedAt: null, + address: 123, + statusname: 1, }, ], }, @@ -28,13 +28,8 @@ describe("Packages Table", () => { cy.get("#packageTable").should("exist"); - cy.get('[data-cy="btnConfirm"]').should("exist"); - - cy.get("#packageTable tr").then(($rows) => { - const numRows = $rows.length; - cy.get('[data-cy="btnConfirm"]').should("have.length", numRows); - }); }); + }); diff --git a/views/packages/assets/index.js b/views/packages/assets/index.js index 3af40c2..5e6b070 100644 --- a/views/packages/assets/index.js +++ b/views/packages/assets/index.js @@ -13,6 +13,11 @@ function createCell(textContent) { return cell; } +function formatDate(dateString) { + const date = new Date(dateString); + return date.toLocaleString(); +} + function createActionsCell(pkg) { const actionsCell = document.createElement("td"); @@ -26,10 +31,10 @@ function createPackageRow(pkg) { const row = document.createElement("tr"); const serviceCell = createCell(pkg.service); - const receivedCell = createCell(pkg.received_at); - const confirmationCell = createCell(pkg.confirmed_at); - const addressCell = createCell(pkg.address_id); - const statusCell = createCell(pkg.status); + const receivedCell = createCell(formatDate(pkg.receivedAt)); + const confirmationCell = createCell(formatDate(pkg.confirmedAt)); + const addressCell = createCell(pkg.address); + const statusCell = createCell(pkg.statusName); const actionsCell = createActionsCell(pkg); row.appendChild(serviceCell); @@ -42,12 +47,14 @@ function createPackageRow(pkg) { return row; } -function createConfirmButton(packageId) { +function createConfirmButton(pkg) { const confirmButton = document.createElement("button"); confirmButton.className = "btn btn-outline-success btn-sm"; confirmButton.title = "Confirmar Entrega"; confirmButton.setAttribute("data-cy", "btnConfirm"); + confirmButton.setAttribute("data-package-id", pkg.id); + const confirmIcon = document.createElement("span"); confirmIcon.className = "material-symbols-outlined"; @@ -56,7 +63,7 @@ function createConfirmButton(packageId) { confirmButton.onclick = async () => { try { - const response = await apiRequest("POST", `packages/${packageId}/confirm`); + const response = await apiRequest("POST", `packages/${pkg.id}/confirm`); if (response.success) { alert("Entrega confirmada."); await loadPackagesTable(); @@ -84,6 +91,9 @@ async function loadPackagesTable() { const row = createPackageRow(pkg); packageTable.appendChild(row); }); + + console.log("Table content:", packageTable.innerHTML); + } catch (error) { console.error("Error al cargar la tabla de paquetes ", error); } From 17ea19cdbae5e38fd6c0f42348029af08832d59c Mon Sep 17 00:00:00 2001 From: IvanJGG Date: Tue, 7 Jan 2025 17:26:59 -0600 Subject: [PATCH 4/7] CAF-43 Saving changes --- tests/cypress/e2e/packages.cy.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/tests/cypress/e2e/packages.cy.js b/tests/cypress/e2e/packages.cy.js index 6364c22..e5def48 100644 --- a/tests/cypress/e2e/packages.cy.js +++ b/tests/cypress/e2e/packages.cy.js @@ -4,18 +4,16 @@ describe("Packages Table", () => { statusCode: 200, body: { message: "OK", - data: { - packages: [ - { - id: 1, - service: "Delivery", - receivedAt: "2023-12-20 14:00:00", - confirmedAt: null, - address: 123, - statusname: 1, - }, - ], - }, + packages: [ + { + id: 1, + service: "Delivery", + receivedAt: "2023-12-20 14:00:00", + confirmedAt: null, + address: "Fake Street 123", + statusName: "confirmar", + }, + ], }, }).as("getPackages"); From a57636db3e8093c63371dfb77112fdeff089c2ae Mon Sep 17 00:00:00 2001 From: IvanJGG Date: Tue, 7 Jan 2025 19:38:17 -0600 Subject: [PATCH 5/7] CAF-43 Add more test --- tests/cypress/e2e/packages.cy.js | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/tests/cypress/e2e/packages.cy.js b/tests/cypress/e2e/packages.cy.js index e5def48..9a04bf8 100644 --- a/tests/cypress/e2e/packages.cy.js +++ b/tests/cypress/e2e/packages.cy.js @@ -17,17 +17,37 @@ describe("Packages Table", () => { }, }).as("getPackages"); - }); - - it("should display the packages table", () => { cy.visitWithToken("/packages"); - cy.wait("@getPackages"); + }); + it("should display the packages table with confirmation buttons", () => { + cy.wait("@getPackages"); cy.get("#packageTable").should("exist"); + cy.get('[data-cy="btnConfirm"]').should("exist"); + cy.get("#packageTable tr").then(($rows) => { + const numRows = $rows.length; + cy.get('[data-cy="btnConfirm"]').should("have.length", numRows); + }); + }); + it("should display an empty table with an error message when the API request fails", () => { + cy.intercept("GET", "/packages", { + statusCode: 500, + body: { message: "Internal Server Error" }, + }).as("getPackagesError"); + cy.visitWithToken("/packages"); + cy.wait("@getPackagesError"); + + cy.get("#packageTable").should("exist"); + cy.get("#packageTable tr").should("have.length", 0); }); + it("should display a confirmation button for each package", () => { + cy.wait("@getPackages"); + cy.get("#packageTable").should("exist"); + cy.get('[data-cy="btnConfirm"]').should("exist"); + }); }); From a4bc310824dc6bd25490fd2115dc8911f73c459c Mon Sep 17 00:00:00 2001 From: IvanJGG Date: Tue, 7 Jan 2025 19:40:00 -0600 Subject: [PATCH 6/7] CAF-43 Delete consoles --- views/packages/assets/index.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/views/packages/assets/index.js b/views/packages/assets/index.js index 5e6b070..f908d3b 100644 --- a/views/packages/assets/index.js +++ b/views/packages/assets/index.js @@ -82,8 +82,6 @@ async function loadPackagesTable() { try { const response = await fetchPackages(); - console.log("API Response:", response); - const packageTable = document.getElementById("packageTable"); packageTable.innerHTML = ""; @@ -92,8 +90,6 @@ async function loadPackagesTable() { packageTable.appendChild(row); }); - console.log("Table content:", packageTable.innerHTML); - } catch (error) { console.error("Error al cargar la tabla de paquetes ", error); } From 950cf15e763563eb75402b6ebe3eb9c793d2f785 Mon Sep 17 00:00:00 2001 From: IvanJGG Date: Tue, 7 Jan 2025 19:43:23 -0600 Subject: [PATCH 7/7] CAF-43 Apply yarn prettier --- tests/cypress/e2e/packages.cy.js | 98 ++++++++++----------- views/packages/assets/index.js | 147 +++++++++++++++---------------- views/packages/index.html | 45 +++++----- 3 files changed, 143 insertions(+), 147 deletions(-) diff --git a/tests/cypress/e2e/packages.cy.js b/tests/cypress/e2e/packages.cy.js index 9a04bf8..f52c5f9 100644 --- a/tests/cypress/e2e/packages.cy.js +++ b/tests/cypress/e2e/packages.cy.js @@ -1,53 +1,51 @@ describe("Packages Table", () => { - beforeEach(() => { - cy.intercept("GET", "/packages", { - statusCode: 200, - body: { - message: "OK", - packages: [ - { - id: 1, - service: "Delivery", - receivedAt: "2023-12-20 14:00:00", - confirmedAt: null, - address: "Fake Street 123", - statusName: "confirmar", - }, - ], - }, - }).as("getPackages"); - - cy.visitWithToken("/packages"); - - }); - - it("should display the packages table with confirmation buttons", () => { - cy.wait("@getPackages"); - cy.get("#packageTable").should("exist"); - cy.get('[data-cy="btnConfirm"]').should("exist"); - cy.get("#packageTable tr").then(($rows) => { - const numRows = $rows.length; - cy.get('[data-cy="btnConfirm"]').should("have.length", numRows); - }); + beforeEach(() => { + cy.intercept("GET", "/packages", { + statusCode: 200, + body: { + message: "OK", + packages: [ + { + id: 1, + service: "Delivery", + receivedAt: "2023-12-20 14:00:00", + confirmedAt: null, + address: "Fake Street 123", + statusName: "confirmar", + }, + ], + }, + }).as("getPackages"); + + cy.visitWithToken("/packages"); + }); + + it("should display the packages table with confirmation buttons", () => { + cy.wait("@getPackages"); + cy.get("#packageTable").should("exist"); + cy.get('[data-cy="btnConfirm"]').should("exist"); + cy.get("#packageTable tr").then(($rows) => { + const numRows = $rows.length; + cy.get('[data-cy="btnConfirm"]').should("have.length", numRows); }); - - it("should display an empty table with an error message when the API request fails", () => { - cy.intercept("GET", "/packages", { - statusCode: 500, - body: { message: "Internal Server Error" }, - }).as("getPackagesError"); - - cy.visitWithToken("/packages"); - cy.wait("@getPackagesError"); - - cy.get("#packageTable").should("exist"); - cy.get("#packageTable tr").should("have.length", 0); - }); - - it("should display a confirmation button for each package", () => { - cy.wait("@getPackages"); - cy.get("#packageTable").should("exist"); - cy.get('[data-cy="btnConfirm"]').should("exist"); - }); - + }); + + it("should display an empty table with an error message when the API request fails", () => { + cy.intercept("GET", "/packages", { + statusCode: 500, + body: { message: "Internal Server Error" }, + }).as("getPackagesError"); + + cy.visitWithToken("/packages"); + cy.wait("@getPackagesError"); + + cy.get("#packageTable").should("exist"); + cy.get("#packageTable tr").should("have.length", 0); + }); + + it("should display a confirmation button for each package", () => { + cy.wait("@getPackages"); + cy.get("#packageTable").should("exist"); + cy.get('[data-cy="btnConfirm"]').should("exist"); + }); }); diff --git a/views/packages/assets/index.js b/views/packages/assets/index.js index f908d3b..8cc0ed4 100644 --- a/views/packages/assets/index.js +++ b/views/packages/assets/index.js @@ -1,104 +1,101 @@ async function fetchPackages() { - try { - return await apiRequest("GET", "packages"); - } catch (error) { - console.error("Error al cargar paquetes:", error); - return null; - } + try { + return await apiRequest("GET", "packages"); + } catch (error) { + console.error("Error al cargar paquetes:", error); + return null; + } } function createCell(textContent) { - const cell = document.createElement("td"); - cell.textContent = textContent; - return cell; + const cell = document.createElement("td"); + cell.textContent = textContent; + return cell; } function formatDate(dateString) { - const date = new Date(dateString); - return date.toLocaleString(); + const date = new Date(dateString); + return date.toLocaleString(); } function createActionsCell(pkg) { - const actionsCell = document.createElement("td"); + const actionsCell = document.createElement("td"); - const confirmButton = createConfirmButton(pkg.id); - actionsCell.appendChild(confirmButton); + const confirmButton = createConfirmButton(pkg.id); + actionsCell.appendChild(confirmButton); - return actionsCell; + return actionsCell; } function createPackageRow(pkg) { - const row = document.createElement("tr"); - - const serviceCell = createCell(pkg.service); - const receivedCell = createCell(formatDate(pkg.receivedAt)); - const confirmationCell = createCell(formatDate(pkg.confirmedAt)); - const addressCell = createCell(pkg.address); - const statusCell = createCell(pkg.statusName); - const actionsCell = createActionsCell(pkg); - - row.appendChild(serviceCell); - row.appendChild(receivedCell); - row.appendChild(confirmationCell); - row.appendChild(addressCell); - row.appendChild(statusCell); - row.appendChild(actionsCell); - - return row; + const row = document.createElement("tr"); + + const serviceCell = createCell(pkg.service); + const receivedCell = createCell(formatDate(pkg.receivedAt)); + const confirmationCell = createCell(formatDate(pkg.confirmedAt)); + const addressCell = createCell(pkg.address); + const statusCell = createCell(pkg.statusName); + const actionsCell = createActionsCell(pkg); + + row.appendChild(serviceCell); + row.appendChild(receivedCell); + row.appendChild(confirmationCell); + row.appendChild(addressCell); + row.appendChild(statusCell); + row.appendChild(actionsCell); + + return row; } function createConfirmButton(pkg) { + const confirmButton = document.createElement("button"); + confirmButton.className = "btn btn-outline-success btn-sm"; + confirmButton.title = "Confirmar Entrega"; + confirmButton.setAttribute("data-cy", "btnConfirm"); + confirmButton.setAttribute("data-package-id", pkg.id); + + const confirmIcon = document.createElement("span"); + confirmIcon.className = "material-symbols-outlined"; + confirmIcon.textContent = "check_circle"; + confirmButton.appendChild(confirmIcon); + + confirmButton.onclick = async () => { + try { + const response = await apiRequest("POST", `packages/${pkg.id}/confirm`); + if (response.success) { + alert("Entrega confirmada."); + await loadPackagesTable(); + } else { + alert("No se pudo confirmar la entrega."); + } + } catch (error) { + console.error("Error al confirmar entrega ", error); + } + }; - const confirmButton = document.createElement("button"); - confirmButton.className = "btn btn-outline-success btn-sm"; - confirmButton.title = "Confirmar Entrega"; - confirmButton.setAttribute("data-cy", "btnConfirm"); - confirmButton.setAttribute("data-package-id", pkg.id); - - - const confirmIcon = document.createElement("span"); - confirmIcon.className = "material-symbols-outlined"; - confirmIcon.textContent = "check_circle"; - confirmButton.appendChild(confirmIcon); - - confirmButton.onclick = async () => { - try { - const response = await apiRequest("POST", `packages/${pkg.id}/confirm`); - if (response.success) { - alert("Entrega confirmada."); - await loadPackagesTable(); - } else { - alert("No se pudo confirmar la entrega."); - } - } catch (error) { - console.error("Error al confirmar entrega ", error); - } - }; - - return confirmButton; + return confirmButton; } async function loadPackagesTable() { - try { - const response = await fetchPackages(); - - const packageTable = document.getElementById("packageTable"); - packageTable.innerHTML = ""; - - response.data.packages.forEach((pkg) => { - const row = createPackageRow(pkg); - packageTable.appendChild(row); - }); - - } catch (error) { - console.error("Error al cargar la tabla de paquetes ", error); - } + try { + const response = await fetchPackages(); + + const packageTable = document.getElementById("packageTable"); + packageTable.innerHTML = ""; + + response.data.packages.forEach((pkg) => { + const row = createPackageRow(pkg); + packageTable.appendChild(row); + }); + } catch (error) { + console.error("Error al cargar la tabla de paquetes ", error); + } } document.getElementById("registerPackage").addEventListener("click", () => { - window.location.href = "/packages/register.html"; + window.location.href = "/packages/register.html"; }); window.addEventListener("load", async () => { - await loadPackagesTable(); + await loadPackagesTable(); }); diff --git a/views/packages/index.html b/views/packages/index.html index 781dd1a..69d908c 100644 --- a/views/packages/index.html +++ b/views/packages/index.html @@ -1,25 +1,26 @@
-
-
-

Lista de Entregas

- - - - - - - - - - - - - - - -
ServicioFecha y Hora de RecibidoFecha y Hora de ConfirmadoDirecciónEstatusAcciones
-
+
+
+

Lista de Entregas

+ + + + + + + + + + + + + + + +
ServicioFecha y Hora de RecibidoFecha y Hora de ConfirmadoDirecciónEstatusAcciones
- - \ No newline at end of file +
+