|
|
|
|
@@ -4,6 +4,8 @@ import ReactDOM from "react-dom";
|
|
|
|
|
import { useRecoilValue, useRecoilState, useSetRecoilState } from "recoil";
|
|
|
|
|
import { readPoiMarkersStore } from "../redux/slices/readPoiMarkersStoreSlice.js";
|
|
|
|
|
import { poiReadFromDbTriggerAtom } from "../redux/slices/poiReadFromDbTriggerSlice.js";
|
|
|
|
|
import { useSelector } from "react-redux";
|
|
|
|
|
import { selectGisStationsStatic } from "../redux/slices/webService/gisStationsStaticSlice";
|
|
|
|
|
|
|
|
|
|
const ShowAddStationPopup = ({ onClose, map, latlng }) => {
|
|
|
|
|
const [poiTypData, setpoiTypData] = useState(); // Recoil State verwenden
|
|
|
|
|
@@ -14,7 +16,6 @@ const ShowAddStationPopup = ({ onClose, map, latlng }) => {
|
|
|
|
|
const [longitude] = useState(latlng.lng.toFixed(5));
|
|
|
|
|
const setLoadData = useSetRecoilState(readPoiMarkersStore);
|
|
|
|
|
const setTrigger = useSetRecoilState(poiReadFromDbTriggerAtom);
|
|
|
|
|
const [locationDeviceData, setLocationDeviceData] = useState([]);
|
|
|
|
|
const [deviceName, setDeviceName] = useState("");
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
@@ -35,46 +36,18 @@ const ShowAddStationPopup = ({ onClose, map, latlng }) => {
|
|
|
|
|
|
|
|
|
|
fetchpoiTypData();
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------
|
|
|
|
|
/* useEffect(() => {
|
|
|
|
|
// Funktion zum Abrufen der Daten von der API -> DB talas_v5.location_device
|
|
|
|
|
const fetchData = async () => {
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch("/api/talas_v5/location_device"); // Pfad zu Ihrem API-Endpunkt
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
setLocationDeviceData(data); // Setzt den Zustand mit den abgerufenen Daten
|
|
|
|
|
console.log("Abgerufene Standort- und Gerätedaten:", data);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(
|
|
|
|
|
"Fehler beim Abrufen der Standort- und Gerätedaten:",
|
|
|
|
|
error
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
fetchData();
|
|
|
|
|
}, []); // Leerarray als Dependency, um den Effekt nur beim Laden der Komponente auszuführen */
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
// Funktion zum Abrufen der Daten von der API -> DB talas_v5.location_device
|
|
|
|
|
const fetchData = async () => {
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch("/api/talas5/location_device");
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
setLocationDeviceData(data);
|
|
|
|
|
if (data.length > 0) {
|
|
|
|
|
setDeviceName(data[0].name); // Setzen des anfänglichen Gerätenamens
|
|
|
|
|
}
|
|
|
|
|
console.log("Abgerufene Standort- und Gerätedaten:", data);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Fehler beim Abrufen der Standort- und Gerätedaten:", error);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const gisStationsStatic = useSelector(selectGisStationsStatic);
|
|
|
|
|
const locationDeviceData = gisStationsStatic?.Points ?? [];
|
|
|
|
|
|
|
|
|
|
fetchData();
|
|
|
|
|
}, []);
|
|
|
|
|
console.log("gisStationsStatic aus AddPOIModal:", gisStationsStatic);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (locationDeviceData?.length > 0) {
|
|
|
|
|
console.log("🎯 Gerätedaten erfolgreich geladen:", locationDeviceData);
|
|
|
|
|
setDeviceName((prev) => prev || locationDeviceData[0]?.LD_Name || "");
|
|
|
|
|
}
|
|
|
|
|
}, [locationDeviceData]);
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------
|
|
|
|
|
//-----------------handleSubmit-------------------
|
|
|
|
|
@@ -85,7 +58,7 @@ const ShowAddStationPopup = ({ onClose, map, latlng }) => {
|
|
|
|
|
poiTypeId,
|
|
|
|
|
latitude,
|
|
|
|
|
longitude,
|
|
|
|
|
idLD: locationDeviceData.find((device) => device.name === deviceName).idLD,
|
|
|
|
|
idLD: locationDeviceData.find((device) => device.LD_Name === deviceName)?.IdLD,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const response = await fetch("/api/talas_v5_DB/pois/addLocation", {
|
|
|
|
|
@@ -134,11 +107,16 @@ const ShowAddStationPopup = ({ onClose, map, latlng }) => {
|
|
|
|
|
Gerät:
|
|
|
|
|
</label>
|
|
|
|
|
<select id="deviceName" name="deviceName" value={deviceName} onChange={(e) => setDeviceName(e.target.value)} className="block p-2 w-full border-2 border-gray-200 rounded-md text-sm">
|
|
|
|
|
{locationDeviceData.map((device, index) => (
|
|
|
|
|
<option key={index} value={device.name}>
|
|
|
|
|
{device.name}
|
|
|
|
|
</option>
|
|
|
|
|
))}
|
|
|
|
|
<option value="">-- Gerät auswählen --</option>
|
|
|
|
|
{locationDeviceData?.length > 0 ? (
|
|
|
|
|
locationDeviceData.map((device, index) => (
|
|
|
|
|
<option key={device?.IdLD || index} value={device?.LD_Name}>
|
|
|
|
|
{device?.LD_Name || "Unbekanntes Gerät"}
|
|
|
|
|
</option>
|
|
|
|
|
))
|
|
|
|
|
) : (
|
|
|
|
|
<option disabled>Keine Geräte gefunden</option>
|
|
|
|
|
)}
|
|
|
|
|
</select>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|