Added modpol.interactions.display and display_processes module, as well as a bunch of bugfixes

This commit is contained in:
Nathan Schneider
2021-12-29 22:07:53 -07:00
parent 6558b7a026
commit 7ef0626357
5 changed files with 149 additions and 34 deletions

View File

@ -17,6 +17,7 @@ dofile (localdir .. "/modules/change_modules.lua")
dofile (localdir .. "/modules/consent.lua")
dofile (localdir .. "/modules/create_token.lua")
dofile (localdir .. "/modules/defer_consent.lua")
dofile (localdir .. "/modules/display_processes.lua")
dofile (localdir .. "/modules/join_org_consent.lua")
dofile (localdir .. "/modules/leave_org.lua")
dofile (localdir .. "/modules/message_org.lua")

View File

@ -168,6 +168,7 @@ function modpol.interactions.org_dashboard(user, org_string)
org:call_module(module_sel, user)
else
print("Error: Module not found.")
modpol.interactions.org_dashboard(user, org.id)
end
elseif sel == 'p' or sel == 'P' then
@ -261,18 +262,26 @@ end
--- Function: modpol.interactions.display
-- Displays complex data to a user
-- @param user Name of target user (string)
-- @param title Title of display (string)
-- @param message Content of message (string or table of strings)
-- @param done Optional function for what happens when user is done
function modpol.interactions.display(user, message, completion)
function modpol.interactions.display(user, title, message, completion)
local output = ""
if type(message) == table then
output = "\n-=< "..title.." >=-\n\n"
if type(message) == "table" then
output = table.concat(message,"\n")
elseif type(message) == string then
elseif type(message) == "string" then
output = message
elseif type(message) == number then
elseif type(message) == "number" then
output = message
else
return nil, "Error: message not typed for display"
modpol.interactions.message(
self.initiator, "Error: message not typed for display")
modpol.interactions.message(
self.initiator, "Error: input not typed for display")
if completion then completion() else
modpol.intereactions.dashboard(user)
end
end
print(message)
print("\nEnter to continue")

View File

@ -0,0 +1,61 @@
--- display_processes
-- @module display_processes
local display_processes = {
name = "Display processes",
slug = "display_processes",
desc = "Presents a detailed list of org processes",
hide = false;
}
--- (Required) Data for module
-- Variables that module uses during the course of a process
-- Can be blank
display_processes.data = {
}
display_processes.config = {
}
--- (Required): initiate function
-- @param result (optional) Callback if this module is embedded in other modules
-- @function initiate
function display_processes:initiate(result)
local display_table = {}
for k,v in pairs(self.org.processes) do
if v ~= "deleted" then
local input = v.id..": "..v.slug
table.insert(display_table, input)
input = "Org: "..v.org.name..
", initiator: "..v.initiator
table.insert(display_table, input)
if v.config
and modpol.util.num_pairs(v.config) > 0 then
table.insert(display_table, "Policies:")
for k2,v2 in pairs(v.config) do
input = k2..": "..v2
table.insert(display_table, input)
end
end
table.insert(display_table, "\n")
end
end
local output = table.concat(display_table,"\n")
if #display_table == 0 then
output = "No processes found"
end
modpol.interactions.display(
self.initiator,
"Processes in org "..self.org.name,
output,
function()
modpol.interactions.org_dashboard(
self.initiator, self.org.id)
if result then result() end
self.org:delete_process(self.id)
end
)
end
--- (Required) Add to module table
modpol.modules.display_processes = display_processes

View File

@ -43,10 +43,12 @@ function module_template:initiate(result)
-- call interaction functions here!
-- concluding functions:
-- first, where appropriate, return users to dashboards.
-- second, result:
-- may need to put result in self.data.result
-- call this when module is successful (not for abort):
if result then result() end
-- third, delete the process
-- call this wherever process might end:
self.org:delete_process(self.id)
end