Bugfixes on CLI interactions
This commit is contained in:
@ -6,7 +6,7 @@ This implementation is a mod for [Minetest](https://minetest.net), a free/open-s
|
|||||||
|
|
||||||
## How to use it
|
## How to use it
|
||||||
|
|
||||||
Modpol is built around groups called *orgs*. At the base is an org with all users in it, called `root` by default.
|
Modpol is built around groups called *orgs*. At the base is an org with all users in it, called `Root` by default.
|
||||||
|
|
||||||
*Modules* enable people to do things within orgs, such as decide on membership, grant powers to the org, and much more. Modules can be added and modified by users to meet their needs. Modules can also be nested in each other, so one module can rely on another module to accomplish a process. Within an org, choose the module that you want to use:
|
*Modules* enable people to do things within orgs, such as decide on membership, grant powers to the org, and much more. Modules can be added and modified by users to meet their needs. Modules can also be nested in each other, so one module can rely on another module to accomplish a process. Within an org, choose the module that you want to use:
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
dofile("modpol_core/modpol.lua")
|
dofile("modpol_core/modpol.lua")
|
||||||
|
|
||||||
|
modpol.orgs.reset()
|
||||||
|
|
||||||
print("Log in as which user?")
|
print("Log in as which user?")
|
||||||
local username = io.read()
|
local username = io.read()
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ function modpol.interactions.dashboard(user)
|
|||||||
|
|
||||||
local all_users = modpol.instance:list_members()
|
local all_users = modpol.instance:list_members()
|
||||||
|
|
||||||
|
print('\n-=< MODPOL DASHBOARD >=-')
|
||||||
print('All orgs: (user orgs indicated by *)')
|
print('All orgs: (user orgs indicated by *)')
|
||||||
for id, org in ipairs(modpol.orgs.array) do
|
for id, org in ipairs(modpol.orgs.array) do
|
||||||
if type(org) == "table" then
|
if type(org) == "table" then
|
||||||
@ -36,7 +37,6 @@ function modpol.interactions.dashboard(user)
|
|||||||
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
|
||||||
modpol.msg(v.name)
|
|
||||||
table.insert(user_pending, v.name)
|
table.insert(user_pending, v.name)
|
||||||
user_pending_count = user_pending_count + 1
|
user_pending_count = user_pending_count + 1
|
||||||
end
|
end
|
||||||
@ -82,31 +82,37 @@ function modpol.interactions.org_dashboard(user, org_string)
|
|||||||
table.insert(children, this_child.name)
|
table.insert(children, this_child.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- list available modules
|
-- prepare modules menu
|
||||||
local org_modules = {}
|
local modules = {}
|
||||||
for k,v in pairs(org.modules) do
|
if org.modules then
|
||||||
if not v.hide then
|
for k,v in pairs(org.modules) do
|
||||||
table.insert(org_modules, v.slug)
|
if not v.hide then -- hide utility modules
|
||||||
|
local module_entry = v.slug
|
||||||
|
table.insert(modules, module_entry)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
table.sort(modules)
|
||||||
|
|
||||||
-- list pending
|
-- list pending
|
||||||
local process_msg = #org.processes .. " total processes"
|
local process_msg = #org.processes .. " total processes"
|
||||||
if org.pending[user] then
|
if org.pending[user] then
|
||||||
process_msg = process_msg .. " (" .. #org.pending[user] .. " pending)"
|
process_msg = process_msg .. " (" ..
|
||||||
|
modpol.util.num_pairs(org.pending[user]) .. " pending)"
|
||||||
else
|
else
|
||||||
process_msg = process_msg .. " (0 pending)"
|
process_msg = process_msg .. " (0 pending)"
|
||||||
end
|
end
|
||||||
|
|
||||||
-- set up output
|
-- set up output
|
||||||
|
print('\n-=< ORG DASHBOARD >=-')
|
||||||
print("Org: " .. org.name)
|
print("Org: " .. org.name)
|
||||||
print("Parent: " .. parent)
|
print("Parent: " .. parent)
|
||||||
print("Members: " .. table.concat(org.members, ", "))
|
print("Members: " .. table.concat(org.members, ", "))
|
||||||
print("Children: " .. table.concat(children, ", "))
|
print("Children: " .. table.concat(children, ", "))
|
||||||
print("Modules: " .. table.concat(org_modules, ", "))
|
print("Modules: " .. table.concat(modules, ", "))
|
||||||
print("Pending: " .. process_msg)
|
print("Pending: " .. process_msg)
|
||||||
print()
|
print()
|
||||||
print("Commands: (M)odules, (P)ending")
|
print("Commands: (M)odules, (P)ending, (B)ack")
|
||||||
|
|
||||||
local sel = io.read()
|
local sel = io.read()
|
||||||
print()
|
print()
|
||||||
@ -116,7 +122,7 @@ function modpol.interactions.org_dashboard(user, org_string)
|
|||||||
local module_sel = io.read()
|
local module_sel = io.read()
|
||||||
print()
|
print()
|
||||||
local module_result = false
|
local module_result = false
|
||||||
for k,v in ipairs(org_modules) do
|
for k,v in ipairs(modules) do
|
||||||
if v == module_sel then
|
if v == module_sel then
|
||||||
module_result = true
|
module_result = true
|
||||||
end
|
end
|
||||||
@ -127,19 +133,20 @@ function modpol.interactions.org_dashboard(user, org_string)
|
|||||||
print("Error: Module not found.")
|
print("Error: Module not found.")
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif sel == 'a' or sel == 'A' then
|
elseif sel == 'p' or sel == 'P' then
|
||||||
local processes = {}
|
local processes = {}
|
||||||
print("All processes: (* indicates pending)")
|
print("All processes: (* indicates pending)")
|
||||||
for k,v in ipairs(org.processes) do
|
for i,v in ipairs(org.processes) do
|
||||||
local active = ''
|
local active = ''
|
||||||
if org.pending[user] then
|
if org.pending[user] then
|
||||||
if org.pending[user][v.id] then
|
if org.pending[user][v.id] then
|
||||||
active = '*'
|
active = '*'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
print("["..v.id.."] "..v.slug..active)
|
||||||
end
|
end
|
||||||
print()
|
print()
|
||||||
print("Interact with which one?")
|
print("Interact with which one (use [id] number)?")
|
||||||
local to_interact = io.read()
|
local to_interact = io.read()
|
||||||
local process = org.processes[tonumber(to_interact)]
|
local process = org.processes[tonumber(to_interact)]
|
||||||
if not process then return end
|
if not process then return end
|
||||||
@ -148,6 +155,8 @@ function modpol.interactions.org_dashboard(user, org_string)
|
|||||||
org:interact(process.id, user)
|
org:interact(process.id, user)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
elseif sel == 'b' or sel == 'B' then
|
||||||
|
modpol.interactions.dashboard(user)
|
||||||
else
|
else
|
||||||
print("Command not found")
|
print("Command not found")
|
||||||
modpol.interactions.org_dashboard(user, org.name)
|
modpol.interactions.org_dashboard(user, org.name)
|
||||||
|
@ -34,7 +34,7 @@ end
|
|||||||
|
|
||||||
function change_modules:add_module()
|
function change_modules:add_module()
|
||||||
-- prepare module options
|
-- prepare module options
|
||||||
local available_modules = modpol.copy_table(modpol.modules)
|
local available_modules = modpol.util.copy_table(modpol.modules)
|
||||||
for k,org_mod in pairs(self.org.modules) do
|
for k,org_mod in pairs(self.org.modules) do
|
||||||
if available_modules[org_mod.slug] then
|
if available_modules[org_mod.slug] then
|
||||||
available_modules[org_mod.slug] = nil
|
available_modules[org_mod.slug] = nil
|
||||||
|
@ -14,7 +14,7 @@ function temp_org()
|
|||||||
return {
|
return {
|
||||||
id = nil,
|
id = nil,
|
||||||
name = nil,
|
name = nil,
|
||||||
modules = modpol.copy_table(modpol.modules),
|
modules = modpol.util.copy_table(modpol.modules),
|
||||||
processes = {},
|
processes = {},
|
||||||
pending = {},
|
pending = {},
|
||||||
members = {},
|
members = {},
|
||||||
@ -98,7 +98,7 @@ function modpol.orgs.init_instance()
|
|||||||
|
|
||||||
local instance = temp_org()
|
local instance = temp_org()
|
||||||
instance.id = 1
|
instance.id = 1
|
||||||
instance.name = "root"
|
instance.name = "Root"
|
||||||
|
|
||||||
setmetatable(instance, modpol.orgs)
|
setmetatable(instance, modpol.orgs)
|
||||||
|
|
||||||
@ -175,7 +175,7 @@ function modpol.orgs:add_org(name, user)
|
|||||||
child_org.name = name
|
child_org.name = name
|
||||||
child_org.parent = self.id
|
child_org.parent = self.id
|
||||||
child_org.processes = {}
|
child_org.processes = {}
|
||||||
child_org.modules = modpol.copy_table(self.modules)
|
child_org.modules = modpol.util.copy_table(self.modules)
|
||||||
|
|
||||||
setmetatable(child_org, modpol.orgs)
|
setmetatable(child_org, modpol.orgs)
|
||||||
|
|
||||||
|
@ -1,9 +1,19 @@
|
|||||||
--- @function modpol.copy_table
|
--- @function modpol.copy_table
|
||||||
-- Returns a copy of the table inputted
|
-- Returns a copy of the table inputted
|
||||||
function modpol.copy_table(t)
|
function modpol.util.copy_table(t)
|
||||||
local t2 = {}
|
local t2 = {}
|
||||||
for k,v in pairs(t) do
|
for k,v in pairs(t) do
|
||||||
t2[k] = v
|
t2[k] = v
|
||||||
end
|
end
|
||||||
return t2
|
return t2
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- @function modpol.copy_table
|
||||||
|
-- Returns the number of elements in a pairs table
|
||||||
|
function modpol.util.num_pairs(t)
|
||||||
|
local i = 0
|
||||||
|
for k,v in pairs(t) do
|
||||||
|
i = i + 1
|
||||||
|
end
|
||||||
|
return i
|
||||||
|
end
|
||||||
|
Reference in New Issue
Block a user