|
@@ -47,23 +47,19 @@ function modpol.interactions.dashboard(user)
|
|
|
-- to add: nested orgs map
|
|
|
local all_orgs = modpol.orgs.list_all()
|
|
|
local user_orgs = modpol.orgs.user_orgs(user)
|
|
|
- local all_users = modpol.list_users()
|
|
|
+ local all_users = modpol.instance:list_members()
|
|
|
-- set up formspec
|
|
|
local formspec = {
|
|
|
"formspec_version[4]",
|
|
|
- "size[10,8]",
|
|
|
- "label[0.5,0.5;MODPOL DASHBOARD]",
|
|
|
+ "size[10,6]",
|
|
|
+ "label[0.5,0.5;M O D U L A R P O L I T I C S]",
|
|
|
"label[0.5,2;All orgs:]",
|
|
|
- "dropdown[2,1.5;5,0.8;all_orgs;"..formspec_list(all_orgs)..";;]",
|
|
|
+ "dropdown[2,1.5;7,0.8;all_orgs;"..formspec_list(all_orgs)..";;]",
|
|
|
"label[0.5,3;Your orgs:]",
|
|
|
- "dropdown[2,2.5;5,0.8;user_orgs;"..formspec_list(user_orgs)..";;]",
|
|
|
+ "dropdown[2,2.5;7,0.8;user_orgs;"..formspec_list(user_orgs)..";;]",
|
|
|
"label[0.5,4;All users:]",
|
|
|
- "dropdown[2,3.5;5,0.8;all_users;"..formspec_list(all_users)..";;]",
|
|
|
- "button[0.5,7;1,0.8;test_poll;Test poll]",
|
|
|
- "button[2,7;1,0.8;add_org;Add 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]",
|
|
|
+ "dropdown[2,3.5;7,0.8;all_users;"..formspec_list(all_users)..";;]",
|
|
|
+ "button_exit[8.5,5;1,0.8;close;Close]",
|
|
|
}
|
|
|
local formspec_string = table.concat(formspec, "")
|
|
|
-- present to player
|
|
@@ -75,26 +71,7 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
|
|
local pname = player:get_player_name()
|
|
|
if nil then
|
|
|
-- buttons first
|
|
|
- elseif fields.test_poll then
|
|
|
- -- FOR TESTING PURPOSES ONLY
|
|
|
- modpol.interactions.text_query(
|
|
|
- pname,"Poll question:",
|
|
|
- function(input)
|
|
|
- modpol.interactions.binary_poll_user(
|
|
|
- pname, input,
|
|
|
- function(vote)
|
|
|
- modpol.interactions.message(
|
|
|
- pname, pname .. " voted " .. vote)
|
|
|
- end)
|
|
|
- end)
|
|
|
- elseif fields.add_org then
|
|
|
- modpol.interactions.add_org(pname, 1)
|
|
|
- elseif fields.remove_org then
|
|
|
- modpol.interactions.remove_org(pname)
|
|
|
- elseif fields.reset_orgs then
|
|
|
- modpol.orgs.reset()
|
|
|
- modpol.instance:add_member(pname)
|
|
|
- modpol.interactions.dashboard(pname)
|
|
|
+ -- none here right now!
|
|
|
|
|
|
-- Put all dropdowns at the end
|
|
|
elseif fields.close then
|
|
@@ -108,86 +85,84 @@ end)
|
|
|
|
|
|
|
|
|
-- Function: modpol.interactions.org_dashboard
|
|
|
--- Params: user (string), org_name (string)
|
|
|
+-- Params: user (string), org_string (string or num)
|
|
|
-- Output: Displays a menu of org-specific commands to the user
|
|
|
-function modpol.interactions.org_dashboard(user, org_name)
|
|
|
+function modpol.interactions.org_dashboard(user, org_string)
|
|
|
-- prepare data
|
|
|
- local org = modpol.orgs.get_org(org_name)
|
|
|
+ local org = modpol.orgs.get_org(org_string)
|
|
|
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 = toggle_code
|
|
|
- ..minetest.formspec_escape("leave")..";"
|
|
|
- ..minetest.formspec_escape("Leave").."]"
|
|
|
- else
|
|
|
- toggle_code = toggle_code
|
|
|
- ..minetest.formspec_escape("join")..";"
|
|
|
- ..minetest.formspec_escape("Join").."]"
|
|
|
+
|
|
|
+ local function membership_toggle(org_display)
|
|
|
+ local current_org = modpol.orgs.get_org(org_display)
|
|
|
+ if current_org then
|
|
|
+ if current_org:has_member(user) then
|
|
|
+ return " (member)"
|
|
|
+ end
|
|
|
end
|
|
|
- return toggle_code
|
|
|
+ return ""
|
|
|
end
|
|
|
+
|
|
|
-- identify parent
|
|
|
local parent = modpol.orgs.get_org(org.parent)
|
|
|
if parent then parent = parent.name
|
|
|
else parent = "none" end
|
|
|
+
|
|
|
-- prepare children menu
|
|
|
- local children = {"View..."}
|
|
|
+ local children = {}
|
|
|
for k,v in ipairs(org.children) do
|
|
|
local this_child = modpol.orgs.get_org(v)
|
|
|
table.insert(children, this_child.name)
|
|
|
end
|
|
|
- -- 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
|
|
|
- local processes = {"View..."}
|
|
|
- for k,v in ipairs(org.processes) do
|
|
|
- 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 .. "] " ..
|
|
|
- active .. this_request.type
|
|
|
- if this_request.params[1] then
|
|
|
- req_str = req_str .. ": " ..
|
|
|
- table.concat(this_request.params, ", ")
|
|
|
+ table.sort(children)
|
|
|
+ table.insert(children,1,"View...")
|
|
|
+
|
|
|
+ -- prepare modules menu
|
|
|
+ local modules = {}
|
|
|
+ if org.modules then
|
|
|
+ for k,v in pairs(org.modules) do
|
|
|
+ if not v.hide then -- hide utility modules
|
|
|
+ local module_entry = v.name..
|
|
|
+ " ["..v.slug.."]"
|
|
|
+ table.insert(modules, module_entry)
|
|
|
end
|
|
|
- table.insert(processes, req_str)
|
|
|
end
|
|
|
end
|
|
|
+ table.sort(modules)
|
|
|
+ table.insert(modules,1,"View...")
|
|
|
+
|
|
|
+ -- prepare pending menu
|
|
|
+ local pending = {}
|
|
|
+ local num_pending = 0
|
|
|
+ if org.pending[user] then
|
|
|
+ for k,v in pairs(org.pending[user]) do
|
|
|
+ local pending_string = org.processes[k].name
|
|
|
+ .." ["..k.."]"
|
|
|
+ table.insert(pending, pending_string)
|
|
|
+ num_pending = num_pending + 1
|
|
|
+ end
|
|
|
+ end
|
|
|
+ table.sort(pending)
|
|
|
+ table.insert(pending,1,"View...")
|
|
|
+
|
|
|
-- set player context
|
|
|
local user_context = {}
|
|
|
- user_context["current_org"] = org_name
|
|
|
+ user_context["current_org"] = org.name
|
|
|
_contexts[user] = user_context
|
|
|
-- set up formspec
|
|
|
local formspec = {
|
|
|
"formspec_version[4]",
|
|
|
"size[10,8]",
|
|
|
"label[0.5,0.5;Org: "..
|
|
|
- minetest.formspec_escape(org_name).."]",
|
|
|
- "label[0.5,1;Parent: "..parent.."]",
|
|
|
- "button[8.5,0.5;1,0.8;"..membership_toggle(),
|
|
|
+ minetest.formspec_escape(org.name)..membership_toggle(org.name).."]",
|
|
|
+ "label[0.5,1;Parent: "..parent..membership_toggle(parent).."]",
|
|
|
"label[0.5,2;Members:]",
|
|
|
- "dropdown[2,1.5;5,0.8;user_orgs;"..formspec_list(org.members)..";;]",
|
|
|
+ "dropdown[2,1.5;7,0.8;user_orgs;"..formspec_list(org.members)..";;]",
|
|
|
"label[0.5,3;Children:]",
|
|
|
- "dropdown[2,2.5;5,0.8;children;"..formspec_list(children)..";;]",
|
|
|
- "label[0.5,4;Policies:]",
|
|
|
- "dropdown[2,3.5;5,0.8;policies;"..formspec_list(policies)..";;]",
|
|
|
- "label[0.5,5;Processes:]",
|
|
|
- "dropdown[2,4.5;5,0.8;processes;"..formspec_list(processes)..";;]",
|
|
|
- "button[0.5,7;1,0.8;test_poll;Test poll]",
|
|
|
- "button[2,7;1,0.8;add_child;Add child]",
|
|
|
- "button[3.5,7;1.5,0.8;remove_org;Remove org]",
|
|
|
+ "dropdown[2,2.5;7,0.8;children;"..formspec_list(children)..";;]",
|
|
|
+ "label[0.5,4;Modules:]",
|
|
|
+ "dropdown[2,3.5;7,0.8;modules;"..formspec_list(modules)..";;]",
|
|
|
+ "label[0.5,5;Pending ("..num_pending.."):]",
|
|
|
+ "dropdown[2,4.5;7,0.8;pending;"..formspec_list(pending)..";;]",
|
|
|
"button[8.5,7;1,0.8;back;Back]",
|
|
|
}
|
|
|
local formspec_string = table.concat(formspec, "")
|
|
@@ -199,72 +174,44 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
|
|
if formname == "modpol:org_dashboard" then
|
|
|
local pname = player:get_player_name()
|
|
|
local org = modpol.orgs.get_org(_contexts[pname].current_org)
|
|
|
- if nil then
|
|
|
- elseif fields.join then
|
|
|
- local new_request = {
|
|
|
- user = pname,
|
|
|
- type = "add_member",
|
|
|
- params = {pname}
|
|
|
- }
|
|
|
- org:make_request(new_request)
|
|
|
- modpol.interactions.org_dashboard(pname,org.name)
|
|
|
- elseif fields.leave then
|
|
|
- org:remove_member(pname)
|
|
|
+ -- just confirm the org still exists:
|
|
|
+ if not org then
|
|
|
+ modpol.interactions.message(pname, "Org no longer exists")
|
|
|
modpol.interactions.dashboard(pname)
|
|
|
- elseif fields.test_poll then
|
|
|
- modpol.interactions.binary_poll_org(
|
|
|
- pname, org.id,
|
|
|
- function(input)
|
|
|
- modpol.interactions.message_org(
|
|
|
- pname,
|
|
|
- org.id,
|
|
|
- "New response: " .. input)
|
|
|
- end)
|
|
|
- elseif fields.add_child then
|
|
|
- modpol.interactions.text_query(
|
|
|
- pname, "Child org name:",
|
|
|
- function(input)
|
|
|
- local new_request = {
|
|
|
- user = pname,
|
|
|
- type = "add_org",
|
|
|
- params = {input}
|
|
|
- }
|
|
|
- org:make_request(new_request)
|
|
|
- modpol.interactions.message(pname,"requested")
|
|
|
- modpol.interactions.org_dashboard(
|
|
|
- pname,org.name)
|
|
|
- end)
|
|
|
- elseif fields.remove_org then
|
|
|
- local new_request = {
|
|
|
- user = pname,
|
|
|
- type = "delete",
|
|
|
- params = {}
|
|
|
- }
|
|
|
- org:make_request(new_request)
|
|
|
- modpol.interactions.org_dashboard(pname,org.name)
|
|
|
+ return end
|
|
|
+ -- okay, onward
|
|
|
+ if nil then
|
|
|
elseif fields.back then
|
|
|
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)]
|
|
|
+ -- Receiving modules
|
|
|
+ elseif fields.modules
|
|
|
+ and fields.modules ~= "View..." then
|
|
|
+ local module = string.match(
|
|
|
+ fields.modules,"%[(.*)%]")
|
|
|
+ modpol.interactions.binary_poll_user(
|
|
|
+ pname,
|
|
|
+ modpol.modules[module].name..":\n"..
|
|
|
+ modpol.modules[module].desc.."\n"..
|
|
|
+ "Proceed?",
|
|
|
+ function(input)
|
|
|
+ if input == "Yes" then
|
|
|
+ org:call_module(module, pname)
|
|
|
+ end
|
|
|
+ end)
|
|
|
+
|
|
|
+ -- Receiving pending
|
|
|
+ elseif fields.pending
|
|
|
+ and fields.pending ~= "View..." then
|
|
|
+ local pending = string.match(
|
|
|
+ fields.pending,"%[(%d)%]")
|
|
|
+ local process = org.processes[tonumber(pending)]
|
|
|
if process then
|
|
|
- process:interact(pname)
|
|
|
+ org:interact(process.id, pname)
|
|
|
end
|
|
|
+
|
|
|
+ -- Children
|
|
|
elseif fields.children
|
|
|
and fields.children ~= "View..." then
|
|
|
local org_name = fields.children
|
|
@@ -286,20 +233,21 @@ function modpol.interactions.policy_dashboard(
|
|
|
end
|
|
|
|
|
|
|
|
|
--- BASIC INTERACTION FUNCTIONS
|
|
|
--- ===========================
|
|
|
+-- INTERACTION FUNCTIONS
|
|
|
+-- =====================
|
|
|
|
|
|
-- Function: modpol.interactions.message
|
|
|
--- input: message (string)
|
|
|
--- output
|
|
|
+-- input: user (string), message (string)
|
|
|
+-- output: displays message to specified user
|
|
|
function modpol.interactions.message(user, message)
|
|
|
- minetest.chat_send_player(user, message)
|
|
|
+ if message then
|
|
|
+ minetest.chat_send_player(user, message)
|
|
|
+ end
|
|
|
end
|
|
|
|
|
|
-- Function: modpol.interactions.text_query
|
|
|
-- Overrides function at modpol/interactions.lua
|
|
|
-- input: user (string), query (string), func (function)
|
|
|
--- func input: user input (string)
|
|
|
-- output: Applies "func" to user input
|
|
|
function modpol.interactions.text_query(user, query, func)
|
|
|
-- set up formspec
|
|
@@ -311,7 +259,7 @@ function modpol.interactions.text_query(user, query, func)
|
|
|
"button[0.5,2.5;1,0.8;yes;OK]",
|
|
|
}
|
|
|
local formspec_string = table.concat(formspec, "")
|
|
|
- -- present to players
|
|
|
+ -- present to player
|
|
|
minetest.show_formspec(user, "modpol:text_query", formspec_string)
|
|
|
-- put func in _contexts
|
|
|
if _contexts[user] == nil then _contexts[user] = {} end
|
|
@@ -341,6 +289,8 @@ end)
|
|
|
-- func input: choice (string)
|
|
|
-- output: calls func on user choice
|
|
|
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
|
|
|
local formspec = {
|
|
|
"formspec_version[4]",
|
|
@@ -360,25 +310,28 @@ end
|
|
|
minetest.register_on_player_receive_fields(function (player, formname, fields)
|
|
|
if formname == "modpol:dropdown_query" then
|
|
|
local pname = player:get_player_name()
|
|
|
- if fields.cancel ~= "cancel" then
|
|
|
+ if fields.cancel then
|
|
|
+ minetest.close_formspec(pname, formname)
|
|
|
+ elseif fields.input == "View..." then
|
|
|
+ -- "View...", do nothing
|
|
|
+ else
|
|
|
local choice = fields.input
|
|
|
local func = _contexts[pname]["dropdown_query_func"]
|
|
|
if not choice then
|
|
|
- -- no choice, do nothing
|
|
|
+ -- empty, do nothing
|
|
|
elseif func then
|
|
|
+ --not sure if we should close
|
|
|
+ --breaks sequential dropdown_queries:
|
|
|
+ --minetest.close_formspec(pname, formname)
|
|
|
func(choice)
|
|
|
else
|
|
|
+ minetest.close_formspec(pname, formname)
|
|
|
modpol.interactions.message(pname, "dropdown_query: " .. choice)
|
|
|
end
|
|
|
end
|
|
|
- minetest.close_formspec(pname, formname)
|
|
|
end
|
|
|
end)
|
|
|
|
|
|
-
|
|
|
--- SECONDARY INTERACTIONS
|
|
|
--- ======================
|
|
|
-
|
|
|
-- Function: modpol.binary_poll_user(user, question, function)
|
|
|
-- Overrides function at modpol/interactions.lua
|
|
|
-- Params: user (string), question (string), func (function)
|
|
@@ -388,12 +341,12 @@ function modpol.interactions.binary_poll_user(user, question, func)
|
|
|
-- set up formspec
|
|
|
local formspec = {
|
|
|
"formspec_version[4]",
|
|
|
- "size[5,3]",
|
|
|
+ "size[8,4]",
|
|
|
"label[0.375,0.5;",minetest.formspec_escape(question), "]",
|
|
|
- "button[1,1.5;1,0.8;yes;Yes]",
|
|
|
- "button[2,1.5;1,0.8;no;No]",
|
|
|
- --TKTK can we enable text wrapping?
|
|
|
- --TKTK we could use scroll boxes to contain the text
|
|
|
+ "button[1,2.5;1,0.8;yes;Yes]",
|
|
|
+ "button[2,2.5;1,0.8;no;No]",
|
|
|
+ --TODO can we enable text wrapping?
|
|
|
+ --TODO we could use scroll boxes to contain the text
|
|
|
}
|
|
|
local formspec_string = table.concat(formspec, "")
|
|
|
if _contexts[user] == nil then _contexts[user] = {} end
|
|
@@ -410,78 +363,9 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
|
|
elseif fields.no then vote = fields.no
|
|
|
end
|
|
|
if vote then
|
|
|
- modpol.interactions.message(pname, "Responded " .. vote)
|
|
|
local func = _contexts[pname]["binary_poll_func"]
|
|
|
if func then func(vote) end
|
|
|
end
|
|
|
minetest.close_formspec(pname, formname)
|
|
|
end
|
|
|
end)
|
|
|
-
|
|
|
--- COMPLEX INTERACTIONS
|
|
|
--- ====================
|
|
|
-
|
|
|
--- Function: modpol.interactions.message_org
|
|
|
--- input: initiator (string), org_id (number), message (string)
|
|
|
--- output: broadcasts message to all org members
|
|
|
-function modpol.interactions.message_org(initiator, org_id, message)
|
|
|
- local org = modpol.orgs.get_org(org_id)
|
|
|
- local users = org:list_members()
|
|
|
- for k,v in ipairs(users) do
|
|
|
- modpol.interactions.message(v, message)
|
|
|
- end
|
|
|
-end
|
|
|
-
|
|
|
-
|
|
|
--- Function: modpol.interactions.binary_poll_org
|
|
|
--- input: initator (user string), org_id (number)
|
|
|
--- output: gets question from initiator, asks all org members, broadcasts answers
|
|
|
--- TODO for testing. This should be implemented as a request.
|
|
|
-function modpol.interactions.binary_poll_org(initiator, org_id, func)
|
|
|
- local org = modpol.orgs.get_org(org_id)
|
|
|
- local users = org:list_members()
|
|
|
- modpol.interactions.text_query(
|
|
|
- initiator, "Yes/no poll question:",
|
|
|
- function(input)
|
|
|
- for k,v in ipairs(users) do
|
|
|
- modpol.interactions.binary_poll_user(v, input, func)
|
|
|
- end
|
|
|
- end)
|
|
|
-end
|
|
|
-
|
|
|
--- Function: modpol.interactions.add_org
|
|
|
--- input: initator (user string), base_org_id (ID)
|
|
|
--- output: interaction begins
|
|
|
--- GODMODE
|
|
|
-function modpol.interactions.add_org(user, base_org_id)
|
|
|
- modpol.interactions.text_query(
|
|
|
- user,"Org name:",
|
|
|
- function(input)
|
|
|
- local base_org = modpol.orgs.get_org(1)
|
|
|
- local result = base_org:add_org(input, user)
|
|
|
- local message = input .. " created"
|
|
|
- modpol.interactions.message(user, message)
|
|
|
- modpol.interactions.dashboard(user)
|
|
|
- end)
|
|
|
-end
|
|
|
-
|
|
|
--- Function: modpol.interactions.remove_org
|
|
|
--- input: initator (user string)
|
|
|
--- output: interaction begins
|
|
|
--- GODMODE
|
|
|
-function modpol.interactions.remove_org(user)
|
|
|
- -- start formspec
|
|
|
- local orgs_list = modpol.orgs.list_all()
|
|
|
- local label = "Choose an org to remove:"
|
|
|
- modpol.interactions.dropdown_query(
|
|
|
- user, label, orgs_list,
|
|
|
- function(input)
|
|
|
- if input then
|
|
|
- local target_org = modpol.orgs.get_org(input)
|
|
|
- local result = target_org:delete()
|
|
|
- local message = input .. " deleted"
|
|
|
- modpol.interactions.message(user, message)
|
|
|
- end
|
|
|
- modpol.interactions.dashboard(user)
|
|
|
- end)
|
|
|
-end
|