Merge branch 'interface' into 'master'
Upgraded CLI Interface See merge request medlabboulder/modpol!30
This commit is contained in:
commit
48058a05b3
2
.gitignore
vendored
2
.gitignore
vendored
@ -1 +1 @@
|
|||||||
/data
|
*/data
|
@ -9,46 +9,40 @@ modpol.interactions = {}
|
|||||||
-- DASHBOARDS
|
-- 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)
|
-- Function: modpol.interactions.dashboard(user)
|
||||||
-- Params: user (string)
|
-- Params: user (string)
|
||||||
-- Q: Should this return a menu of commands relevant to the specific user?
|
-- Q: Should this return a menu of commands relevant to the specific user?
|
||||||
-- Output: Displays a menu of commands to the user
|
-- Output: Displays a menu of commands to the user
|
||||||
-- TKTK currently just prints all of modpol---needs major improvement
|
-- TKTK currently just prints all of modpol---needs major improvement
|
||||||
function modpol.interactions.dashboard(user)
|
function modpol.interactions.dashboard(user)
|
||||||
print()
|
-- adds user to root org if not already in it
|
||||||
local org_list = modpol.orgs.list_all()
|
if not modpol.instance:has_member(user) then
|
||||||
|
modpol.instance:add_member(user)
|
||||||
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)
|
|
||||||
end
|
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('All users: ' .. table.concat(all_users, ', '))
|
||||||
|
print()
|
||||||
|
|
||||||
|
print('Access which org?')
|
||||||
|
|
||||||
local sel = io.read()
|
local sel = io.read()
|
||||||
local sel_org = org_list[tonumber(sel)]
|
print()
|
||||||
|
local sel_org = modpol.orgs.array[tonumber(sel)].name
|
||||||
|
|
||||||
if not sel_org then return end
|
if not sel_org then return end
|
||||||
|
|
||||||
modpol.interactions.org_dashboard(user, sel_org)
|
modpol.interactions.org_dashboard(user, sel_org)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -56,10 +50,15 @@ end
|
|||||||
-- Params: user (string), org_name (string)
|
-- Params: user (string), org_name (string)
|
||||||
-- Output: Displays a menu of org-specific commands to the user
|
-- Output: Displays a menu of org-specific commands to the user
|
||||||
function modpol.interactions.org_dashboard(user, org_name)
|
function modpol.interactions.org_dashboard(user, org_name)
|
||||||
print()
|
|
||||||
local org = modpol.orgs.get_org(org_name)
|
local org = modpol.orgs.get_org(org_name)
|
||||||
if not org then return nil end
|
if not org then return nil end
|
||||||
|
|
||||||
|
local parent = ""
|
||||||
|
if org.id == 1 then
|
||||||
|
parent = "none"
|
||||||
|
else
|
||||||
|
parent = modpol.orgs.get_org(org.parent).name
|
||||||
|
end
|
||||||
|
|
||||||
local children = {}
|
local children = {}
|
||||||
for k,v in ipairs(org.children) do
|
for k,v in ipairs(org.children) do
|
||||||
@ -67,38 +66,77 @@ function modpol.interactions.org_dashboard(user, org_name)
|
|||||||
table.insert(children, this_child.name)
|
table.insert(children, this_child.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
local processes = {}
|
local process_msg = #org.processes .. " total"
|
||||||
for k,v in ipairs(org.processes) do
|
|
||||||
print(k, v)
|
if org.pending[user] then
|
||||||
local this_request = org.requests[v.request_id]
|
process_msg = process_msg .. " (" .. #org.pending[user] .. " pending)"
|
||||||
if type(this_request) == "table" then
|
else
|
||||||
local active = ''
|
process_msg = process_msg .. " (0 pending)"
|
||||||
if org.pending[user] then
|
|
||||||
if org.pending[user][v.id] then
|
|
||||||
active = '*'
|
|
||||||
end
|
|
||||||
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
|
|
||||||
local req_str = v.id .. " (" .. this_request.type .. " -> " .. table.concat(this_request.params, ", ") .. ")" .. active
|
|
||||||
table.insert(processes, req_str)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- set up output
|
-- set up output
|
||||||
print("Org: " .. org_name)
|
print("Org: " .. org_name)
|
||||||
|
print("Parent: " .. parent)
|
||||||
print("Members: " .. table.concat(org.members, ", "))
|
print("Members: " .. table.concat(org.members, ", "))
|
||||||
print("Children: " .. table.concat(children, ", "))
|
print("Children: " .. table.concat(children, ", "))
|
||||||
print("Processes: " .. table.concat(processes, ", "))
|
print("Processes: " .. process_msg)
|
||||||
|
print()
|
||||||
|
print("Commands: (L)eave, (J)oin, (P)rocesses, (A)dd child, (D)elete org")
|
||||||
|
|
||||||
print('Interact with which process?')
|
|
||||||
local sel = io.read()
|
local sel = io.read()
|
||||||
local process = org.processes[tonumber(sel)]
|
print()
|
||||||
if not process then return end
|
|
||||||
process:interact(user)
|
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}})
|
||||||
|
|
||||||
|
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
|
||||||
|
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()
|
||||||
|
print("Interact with which one?")
|
||||||
|
local to_interact = io.read()
|
||||||
|
local process = org.processes[tonumber(to_interact)]
|
||||||
|
if not process then return end
|
||||||
|
if org:has_pending_actions(user) then
|
||||||
|
if org.pending[user][process.id] then
|
||||||
|
process:interact(user)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Function: modpol.interactions.policy_dashboard
|
-- Function: modpol.interactions.policy_dashboard
|
||||||
|
7
modpol/interactions/login.lua
Normal file
7
modpol/interactions/login.lua
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
dofile("../modpol.lua")
|
||||||
|
|
||||||
|
print("Log in as which user?")
|
||||||
|
local username = io.read()
|
||||||
|
|
||||||
|
print()
|
||||||
|
modpol.interactions.dashboard(username)
|
@ -13,6 +13,7 @@ function temp_consent_process()
|
|||||||
request_id = nil,
|
request_id = nil,
|
||||||
total_votes = 0,
|
total_votes = 0,
|
||||||
majority_to_pass = 0.51,
|
majority_to_pass = 0.51,
|
||||||
|
votes_needed = nil,
|
||||||
votes_yes = {},
|
votes_yes = {},
|
||||||
votes_no = {}
|
votes_no = {}
|
||||||
}
|
}
|
||||||
@ -35,6 +36,8 @@ function modpol.modules.consent:new_process(id, request_id, org_id)
|
|||||||
p_org:add_pending_action(id, member)
|
p_org:add_pending_action(id, member)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
process.votes_needed = math.ceil(process.majority_to_pass * p_org:get_member_count())
|
||||||
|
|
||||||
return process
|
return process
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -82,13 +85,11 @@ end
|
|||||||
-- determines whether process has finished and resolves request if it has (unfinished)
|
-- determines whether process has finished and resolves request if it has (unfinished)
|
||||||
function modpol.modules.consent:update_status()
|
function modpol.modules.consent:update_status()
|
||||||
local process_org = modpol.orgs.get_org(self.org_id)
|
local process_org = modpol.orgs.get_org(self.org_id)
|
||||||
local eligible_voters = process_org:get_member_count()
|
|
||||||
local votes_needed = math.ceil(self.majority_to_pass * eligible_voters)
|
|
||||||
|
|
||||||
if #self.votes_yes >= votes_needed then
|
if #self.votes_yes >= self.votes_needed then
|
||||||
modpol.ocutil.log('Request #' .. self.request_id .. ' passes')
|
modpol.ocutil.log('Request #' .. self.request_id .. ' passes')
|
||||||
process_org:resolve_request(self.request_id, true)
|
process_org:resolve_request(self.request_id, true)
|
||||||
elseif #self.votes_no >= votes_needed then
|
elseif #self.votes_no >= self.votes_needed then
|
||||||
modpol.ocutil.log('Request #' .. self.request_id .. ' fails to pass')
|
modpol.ocutil.log('Request #' .. self.request_id .. ' fails to pass')
|
||||||
process_org:resolve_request(self.request_id, false)
|
process_org:resolve_request(self.request_id, false)
|
||||||
else
|
else
|
||||||
|
@ -255,3 +255,18 @@ function modpol.orgs:make_request(request)
|
|||||||
return process_id
|
return process_id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- wrapper for process:interact function, ensures that user actually has a pending action for that process
|
||||||
|
function modpol.orgs:interact(process_id, user)
|
||||||
|
process = self.processes[process_id]
|
||||||
|
if self.pending[user] then
|
||||||
|
if self.pending[user][process_id] == true then
|
||||||
|
process:interact(user)
|
||||||
|
else
|
||||||
|
modpol.ocutil.log("Cannot interact with process, user does not have a valid pending action")
|
||||||
|
end
|
||||||
|
else
|
||||||
|
modpol.ocutil.log("Cannot interact with process, user does not have any pending actions")
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
@ -13,10 +13,10 @@
|
|||||||
modpol.list_users = function(org)
|
modpol.list_users = function(org)
|
||||||
local users = {}
|
local users = {}
|
||||||
if (org == nil) then -- no specified org; all players
|
if (org == nil) then -- no specified org; all players
|
||||||
if modpol.orgs["instance"]
|
if modpol.instance
|
||||||
and modpol.orgs["instance"]["members"] then
|
and modpol.instance.members then
|
||||||
-- if instance exists and has membership
|
-- if instance exists and has membership
|
||||||
users = modpol.orgs["instance"]["members"]
|
users = modpol.instance.members
|
||||||
else
|
else
|
||||||
users = {}
|
users = {}
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user