|
@@ -38,10 +38,12 @@ function modpol.interactions.dashboard(user)
|
|
|
|
|
|
local sel = io.read()
|
|
|
print()
|
|
|
- local sel_org = modpol.orgs.array[tonumber(sel)].name
|
|
|
|
|
|
- if not sel_org then return end
|
|
|
-
|
|
|
+ if modpol.orgs.array[tonumber(sel)] then
|
|
|
+ local sel_org = modpol.orgs.array[tonumber(sel)].name
|
|
|
+ else
|
|
|
+ return
|
|
|
+ end
|
|
|
modpol.interactions.org_dashboard(user, sel_org)
|
|
|
end
|
|
|
|
|
@@ -53,6 +55,7 @@ function modpol.interactions.org_dashboard(user, org_name)
|
|
|
local org = modpol.orgs.get_org(org_name)
|
|
|
if not org then return nil end
|
|
|
|
|
|
+ -- identify parent
|
|
|
local parent = ""
|
|
|
if org.id == 1 then
|
|
|
parent = "none"
|
|
@@ -60,66 +63,65 @@ function modpol.interactions.org_dashboard(user, org_name)
|
|
|
parent = modpol.orgs.get_org(org.parent).name
|
|
|
end
|
|
|
|
|
|
+ -- identify children
|
|
|
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
|
|
|
|
|
|
- local process_msg = #org.processes .. " total"
|
|
|
+ -- list available modules
|
|
|
+ local org_modules = {}
|
|
|
+ for k,v in ipairs(org.modules) do
|
|
|
+ table.insert(org_modules, org.modules[k].slug)
|
|
|
+ end
|
|
|
|
|
|
+ -- list pending actions
|
|
|
+ local process_msg = #org.processes .. " total actions"
|
|
|
if org.pending[user] then
|
|
|
process_msg = process_msg .. " (" .. #org.pending[user] .. " pending)"
|
|
|
else
|
|
|
process_msg = process_msg .. " (0 pending)"
|
|
|
end
|
|
|
-
|
|
|
|
|
|
-- set up output
|
|
|
print("Org: " .. org_name)
|
|
|
print("Parent: " .. parent)
|
|
|
print("Members: " .. table.concat(org.members, ", "))
|
|
|
print("Children: " .. table.concat(children, ", "))
|
|
|
- print("Processes: " .. process_msg)
|
|
|
+ print("Modules: " .. table.concat(org_modules, ", "))
|
|
|
+ print("Actions: " .. process_msg)
|
|
|
print()
|
|
|
- print("Commands: (L)eave, (J)oin, (P)rocesses, (A)dd child, (D)elete org")
|
|
|
+ print("Commands: (M)odules, (A)ctions")
|
|
|
|
|
|
local sel = io.read()
|
|
|
print()
|
|
|
|
|
|
- if sel == 'l' or sel == 'L' then
|
|
|
- org:remove_member(user)
|
|
|
-
|
|
|
- elseif sel == 'j' or sel == 'J' then
|
|
|
- org:make_request({user=user, type="add_member", params={user}})
|
|
|
-
|
|
|
+ if sel == 'm' or sel == 'M' then
|
|
|
+ print("Type module name: ")
|
|
|
+ local module_sel = io.read()
|
|
|
+ print()
|
|
|
+ local module_result = false
|
|
|
+ for k,v in ipairs(org_modules) do
|
|
|
+ if v == module_sel then
|
|
|
+ module_result = true
|
|
|
+ end
|
|
|
+ end
|
|
|
+ if module_result then
|
|
|
+ org:call_module(module_sel, user)
|
|
|
+ else
|
|
|
+ print("Error: Module not found.")
|
|
|
+ end
|
|
|
+
|
|
|
elseif sel == 'a' or sel == 'A' then
|
|
|
- print("What should the new org be named?")
|
|
|
- local new_org_name = io.read()
|
|
|
- org:make_request({user=user, type="add_org", params={new_org_name}})
|
|
|
-
|
|
|
- elseif sel == 'd' or sel == 'D' then
|
|
|
- org:make_request({user=user, type="delete", params={}})
|
|
|
-
|
|
|
- elseif sel == 'p' or sel == 'P' then
|
|
|
local processes = {}
|
|
|
print("All processes: (* indicates pending action)")
|
|
|
for k,v in ipairs(org.processes) do
|
|
|
- local this_request = org.requests[v.request_id]
|
|
|
- if type(this_request) == "table" then
|
|
|
- local active = ''
|
|
|
- if org.pending[user] then
|
|
|
- if org.pending[user][v.id] then
|
|
|
- active = '*'
|
|
|
- end
|
|
|
+ local active = ''
|
|
|
+ if org.pending[user] then
|
|
|
+ if org.pending[user][v.id] then
|
|
|
+ active = '*'
|
|
|
end
|
|
|
- local req_str = "[" .. v.id .. "] " ..
|
|
|
- active .. this_request.type
|
|
|
- if this_request.params[1] then
|
|
|
- req_str = req_str .. ": " ..
|
|
|
- table.concat(this_request.params, ", ")
|
|
|
- end
|
|
|
- print(req_str)
|
|
|
end
|
|
|
end
|
|
|
print()
|
|
@@ -129,14 +131,12 @@ function modpol.interactions.org_dashboard(user, org_name)
|
|
|
if not process then return end
|
|
|
if org:has_pending_actions(user) then
|
|
|
if org.pending[user][process.id] then
|
|
|
- process:interact(user)
|
|
|
+ org:interact(process.id, user)
|
|
|
end
|
|
|
end
|
|
|
+ else
|
|
|
+ print("Command not found")
|
|
|
end
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
end
|
|
|
|
|
|
-- Function: modpol.interactions.policy_dashboard
|