Merge branch 'v1.0.8.1' into fix/ohne-externe-babel
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// pages/api/poiUpdateModal.js
|
||||
|
||||
//
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { useRecoilValue } from "recoil";
|
||||
import { selectedPoiState } from "../redux/slices/selectedPoiSlice";
|
||||
@@ -15,22 +15,50 @@ const PoiUpdateModal = ({ onClose, poiData }) => {
|
||||
const [locationDeviceData, setLocationDeviceData] = useState([]);
|
||||
const [deviceName, setDeviceName] = useState("");
|
||||
const [idLD, setIdLD] = useState(poiData ? poiData.idLD : "");
|
||||
const [idLocationDevice, setIdLocationDevice] = useState("");
|
||||
|
||||
const [description, setDescription] = useState(poiData ? poiData.description : "");
|
||||
|
||||
// Log the initial POI data
|
||||
useEffect(() => {
|
||||
if (poiData) {
|
||||
console.log("Initial poiData:", poiData);
|
||||
setPoiId(poiData.idPoi);
|
||||
setName(poiData.name);
|
||||
setPoiTypeId(poiData.idPoiTyp);
|
||||
setIdLD(poiData.idLD);
|
||||
|
||||
setDescription(poiData.description);
|
||||
setDeviceName(poiData.idLD);
|
||||
console.log("Loaded POI Data for editing:", poiData);
|
||||
console.log("POI ID:", poiData.idPoi);
|
||||
console.log("POI Name:", poiData.name);
|
||||
console.log("POI Typ ID:", poiData.idPoiTyp);
|
||||
console.log("POI Beschreibung:", poiData.description);
|
||||
console.log("POI Geräte-ID:", poiData.idLD);
|
||||
}
|
||||
}, [poiData]);
|
||||
|
||||
/* const fetchDeviceNameById = async (idLD) => {
|
||||
try {
|
||||
const response = await fetch(`/api/getDeviceNameById?idLD=${idLD}`);
|
||||
const data = await response.json();
|
||||
setDeviceName(data.deviceName);
|
||||
} catch (error) {
|
||||
console.error("Error fetching device name:", error);
|
||||
}
|
||||
}; */
|
||||
|
||||
/* const fetchDeviceNameById = async (idLD) => {
|
||||
try {
|
||||
const response = await fetch(`/api/talas_v5_DB/locationDevice/locationDeviceNameById?idLD=${idLD}`);
|
||||
const data = await response.json();
|
||||
setDeviceName(data.deviceName);
|
||||
} catch (error) {
|
||||
console.error("Error fetching device name:", error);
|
||||
}
|
||||
}; */
|
||||
|
||||
// Beim Öffnen des Modals die Geräte-ID basierend auf dem Gerätenamen abrufen, wenn vorhanden
|
||||
useEffect(() => {
|
||||
const fetchDeviceId = async () => {
|
||||
if (poiData && poiData.idLD) {
|
||||
@@ -47,6 +75,7 @@ const PoiUpdateModal = ({ onClose, poiData }) => {
|
||||
fetchDeviceId();
|
||||
}, [poiData]);
|
||||
|
||||
// Function to handle deleting a POI
|
||||
const handleDeletePoi = async () => {
|
||||
if (confirm("Sind Sie sicher, dass Sie diesen POI löschen möchten?")) {
|
||||
try {
|
||||
@@ -55,7 +84,8 @@ const PoiUpdateModal = ({ onClose, poiData }) => {
|
||||
});
|
||||
if (response.ok) {
|
||||
alert("POI wurde erfolgreich gelöscht.");
|
||||
onClose();
|
||||
onClose(); // Close the modal
|
||||
//Browser neu laden, um die aktualisierte Liste anzuzeigen
|
||||
window.location.reload();
|
||||
} else {
|
||||
throw new Error("Fehler beim Löschen des POI.");
|
||||
@@ -67,6 +97,7 @@ const PoiUpdateModal = ({ onClose, poiData }) => {
|
||||
}
|
||||
};
|
||||
|
||||
// Fetch POI types
|
||||
useEffect(() => {
|
||||
const fetchPoiTypData = async () => {
|
||||
try {
|
||||
@@ -86,13 +117,16 @@ const PoiUpdateModal = ({ onClose, poiData }) => {
|
||||
fetchPoiTypData();
|
||||
}, [selectedPoi]);
|
||||
|
||||
// Fetch device data um den Gerät Namen in den dropdown menu anzuzeigen also erstmal die Liste der Geräte abrufen
|
||||
useEffect(() => {
|
||||
const fetchData = async () => {
|
||||
try {
|
||||
// const response = await fetch("/api/talas_v5/location_device"); //"/api/talas_v5_DB/locationDevice/location_device"
|
||||
const response = await fetch("/api/talas_v5_DB/locationDevice/locationDevices");
|
||||
const data = await response.json();
|
||||
//console.log("Standort- und Gerätedaten:", data);
|
||||
setLocationDeviceData(data);
|
||||
console.log("Standort- und Gerätedaten poiData:", poiData);
|
||||
if (poiData && poiData.idLD) {
|
||||
const selectedDevice = data.find((device) => device.id === poiData.idLD);
|
||||
setDeviceName(selectedDevice ? selectedDevice.id : data[0].id); // Hier wird die ID als initialer Zustand gesetzt
|
||||
@@ -105,8 +139,11 @@ const PoiUpdateModal = ({ onClose, poiData }) => {
|
||||
};
|
||||
fetchData();
|
||||
}, []);
|
||||
//--------------------------------------------------------------------------------------------
|
||||
// Fetch device name basierend auf der Geräte-ID
|
||||
|
||||
useEffect(() => {
|
||||
console.log("currentPoi von PoiUpdateModal.js : ", currentPoi.idLD);
|
||||
fetch("/api/talas_v5_DB/locationDevice/locationDevices")
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
@@ -125,6 +162,10 @@ const PoiUpdateModal = ({ onClose, poiData }) => {
|
||||
});
|
||||
}, [poiData?.idLD, currentPoi]);
|
||||
|
||||
//--------------------------------------------------------------------------------------------
|
||||
// Angenommen, deviceName enthält die Geräte-ID
|
||||
//const idLD = deviceName; // Stellen Sie sicher, dass dies eine ID ist und kein Name
|
||||
|
||||
const handleSubmit = async (event) => {
|
||||
event.preventDefault();
|
||||
const idLDResponse = await fetch(`/api/talas_v5_DB/locationDevice/getDeviceId?deviceName=${encodeURIComponent(deviceName)}`);
|
||||
@@ -142,6 +183,7 @@ const PoiUpdateModal = ({ onClose, poiData }) => {
|
||||
description: description,
|
||||
idPoiTyp: poiTypeId,
|
||||
idLD: idLD,
|
||||
//idLD: parseInt(deviceName, 10), // Konvertieren in eine Ganzzahl
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user