Added modpol.interactions.display and display_processes module, as well as a bunch of bugfixes
This commit is contained in:
modpol_core
modpol_minetest/overrides
@ -17,6 +17,7 @@ dofile (localdir .. "/modules/change_modules.lua")
|
|||||||
dofile (localdir .. "/modules/consent.lua")
|
dofile (localdir .. "/modules/consent.lua")
|
||||||
dofile (localdir .. "/modules/create_token.lua")
|
dofile (localdir .. "/modules/create_token.lua")
|
||||||
dofile (localdir .. "/modules/defer_consent.lua")
|
dofile (localdir .. "/modules/defer_consent.lua")
|
||||||
|
dofile (localdir .. "/modules/display_processes.lua")
|
||||||
dofile (localdir .. "/modules/join_org_consent.lua")
|
dofile (localdir .. "/modules/join_org_consent.lua")
|
||||||
dofile (localdir .. "/modules/leave_org.lua")
|
dofile (localdir .. "/modules/leave_org.lua")
|
||||||
dofile (localdir .. "/modules/message_org.lua")
|
dofile (localdir .. "/modules/message_org.lua")
|
||||||
|
@ -168,6 +168,7 @@ function modpol.interactions.org_dashboard(user, org_string)
|
|||||||
org:call_module(module_sel, user)
|
org:call_module(module_sel, user)
|
||||||
else
|
else
|
||||||
print("Error: Module not found.")
|
print("Error: Module not found.")
|
||||||
|
modpol.interactions.org_dashboard(user, org.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif sel == 'p' or sel == 'P' then
|
elseif sel == 'p' or sel == 'P' then
|
||||||
@ -261,18 +262,26 @@ end
|
|||||||
--- Function: modpol.interactions.display
|
--- Function: modpol.interactions.display
|
||||||
-- Displays complex data to a user
|
-- Displays complex data to a user
|
||||||
-- @param user Name of target user (string)
|
-- @param user Name of target user (string)
|
||||||
|
-- @param title Title of display (string)
|
||||||
-- @param message Content of message (string or table of strings)
|
-- @param message Content of message (string or table of strings)
|
||||||
-- @param done Optional function for what happens when user is done
|
-- @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 = ""
|
local output = ""
|
||||||
if type(message) == table then
|
output = "\n-=< "..title.." >=-\n\n"
|
||||||
|
if type(message) == "table" then
|
||||||
output = table.concat(message,"\n")
|
output = table.concat(message,"\n")
|
||||||
elseif type(message) == string then
|
elseif type(message) == "string" then
|
||||||
output = message
|
output = message
|
||||||
elseif type(message) == number then
|
elseif type(message) == "number" then
|
||||||
output = message
|
output = message
|
||||||
else
|
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
|
end
|
||||||
print(message)
|
print(message)
|
||||||
print("\nEnter to continue")
|
print("\nEnter to continue")
|
||||||
|
61
modpol_core/modules/display_processes.lua
Normal file
61
modpol_core/modules/display_processes.lua
Normal 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
|
@ -43,10 +43,12 @@ function module_template:initiate(result)
|
|||||||
-- call interaction functions here!
|
-- call interaction functions here!
|
||||||
|
|
||||||
-- concluding functions:
|
-- concluding functions:
|
||||||
|
-- first, where appropriate, return users to dashboards.
|
||||||
|
-- second, result:
|
||||||
-- may need to put result in self.data.result
|
-- may need to put result in self.data.result
|
||||||
-- call this when module is successful (not for abort):
|
-- call this when module is successful (not for abort):
|
||||||
if result then result() end
|
if result then result() end
|
||||||
|
-- third, delete the process
|
||||||
-- call this wherever process might end:
|
-- call this wherever process might end:
|
||||||
self.org:delete_process(self.id)
|
self.org:delete_process(self.id)
|
||||||
end
|
end
|
||||||
|
@ -49,7 +49,6 @@ function modpol.interactions.dashboard(user)
|
|||||||
local user_orgs = modpol.orgs.user_orgs(user)
|
local user_orgs = modpol.orgs.user_orgs(user)
|
||||||
local all_users = modpol.instance:list_members()
|
local all_users = modpol.instance:list_members()
|
||||||
-- pending list
|
-- pending list
|
||||||
local user_pending = {"View..."}
|
|
||||||
local user_pending_count = 0
|
local user_pending_count = 0
|
||||||
for k,v in ipairs(modpol.orgs.array) do
|
for k,v in ipairs(modpol.orgs.array) do
|
||||||
if v.pending and v.pending[user] then
|
if v.pending and v.pending[user] then
|
||||||
@ -64,15 +63,15 @@ function modpol.interactions.dashboard(user)
|
|||||||
local formspec = {
|
local formspec = {
|
||||||
"formspec_version[4]",
|
"formspec_version[4]",
|
||||||
"size[10,8]",
|
"size[10,8]",
|
||||||
"label[0.5,0.5;M O D P O L]",
|
"hypertext[0.5,0.5;9,1;title;<big>Org dashboard</big>]",
|
||||||
"label[0.5,2;All orgs:]",
|
"label[0.5,2;All orgs:]",
|
||||||
"dropdown[2,1.5;7,0.8;all_orgs;"..formspec_list(all_orgs)..";;]",
|
"dropdown[2,1.5;7,0.8;all_orgs;View...,"..formspec_list(all_orgs)..";;]",
|
||||||
"label[0.5,3;Your orgs:]",
|
"label[0.5,3;Your orgs:]",
|
||||||
"dropdown[2,2.5;7,0.8;user_orgs;"..formspec_list(user_orgs)..";;]",
|
"dropdown[2,2.5;7,0.8;user_orgs;View...,"..formspec_list(user_orgs)..";;]",
|
||||||
"label[0.5,4;All users:]",
|
"label[0.5,4;All users:]",
|
||||||
"dropdown[2,3.5;7,0.8;all_users;"..formspec_list(all_users)..";;]",
|
"dropdown[2,3.5;7,0.8;all_users;View...,"..formspec_list(all_users)..";;]",
|
||||||
"label[0.5,5;Pending ("..user_pending_count.."):]",
|
"label[0.5,5;Pending ("..user_pending_count.."):]",
|
||||||
"dropdown[2,4.5;7,0.8;pending;"..formspec_list(user_pending)..";;]",
|
"dropdown[2,4.5;7,0.8;pending;View...,"..formspec_list(user_pending)..";;]",
|
||||||
"button[0.5,7;1,0.8;refresh;Refresh]",
|
"button[0.5,7;1,0.8;refresh;Refresh]",
|
||||||
"button_exit[8.5,7;1,0.8;close;Close]",
|
"button_exit[8.5,7;1,0.8;close;Close]",
|
||||||
}
|
}
|
||||||
@ -90,7 +89,8 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
|||||||
elseif fields.refresh then
|
elseif fields.refresh then
|
||||||
modpol.interactions.dashboard(pname)
|
modpol.interactions.dashboard(pname)
|
||||||
-- Put all dropdowns at the end
|
-- Put all dropdowns at the end
|
||||||
elseif fields.all_users then
|
elseif fields.all_users
|
||||||
|
and fields.all_users ~= "View..." then
|
||||||
modpol.interactions.user_dashboard(
|
modpol.interactions.user_dashboard(
|
||||||
pname,
|
pname,
|
||||||
fields.all_users,
|
fields.all_users,
|
||||||
@ -100,7 +100,10 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
|||||||
)
|
)
|
||||||
elseif fields.all_orgs or fields.user_orgs or fields.pending then
|
elseif fields.all_orgs or fields.user_orgs or fields.pending then
|
||||||
local org_name = fields.all_orgs or fields.user_orgs or fields.pending
|
local org_name = fields.all_orgs or fields.user_orgs or fields.pending
|
||||||
modpol.interactions.org_dashboard(pname, org_name)
|
if org_name ~= "View..." then
|
||||||
|
modpol.interactions.org_dashboard(
|
||||||
|
pname, org_name)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
@ -129,6 +132,9 @@ function modpol.interactions.org_dashboard(user, org_string)
|
|||||||
if parent then parent = parent.name
|
if parent then parent = parent.name
|
||||||
else parent = "none" end
|
else parent = "none" end
|
||||||
|
|
||||||
|
-- prepare members menu
|
||||||
|
local members = org.members
|
||||||
|
|
||||||
-- prepare children menu
|
-- prepare children menu
|
||||||
local children = {}
|
local children = {}
|
||||||
for k,v in ipairs(org.children) do
|
for k,v in ipairs(org.children) do
|
||||||
@ -136,7 +142,6 @@ function modpol.interactions.org_dashboard(user, org_string)
|
|||||||
table.insert(children, this_child.name)
|
table.insert(children, this_child.name)
|
||||||
end
|
end
|
||||||
table.sort(children)
|
table.sort(children)
|
||||||
table.insert(children,1,"View...")
|
|
||||||
|
|
||||||
-- prepare modules menu
|
-- prepare modules menu
|
||||||
local modules = {}
|
local modules = {}
|
||||||
@ -149,7 +154,6 @@ function modpol.interactions.org_dashboard(user, org_string)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
table.sort(modules)
|
table.sort(modules)
|
||||||
table.insert(modules,1,"View...")
|
|
||||||
|
|
||||||
-- prepare pending menu
|
-- prepare pending menu
|
||||||
local pending = {}
|
local pending = {}
|
||||||
@ -163,7 +167,6 @@ function modpol.interactions.org_dashboard(user, org_string)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
table.sort(pending)
|
table.sort(pending)
|
||||||
table.insert(pending,1,"View...")
|
|
||||||
|
|
||||||
-- set player context
|
-- set player context
|
||||||
local user_context = {}
|
local user_context = {}
|
||||||
@ -173,17 +176,17 @@ function modpol.interactions.org_dashboard(user, org_string)
|
|||||||
local formspec = {
|
local formspec = {
|
||||||
"formspec_version[4]",
|
"formspec_version[4]",
|
||||||
"size[10,8]",
|
"size[10,8]",
|
||||||
"label[0.5,0.5;Org: "..
|
"hypertext[0.5,0.5;9,1;title;<big>Org: <b>"..
|
||||||
minetest.formspec_escape(org.name)..membership_toggle(org.name).."]",
|
minetest.formspec_escape(org.name).."</b>"..membership_toggle(org.name).."</big>]",
|
||||||
"label[0.5,1;Parent: "..parent..membership_toggle(parent).."]",
|
"label[0.5,1.25;Parent: "..parent..membership_toggle(parent).."]",
|
||||||
"label[0.5,2;Members:]",
|
"label[0.5,2;Members:]",
|
||||||
"dropdown[2,1.5;7,0.8;members;"..formspec_list(org.members)..";;]",
|
"dropdown[2,1.5;7,0.8;members;View...,"..formspec_list(members)..";;]",
|
||||||
"label[0.5,3;Child orgs:]",
|
"label[0.5,3;Child orgs:]",
|
||||||
"dropdown[2,2.5;7,0.8;children;"..formspec_list(children)..";;]",
|
"dropdown[2,2.5;7,0.8;children;View...,"..formspec_list(children)..";;]",
|
||||||
"label[0.5,4;Modules:]",
|
"label[0.5,4;Modules:]",
|
||||||
"dropdown[2,3.5;7,0.8;modules;"..formspec_list(modules)..";;]",
|
"dropdown[2,3.5;7,0.8;modules;View...,"..formspec_list(modules)..";;]",
|
||||||
"label[0.5,5;Pending ("..num_pending.."):]",
|
"label[0.5,5;Pending ("..num_pending.."):]",
|
||||||
"dropdown[2,4.5;7,0.8;pending;"..formspec_list(pending)..";;]",
|
"dropdown[2,4.5;7,0.8;pending;View...,"..formspec_list(pending)..";;]",
|
||||||
"button[0.5,7;1,0.8;refresh;Refresh]",
|
"button[0.5,7;1,0.8;refresh;Refresh]",
|
||||||
"button[8.5,7;1,0.8;back;Back]",
|
"button[8.5,7;1,0.8;back;Back]",
|
||||||
}
|
}
|
||||||
@ -210,7 +213,8 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
|||||||
|
|
||||||
-- Put all dropdowns at the end
|
-- Put all dropdowns at the end
|
||||||
-- Receiving modules
|
-- Receiving modules
|
||||||
elseif fields.members then
|
elseif fields.members
|
||||||
|
and fields.members ~= "View..." then
|
||||||
modpol.interactions.user_dashboard(
|
modpol.interactions.user_dashboard(
|
||||||
pname,
|
pname,
|
||||||
fields.members,
|
fields.members,
|
||||||
@ -268,7 +272,6 @@ end)
|
|||||||
-- @param completion Optional function to call on Done button
|
-- @param completion Optional function to call on Done button
|
||||||
function modpol.interactions.user_dashboard(viewer, user, completion)
|
function modpol.interactions.user_dashboard(viewer, user, completion)
|
||||||
local user_orgs = modpol.orgs.user_orgs(user)
|
local user_orgs = modpol.orgs.user_orgs(user)
|
||||||
table.insert(user_orgs,1,"View...")
|
|
||||||
|
|
||||||
-- set player context
|
-- set player context
|
||||||
local user_context = {}
|
local user_context = {}
|
||||||
@ -280,9 +283,9 @@ function modpol.interactions.user_dashboard(viewer, user, completion)
|
|||||||
local formspec = {
|
local formspec = {
|
||||||
"formspec_version[4]",
|
"formspec_version[4]",
|
||||||
"size[10,8]",
|
"size[10,8]",
|
||||||
"label[0.5,0.5;User: "..user.."]",
|
"hypertext[0.5,0.5;9,1;title;<big>User: <b>"..user.."</b></big>]",
|
||||||
"label[0.5,2;User's orgs:]",
|
"label[0.5,2;User's orgs:]",
|
||||||
"dropdown[2,1.5;7,0.8;user_orgs;"..formspec_list(user_orgs)..";;]",
|
"dropdown[2,1.5;7,0.8;user_orgs;View...,"..formspec_list(user_orgs)..";;]",
|
||||||
"button[0.5,7;1.5,0.8;message;Message]",
|
"button[0.5,7;1.5,0.8;message;Message]",
|
||||||
"button_exit[8.5,7;1,0.8;close;Close]",
|
"button_exit[8.5,7;1,0.8;close;Close]",
|
||||||
}
|
}
|
||||||
@ -350,10 +353,51 @@ end
|
|||||||
--- Function: modpol.interactions.display
|
--- Function: modpol.interactions.display
|
||||||
-- Displays complex data to a user
|
-- Displays complex data to a user
|
||||||
-- @param user Name of target user (string)
|
-- @param user Name of target user (string)
|
||||||
|
-- @param title Title of display (string)
|
||||||
-- @param message Content of message (string or table of strings)
|
-- @param message Content of message (string or table of strings)
|
||||||
-- @param done Optional function for what happens when user is done
|
-- @param completion Optional function for what happens when user is done
|
||||||
|
function modpol.interactions.display(
|
||||||
|
user, title, message, completion)
|
||||||
|
-- set up contexts
|
||||||
|
_contexts[user]["completion"] = completion
|
||||||
|
-- set up output
|
||||||
|
local output = ""
|
||||||
|
if type(message) == "table" then
|
||||||
|
output = table.concat(message,"\n")
|
||||||
|
elseif type(message) == "string" then
|
||||||
|
output = message
|
||||||
|
elseif type(message) == "number" then
|
||||||
|
output = message
|
||||||
|
else
|
||||||
|
modpol.interactions.message(
|
||||||
|
self.initiator, "Error: message not typed for display")
|
||||||
|
if completion then completion() else
|
||||||
|
modpol.intereactions.dashboard(user)
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
-- set up formspec
|
||||||
|
local formspec = {
|
||||||
|
"formspec_version[4]",
|
||||||
|
"size[10,8]",
|
||||||
|
"label[0.5,0.5;"..title.."]",
|
||||||
|
"hypertext[0.5,1;9,5.5;display;<global background=black margin=10>"..output.."]",
|
||||||
|
"button_exit[8.5,7;1,0.8;done;Done]",
|
||||||
|
}
|
||||||
|
local formspec_string = table.concat(formspec, "")
|
||||||
|
-- present to player
|
||||||
|
minetest.show_formspec(user, "modpol:display", formspec_string)
|
||||||
|
end
|
||||||
|
-- receive fields
|
||||||
|
minetest.register_on_player_receive_fields(function (player, formname, fields)
|
||||||
|
local pname = player:get_player_name()
|
||||||
|
if formname == "modpol:display" then
|
||||||
|
if fields.done and _contexts[pname].completion then
|
||||||
|
minetest.close_formspec(pname, formname)
|
||||||
|
_contexts[pname].completion()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
-- Function: modpol.interactions.text_query
|
-- Function: modpol.interactions.text_query
|
||||||
-- Overrides function at modpol/interactions.lua
|
-- Overrides function at modpol/interactions.lua
|
||||||
@ -399,14 +443,12 @@ end)
|
|||||||
-- func input: choice (string)
|
-- func input: choice (string)
|
||||||
-- output: calls func on user choice
|
-- output: calls func on user choice
|
||||||
function modpol.interactions.dropdown_query(user, label, options, func)
|
function modpol.interactions.dropdown_query(user, label, options, func)
|
||||||
-- Add "View..." to the top of the list
|
|
||||||
table.insert(options,1,"View...")
|
|
||||||
-- set up formspec
|
-- set up formspec
|
||||||
local formspec = {
|
local formspec = {
|
||||||
"formspec_version[4]",
|
"formspec_version[4]",
|
||||||
"size[10,4]",
|
"size[10,4]",
|
||||||
"label[0.5,1;"..minetest.formspec_escape(label).."]",
|
"label[0.5,1;"..minetest.formspec_escape(label).."]",
|
||||||
"dropdown[0.5,1.25;9,0.8;input;"..formspec_list(options)..";;]",
|
"dropdown[0.5,1.25;9,0.8;input;View...,"..formspec_list(options)..";;]",
|
||||||
"button[0.5,2.5;1,0.8;cancel;Cancel]",
|
"button[0.5,2.5;1,0.8;cancel;Cancel]",
|
||||||
}
|
}
|
||||||
local formspec_string = table.concat(formspec, "")
|
local formspec_string = table.concat(formspec, "")
|
||||||
|
Reference in New Issue
Block a user