From b4e4db72d192decbab57cdd060fcab05133205b2 Mon Sep 17 00:00:00 2001 From: MrMelbert <51863163+MrMelbert@users.noreply.github.com> Date: Fri, 21 Feb 2025 18:05:54 -0600 Subject: [PATCH] Adds a very simple admin verb to view everything in the policy json (#89541) ## About The Pull Request Adds `Policy Panel` admin verb. It opens up a very plain, very simple tgui that shows you a dropdown of all `policy.json` entries, allowing you to refer to them if necessary. There's also a search bar. ![image](https://github.com/user-attachments/assets/11e5c4b1-815b-488d-8566-943145c2d64c) ## Why It's Good For The Game Half request, half something I thought would be useful. While admins could VV into config and find the `policy.json`, they generally appreciate something more user-facing. ## Changelog :cl: Melbert admin: Adds the Policy Panel verb, which shows you all the policy the server has set. /:cl: --- code/modules/admin/verbs/policy_panel.dm | 28 ++++++++ tgstation.dme | 1 + tgui/packages/tgui/interfaces/Policypanel.tsx | 70 +++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 code/modules/admin/verbs/policy_panel.dm create mode 100644 tgui/packages/tgui/interfaces/Policypanel.tsx diff --git a/code/modules/admin/verbs/policy_panel.dm b/code/modules/admin/verbs/policy_panel.dm new file mode 100644 index 00000000000..cc70dc2babb --- /dev/null +++ b/code/modules/admin/verbs/policy_panel.dm @@ -0,0 +1,28 @@ +ADMIN_VERB(policy_panel, R_ADMIN, "Policy Panel", "View all policy the server has set.", ADMIN_CATEGORY_MAIN) + if(!length(global.config?.policy)) + tgui_alert(usr, "Policy hasn't loaded yet (or the server has none set).", "Policy Panel", list("OK")) + return + + var/datum/policy_panel/tgui = new + tgui.ui_interact(user.mob) + BLACKBOX_LOG_ADMIN_VERB("Policy Panel") + +// Very simple panel that reports all the policy the server has set. +/datum/policy_panel + +/datum/policy_panel/ui_interact(mob/user, datum/tgui/ui) + ui = SStgui.try_update_ui(user, src, ui) + if(!ui) + ui = new(user, src, "Policypanel") + ui.open() + +/datum/policy_panel/ui_state(mob/user) + return ADMIN_STATE(R_ADMIN) + +/datum/policy_panel/ui_close(mob/user) + qdel(src) + +/datum/policy_panel/ui_static_data(mob/user) + var/list/data = list() + data["policy"] = global.config.policy + return data diff --git a/tgstation.dme b/tgstation.dme index 53f014194ff..98bb7da2fcb 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -3033,6 +3033,7 @@ #include "code\modules\admin\verbs\plane_debugger.dm" #include "code\modules\admin\verbs\player_ticket_history.dm" #include "code\modules\admin\verbs\playsound.dm" +#include "code\modules\admin\verbs\policy_panel.dm" #include "code\modules\admin\verbs\possess.dm" #include "code\modules\admin\verbs\pray.dm" #include "code\modules\admin\verbs\reestablish_db_connection.dm" diff --git a/tgui/packages/tgui/interfaces/Policypanel.tsx b/tgui/packages/tgui/interfaces/Policypanel.tsx new file mode 100644 index 00000000000..36c8f72e0d6 --- /dev/null +++ b/tgui/packages/tgui/interfaces/Policypanel.tsx @@ -0,0 +1,70 @@ +import { useState } from 'react'; +import { + BlockQuote, + Dropdown, + Flex, + Input, + Section, + Stack, +} from 'tgui-core/components'; + +import { useBackend } from '../backend'; +import { Window } from '../layouts'; + +type Data = { + policy: Record; +}; + +function searchForPolicy(policy: Record, token: string) { + return Object.keys(policy).filter((key) => + key.toLowerCase().includes(token.toLowerCase()), + ); +} + +export const Policypanel = () => { + const { data } = useBackend(); + const { policy } = data; + + const [currentPolicy, setCurrentPolicy] = useState(''); + + return ( + + + + + + + + + + { + const results = searchForPolicy(policy, value); + if (results.length === 1) { + setCurrentPolicy(results[0]); + } + }} + /> + + + + +
+
+ {policy[currentPolicy] || + `Select a policy to view. These policies are displayed + to players upon gaining the relevant role.`} +
+
+
+
+
+
+ ); +};