From 09897a51813f250bf49c336bfc97adb5597ad9bd Mon Sep 17 00:00:00 2001 From: Arcade69 <65565653+Arcade69@users.noreply.github.com> Date: Sun, 13 Apr 2025 01:36:50 +0200 Subject: [PATCH] Update Dashboard.jsx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ajout du widget qui génère des rapports détaillés du site sur un csv --- Front-end/src/pages/Admin/Dashboard.jsx | 95 +++++++++++++++++++++++-- 1 file changed, 88 insertions(+), 7 deletions(-) diff --git a/Front-end/src/pages/Admin/Dashboard.jsx b/Front-end/src/pages/Admin/Dashboard.jsx index cf44c35..1a945ae 100644 --- a/Front-end/src/pages/Admin/Dashboard.jsx +++ b/Front-end/src/pages/Admin/Dashboard.jsx @@ -4,10 +4,45 @@ import { RadioTower, ArrowRight, BadgePlus, Settings } from "lucide-react"; import { API_BASE_URL } from "../../config.js"; import axios from "axios"; +const exportCSV = () => { + const headers = ["Catégorie", "Valeur"]; + const rows = [ + ["Consommation énergétique", "1372 kWh"], + ["Taux de connexion", "87%"], + ["Service", "Consultation des données météo"], + ["Service", "Alertes et suivi de consommation"], + ["Service", "Ajout d'objets connectés"], + ]; + + const csvContent = + "\uFEFF" + + [headers, ...rows] + .map((row) => + row + .map((val) => `"${val.replace(/"/g, '""')}"`) + .join(",") + ) + .join("\n"); + + const blob = new Blob([csvContent], { + type: "text/csv;charset=utf-8;", + }); + + const link = document.createElement("a"); + link.href = URL.createObjectURL(blob); + link.setAttribute("download", "rapport_plateforme.csv"); + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); +}; + + const initialWidgets = [ { id: 1, type: "summary" }, { id: 2, type: "users" }, - { id: 3, type: "objects" }, + { id: 3, type: "reporting" }, + { id: 4, type: "adminobjet" }, + { id: 5, type: "objects" }, ]; function Dashboard() { @@ -16,14 +51,14 @@ function Dashboard() { const [logs, setLogs] = useState([ { id: 1, - username: "Alice", - action: "User added", + username: "complexe", + action: "Accès attribué", timestamp: new Date().toLocaleString(), }, { id: 2, - username: "Bob", - action: "Access assigned", + username: "admin", + action: "Accès attribué", timestamp: new Date().toLocaleString(), }, ]); @@ -31,6 +66,10 @@ function Dashboard() { axios.get(`${API_BASE_URL}/users`).then((response) => { setUsers(response.data); }); + + axios.get(`${API_BASE_URL}/objets`).then((response) => { + setAdminObjects(response.data); + }); }, []); const [adminObjects, setAdminObjects] = useState([ @@ -231,7 +270,7 @@ function Dashboard() { key={obj.id} className="border border-gray-200 p-2 rounded" > -

{obj.nom}

+

{obj.name}

{obj.type}

{obj.status}

@@ -245,6 +284,42 @@ function Dashboard() { )} + {widget.type === "reporting" && ( +
+

Rapports et Statistiques

+ +
+

Générer des rapports d'utilisation :

+
+ +
+
+ +
+
+

Consommation énergétique totale

+

1372 kWh cumulés (estimation)

+
+
+

Taux de connexion des utilisateurs

+

87% des utilisateurs actifs ce mois-ci

+
+
+

Services les plus utilisés

+
    +
  • Consultation des données météo
  • +
  • Alertes et suivi de consommation
  • +
  • Ajout d'objets connectés
  • +
+
+
+
+ )} ))} @@ -291,7 +366,13 @@ function Dashboard() { > Liste des Objets et Outils/Services - + +