From 2432633d556e0fbc98687164bee3a3800b9a6c85 Mon Sep 17 00:00:00 2001 From: Nathan Schneider Date: Tue, 11 May 2021 16:30:55 -0600 Subject: [PATCH] Added org_dashboard to CLI interactions --- modpol/interactions/interactions.lua | 44 ++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/modpol/interactions/interactions.lua b/modpol/interactions/interactions.lua index 4eb9c26..18d474f 100644 --- a/modpol/interactions/interactions.lua +++ b/modpol/interactions/interactions.lua @@ -5,7 +5,10 @@ modpol.interactions = {} --- =================================================================== + +-- DASHBOARDS +-- ========== + -- Function: modpol.dashboard(user) -- Params: user (string) -- Q: Should this return a menu of commands relevant to the specific user? @@ -17,7 +20,7 @@ function modpol.dashboard(user) output = output .. "Orgs:\n" .. table.concat(modpol.orgs.list_all(),"\n") -- Process status (ongoing processes) - output = output .. "\nProcesses:\n" .. table.concat(modpol.processes) + output = output .. "\nProcesses:\n" .. table.concat(modpol.list_processes(),"\n") -- Command list (should be redone to be org-specific) output = output .. "\nCommand list:\n" for key,value in pairs(modpol) do @@ -27,6 +30,43 @@ function modpol.dashboard(user) end +-- Function: modpol.interactions.org_dashboard +-- Params: user (string), org_name (string) +-- Output: Displays a menu of org-specific commands to the user +function modpol.interactions.org_dashboard(user, org_name) + local org = modpol.orgs.get_org(org_name) + if not org then return nil end + local is_member = org:has_member(user) + local membership_toggle = function() + local toggle_code = "" + if is_member then + toggle_code = "[Leave]" + else + toggle_code = "[Join]" + end + return toggle_code + end + local children = {} + for k,v in ipairs(org.children) do + local this_child = modpol.orgs.get_org(v) + table.insert(children, this_child.name) + end + -- set up output + local dashboard_table = { + "Org: " .. org_name, + membership_toggle(), + "Members: " .. table.concat(org.members, ", "), + "Children: " .. table.concat(children, ", "), + "Policies: " .. table.concat(org.policies, ", "), + "Processes: " .. table.concat(org.processes, ", "), + "[Add child]", + "[Remove org]", + "[Dashboard: modpol.dashboard()]" + } + -- present to player + print(table.concat(dashboard_table, "\n")) +end + -- =================================================================== -- Function: modpol.interactions.message -- input: user (string), message (string)