From 93aba479668135e27c8ac5081a65f86dc4c65cf1 Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 4 Sep 2023 23:14:16 +0200 Subject: [PATCH] added admin area manage for checking which categories are available --- public/locales/de/translation.json | 12 +++++++-- public/locales/en/translation.json | 12 +++++++-- src/Components/AppRoutes/index.js | 15 +++++++++++ src/Components/SideMenu/index.js | 25 ++++++++++------- src/Handlers/WebSocketMessageHandler.js | 7 +++-- src/Pages/AdminArea/Manage/index.js | 36 +++++++++++++++++++++++++ src/Pages/GroupTasks/Overview/index.js | 4 +-- src/utils.js | 5 ++++ 8 files changed, 99 insertions(+), 17 deletions(-) create mode 100644 src/Pages/AdminArea/Manage/index.js diff --git a/public/locales/de/translation.json b/public/locales/de/translation.json index 1e2a56f..419ec2a 100644 --- a/public/locales/de/translation.json +++ b/public/locales/de/translation.json @@ -36,7 +36,8 @@ "menuCategory": "Adminbereich", "roles": "Rollen", "logs": "Logs", - "noScannerSelected": "Kein Scanner ausgewählt" + "noScannerSelected": "Kein Scanner ausgewählt", + "manage": "Verwalten" }, "usersCount": { "single": "Benutzer online", @@ -259,7 +260,14 @@ "save": { "tooltip": { "title": "Speichern" } }, "close": { "tooltip": { "title": "Schließen" } }, "edit": { "tooltip": { "title": "Bearbeiten" } }, - "masterRoleRightsMessage": "Rechte können nicht bearbeitet werden, da diese Rolle der Master ist und alle Rechte besitzt." + "masterRoleRightsMessage": "Rechte können nicht bearbeitet werden, da diese Rolle der Master ist und alle Rechte besitzt.", + "manage": { + "groupTasksCard": { + "title": "Gruppenaufgaben Kategorien", + "description": "Die Suche nach Kategorieänderungen zwingt den Server, nach neuen Kategorien zu suchen oder alte aus dem Cache zu löschen.", + "buttonText": "Prüfen, welche Kategorien verfügbar sind" + } + } }, "userProfile": { "header": { diff --git a/public/locales/en/translation.json b/public/locales/en/translation.json index 34280b7..2a01339 100644 --- a/public/locales/en/translation.json +++ b/public/locales/en/translation.json @@ -36,7 +36,8 @@ "menuCategory": "Admin Area", "roles": "Roles", "logs": "Logs", - "noScannerSelected": "No scanner selected" + "noScannerSelected": "No scanner selected", + "manage": "Manage" }, "usersCount": { "single": "User online", @@ -259,7 +260,14 @@ "save": { "tooltip": { "title": "Save" } }, "close": { "tooltip": { "title": "Close" } }, "edit": { "tooltip": { "title": "Edit" } }, - "masterRoleRightsMessage": "Rights cannot be edited as this role is the master and has all rights." + "masterRoleRightsMessage": "Rights cannot be edited as this role is the master and has all rights.", + "manage": { + "groupTasksCard": { + "title": "Group Task Categories", + "description": "Searching for category changes forces the server to search for new categories or delete old ones from the cache.", + "buttonText": "Check which categories are available" + } + } }, "userProfile": { "header": { diff --git a/src/Components/AppRoutes/index.js b/src/Components/AppRoutes/index.js index 6ded517..b41ee98 100644 --- a/src/Components/AppRoutes/index.js +++ b/src/Components/AppRoutes/index.js @@ -11,6 +11,7 @@ const UserProfile = lazy(() => import("../../Pages/UserProfile")); const Scanners = lazy(() => import("../../Pages/Scanners")); const AdminAreaRoles = lazy(() => import("../../Pages/AdminArea/Roles")); const AdminAreaLogs = lazy(() => import("../../Pages/AdminArea/Logs")); +const AdminAreaManage = lazy(() => import("../../Pages/AdminArea/Manage")); const AllUsers = lazy(() => import("../../Pages/AllUsers")); const GroupTasksHistory = lazy(() => import("../../Pages/GroupTasks/History")); const PageNotFound = lazy(() => import("../../Pages/PageNotFound")); @@ -216,6 +217,20 @@ export default function AppRoutes() { /> )} + {hasPermission( + appContext.userPermissions, + Constants.PERMISSIONS.ADMIN_AREA.MANAGE + ) && ( + + + + } + /> + )} + , - key: `/group-tasks/${sideBarContext.availableCategoryGroups[i]}`, - }); - } */ groupTasksGroup.children.push(groupTasks); @@ -132,7 +125,8 @@ export default function SideMenu({ Constants.PERMISSIONS.ADMIN_AREA.ROLES.UPDATE_ROLE, Constants.PERMISSIONS.ADMIN_AREA.ROLES.DELETE_ROLE, Constants.PERMISSIONS.ADMIN_AREA.ROLES.MOVE_ROLE_UP_DOWN, - Constants.PERMISSIONS.ADMIN_AREA.LOGS + Constants.PERMISSIONS.ADMIN_AREA.LOGS, + Constants.PERMISSIONS.ADMIN_AREA.MANAGE ) ) { items.push({ @@ -175,6 +169,19 @@ export default function SideMenu({ }); } + if ( + hasPermission( + appContext.userPermissions, + Constants.PERMISSIONS.ADMIN_AREA.MANAGE + ) + ) { + adminArea.children.push({ + label: t("sideMenu.adminArea.manage"), + icon: , + key: Constants.ROUTE_PATHS.ADMIN_AREA_MANAGE, + }); + } + items.push(adminArea); } diff --git a/src/Handlers/WebSocketMessageHandler.js b/src/Handlers/WebSocketMessageHandler.js index dfc5f12..4db05cd 100644 --- a/src/Handlers/WebSocketMessageHandler.js +++ b/src/Handlers/WebSocketMessageHandler.js @@ -74,6 +74,7 @@ export const SentMessagesCommands = { SubscribeToTopic: 23, DeleteAllNotifications: 24, DeleteOneNotification: 25, + AdminAreaManageCheckWhichCategoriesAreAvailable: 26, }; /* @@ -798,11 +799,13 @@ export function handleWebSocketMessage( }); } + /* + TODO: handle this if ( body["AddedCategoryGroups"] !== undefined || body["RemovedCategoryGroups"] !== undefined ) { - groupTasksContext.setCategoryGroups((arr) => { + groupTasksContext.setCategoryGroup((arr) => { let newArr = [...arr]; if (body["RemovedCategoryGroups"] !== undefined) { @@ -827,7 +830,7 @@ export function handleWebSocketMessage( return newArr; }); - } + } */ notificationApi["success"]({ message: `Category group changes reloaded`, diff --git a/src/Pages/AdminArea/Manage/index.js b/src/Pages/AdminArea/Manage/index.js new file mode 100644 index 0000000..dfce9f8 --- /dev/null +++ b/src/Pages/AdminArea/Manage/index.js @@ -0,0 +1,36 @@ +import { Button, Card } from "antd"; +import { useTranslation } from "react-i18next"; +import { useWebSocketContext } from "../../../Contexts/WebSocketContext"; +import { SentMessagesCommands } from "../../../Handlers/WebSocketMessageHandler"; +import { Constants, hasPermission } from "../../../utils"; +import { useAppContext } from "../../../Contexts/AppContext"; + +export default function AdminAreaManage() { + const { t } = useTranslation(); + const appContext = useAppContext(); + const webSocketContext = useWebSocketContext(); + + return ( + <> + {hasPermission( + appContext.userPermissions, + Constants.PERMISSIONS.ADMIN_AREA + .MANAGE_CHECK_WHICH_CATEGORIES_ARE_AVAILABLE + ) && ( + +

{t("adminArea.manage.groupTasksCard.description")}

+ +
+ )} + + ); +} diff --git a/src/Pages/GroupTasks/Overview/index.js b/src/Pages/GroupTasks/Overview/index.js index bff8419..e4f8ea0 100644 --- a/src/Pages/GroupTasks/Overview/index.js +++ b/src/Pages/GroupTasks/Overview/index.js @@ -3,7 +3,7 @@ import { useEffect, useRef, useState } from "react"; import GroupTasksViewModal from "./GroupTasksViewModal"; import GroupTypeSelectionModal from "./GroupTypeSelectionModal"; import GroupTaskTableList from "./GroupTasksTableList"; -import { Constants, hasPermission, myFetch } from "../../../utils"; +import { AppStyle, Constants, hasPermission, myFetch } from "../../../utils"; import { useTranslation } from "react-i18next"; import { ReloadOutlined } from "@ant-design/icons"; import { useGroupTasksContext } from "../../../Contexts/GroupTasksContext"; @@ -146,7 +146,7 @@ export default function GroupTasks({ isGroupTasksViewModalOpen }) { style={{ display: "flex", justifyContent: "center", - marginTop: 20, + marginTop: AppStyle.app.margin, }} >