Progress on bugfixes and Minetest interfaces, but processes are still not completing
This commit is contained in:
parent
3775f77c2e
commit
30e25aee3d
@ -78,6 +78,12 @@ function modpol.interactions.org_dashboard(user, org_name)
|
|||||||
active = '*'
|
active = '*'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
local req_str = "[" .. v.id .. "] " ..
|
||||||
|
active .. this_request.type
|
||||||
|
if this_request.params[1] then
|
||||||
|
req_str = req_str ": " ..
|
||||||
|
table.concat(this_request.params, ", ")
|
||||||
|
end
|
||||||
local req_str = v.id .. " (" .. this_request.type .. " -> " .. table.concat(this_request.params, ", ") .. ")" .. active
|
local req_str = v.id .. " (" .. this_request.type .. " -> " .. table.concat(this_request.params, ", ") .. ")" .. active
|
||||||
table.insert(processes, req_str)
|
table.insert(processes, req_str)
|
||||||
end
|
end
|
||||||
@ -95,6 +101,13 @@ function modpol.interactions.org_dashboard(user, org_name)
|
|||||||
process:interact(user)
|
process:interact(user)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Function: modpol.interactions.policy_dashboard
|
||||||
|
-- input: user (string), org_id (int), policy (string)
|
||||||
|
-- if policy is nil, enables creating a new policy
|
||||||
|
-- output: opens a dashboard for viewing/editing policy details
|
||||||
|
-- TODO
|
||||||
|
|
||||||
|
|
||||||
-- Function: modpol.interactions.message
|
-- Function: modpol.interactions.message
|
||||||
-- input: user (string), message (string)
|
-- input: user (string), message (string)
|
||||||
-- output: prints message to CLI
|
-- output: prints message to CLI
|
||||||
|
@ -40,10 +40,11 @@ end
|
|||||||
|
|
||||||
-- ============================
|
-- ============================
|
||||||
-- interact function for the consent module
|
-- interact function for the consent module
|
||||||
|
-- input: user (string)
|
||||||
function modpol.modules.consent:interact(user)
|
function modpol.modules.consent:interact(user)
|
||||||
-- TODO this needs more context on the vote at hand
|
-- TODO this needs more context on the vote at hand
|
||||||
modpol.interactions.binary_poll_user(
|
modpol.interactions.binary_poll_user(
|
||||||
user, "How do you vote?",
|
user, "Do you consent?",
|
||||||
function(vote)
|
function(vote)
|
||||||
if vote == 'yes' then
|
if vote == 'yes' then
|
||||||
self:approve(user, true)
|
self:approve(user, true)
|
||||||
|
@ -101,15 +101,15 @@ function modpol.orgs.init_instance()
|
|||||||
|
|
||||||
local instance = temp_org()
|
local instance = temp_org()
|
||||||
instance.id = 1
|
instance.id = 1
|
||||||
instance.name = "instance"
|
instance.name = "root"
|
||||||
|
|
||||||
setmetatable(instance, modpol.orgs)
|
setmetatable(instance, modpol.orgs)
|
||||||
|
|
||||||
-- adding instance to org list
|
-- adding instance to org list
|
||||||
modpol.orgs.array[1] = instance
|
modpol.orgs.array[1] = instance
|
||||||
|
|
||||||
modpol.ocutil.log('Initialized the instance org')
|
modpol.ocutil.log('Initialized the instance root org')
|
||||||
modpol.orgs:record('Initialized the instance org', 'create_instance')
|
modpol.orgs:record('Initialized the instance root org', 'create_instance')
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
end
|
end
|
||||||
@ -153,6 +153,7 @@ end
|
|||||||
|
|
||||||
-- ==================================================
|
-- ==================================================
|
||||||
-- adds a new sub org to the org it is called on
|
-- adds a new sub org to the org it is called on
|
||||||
|
-- input: name (string), user (string)
|
||||||
-- ex: instance:add_org('town hall')
|
-- ex: instance:add_org('town hall')
|
||||||
function modpol.orgs:add_org(name, user)
|
function modpol.orgs:add_org(name, user)
|
||||||
if self.id == nil then
|
if self.id == nil then
|
||||||
@ -176,6 +177,7 @@ function modpol.orgs:add_org(name, user)
|
|||||||
child_org.id = modpol.orgs.count
|
child_org.id = modpol.orgs.count
|
||||||
child_org.name = name
|
child_org.name = name
|
||||||
child_org.parent = self.id
|
child_org.parent = self.id
|
||||||
|
child_org.processes = self.processes
|
||||||
|
|
||||||
setmetatable(child_org, modpol.orgs)
|
setmetatable(child_org, modpol.orgs)
|
||||||
|
|
||||||
|
@ -62,6 +62,7 @@ function modpol.interactions.dashboard(user)
|
|||||||
"button[0.5,7;1,0.8;test_poll;Test poll]",
|
"button[0.5,7;1,0.8;test_poll;Test poll]",
|
||||||
"button[2,7;1,0.8;add_org;Add org]",
|
"button[2,7;1,0.8;add_org;Add org]",
|
||||||
"button[3.5,7;1.5,0.8;remove_org;Remove org]",
|
"button[3.5,7;1.5,0.8;remove_org;Remove org]",
|
||||||
|
"button[5.5,7;1.5,0.8;reset_orgs;Reset orgs]",
|
||||||
"button_exit[8.5,7;1,0.8;close;Close]",
|
"button_exit[8.5,7;1,0.8;close;Close]",
|
||||||
}
|
}
|
||||||
local formspec_string = table.concat(formspec, "")
|
local formspec_string = table.concat(formspec, "")
|
||||||
@ -90,7 +91,12 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
|||||||
modpol.interactions.add_org(pname, 1)
|
modpol.interactions.add_org(pname, 1)
|
||||||
elseif fields.remove_org then
|
elseif fields.remove_org then
|
||||||
modpol.interactions.remove_org(pname)
|
modpol.interactions.remove_org(pname)
|
||||||
-- dropdowns need to go last
|
elseif fields.reset_orgs then
|
||||||
|
modpol.orgs.reset()
|
||||||
|
modpol.instance:add_member(pname)
|
||||||
|
modpol.interactions.dashboard(pname)
|
||||||
|
|
||||||
|
-- Put all dropdowns at the end
|
||||||
elseif fields.close then
|
elseif fields.close then
|
||||||
minetest.close_formspec(pname, formname)
|
minetest.close_formspec(pname, formname)
|
||||||
elseif fields.all_orgs or fields.user_orgs then
|
elseif fields.all_orgs or fields.user_orgs then
|
||||||
@ -122,16 +128,25 @@ function modpol.interactions.org_dashboard(user, org_name)
|
|||||||
end
|
end
|
||||||
return toggle_code
|
return toggle_code
|
||||||
end
|
end
|
||||||
-- identify parent TODO
|
-- identify parent
|
||||||
|
local parent = modpol.orgs.get_org(org.parent)
|
||||||
|
if parent then parent = parent.name
|
||||||
|
else parent = "none" end
|
||||||
-- prepare children menu
|
-- prepare children menu
|
||||||
local children = {}
|
local children = {"View..."}
|
||||||
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
|
||||||
-- prepare policies menu
|
-- prepare policies menu
|
||||||
|
local policies = {"View..."}
|
||||||
|
for k,v in pairs(org.policies) do
|
||||||
|
table.insert(policies, k .. ": " ..
|
||||||
|
org.policies[k].process_type)
|
||||||
|
end
|
||||||
|
table.insert(policies, "Add policy")
|
||||||
-- prepare processes menu
|
-- prepare processes menu
|
||||||
local processes = {}
|
local processes = {"View..."}
|
||||||
for k,v in ipairs(org.processes) do
|
for k,v in ipairs(org.processes) do
|
||||||
local this_request = org.requests[v.request_id]
|
local this_request = org.requests[v.request_id]
|
||||||
if type(this_request) == "table" then
|
if type(this_request) == "table" then
|
||||||
@ -142,8 +157,11 @@ function modpol.interactions.org_dashboard(user, org_name)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
local req_str = "[" .. v.id .. "] " ..
|
local req_str = "[" .. v.id .. "] " ..
|
||||||
this_request.type .. ": " ..
|
active .. this_request.type
|
||||||
this_request.params[1] .. active
|
if this_request.params[1] then
|
||||||
|
req_str = req_str .. ": " ..
|
||||||
|
table.concat(this_request.params, ", ")
|
||||||
|
end
|
||||||
table.insert(processes, req_str)
|
table.insert(processes, req_str)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -157,14 +175,14 @@ function modpol.interactions.org_dashboard(user, org_name)
|
|||||||
"size[10,8]",
|
"size[10,8]",
|
||||||
"label[0.5,0.5;Org: "..
|
"label[0.5,0.5;Org: "..
|
||||||
minetest.formspec_escape(org_name).."]",
|
minetest.formspec_escape(org_name).."]",
|
||||||
"label[0.5,1;Parent: TODO]",
|
"label[0.5,1;Parent: "..parent.."]",
|
||||||
"button[8.5,0.5;1,0.8;"..membership_toggle(),
|
"button[8.5,0.5;1,0.8;"..membership_toggle(),
|
||||||
"label[0.5,2;Members:]",
|
"label[0.5,2;Members:]",
|
||||||
"dropdown[2,1.5;5,0.8;user_orgs;"..formspec_list(org.members)..";;]",
|
"dropdown[2,1.5;5,0.8;user_orgs;"..formspec_list(org.members)..";;]",
|
||||||
"label[0.5,3;Children:]",
|
"label[0.5,3;Children:]",
|
||||||
"dropdown[2,2.5;5,0.8;children;"..formspec_list(children)..";;]",
|
"dropdown[2,2.5;5,0.8;children;"..formspec_list(children)..";;]",
|
||||||
"label[0.5,4;Policies:]",
|
"label[0.5,4;Policies:]",
|
||||||
"dropdown[2,3.5;5,0.8;policies;"..formspec_list(org.policies)..";;]",
|
"dropdown[2,3.5;5,0.8;policies;"..formspec_list(policies)..";;]",
|
||||||
"label[0.5,5;Processes:]",
|
"label[0.5,5;Processes:]",
|
||||||
"dropdown[2,4.5;5,0.8;processes;"..formspec_list(processes)..";;]",
|
"dropdown[2,4.5;5,0.8;processes;"..formspec_list(processes)..";;]",
|
||||||
"button[0.5,7;1,0.8;test_poll;Test poll]",
|
"button[0.5,7;1,0.8;test_poll;Test poll]",
|
||||||
@ -182,13 +200,6 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
|||||||
local pname = player:get_player_name()
|
local pname = player:get_player_name()
|
||||||
local org = modpol.orgs.get_org(_contexts[pname].current_org)
|
local org = modpol.orgs.get_org(_contexts[pname].current_org)
|
||||||
if nil then
|
if nil then
|
||||||
elseif fields.processes then
|
|
||||||
local sel =
|
|
||||||
string.match(fields.processes,"%[(%d)%]")
|
|
||||||
local process = org.processes[tonumber(sel)]
|
|
||||||
if process then
|
|
||||||
process:interact(user)
|
|
||||||
end
|
|
||||||
elseif fields.join then
|
elseif fields.join then
|
||||||
local new_request = {
|
local new_request = {
|
||||||
user = pname,
|
user = pname,
|
||||||
@ -196,7 +207,6 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
|||||||
params = {pname}
|
params = {pname}
|
||||||
}
|
}
|
||||||
org:make_request(new_request)
|
org:make_request(new_request)
|
||||||
--org:add_member(pname)
|
|
||||||
modpol.interactions.org_dashboard(pname,org.name)
|
modpol.interactions.org_dashboard(pname,org.name)
|
||||||
elseif fields.leave then
|
elseif fields.leave then
|
||||||
org:remove_member(pname)
|
org:remove_member(pname)
|
||||||
@ -208,20 +218,74 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
|||||||
modpol.interactions.message_org(
|
modpol.interactions.message_org(
|
||||||
pname,
|
pname,
|
||||||
org.id,
|
org.id,
|
||||||
pname .. " voted " .. input)
|
pname .. " responded " .. input)
|
||||||
end)
|
end)
|
||||||
elseif fields.add_child then
|
elseif fields.add_child then
|
||||||
modpol.interactions.add_org(
|
modpol.interactions.text_query(
|
||||||
pname, org.id)
|
pname, "Child org name:",
|
||||||
|
function(input)
|
||||||
|
local new_request = {
|
||||||
|
user = pname,
|
||||||
|
type = "add_org",
|
||||||
|
params = {input,pname}
|
||||||
|
}
|
||||||
|
org:make_request(new_request)
|
||||||
|
modpol.interactions.message(pname,"requested")
|
||||||
|
modpol.interactions.org_dashboard(
|
||||||
|
pname,org.name)
|
||||||
|
end)
|
||||||
elseif fields.remove_org then
|
elseif fields.remove_org then
|
||||||
modpol.interactions.remove_org(pname)
|
local new_request = {
|
||||||
|
user = pname,
|
||||||
|
type = "delete",
|
||||||
|
params = {}
|
||||||
|
}
|
||||||
|
org:make_request(new_request)
|
||||||
|
modpol.interactions.org_dashboard(pname,org.name)
|
||||||
elseif fields.back then
|
elseif fields.back then
|
||||||
modpol.interactions.dashboard(pname)
|
modpol.interactions.dashboard(pname)
|
||||||
|
|
||||||
|
-- Put all dropdowns at the end
|
||||||
|
elseif fields.policies
|
||||||
|
and fields.policies ~= "View..." then
|
||||||
|
local policy
|
||||||
|
if fields.policies == "Add policy" then
|
||||||
|
policy = nil
|
||||||
|
elseif fields.policies == "View..." then
|
||||||
|
return
|
||||||
|
else
|
||||||
|
policy = string.match(fields.policies,"(%w+)%:")
|
||||||
|
end
|
||||||
|
modpol.interactions.policy_dashboard(
|
||||||
|
pname, org.id, policy)
|
||||||
|
elseif fields.processes
|
||||||
|
and fields.processes ~= "View..." then
|
||||||
|
local sel = string.match(fields.processes,"%[(%d)%]")
|
||||||
|
local process = org.processes[tonumber(sel)]
|
||||||
|
if process then
|
||||||
|
process:interact(pname)
|
||||||
|
end
|
||||||
|
elseif fields.children
|
||||||
|
and fields.children ~= "View..." then
|
||||||
|
local org_name = fields.children
|
||||||
|
modpol.interactions.org_dashboard(pname, org_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
-- Function: modpol.interactions.policy_dashboard
|
||||||
|
-- input: user (string), org_id (int), policy (string)
|
||||||
|
-- output: opens a dashboard for viewing/editing policy details
|
||||||
|
-- TODO
|
||||||
|
function modpol.interactions.policy_dashboard(
|
||||||
|
user, org_id, policy)
|
||||||
|
modpol.interactions.message(
|
||||||
|
user,
|
||||||
|
"Not yet implemented: " .. policy)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- BASIC INTERACTION FUNCTIONS
|
-- BASIC INTERACTION FUNCTIONS
|
||||||
-- ===========================
|
-- ===========================
|
||||||
|
|
||||||
@ -250,7 +314,7 @@ function modpol.interactions.text_query(user, query, func)
|
|||||||
-- present to players
|
-- present to players
|
||||||
minetest.show_formspec(user, "modpol:text_query", formspec_string)
|
minetest.show_formspec(user, "modpol:text_query", formspec_string)
|
||||||
-- put func in _contexts
|
-- put func in _contexts
|
||||||
_contexts[user] = {}
|
if _contexts[user] == nil then _contexts[user] = {} end
|
||||||
_contexts[user]["text_query_func"] = func
|
_contexts[user]["text_query_func"] = func
|
||||||
end
|
end
|
||||||
-- receive fields
|
-- receive fields
|
||||||
@ -283,19 +347,20 @@ function modpol.interactions.dropdown_query(user, label, options, func)
|
|||||||
"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;"..formspec_list(options)..";;]",
|
||||||
"button[0.5,2.5;1,0.8;yes;OK]",
|
"button[0.5,2.5;1,0.8;cancel;Cancel]",
|
||||||
}
|
}
|
||||||
local formspec_string = table.concat(formspec, "")
|
local formspec_string = table.concat(formspec, "")
|
||||||
-- present to players
|
-- present to players
|
||||||
minetest.show_formspec(user, "modpol:dropdown_query", formspec_string)
|
minetest.show_formspec(user, "modpol:dropdown_query", formspec_string)
|
||||||
-- put func in _contexts
|
-- put func in _contexts
|
||||||
_contexts[user] = {}
|
if _contexts[user] == nil then _contexts[user] = {} end
|
||||||
_contexts[user]["dropdown_query_func"] = func
|
_contexts[user]["dropdown_query_func"] = func
|
||||||
end
|
end
|
||||||
-- receive fields
|
-- receive fields
|
||||||
minetest.register_on_player_receive_fields(function (player, formname, fields)
|
minetest.register_on_player_receive_fields(function (player, formname, fields)
|
||||||
if formname == "modpol:dropdown_query" then
|
if formname == "modpol:dropdown_query" then
|
||||||
local pname = player:get_player_name()
|
local pname = player:get_player_name()
|
||||||
|
if fields.cancel ~= "cancel" then
|
||||||
local choice = fields.input
|
local choice = fields.input
|
||||||
local func = _contexts[pname]["dropdown_query_func"]
|
local func = _contexts[pname]["dropdown_query_func"]
|
||||||
if not choice then
|
if not choice then
|
||||||
@ -305,6 +370,7 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
|||||||
else
|
else
|
||||||
modpol.interactions.message(pname, "dropdown_query: " .. choice)
|
modpol.interactions.message(pname, "dropdown_query: " .. choice)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
minetest.close_formspec(pname, formname)
|
minetest.close_formspec(pname, formname)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
@ -320,18 +386,17 @@ end)
|
|||||||
-- Output: Applies "func" to user input
|
-- Output: Applies "func" to user input
|
||||||
function modpol.interactions.binary_poll_user(user, question, func)
|
function modpol.interactions.binary_poll_user(user, question, func)
|
||||||
-- set up formspec
|
-- set up formspec
|
||||||
local text = "Poll: " .. question
|
|
||||||
local formspec = {
|
local formspec = {
|
||||||
"formspec_version[4]",
|
"formspec_version[4]",
|
||||||
"size[5,3]",
|
"size[5,3]",
|
||||||
"label[0.375,0.5;", minetest.formspec_escape(text), "]",
|
"label[0.375,0.5;",minetest.formspec_escape(question), "]",
|
||||||
"button[1,1.5;1,0.8;yes;Yes]",
|
"button[1,1.5;1,0.8;yes;Yes]",
|
||||||
"button[2,1.5;1,0.8;no;No]",
|
"button[2,1.5;1,0.8;no;No]",
|
||||||
--TKTK can we enable text wrapping?
|
--TKTK can we enable text wrapping?
|
||||||
--TKTK we could use scroll boxes to contain the text
|
--TKTK we could use scroll boxes to contain the text
|
||||||
}
|
}
|
||||||
local formspec_string = table.concat(formspec, "")
|
local formspec_string = table.concat(formspec, "")
|
||||||
_contexts[user] = {}
|
if _contexts[user] == nil then _contexts[user] = {} end
|
||||||
_contexts[user]["binary_poll_func"] = func
|
_contexts[user]["binary_poll_func"] = func
|
||||||
-- present to player
|
-- present to player
|
||||||
minetest.show_formspec(user, "modpol:binary_poll_user", formspec_string)
|
minetest.show_formspec(user, "modpol:binary_poll_user", formspec_string)
|
||||||
@ -345,7 +410,7 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
|||||||
elseif fields.no then vote = fields.no
|
elseif fields.no then vote = fields.no
|
||||||
end
|
end
|
||||||
if vote then
|
if vote then
|
||||||
modpol.interactions.message(pname, "Voted " .. vote)
|
modpol.interactions.message(pname, "Responded " .. vote)
|
||||||
local func = _contexts[pname]["binary_poll_func"]
|
local func = _contexts[pname]["binary_poll_func"]
|
||||||
if func then func(vote) end
|
if func then func(vote) end
|
||||||
end
|
end
|
||||||
@ -385,9 +450,9 @@ function modpol.interactions.binary_poll_org(initiator, org_id, func)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Function: modpol.interactions.add_org
|
-- Function: modpol.interactions.add_org
|
||||||
-- TODO: NEEDS TO BE MADE INTO A REQUEST
|
|
||||||
-- input: initator (user string), base_org_id (ID)
|
-- input: initator (user string), base_org_id (ID)
|
||||||
-- output: interaction begins
|
-- output: interaction begins
|
||||||
|
-- GODMODE
|
||||||
function modpol.interactions.add_org(user, base_org_id)
|
function modpol.interactions.add_org(user, base_org_id)
|
||||||
modpol.interactions.text_query(
|
modpol.interactions.text_query(
|
||||||
user,"Org name:",
|
user,"Org name:",
|
||||||
@ -401,9 +466,9 @@ function modpol.interactions.add_org(user, base_org_id)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Function: modpol.interactions.remove_org
|
-- Function: modpol.interactions.remove_org
|
||||||
-- TODO: NEEDS TO BE MADE INTO A REQUEST
|
|
||||||
-- input: initator (user string)
|
-- input: initator (user string)
|
||||||
-- output: interaction begins
|
-- output: interaction begins
|
||||||
|
-- GODMODE
|
||||||
function modpol.interactions.remove_org(user)
|
function modpol.interactions.remove_org(user)
|
||||||
-- start formspec
|
-- start formspec
|
||||||
local orgs_list = modpol.orgs.list_all()
|
local orgs_list = modpol.orgs.list_all()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user