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
|
-- 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)
|
-- 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.dashboard(user)
|
function modpol.interactions.dashboard(user)
|
||||||
print()
|
print()
|
||||||
local user_orgs = modpol.orgs.user_orgs(user)
|
local org_list = modpol.orgs.list_all()
|
||||||
|
|
||||||
print('Select an org')
|
print('Select an org')
|
||||||
for i, org in ipairs(user_orgs) do
|
for i, org_name in ipairs(org_list) do
|
||||||
print('['..i..']'..' '..org)
|
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 sel = io.read()
|
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
|
end
|
||||||
|
|
||||||
@ -37,35 +60,39 @@ function modpol.interactions.org_dashboard(user, org_name)
|
|||||||
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 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 = {}
|
local children = {}
|
||||||
for k,v in ipairs(org.children) do
|
for k,v in ipairs(org.children) do
|
||||||
local this_child = modpol.orgs.get_org(v)
|
local this_child = modpol.orgs.get_org(v)
|
||||||
table.insert(children, this_child.name)
|
table.insert(children, this_child.name)
|
||||||
end
|
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
|
-- set up output
|
||||||
local dashboard_table = {
|
print("Org: " .. org_name)
|
||||||
"Org: " .. org_name,
|
print("Members: " .. table.concat(org.members, ", "))
|
||||||
membership_toggle(),
|
print("Children: " .. table.concat(children, ", "))
|
||||||
"Members: " .. table.concat(org.members, ", "),
|
print("Processes: " .. table.concat(processes, ", "))
|
||||||
"Children: " .. table.concat(children, ", "),
|
|
||||||
"Policies: " .. table.concat(org.policies, ", "),
|
print('Interact with which process?')
|
||||||
"Processes: " .. table.concat(org.processes, ", "),
|
local sel = io.read()
|
||||||
"[Add child]",
|
local process = org.processes[tonumber(sel)]
|
||||||
"[Remove org]",
|
if not process then return end
|
||||||
"[Dashboard: modpol.dashboard()]"
|
process:interact(user)
|
||||||
}
|
|
||||||
-- present to player
|
|
||||||
print(table.concat(dashboard_table, "\n"))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ===================================================================
|
-- ===================================================================
|
||||||
@ -97,10 +124,10 @@ function modpol.interactions.binary_poll_user(user, question)
|
|||||||
answer = io.read()
|
answer = io.read()
|
||||||
until answer == "y" or answer == "n" or answer == "a"
|
until answer == "y" or answer == "n" or answer == "a"
|
||||||
if answer == "y" then
|
if answer == "y" then
|
||||||
return "Yes"
|
return "yes"
|
||||||
elseif answer == "n" then
|
elseif answer == "n" then
|
||||||
return "No"
|
return "no"
|
||||||
else
|
else
|
||||||
return "Abstain"
|
return "abstain"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -38,6 +38,16 @@ function modpol.modules.consent:new_process(id, request_id, org_id)
|
|||||||
return process
|
return process
|
||||||
end
|
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
|
-- 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)
|
modpol.ocutil.log("Removed all pending actions for process #" .. process_id)
|
||||||
end
|
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
|
-- compares to requests to see if they are identical
|
||||||
function modpol.orgs.comp_req(req1, req2)
|
function modpol.orgs.comp_req(req1, req2)
|
||||||
|
@ -28,7 +28,7 @@ end
|
|||||||
modpol.instance:set_policy("add_org", "consent", false);
|
modpol.instance:set_policy("add_org", "consent", false);
|
||||||
|
|
||||||
new_request = {
|
new_request = {
|
||||||
user = "lukvmil",
|
user = "luke",
|
||||||
type = "add_org",
|
type = "add_org",
|
||||||
params = {"new_org"}
|
params = {"new_org"}
|
||||||
}
|
}
|
||||||
@ -39,6 +39,13 @@ modpol.instance:add_member('josh')
|
|||||||
modpol.instance:add_member('nathan')
|
modpol.instance:add_member('nathan')
|
||||||
|
|
||||||
request_id = modpol.instance:make_request(new_request)
|
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
|
for id, process in ipairs(modpol.instance.processes) do
|
||||||
-- process:approve('luke', true)
|
-- process:approve('luke', true)
|
||||||
|
Reference in New Issue
Block a user