Kontextmenü Item "POI Bearbeiten", "POI hinzufügen" und "Stützpunkt hinzufügen" ausblenden wenn localStorage Variable "editMode" false ist
This commit is contained in:
172
services/apiService copy.js
Normal file
172
services/apiService copy.js
Normal file
@@ -0,0 +1,172 @@
|
||||
// services/apiService.js
|
||||
import * as config from "../config/config";
|
||||
import * as urls from "../config/urls";
|
||||
|
||||
let timeoutId;
|
||||
|
||||
const fetchWithTimeout = async (url, options, timeout = 5000) => {
|
||||
const controller = new AbortController();
|
||||
const id = setTimeout(() => controller.abort(), timeout);
|
||||
|
||||
try {
|
||||
const response = await fetch(url, {
|
||||
...options,
|
||||
signal: controller.signal,
|
||||
});
|
||||
clearTimeout(id);
|
||||
return response;
|
||||
} catch (error) {
|
||||
clearTimeout(id); // Im Falle eines Fehlers den Timeout abbrechen
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const fetchGisStatusStations = async (idMap, idUser) => {
|
||||
// Verhindere wiederholte schnelle API-Aufrufe durch Debouncing
|
||||
if (timeoutId) {
|
||||
clearTimeout(timeoutId);
|
||||
}
|
||||
|
||||
timeoutId = setTimeout(async () => {
|
||||
const SERVER_URL = process.env.NEXT_PUBLIC_SERVER_URL;
|
||||
|
||||
try {
|
||||
// Verwende das Timeout für die API-Anfrage
|
||||
const response = await fetchWithTimeout(
|
||||
`${SERVER_URL}/talas5/ClientData/WebServiceMap.asmx/GisStationsStatusDistrict?idMap=${idMap}&idUser=${idUser}`,
|
||||
null,
|
||||
5000 // Timeout auf 5 Sekunden gesetzt
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Error: ${response.statusText}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Abrufen der Daten:", error);
|
||||
throw error;
|
||||
}
|
||||
}, 500); // Debounce-Zeit auf 500ms gesetzt
|
||||
};
|
||||
|
||||
// ----------------------------------------------
|
||||
/* export const fetchPriorityConfig = async () => {
|
||||
try {
|
||||
const response = await fetch("/api/talas_v5_DB/priorityConfig");
|
||||
const data = await response.json();
|
||||
console.log("Prioritätskonfiguration:", data);
|
||||
setPriorityConfig(data);
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Laden der Prioritätskonfiguration:", error);
|
||||
}
|
||||
}; */
|
||||
|
||||
// ----------------------------------------------
|
||||
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,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Abrufen der POI-Daten", error);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
// ----------------------------------------------
|
||||
// Funktion zum Aktualisieren der Position in der Datenbank
|
||||
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) {
|
||||
//schreib die neue Kooridnaten in die Console
|
||||
//akuellisiere die Position in der Datenbank mit den neuen Koordinaten mit updateLocation mit SQL Anweisung UPDATE
|
||||
} else {
|
||||
console.error("Fehler beim Aktualisieren der Position");
|
||||
}
|
||||
};
|
||||
|
||||
// ----------------------------------------------
|
||||
// Funktionen zur Überwachung der Internetverbindung
|
||||
export const checkInternet = () => {
|
||||
fetch("https://tile.openstreetmap.org/1/1/1.png", { method: "HEAD" })
|
||||
.then((response) => setOnline(response.ok))
|
||||
.catch(() => setOnline(false));
|
||||
};
|
||||
|
||||
// ----------------------------------------------
|
||||
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(data.error || "Gerät nicht gefunden");
|
||||
throw new Error("Gerät nicht gefunden in apiService.js");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Abrufen des Gerätenamens in apiService.js:", error);
|
||||
return "Unbekannt";
|
||||
}
|
||||
};
|
||||
|
||||
// ----------------------------------------------
|
||||
// services/apiService.js
|
||||
export const fetchUserRights = async () => {
|
||||
// Zähler für API-Aufrufe in localStorage speichern
|
||||
let userRightsRequestCount = localStorage.getItem("userRightsRequestCount") || 0;
|
||||
userRightsRequestCount++;
|
||||
localStorage.setItem("userRightsRequestCount", userRightsRequestCount);
|
||||
console.log(`fetchUserRights wurde ${userRightsRequestCount} Mal aufgerufen.`);
|
||||
|
||||
// Debouncing, um wiederholte schnelle API-Aufrufe zu verhindern
|
||||
if (timeoutId) {
|
||||
clearTimeout(timeoutId); // Falls innerhalb der Debounce-Zeit wieder ein Aufruf erfolgt, wird der alte abgebrochen
|
||||
}
|
||||
|
||||
timeoutId = setTimeout(async () => {
|
||||
try {
|
||||
const response = await fetchWithTimeout(
|
||||
`${process.env.NEXT_PUBLIC_SERVER_URL}/talas5/ClientData/WebserviceMap.asmx/GisSystemStatic?idMap=${config.idMap}&idUser=${config.idUser}`,
|
||||
null,
|
||||
5000 // Timeout für die API-Anfrage auf 5 Sekunden gesetzt
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
// Überprüfen der Struktur der Antwort
|
||||
if (!data || !data.Rights || !Array.isArray(data.Rights)) {
|
||||
throw new Error("Invalid response structure");
|
||||
}
|
||||
|
||||
const rightsArray = data.Rights; // Nehmen an, dass 'Rights' das Array von Rechten ist
|
||||
const userRightsIds = rightsArray.map((right) => right.IdRight);
|
||||
|
||||
return userRightsIds;
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Abrufen der Benutzerrechte", error);
|
||||
return [];
|
||||
}
|
||||
}, 500); // Debounce-Zeit auf 500 ms gesetzt
|
||||
};
|
||||
@@ -2,31 +2,55 @@
|
||||
import * as config from "../config/config";
|
||||
import * as urls from "../config/urls";
|
||||
|
||||
export const fetchGisStatusStations = async (idMap, idUser) => {
|
||||
const SERVER_URL = process.env.NEXT_PUBLIC_SERVER_URL;
|
||||
let timeoutId;
|
||||
|
||||
// Zähler für API-Aufrufe in localStorage speichern
|
||||
let requestCount = localStorage.getItem("gisStatusStationsCount") || 0;
|
||||
requestCount++;
|
||||
localStorage.setItem("gisStatusStationsCount", requestCount);
|
||||
console.log(`fetchGisStatusStations wurde ${requestCount} Mal aufgerufen.`);
|
||||
const fetchWithTimeout = async (url, options, timeout = 5000) => {
|
||||
const controller = new AbortController();
|
||||
const id = setTimeout(() => controller.abort(), timeout);
|
||||
|
||||
try {
|
||||
const response = await fetch(`${SERVER_URL}/talas5/ClientData/WebServiceMap.asmx/GisStationsStatusDistrict?idMap=${idMap}&idUser=${idUser}`);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Error: ${response.statusText}
|
||||
MySQL Datenbankverbindung fehlgeschlagen!
|
||||
MySQL-Mode: SET GLOBAL sql_mode = 'STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
|
||||
prüfen oder nodeMap Dienst neu starten`);
|
||||
}
|
||||
const data = await response.json();
|
||||
return data;
|
||||
const response = await fetch(url, {
|
||||
...options,
|
||||
signal: controller.signal,
|
||||
});
|
||||
clearTimeout(id);
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Abrufen der Daten:", error);
|
||||
throw error; // Fehler weiter werfen, um ihn in der Komponente behandeln zu können
|
||||
clearTimeout(id); // Im Falle eines Fehlers den Timeout abbrechen
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const fetchGisStatusStations = async (idMap, idUser) => {
|
||||
// Verhindere wiederholte schnelle API-Aufrufe durch Debouncing
|
||||
if (timeoutId) {
|
||||
clearTimeout(timeoutId);
|
||||
}
|
||||
|
||||
timeoutId = setTimeout(async () => {
|
||||
const SERVER_URL = process.env.NEXT_PUBLIC_SERVER_URL;
|
||||
|
||||
try {
|
||||
// Verwende das Timeout für die API-Anfrage
|
||||
const response = await fetchWithTimeout(
|
||||
`${SERVER_URL}/talas5/ClientData/WebServiceMap.asmx/GisStationsStatusDistrict?idMap=${idMap}&idUser=${idUser}`,
|
||||
null,
|
||||
5000 // Timeout auf 5 Sekunden gesetzt
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Error: ${response.statusText}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Abrufen der Daten:", error);
|
||||
throw error;
|
||||
}
|
||||
}, 500); // Debounce-Zeit auf 500ms gesetzt
|
||||
};
|
||||
|
||||
// ----------------------------------------------
|
||||
/* export const fetchPriorityConfig = async () => {
|
||||
try {
|
||||
@@ -113,7 +137,13 @@ export const fetchUserRights = async () => {
|
||||
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}`);
|
||||
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: "keep-alive", // Keep-Alive Header hinzufügen
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user