basic interaction dashboard, interact callback function in consent module
This commit is contained in:
@ -1,7 +0,0 @@
|
||||
dofile("../modpol.lua")
|
||||
|
||||
print("Log in as which user?")
|
||||
local username = io.read()
|
||||
|
||||
local org = modpol.dashboard(username)
|
||||
modpol.interactions.org_dashboard(username, org)
|
@ -9,22 +9,45 @@ modpol.interactions = {}
|
||||
-- DASHBOARDS
|
||||
-- ==========
|
||||
|
||||
-- Function: modpol.dashboard(user)
|
||||
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.dashboard(user)
|
||||
function modpol.interactions.dashboard(user)
|
||||
print()
|
||||
local user_orgs = modpol.orgs.user_orgs(user)
|
||||
local org_list = modpol.orgs.list_all()
|
||||
|
||||
print('Select an org')
|
||||
for i, org in ipairs(user_orgs) do
|
||||
print('['..i..']'..' '..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
|
||||
|
||||
local sel = io.read()
|
||||
return user_orgs[tonumber(sel)]
|
||||
local sel_org = org_list[tonumber(sel)]
|
||||
|
||||
if not sel_org then return end
|
||||
|
||||
modpol.interactions.org_dashboard(user, sel_org)
|
||||
|
||||
end
|
||||
|
||||
@ -37,35 +60,39 @@ 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
|
||||
|
||||
local processes = {}
|
||||
for k,v in ipairs(org.processes) do
|
||||
print(k, v)
|
||||
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 .. " (" .. this_request.type .. " -> " .. table.concat(this_request.params, ", ") .. ")" .. active
|
||||
table.insert(processes, req_str)
|
||||
end
|
||||
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"))
|
||||
print("Org: " .. org_name)
|
||||
print("Members: " .. table.concat(org.members, ", "))
|
||||
print("Children: " .. table.concat(children, ", "))
|
||||
print("Processes: " .. table.concat(processes, ", "))
|
||||
|
||||
print('Interact with which process?')
|
||||
local sel = io.read()
|
||||
local process = org.processes[tonumber(sel)]
|
||||
if not process then return end
|
||||
process:interact(user)
|
||||
end
|
||||
|
||||
-- ===================================================================
|
||||
@ -97,10 +124,10 @@ function modpol.interactions.binary_poll_user(user, question)
|
||||
answer = io.read()
|
||||
until answer == "y" or answer == "n" or answer == "a"
|
||||
if answer == "y" then
|
||||
return "Yes"
|
||||
return "yes"
|
||||
elseif answer == "n" then
|
||||
return "No"
|
||||
return "no"
|
||||
else
|
||||
return "Abstain"
|
||||
return "abstain"
|
||||
end
|
||||
end
|
||||
|
@ -38,6 +38,16 @@ function modpol.modules.consent:new_process(id, request_id, org_id)
|
||||
return process
|
||||
end
|
||||
|
||||
-- ============================
|
||||
-- interact function for the consent module
|
||||
function modpol.modules.consent:interact(user)
|
||||
local resp = modpol.interactions.binary_poll_user(user, "How do you vote?")
|
||||
if resp == 'yes' then
|
||||
self:approve(user, true)
|
||||
elseif resp == 'no' then
|
||||
self:approve(user, false)
|
||||
end
|
||||
end
|
||||
|
||||
-- =========================================
|
||||
-- function to delete a process, called when process finishes
|
||||
|
@ -70,6 +70,22 @@ function modpol.orgs:wipe_pending_actions(process_id)
|
||||
modpol.ocutil.log("Removed all pending actions for process #" .. process_id)
|
||||
end
|
||||
|
||||
-- ======================
|
||||
-- returns a boolean to indicate whether a user has any active pending actions
|
||||
function modpol.orgs:has_pending_actions(user)
|
||||
-- next() will return the next pair in a table
|
||||
-- if next() returns nil, the table is empty
|
||||
if not self.pending[user] then
|
||||
return false
|
||||
else
|
||||
if not next(self.pending[user]) then
|
||||
return false
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- ===========================
|
||||
-- compares to requests to see if they are identical
|
||||
function modpol.orgs.comp_req(req1, req2)
|
||||
|
@ -28,7 +28,7 @@ end
|
||||
modpol.instance:set_policy("add_org", "consent", false);
|
||||
|
||||
new_request = {
|
||||
user = "lukvmil",
|
||||
user = "luke",
|
||||
type = "add_org",
|
||||
params = {"new_org"}
|
||||
}
|
||||
@ -39,6 +39,13 @@ modpol.instance:add_member('josh')
|
||||
modpol.instance:add_member('nathan')
|
||||
|
||||
request_id = modpol.instance:make_request(new_request)
|
||||
modpol.instance:make_request({
|
||||
user="luke",
|
||||
type="add_org",
|
||||
params={"second_org"}
|
||||
})
|
||||
|
||||
modpol.interactions.login()
|
||||
|
||||
for id, process in ipairs(modpol.instance.processes) do
|
||||
-- process:approve('luke', true)
|
||||
|
Reference in New Issue
Block a user