talas5 Verzeichnis gelöscht, weil ich bekomme alles von WebServices und in der Produktionsumgebung läuft Entwicklungsumgebung

This commit is contained in:
ISA
2025-03-05 09:28:30 +01:00
parent e185bad1ea
commit e355fdc919
20 changed files with 175 additions and 1030 deletions

View File

@@ -0,0 +1,5 @@
export const checkInternet = () => {
fetch("https://tile.openstreetmap.org/1/1/1.png", { method: "HEAD" })
.then((response) => setOnline(response.ok))
.catch(() => setOnline(false));
};

View File

@@ -0,0 +1,14 @@
export const fetchDeviceNameById = async (idLD) => {
try {
const response = await fetch(`/api/talas_v5_DB/locationDevice/locationDeviceNameById?idLD=${idLD}`);
const data = await response.json();
if (response.ok) {
return data.name;
} else {
throw new Error("Gerät nicht gefunden");
}
} catch (error) {
console.error("Fehler beim Abrufen des Gerätenamens in fetchDeviceNameById:", error);
return "Unbekannt";
}
};

View File

@@ -0,0 +1,15 @@
export const fetchGisStationsMeasurements = async (url, setGisStationsMeasurements) => {
try {
const response = await fetch(url);
const jsonResponse = await response.json();
if (jsonResponse && jsonResponse.Statis) {
setGisStationsMeasurements(jsonResponse.Statis);
} else {
console.error('Erwartete Daten im "Statis"-Array nicht gefunden', jsonResponse);
setGisStationsMeasurements([]);
}
} catch (error) {
console.error("Fehler beim Laden der Daten: ", error);
setGisStationsMeasurements([]);
}
};

View File

@@ -0,0 +1,17 @@
import { setGisStationsStaticDistrict } from "../../redux/slices/gisStationsStaticDistrictSlice";
export const fetchGisStationsStaticDistrict = async (url, dispatch, fetchOptions) => {
try {
const response = await fetch(url, fetchOptions);
const jsonResponse = await response.json();
if (jsonResponse && jsonResponse.Points) {
dispatch(setGisStationsStaticDistrict(jsonResponse.Points));
} else {
console.error('Erwartete Daten im "Points"-Array nicht gefunden', jsonResponse);
dispatch(setGisStationsStaticDistrict([]));
}
} catch (error) {
console.error("Fehler beim Laden der Daten: ", error);
dispatch(setGisStationsStaticDistrict([]));
}
};

View File

@@ -0,0 +1,15 @@
export const fetchGisStationsStatusDistrict = async (url, setGisStationsStatusDistrict) => {
try {
const response = await fetch(url);
const jsonResponse = await response.json();
if (jsonResponse && jsonResponse.Statis) {
setGisStationsStatusDistrict(jsonResponse.Statis);
} else {
console.error('Erwartete Daten im "Statis"-Array nicht gefunden', jsonResponse);
setGisStationsStatusDistrict([]);
}
} catch (error) {
console.error("Fehler beim Laden der Daten: ", error);
setGisStationsStatusDistrict([]);
}
};

View File

@@ -0,0 +1,23 @@
import fetchWithTimeout from "./fetchWithTimeout";
export const fetchGisStatusStations = async (idMap, idUser) => {
const SERVER_URL = process.env.NEXT_PUBLIC_SERVER_URL;
return fetchWithTimeout(
`${SERVER_URL}/talas5/ClientData/WebServiceMap.asmx/GisStationsStatusDistrict?idMap=${idMap}&idUser=${idUser}`,
{
method: "GET",
headers: {
Connection: "close",
},
},
5000
)
.then((response) => {
if (!response.ok) throw new Error(`Error: ${response.statusText}`);
return response.json();
})
.catch((error) => {
console.error("Fehler beim Abrufen der Daten in fetchGisStatusStations:", error);
throw error;
});
};

View File

@@ -0,0 +1,16 @@
export const fetchGisSystemStatic = async (url, setGisSystemStatic, setGisSystemStaticLoaded) => {
try {
const response = await fetch(url);
const jsonResponse = await response.json();
if (jsonResponse && jsonResponse.Systems) {
setGisSystemStatic(jsonResponse.Systems);
setGisSystemStaticLoaded(true);
} else {
console.error('Erwartete Daten im "Systems"-Array nicht gefunden', jsonResponse);
setGisSystemStatic([]);
}
} catch (error) {
console.error("Fehler beim Laden der Daten: ", error);
setGisSystemStatic([]);
}
};

16
services/fetchPoiData.js Normal file
View File

@@ -0,0 +1,16 @@
export const fetchPoiData = async (idPoi) => {
try {
const response = await fetch(`/api/talas_v5_DB/pois/getPoiById?idPoi=${idPoi}`);
if (!response.ok) throw new Error("Fehler beim Abrufen der POI-Daten");
const data = await response.json();
return {
idPoi,
name: data.name,
description: data.description,
idLD: data.idLD,
};
} catch (error) {
console.error("Fehler beim Abrufen der POI-Daten", error);
return null;
}
};

View File

@@ -0,0 +1,26 @@
import * as config from "../../config/config";
export const fetchUserRights = async () => {
let userRightsRequestCount = localStorage.getItem("userRightsRequestCount") || 0;
userRightsRequestCount++;
localStorage.setItem("userRightsRequestCount", userRightsRequestCount);
console.log(`fetchUserRights wurde ${userRightsRequestCount} Mal aufgerufen.`);
try {
const response = await fetch(`${process.env.NEXT_PUBLIC_SERVER_URL}/talas5/ClientData/WebserviceMap.asmx/GisSystemStatic?idMap=${config.idMap}&idUser=${config.idUser}`, {
method: "GET",
headers: { Connection: "close" },
});
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
const data = await response.json();
if (!data || !data.Rights || !Array.isArray(data.Rights)) throw new Error("Invalid response structure");
return data.Rights.map((right) => right.IdRight);
} catch (error) {
console.error("Fehler beim Abrufen der Benutzerrechte", error);
return [];
}
};

View File

@@ -0,0 +1,16 @@
const fetchWithTimeout = (url, options, timeout = 5000) => {
const controller = new AbortController();
const id = setTimeout(() => controller.abort(), timeout);
return fetch(url, { ...options, signal: controller.signal })
.then((response) => {
clearTimeout(id);
return response;
})
.catch((error) => {
clearTimeout(id);
throw error;
});
};
export default fetchWithTimeout;

View File

@@ -0,0 +1,11 @@
export const updateLocationInDatabase = async (id, newLatitude, newLongitude) => {
const response = await fetch("/api/talas_v5_DB/pois/updateLocation", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ id, latitude: newLatitude, longitude: newLongitude }),
});
if (!response.ok) {
console.error("Fehler beim Aktualisieren der Position");
}
};