doc: addItemsToMapContextMenu und hasRights in progress
This commit is contained in:
@@ -36,7 +36,7 @@ import { currentPoiState } from "../store/atoms/currentPoiState.js";
|
|||||||
import { ToastContainer, toast } from "react-toastify";
|
import { ToastContainer, toast } from "react-toastify";
|
||||||
import "react-toastify/dist/ReactToastify.css";
|
import "react-toastify/dist/ReactToastify.css";
|
||||||
import { mapIdState, userIdState } from "../store/atoms/urlParameterState.js";
|
import { mapIdState, userIdState } from "../store/atoms/urlParameterState.js";
|
||||||
import { set } from "lodash";
|
import { has, set } from "lodash";
|
||||||
import { poiLayerVisibleState } from "../store/atoms/poiLayerVisible.js";
|
import { poiLayerVisibleState } from "../store/atoms/poiLayerVisible.js";
|
||||||
import { data } from "autoprefixer";
|
import { data } from "autoprefixer";
|
||||||
import plusRoundIcon from "./PlusRoundIcon.js";
|
import plusRoundIcon from "./PlusRoundIcon.js";
|
||||||
@@ -278,35 +278,32 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Kontextmenü Callback für "POI hinzufügen"
|
// Kontextmenü Callback für "POI hinzufügen"
|
||||||
const addStationCallback = useCallback(
|
const addStationCallback = useCallback((event, hasRights) => {
|
||||||
(event) => {
|
console.log(
|
||||||
console.log(
|
"Überprüfung der Berechtigung in addStationCallback: ",
|
||||||
"Überprüfung der Berechtigung in addStationCallback: ",
|
hasRights
|
||||||
hasRights
|
);
|
||||||
);
|
if (hasRights) {
|
||||||
if (hasRights) {
|
setPopupCoordinates(event.latlng);
|
||||||
setPopupCoordinates(event.latlng);
|
setShowPopup(true);
|
||||||
setShowPopup(true);
|
} else {
|
||||||
} else {
|
toast.error("Benutzer hat keine Berechtigung zum Hinzufügen.", {
|
||||||
toast.error("Benutzer hat keine Berechtigung zum Hinzufügen.", {
|
position: "top-center",
|
||||||
position: "top-center",
|
autoClose: 5000,
|
||||||
autoClose: 5000,
|
hideProgressBar: false,
|
||||||
hideProgressBar: false,
|
closeOnClick: true,
|
||||||
closeOnClick: true,
|
pauseOnHover: true,
|
||||||
pauseOnHover: true,
|
draggable: true,
|
||||||
draggable: true,
|
progress: undefined,
|
||||||
progress: undefined,
|
});
|
||||||
});
|
console.error("Benutzer hat keine Berechtigung zum Hinzufügen.");
|
||||||
console.error("Benutzer hat keine Berechtigung zum Hinzufügen.");
|
}
|
||||||
}
|
});
|
||||||
},
|
|
||||||
[hasRights]
|
|
||||||
);
|
|
||||||
|
|
||||||
//-----Kontextmenu----ende------------
|
//-----Kontextmenu----ende------------
|
||||||
|
|
||||||
const addItemsToMapContextMenu = () => {
|
const addItemsToMapContextMenu = (hasRights) => {
|
||||||
if (!menuItemAdded) {
|
if (!menuItemAdded && map) {
|
||||||
map.contextmenu.addItem({
|
map.contextmenu.addItem({
|
||||||
text: "Koordinaten anzeigen",
|
text: "Koordinaten anzeigen",
|
||||||
icon: "img/not_listed_location.png",
|
icon: "img/not_listed_location.png",
|
||||||
@@ -346,6 +343,43 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (
|
||||||
|
map &&
|
||||||
|
poiLayerRef.current &&
|
||||||
|
isPoiTypLoaded &&
|
||||||
|
!menuItemAdded &&
|
||||||
|
isRightsLoaded
|
||||||
|
) {
|
||||||
|
console.log(
|
||||||
|
"Überprüfung der Berechtigung vor addItemsToMapContextMenu: ",
|
||||||
|
hasRights
|
||||||
|
);
|
||||||
|
addItemsToMapContextMenu(hasRights);
|
||||||
|
}
|
||||||
|
}, [
|
||||||
|
map,
|
||||||
|
poiLayerRef,
|
||||||
|
isPoiTypLoaded,
|
||||||
|
menuItemAdded, // Hinzufügen zu den Abhängigkeiten, um den Effekt korrekt zu steuern
|
||||||
|
hasRights, // Sicherstellen, dass hasRights berücksichtigt wird
|
||||||
|
isRightsLoaded, // Überprüfung, ob die Rechte geladen sind
|
||||||
|
]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchAndSetUserRights = async () => {
|
||||||
|
const rights = await fetchUserRights();
|
||||||
|
console.log("Benutzerrechte in server URL:", rights);
|
||||||
|
setUserRights(rights);
|
||||||
|
setIsRightsLoaded(true);
|
||||||
|
setHasRights(rights && rights.includes(56)); // Prüfen, ob Benutzer die Rechte hat
|
||||||
|
console.log("Benutzerrechte in useEffect in MapComponent:", rights);
|
||||||
|
};
|
||||||
|
|
||||||
|
fetchAndSetUserRights();
|
||||||
|
}, [urls.SERVER_URL]); // Lade die Berechtigungen beim Initialisieren der Komponente
|
||||||
|
|
||||||
|
//----------------------------------------------------
|
||||||
//------------------------------------------ */
|
//------------------------------------------ */
|
||||||
const layerNames = {
|
const layerNames = {
|
||||||
"GSM Modem": "GSMMODEM",
|
"GSM Modem": "GSMMODEM",
|
||||||
@@ -612,8 +646,9 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
|||||||
setUserRights(rights);
|
setUserRights(rights);
|
||||||
setIsRightsLoaded(true);
|
setIsRightsLoaded(true);
|
||||||
setHasRights(rights && rights.includes(56)); // Prüfen, ob Benutzer die Rechte hat
|
setHasRights(rights && rights.includes(56)); // Prüfen, ob Benutzer die Rechte hat
|
||||||
|
console.log("Benutzerrechte in useEffect in MapComponent:", hasRights);
|
||||||
});
|
});
|
||||||
}, [urls.SERVER_URL]); // Läuft, wenn serverURL sich ändert
|
}, []);
|
||||||
|
|
||||||
// Anzeigen von Modals basierend auf Benutzerrechten
|
// Anzeigen von Modals basierend auf Benutzerrechten
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -1022,7 +1057,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
|||||||
}
|
}
|
||||||
}; */
|
}; */
|
||||||
|
|
||||||
useEffect(() => {
|
/* useEffect(() => {
|
||||||
if (map && poiLayerRef.current && isPoiTypLoaded && !menuItemAdded) {
|
if (map && poiLayerRef.current && isPoiTypLoaded && !menuItemAdded) {
|
||||||
addItemsToMapContextMenu();
|
addItemsToMapContextMenu();
|
||||||
}
|
}
|
||||||
@@ -1031,7 +1066,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
|||||||
poiLayerRef,
|
poiLayerRef,
|
||||||
isPoiTypLoaded,
|
isPoiTypLoaded,
|
||||||
menuItemAdded, // Hinzufügen zu den Abhängigkeiten, um den Effekt korrekt zu steuern
|
menuItemAdded, // Hinzufügen zu den Abhängigkeiten, um den Effekt korrekt zu steuern
|
||||||
]);
|
]); */
|
||||||
//------------------------------------------
|
//------------------------------------------
|
||||||
|
|
||||||
// poiLayerRef(poiDbLayer) POI hinzufügen
|
// poiLayerRef(poiDbLayer) POI hinzufügen
|
||||||
|
|||||||
Reference in New Issue
Block a user