Merge branch 'infoHomePage'
This commit is contained in:
commit
bc08395e50
@ -69,6 +69,8 @@ public class MainVerticle extends AbstractVerticle {
|
|||||||
router.post("/changePassword").handler(setUser::changeUserPassword);
|
router.post("/changePassword").handler(setUser::changeUserPassword);
|
||||||
router.post("/publicUser").handler(queryUsers::getPublicUser);
|
router.post("/publicUser").handler(queryUsers::getPublicUser);
|
||||||
router.get("/getCategories").handler(queryObjects::getCategories);
|
router.get("/getCategories").handler(queryObjects::getCategories);
|
||||||
|
router.get("/getLocations").handler(queryObjects::getLocations);
|
||||||
|
router.post("/getMeteoHome").handler(queryWeather::getMeteoInfosHomePage);
|
||||||
router.post("/addCategories").handler(setObjects::newCategorie);
|
router.post("/addCategories").handler(setObjects::newCategorie);
|
||||||
router.post("/deleteCategories").handler(setObjects::deleteCategories);
|
router.post("/deleteCategories").handler(setObjects::deleteCategories);
|
||||||
router.post("/requestDeleteObject").handler(RequestDeleteObject::deleteObject);
|
router.post("/requestDeleteObject").handler(RequestDeleteObject::deleteObject);
|
||||||
|
|||||||
@ -40,6 +40,33 @@ public class QueryObjects {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void getLocations(RoutingContext context) {
|
||||||
|
databaseService.pool
|
||||||
|
.query("SELECT DISTINCT location FROM weather_objects;")
|
||||||
|
.execute()
|
||||||
|
.onFailure(e -> {
|
||||||
|
System.err.println("Erreur de récupération de la BDD :" + e.getMessage());
|
||||||
|
context.response()
|
||||||
|
.setStatusCode(500)
|
||||||
|
.end(new JsonObject().put("error", "Erreur de récupération de la BDD").encode());
|
||||||
|
})
|
||||||
|
.onSuccess(rows -> {
|
||||||
|
if (!rows.iterator().hasNext()) {
|
||||||
|
context.response()
|
||||||
|
.setStatusCode(404)
|
||||||
|
.end(new JsonObject().put("error", "Aucun lieu trouvé dans la base de données").encode());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonArray types = new JsonArray();
|
||||||
|
rows.forEach(row -> types.add(row.getString("location")));
|
||||||
|
|
||||||
|
context.response()
|
||||||
|
.putHeader("content-type", "application/json; charset=UTF-8")
|
||||||
|
.end(types.encode());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public void getCategories(RoutingContext context) {
|
public void getCategories(RoutingContext context) {
|
||||||
databaseService.pool
|
databaseService.pool
|
||||||
.query("SELECT name FROM categories;")
|
.query("SELECT name FROM categories;")
|
||||||
|
|||||||
@ -48,6 +48,42 @@ public class QueryWeatherData {
|
|||||||
.end((convertRowsToJson(rows)).encode());
|
.end((convertRowsToJson(rows)).encode());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void getMeteoInfosHomePage(RoutingContext context) {
|
||||||
|
JsonObject body = context.body().asJsonObject();
|
||||||
|
String location = body.getString("location");
|
||||||
|
if (location == null) {
|
||||||
|
context.response()
|
||||||
|
.setStatusCode(400)
|
||||||
|
.end(new JsonObject().put("error", "Paramètre 'location' manquant").encode());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
System.out.println("Paramètre passé à la requête : '" + location + "'");
|
||||||
|
databaseService.pool
|
||||||
|
.query("SELECT wd.wind_speed, wd.temperature, wd.humidity, wd.pressure FROM weather_data wd " +
|
||||||
|
"JOIN weather_objects s ON wd.station_id = s.id WHERE s.location = '" + location +
|
||||||
|
"' ORDER BY wd.timestamp DESC LIMIT 1;")
|
||||||
|
.execute()
|
||||||
|
.onFailure(e -> {
|
||||||
|
System.err.println("Erreur de récupération de la BDD : " + e.getMessage());
|
||||||
|
context.response()
|
||||||
|
.setStatusCode(500)
|
||||||
|
.end(new JsonObject().put("error", "Erreur de récupération de la BDD").encode());
|
||||||
|
})
|
||||||
|
.onSuccess(rows -> {
|
||||||
|
if (rows.size() == 0) {
|
||||||
|
context.response()
|
||||||
|
.setStatusCode(404)
|
||||||
|
.end(new JsonObject().put("error", "Aucune donnée trouvée pour cette location").encode());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
context.response()
|
||||||
|
.putHeader("content-type", "application/json; charset=UTF-8")
|
||||||
|
.end(convertRowsToJson(rows).encode());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public void getMeteoInfos(RoutingContext context) {
|
public void getMeteoInfos(RoutingContext context) {
|
||||||
String id = context.request().getParam("id");
|
String id = context.request().getParam("id");
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
@ -78,35 +114,37 @@ public class QueryWeatherData {
|
|||||||
.end((convertRowsToJson(rows)).encode());
|
.end((convertRowsToJson(rows)).encode());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
public void getRangeData(RoutingContext context){
|
|
||||||
String id= context.request().getParam("id");
|
public void getRangeData(RoutingContext context) {
|
||||||
if(id==null){
|
String id = context.request().getParam("id");
|
||||||
|
if (id == null) {
|
||||||
context.response()
|
context.response()
|
||||||
.setStatusCode(400)
|
.setStatusCode(400)
|
||||||
.end(new JsonObject().put("error","Paramètre 'id' manquant").encode());
|
.end(new JsonObject().put("error", "Paramètre 'id' manquant").encode());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
databaseService.pool
|
databaseService.pool
|
||||||
.preparedQuery("SELECT temperature_min,temperature_max,pressure_min,pressure_max,humidity_min,humidity_max FROM range_data WHERE station_id=?")
|
.preparedQuery(
|
||||||
.execute(Tuple.of(Integer.parseInt(id)))
|
"SELECT temperature_min,temperature_max,pressure_min,pressure_max,humidity_min,humidity_max FROM range_data WHERE station_id=?")
|
||||||
.onFailure(e->{
|
.execute(Tuple.of(Integer.parseInt(id)))
|
||||||
System.err.println("Erreur de récupération de la BDD: "+e.getMessage());
|
.onFailure(e -> {
|
||||||
context.response()
|
System.err.println("Erreur de récupération de la BDD: " + e.getMessage());
|
||||||
.setStatusCode(500)
|
context.response()
|
||||||
.end(new JsonObject().put("error","Erreur de récupération de la BDD").encode());
|
.setStatusCode(500)
|
||||||
return;
|
.end(new JsonObject().put("error", "Erreur de récupération de la BDD").encode());
|
||||||
})
|
return;
|
||||||
.onSuccess(rows->{
|
})
|
||||||
if(rows.size() == 0){
|
.onSuccess(rows -> {
|
||||||
context.response()
|
if (rows.size() == 0) {
|
||||||
.setStatusCode(404)
|
context.response()
|
||||||
.end(new JsonObject().put("error","Objet non trouvé").encode());
|
.setStatusCode(404)
|
||||||
return;
|
.end(new JsonObject().put("error", "Objet non trouvé").encode());
|
||||||
}
|
return;
|
||||||
context.response()
|
}
|
||||||
.putHeader("content-type","application/json:charset=UTF-8")
|
context.response()
|
||||||
.end((convertRowsToJson(rows)).encode());
|
.putHeader("content-type", "application/json:charset=UTF-8")
|
||||||
});
|
.end((convertRowsToJson(rows)).encode());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private JsonArray convertRowsToJson(RowSet<Row> rows) {
|
private JsonArray convertRowsToJson(RowSet<Row> rows) {
|
||||||
@ -116,13 +154,13 @@ public class QueryWeatherData {
|
|||||||
JsonObject jsonObject = new JsonObject();
|
JsonObject jsonObject = new JsonObject();
|
||||||
for (int i = 0; i < row.size(); i++) {
|
for (int i = 0; i < row.size(); i++) {
|
||||||
String column = row.getColumnName(i);
|
String column = row.getColumnName(i);
|
||||||
if(column.compareTo("timestamp") == 0){
|
if (column.compareTo("timestamp") == 0) {
|
||||||
jsonObject.put("timestamp",row.getLocalDateTime("timestamp").format(formatter));
|
jsonObject.put("timestamp", row.getLocalDateTime("timestamp").format(formatter));
|
||||||
}else{
|
} else {
|
||||||
jsonObject.put(column, row.getValue(column));
|
jsonObject.put(column, row.getValue(column));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
jsonArray.add(jsonObject);
|
jsonArray.add(jsonObject);
|
||||||
}
|
}
|
||||||
return jsonArray;
|
return jsonArray;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,13 +20,17 @@ import {
|
|||||||
TowerControl,
|
TowerControl,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { useAuth } from "../AuthContext";
|
import { useAuth } from "../AuthContext";
|
||||||
|
import axios from "axios";
|
||||||
|
import { API_BASE_URL } from "../config";
|
||||||
|
|
||||||
function EnhancedWeatherHome() {
|
function EnhancedWeatherHome() {
|
||||||
const [searchQuery, setSearchQuery] = useState("");
|
const [searchQuery, setSearchQuery] = useState("");
|
||||||
|
const [locations, setLocations] = useState([]);
|
||||||
|
const [infoMeteo,setInfoMeteo] = useState([]);
|
||||||
const [activeFilter, setActiveFilter] = useState("all");
|
const [activeFilter, setActiveFilter] = useState("all");
|
||||||
const [currentTime, setCurrentTime] = useState(new Date());
|
const [currentTime, setCurrentTime] = useState(new Date());
|
||||||
const { user, token } = useAuth();
|
const { user, token } = useAuth();
|
||||||
|
const [ville, setVille] = useState("Paris, France");
|
||||||
const isDayTime = currentTime.getHours() > 6 && currentTime.getHours() < 20;
|
const isDayTime = currentTime.getHours() > 6 && currentTime.getHours() < 20;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -36,7 +40,41 @@ function EnhancedWeatherHome() {
|
|||||||
|
|
||||||
return () => clearInterval(timer);
|
return () => clearInterval(timer);
|
||||||
}, []);
|
}, []);
|
||||||
|
useEffect(() => {
|
||||||
|
axios
|
||||||
|
.post(`${API_BASE_URL}/getMeteoHome`, {
|
||||||
|
location:ville,
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
if (response.data.length === 0) {
|
||||||
|
console.warn("Aucun infos disponible.");
|
||||||
|
} else {
|
||||||
|
console.log(response.data[0]);
|
||||||
|
setInfoMeteo(response.data[0]);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error("Erreur lors de la récupération des infos :", error);
|
||||||
|
});
|
||||||
|
}, [ville]);
|
||||||
|
useEffect(() => {
|
||||||
|
axios
|
||||||
|
.get(`${API_BASE_URL}/getLocations`)
|
||||||
|
.then((response) => {
|
||||||
|
if (response.data.length === 0) {
|
||||||
|
console.warn("Aucun lieu disponible.");
|
||||||
|
} else {
|
||||||
|
console.log(response.data);
|
||||||
|
setLocations(response.data);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error("Erreur lors de la récupération des catégories :", error);
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
const filteredLocations = locations.filter((loc) =>
|
||||||
|
loc.toLowerCase().includes(searchQuery.toLowerCase())
|
||||||
|
);
|
||||||
const formatDate = (date) => {
|
const formatDate = (date) => {
|
||||||
const options = { weekday: "long", day: "numeric", month: "long" };
|
const options = { weekday: "long", day: "numeric", month: "long" };
|
||||||
return date.toLocaleDateString("fr-FR", options);
|
return date.toLocaleDateString("fr-FR", options);
|
||||||
@ -45,7 +83,7 @@ function EnhancedWeatherHome() {
|
|||||||
const hourlyForecast = [
|
const hourlyForecast = [
|
||||||
{
|
{
|
||||||
time: "Maintenant",
|
time: "Maintenant",
|
||||||
temp: "21°",
|
temp: infoMeteo.temperature+"°",
|
||||||
icon: <Cloud className="text-indigo-500" size={24} />,
|
icon: <Cloud className="text-indigo-500" size={24} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -166,7 +204,7 @@ function EnhancedWeatherHome() {
|
|||||||
/>
|
/>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Rechercher une ville ou un code postal..."
|
placeholder="Rechercher une ville ..."
|
||||||
className={`w-full pl-12 pr-4 py-4 rounded-xl border ${
|
className={`w-full pl-12 pr-4 py-4 rounded-xl border ${
|
||||||
isDayTime
|
isDayTime
|
||||||
? "border-gray-200 bg-white"
|
? "border-gray-200 bg-white"
|
||||||
@ -175,10 +213,29 @@ function EnhancedWeatherHome() {
|
|||||||
value={searchQuery}
|
value={searchQuery}
|
||||||
onChange={(e) => setSearchQuery(e.target.value)}
|
onChange={(e) => setSearchQuery(e.target.value)}
|
||||||
/>
|
/>
|
||||||
<button className="absolute right-2 top-1/2 transform -translate-y-1/2 bg-indigo-600 text-white px-4 py-2 rounded-lg hover:bg-indigo-700 transition-colors">
|
|
||||||
Rechercher
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
|
{searchQuery.length > 0 && (
|
||||||
|
<ul className="mt-4 space-y-2 bg-white dark:bg-gray-100 rounded-xl p-4 shadow-md">
|
||||||
|
{filteredLocations.length > 0 ? (
|
||||||
|
filteredLocations.map((loc, idx) => (
|
||||||
|
<li
|
||||||
|
key={idx}
|
||||||
|
className="p-2 rounded text-gray-800 hover:bg-gray-200 dark:hover:bg-gray-300 cursor-pointer"
|
||||||
|
onClick={() => {
|
||||||
|
setVille(loc);
|
||||||
|
setSearchQuery("");
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{loc}
|
||||||
|
</li>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<li className="text-gray-900 dark:text-gray-500">
|
||||||
|
Aucune ville trouvée.
|
||||||
|
</li>
|
||||||
|
)}
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -204,7 +261,7 @@ function EnhancedWeatherHome() {
|
|||||||
isDayTime ? "text-gray-700" : "text-gray-200"
|
isDayTime ? "text-gray-700" : "text-gray-200"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
Paris, France
|
{ville}
|
||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
<p
|
<p
|
||||||
@ -226,7 +283,7 @@ function EnhancedWeatherHome() {
|
|||||||
isDayTime ? "text-gray-900" : "text-white"
|
isDayTime ? "text-gray-900" : "text-white"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
21°C
|
{infoMeteo.temperature}°C
|
||||||
</h2>
|
</h2>
|
||||||
<p
|
<p
|
||||||
className={`text-lg ${
|
className={`text-lg ${
|
||||||
@ -264,7 +321,7 @@ function EnhancedWeatherHome() {
|
|||||||
isDayTime ? "text-gray-900" : "text-white"
|
isDayTime ? "text-gray-900" : "text-white"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
23°C
|
{infoMeteo.temperature-2}°C
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -292,7 +349,7 @@ function EnhancedWeatherHome() {
|
|||||||
isDayTime ? "text-gray-900" : "text-white"
|
isDayTime ? "text-gray-900" : "text-white"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
68%
|
{infoMeteo.humidity}%
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -320,7 +377,7 @@ function EnhancedWeatherHome() {
|
|||||||
isDayTime ? "text-gray-900" : "text-white"
|
isDayTime ? "text-gray-900" : "text-white"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
12 km/h
|
{infoMeteo.wind_speed} km/h
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -721,8 +778,7 @@ function EnhancedWeatherHome() {
|
|||||||
: "text-indigo-400 hover:text-indigo-300"
|
: "text-indigo-400 hover:text-indigo-300"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
Ajouter un objet{" "}
|
Ajouter un objet <ArrowRight size={16} className="ml-2" />
|
||||||
<ArrowRight size={16} className="ml-2" />
|
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -757,7 +813,8 @@ function EnhancedWeatherHome() {
|
|||||||
isDayTime ? "text-gray-600" : "text-gray-300"
|
isDayTime ? "text-gray-600" : "text-gray-300"
|
||||||
} mb-4`}
|
} mb-4`}
|
||||||
>
|
>
|
||||||
Vous pourrez gérer les utilisateurs du site mais aussi les objets connectés
|
Vous pourrez gérer les utilisateurs du site mais aussi les
|
||||||
|
objets connectés
|
||||||
</p>
|
</p>
|
||||||
<a
|
<a
|
||||||
href="/dashboard"
|
href="/dashboard"
|
||||||
@ -767,7 +824,8 @@ function EnhancedWeatherHome() {
|
|||||||
: "text-indigo-400 hover:text-indigo-300"
|
: "text-indigo-400 hover:text-indigo-300"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
Tableau d'Administration <ArrowRight size={16} className="ml-2" />
|
Tableau d'Administration{" "}
|
||||||
|
<ArrowRight size={16} className="ml-2" />
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -799,7 +857,8 @@ function EnhancedWeatherHome() {
|
|||||||
isDayTime ? "text-gray-600" : "text-gray-300"
|
isDayTime ? "text-gray-600" : "text-gray-300"
|
||||||
} mb-4`}
|
} mb-4`}
|
||||||
>
|
>
|
||||||
Ce module vous permet de gérer les capteurs et stations connectés de France de manière simple et efficace.
|
Ce module vous permet de gérer les capteurs et stations
|
||||||
|
connectés de France de manière simple et efficace.
|
||||||
</p>
|
</p>
|
||||||
<a
|
<a
|
||||||
href="/gestion"
|
href="/gestion"
|
||||||
@ -809,8 +868,7 @@ function EnhancedWeatherHome() {
|
|||||||
: "text-indigo-400 hover:text-indigo-300"
|
: "text-indigo-400 hover:text-indigo-300"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
Gestion des objets{" "}
|
Gestion des objets <ArrowRight size={16} className="ml-2" />
|
||||||
<ArrowRight size={16} className="ml-2" />
|
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user