Added basic policy backend for modules. Also added confirmation in CLI to call a module. At that confirmation, the relevant policies are shown. Still need to create a module for changing policies and to add more configuration options to existing policies.
This commit is contained in:
parent
fc8cd20e7f
commit
b92272afa2
@ -5,6 +5,35 @@
|
|||||||
|
|
||||||
modpol.interactions = {}
|
modpol.interactions = {}
|
||||||
|
|
||||||
|
-- UTILITIES
|
||||||
|
-- =========
|
||||||
|
|
||||||
|
--- Output: returns a string listing a module's policies
|
||||||
|
-- @function modpol.interactions.get_policy_string
|
||||||
|
-- @param org (string or number) name or id for the org
|
||||||
|
-- @param module_slug (string)
|
||||||
|
-- @param sep (string) separator string
|
||||||
|
function modpol.interactions.get_policy_string(
|
||||||
|
org, module_slug, sep)
|
||||||
|
local this_org = modpol.orgs.get_org(org)
|
||||||
|
local this_module = modpol.modules[module_slug]
|
||||||
|
local output = {}
|
||||||
|
if modpol.util.num_pairs(this_module.config) > 0 then
|
||||||
|
for k, v in pairs(this_module.config) do
|
||||||
|
local this_policy = ""
|
||||||
|
-- org policies
|
||||||
|
if this_org.policies[module_slug]
|
||||||
|
and this_org.policies[module_slug][k] then
|
||||||
|
this_policy = k .. " - " ..
|
||||||
|
tostring(this_org.policies[module_slug][k])
|
||||||
|
else
|
||||||
|
this_policy = k .. " - " .. tostring(v)
|
||||||
|
end
|
||||||
|
table.insert(output,this_policy)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return "Policies:\n" .. table.concat(output, sep)
|
||||||
|
end
|
||||||
|
|
||||||
-- DASHBOARDS
|
-- DASHBOARDS
|
||||||
-- ==========
|
-- ==========
|
||||||
@ -165,8 +194,23 @@ function modpol.interactions.org_dashboard(user, org_string)
|
|||||||
module_result = true
|
module_result = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
local module = org.modules[module_sel]
|
||||||
if module_result then
|
if module_result then
|
||||||
org:call_module(module_sel, user)
|
modpol.interactions.binary_poll_user(
|
||||||
|
user,
|
||||||
|
module.name..":\n"..
|
||||||
|
module.desc.."\n"..
|
||||||
|
modpol.interactions.get_policy_string(
|
||||||
|
org.name, module.slug, "\n")..
|
||||||
|
"\n".."Proceed?",
|
||||||
|
function(input)
|
||||||
|
if input == "Yes" then
|
||||||
|
org:call_module(module_sel, user)
|
||||||
|
elseif input == "No" then
|
||||||
|
modpol.interactions.org_dashboard(
|
||||||
|
pname, org.id)
|
||||||
|
end
|
||||||
|
end)
|
||||||
else
|
else
|
||||||
print("Error: Module not found.")
|
print("Error: Module not found.")
|
||||||
modpol.interactions.org_dashboard(user, org.id)
|
modpol.interactions.org_dashboard(user, org.id)
|
||||||
|
@ -15,11 +15,12 @@ function temp_org()
|
|||||||
id = nil,
|
id = nil,
|
||||||
name = nil,
|
name = nil,
|
||||||
modules = modpol.util.copy_table(modpol.modules),
|
modules = modpol.util.copy_table(modpol.modules),
|
||||||
|
policies = {},
|
||||||
processes = {},
|
processes = {},
|
||||||
pending = {},
|
pending = {},
|
||||||
members = {},
|
members = {},
|
||||||
parent = nil,
|
parent = nil,
|
||||||
children = {}
|
children = {},
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -18,12 +18,22 @@ function modpol.orgs:call_module(module_slug, initiator, config, result, parent_
|
|||||||
local module = modpol.modules[module_slug]
|
local module = modpol.modules[module_slug]
|
||||||
|
|
||||||
-- sets default values for undeclared config variables
|
-- sets default values for undeclared config variables
|
||||||
if modpol.util.num_pairs(module.config) > 0 and config then
|
-- first applies any relevant org policies
|
||||||
for k, v in pairs(module.config) do
|
-- then overrides with the config values given on input
|
||||||
if config[k] == nil then
|
local new_config = {}
|
||||||
config[k] = v
|
if modpol.util.num_pairs(module.config) > 0 then
|
||||||
end
|
for k, v in pairs(module.config) do
|
||||||
end
|
new_config[k] = v
|
||||||
|
-- org policies
|
||||||
|
if self.policies[module_slug]
|
||||||
|
and self.policies[module_slug][k] then
|
||||||
|
new_config[k] = self.policies[module_slug][k]
|
||||||
|
end
|
||||||
|
-- input settings
|
||||||
|
if config and config[k] then
|
||||||
|
new_config[k] = config[k]
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- setting default params
|
-- setting default params
|
||||||
@ -34,7 +44,7 @@ function modpol.orgs:call_module(module_slug, initiator, config, result, parent_
|
|||||||
id = index,
|
id = index,
|
||||||
parent_id = parent_id,
|
parent_id = parent_id,
|
||||||
children = {},
|
children = {},
|
||||||
config = config,
|
config = modpol.util.copy_table(new_config),
|
||||||
data = modpol.util.copy_table(module.data),
|
data = modpol.util.copy_table(module.data),
|
||||||
slug = module_slug
|
slug = module_slug
|
||||||
}
|
}
|
||||||
|
@ -237,7 +237,9 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
|||||||
pname,
|
pname,
|
||||||
module.name..":\n"..
|
module.name..":\n"..
|
||||||
module.desc.."\n"..
|
module.desc.."\n"..
|
||||||
"Proceed?",
|
modpol.interactions.get_policy_string(
|
||||||
|
org.name, module.slug, ", ")..
|
||||||
|
"\n".."Proceed?",
|
||||||
function(input)
|
function(input)
|
||||||
if input == "Yes" then
|
if input == "Yes" then
|
||||||
org:call_module(module.slug, pname)
|
org:call_module(module.slug, pname)
|
||||||
@ -570,10 +572,10 @@ function modpol.interactions.binary_poll_user(user, question, func)
|
|||||||
-- set up formspec
|
-- set up formspec
|
||||||
local formspec = {
|
local formspec = {
|
||||||
"formspec_version[4]",
|
"formspec_version[4]",
|
||||||
"size[8,4]",
|
"size[8,6]",
|
||||||
"label[0.375,0.5;",minetest.formspec_escape(question), "]",
|
"label[0.375,0.5;",minetest.formspec_escape(question), "]",
|
||||||
"button[1,2.5;1,0.8;yes;Yes]",
|
"button[1,5;1,0.8;yes;Yes]",
|
||||||
"button[2,2.5;1,0.8;no;No]",
|
"button[2,5;1,0.8;no;No]",
|
||||||
--TODO can we enable text wrapping?
|
--TODO can we enable text wrapping?
|
||||||
--TODO we could use scroll boxes to contain the text
|
--TODO we could use scroll boxes to contain the text
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user