fix: Korrektur der Datenquelle für Geräte-Dropdown
- API-Antwort direkt analysiert: `Points` liegt auf oberster Ebene, nicht unter `data` - Anpassung der Zuweisung: `const locationDeviceData = gisStationsStatic?.Points ?? [];` - Dropdown wird nun korrekt mit Gerätenamen befüllt
This commit is contained in:
@@ -4,6 +4,8 @@ import ReactDOM from "react-dom";
|
|||||||
import { useRecoilValue, useRecoilState, useSetRecoilState } from "recoil";
|
import { useRecoilValue, useRecoilState, useSetRecoilState } from "recoil";
|
||||||
import { readPoiMarkersStore } from "../redux/slices/readPoiMarkersStoreSlice.js";
|
import { readPoiMarkersStore } from "../redux/slices/readPoiMarkersStoreSlice.js";
|
||||||
import { poiReadFromDbTriggerAtom } from "../redux/slices/poiReadFromDbTriggerSlice.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 ShowAddStationPopup = ({ onClose, map, latlng }) => {
|
||||||
const [poiTypData, setpoiTypData] = useState(); // Recoil State verwenden
|
const [poiTypData, setpoiTypData] = useState(); // Recoil State verwenden
|
||||||
@@ -14,7 +16,6 @@ const ShowAddStationPopup = ({ onClose, map, latlng }) => {
|
|||||||
const [longitude] = useState(latlng.lng.toFixed(5));
|
const [longitude] = useState(latlng.lng.toFixed(5));
|
||||||
const setLoadData = useSetRecoilState(readPoiMarkersStore);
|
const setLoadData = useSetRecoilState(readPoiMarkersStore);
|
||||||
const setTrigger = useSetRecoilState(poiReadFromDbTriggerAtom);
|
const setTrigger = useSetRecoilState(poiReadFromDbTriggerAtom);
|
||||||
const [locationDeviceData, setLocationDeviceData] = useState([]);
|
|
||||||
const [deviceName, setDeviceName] = useState("");
|
const [deviceName, setDeviceName] = useState("");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -35,46 +36,18 @@ const ShowAddStationPopup = ({ onClose, map, latlng }) => {
|
|||||||
|
|
||||||
fetchpoiTypData();
|
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(() => {
|
const gisStationsStatic = useSelector(selectGisStationsStatic);
|
||||||
// Funktion zum Abrufen der Daten von der API -> DB talas_v5.location_device
|
const locationDeviceData = gisStationsStatic?.Points ?? [];
|
||||||
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);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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-------------------
|
//-----------------handleSubmit-------------------
|
||||||
@@ -85,7 +58,7 @@ const ShowAddStationPopup = ({ onClose, map, latlng }) => {
|
|||||||
poiTypeId,
|
poiTypeId,
|
||||||
latitude,
|
latitude,
|
||||||
longitude,
|
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", {
|
const response = await fetch("/api/talas_v5_DB/pois/addLocation", {
|
||||||
@@ -134,11 +107,16 @@ const ShowAddStationPopup = ({ onClose, map, latlng }) => {
|
|||||||
Gerät:
|
Gerät:
|
||||||
</label>
|
</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">
|
<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 value="">-- Gerät auswählen --</option>
|
||||||
<option key={index} value={device.name}>
|
{locationDeviceData?.length > 0 ? (
|
||||||
{device.name}
|
locationDeviceData.map((device, index) => (
|
||||||
</option>
|
<option key={device?.IdLD || index} value={device?.LD_Name}>
|
||||||
))}
|
{device?.LD_Name || "Unbekanntes Gerät"}
|
||||||
|
</option>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<option disabled>Keine Geräte gefunden</option>
|
||||||
|
)}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ import { useInitGisStationsMeasurements } from "./hooks/useInitGisStationsMeasur
|
|||||||
import { useInitGisSystemStatic } from "./hooks/useInitGisSystemStatic";
|
import { useInitGisSystemStatic } from "./hooks/useInitGisSystemStatic";
|
||||||
import { selectGisSystemStatic, setGisSystemStatic } from "../../redux/slices/webService/gisSystemStaticSlice";
|
import { selectGisSystemStatic, setGisSystemStatic } from "../../redux/slices/webService/gisSystemStaticSlice";
|
||||||
import ShowAddStationPopup from "../AddPOIModal.js";
|
import ShowAddStationPopup from "../AddPOIModal.js";
|
||||||
|
import { useInitGisStationsStatic } from "../mainComponent/hooks/useInitGisStationsStatic";
|
||||||
|
|
||||||
const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
@@ -1039,6 +1040,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
|||||||
useInitGisStationsStatusDistrict();
|
useInitGisStationsStatusDistrict();
|
||||||
useInitGisStationsMeasurements();
|
useInitGisStationsMeasurements();
|
||||||
useInitGisSystemStatic();
|
useInitGisSystemStatic();
|
||||||
|
useInitGisStationsStatic();
|
||||||
|
|
||||||
//--------------------------------------
|
//--------------------------------------
|
||||||
|
|
||||||
|
|||||||
@@ -71,7 +71,6 @@ const addItemsToMapContextMenu = (
|
|||||||
if (!menuItemAdded && map && map.contextmenu) {
|
if (!menuItemAdded && map && map.contextmenu) {
|
||||||
const editMode = localStorage.getItem("editMode") === "true";
|
const editMode = localStorage.getItem("editMode") === "true";
|
||||||
if (editMode) {
|
if (editMode) {
|
||||||
console.log("map :", map);
|
|
||||||
console.log("editMode localStorage:", localStorage.getItem("editMode"));
|
console.log("editMode localStorage:", localStorage.getItem("editMode"));
|
||||||
console.log("editMode:", editMode);
|
console.log("editMode:", editMode);
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
// /config/appVersion
|
// /config/appVersion
|
||||||
export const APP_VERSION = "1.1.34";
|
export const APP_VERSION = "1.1.35";
|
||||||
|
|||||||
Reference in New Issue
Block a user