upgraded dashboard to be more streamlined for CLI

This commit is contained in:
Luke Miller 2021-08-14 17:04:03 -04:00
parent beeaa626a9
commit a6963ed84f

View File

@ -9,58 +9,47 @@ modpol.interactions = {}
-- DASHBOARDS
-- ==========
function modpol.interactions.login()
print("Log in as which user?")
local username = io.read()
while true do
local org = modpol.interactions.dashboard(username)
if org then
modpol.interactions.org_dashboard(username, org)
else
break
end
end
end
-- Function: modpol.interactions.dashboard(user)
-- Params: user (string)
-- Q: Should this return a menu of commands relevant to the specific user?
-- Output: Displays a menu of commands to the user
-- TKTK currently just prints all of modpol---needs major improvement
function modpol.interactions.dashboard(user)
print()
local org_list = modpol.orgs.list_all()
print('Select an org')
for i, org_name in ipairs(org_list) do
local org = modpol.orgs.get_org(org_name)
local indicator = ""
if org:has_pending_actions(user) then
indicator = "*"
end
print('['..i..']'..' '..org_name..indicator)
-- adds user to root org if not already in it
if not modpol.instance:has_member(user) then
modpol.instance:add_member(user)
end
local all_users = modpol.list_users()
print('All orgs: (user orgs indicated by *)')
for id, org in ipairs(modpol.orgs.array) do
if type(org) == "table" then
local indicator = ""
if org:has_member(user) then indicator = "*" end
print('['..id..'] '..indicator..org.name)
end
end
print()
print('Users: ' .. table.concat(all_users, ', '))
print()
print('Access which org?')
local sel = io.read()
local sel_org = org_list[tonumber(sel)]
local sel_org = modpol.orgs.array[tonumber(sel)]
if not sel_org then return end
modpol.interactions.org_dashboard(user, sel_org)
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)
print()
local org = modpol.orgs.get_org(org_name)
if not org then return nil end
function modpol.interactions.org_dashboard(user, org)
local children = {}
for k,v in ipairs(org.children) do
local this_child = modpol.orgs.get_org(v)