Bugfixes on CLI interactions
This commit is contained in:
parent
fe2d5fdb2a
commit
cfef9b29b0
@ -6,7 +6,7 @@ This implementation is a mod for [Minetest](https://minetest.net), a free/open-s
|
||||
|
||||
## 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:
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
dofile("modpol_core/modpol.lua")
|
||||
|
||||
modpol.orgs.reset()
|
||||
|
||||
print("Log in as which user?")
|
||||
local username = io.read()
|
||||
|
||||
|
@ -22,6 +22,7 @@ function modpol.interactions.dashboard(user)
|
||||
|
||||
local all_users = modpol.instance:list_members()
|
||||
|
||||
print('\n-=< MODPOL DASHBOARD >=-')
|
||||
print('All orgs: (user orgs indicated by *)')
|
||||
for id, org in ipairs(modpol.orgs.array) do
|
||||
if type(org) == "table" then
|
||||
@ -36,7 +37,6 @@ function modpol.interactions.dashboard(user)
|
||||
local user_pending_count = 0
|
||||
for k,v in ipairs(modpol.orgs.array) do
|
||||
if v.pending and v.pending[user] then
|
||||
modpol.msg(v.name)
|
||||
table.insert(user_pending, v.name)
|
||||
user_pending_count = user_pending_count + 1
|
||||
end
|
||||
@ -82,31 +82,37 @@ function modpol.interactions.org_dashboard(user, org_string)
|
||||
table.insert(children, this_child.name)
|
||||
end
|
||||
|
||||
-- list available modules
|
||||
local org_modules = {}
|
||||
for k,v in pairs(org.modules) do
|
||||
if not v.hide then
|
||||
table.insert(org_modules, v.slug)
|
||||
-- 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.slug
|
||||
table.insert(modules, module_entry)
|
||||
end
|
||||
end
|
||||
end
|
||||
table.sort(modules)
|
||||
|
||||
-- list pending
|
||||
local process_msg = #org.processes .. " total processes"
|
||||
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
|
||||
process_msg = process_msg .. " (0 pending)"
|
||||
end
|
||||
|
||||
-- set up output
|
||||
print('\n-=< ORG DASHBOARD >=-')
|
||||
print("Org: " .. org.name)
|
||||
print("Parent: " .. parent)
|
||||
print("Members: " .. table.concat(org.members, ", "))
|
||||
print("Children: " .. table.concat(children, ", "))
|
||||
print("Modules: " .. table.concat(org_modules, ", "))
|
||||
print("Modules: " .. table.concat(modules, ", "))
|
||||
print("Pending: " .. process_msg)
|
||||
print()
|
||||
print("Commands: (M)odules, (P)ending")
|
||||
print("Commands: (M)odules, (P)ending, (B)ack")
|
||||
|
||||
local sel = io.read()
|
||||
print()
|
||||
@ -116,7 +122,7 @@ function modpol.interactions.org_dashboard(user, org_string)
|
||||
local module_sel = io.read()
|
||||
print()
|
||||
local module_result = false
|
||||
for k,v in ipairs(org_modules) do
|
||||
for k,v in ipairs(modules) do
|
||||
if v == module_sel then
|
||||
module_result = true
|
||||
end
|
||||
@ -127,19 +133,20 @@ function modpol.interactions.org_dashboard(user, org_string)
|
||||
print("Error: Module not found.")
|
||||
end
|
||||
|
||||
elseif sel == 'a' or sel == 'A' then
|
||||
elseif sel == 'p' or sel == 'P' then
|
||||
local processes = {}
|
||||
print("All processes: (* indicates pending)")
|
||||
for k,v in ipairs(org.processes) do
|
||||
for i,v in ipairs(org.processes) do
|
||||
local active = ''
|
||||
if org.pending[user] then
|
||||
if org.pending[user][v.id] then
|
||||
active = '*'
|
||||
end
|
||||
end
|
||||
print("["..v.id.."] "..v.slug..active)
|
||||
end
|
||||
print()
|
||||
print("Interact with which one?")
|
||||
print("Interact with which one (use [id] number)?")
|
||||
local to_interact = io.read()
|
||||
local process = org.processes[tonumber(to_interact)]
|
||||
if not process then return end
|
||||
@ -148,6 +155,8 @@ function modpol.interactions.org_dashboard(user, org_string)
|
||||
org:interact(process.id, user)
|
||||
end
|
||||
end
|
||||
elseif sel == 'b' or sel == 'B' then
|
||||
modpol.interactions.dashboard(user)
|
||||
else
|
||||
print("Command not found")
|
||||
modpol.interactions.org_dashboard(user, org.name)
|
||||
|
@ -34,7 +34,7 @@ end
|
||||
|
||||
function change_modules:add_module()
|
||||
-- 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
|
||||
if available_modules[org_mod.slug] then
|
||||
available_modules[org_mod.slug] = nil
|
||||
|
@ -14,7 +14,7 @@ function temp_org()
|
||||
return {
|
||||
id = nil,
|
||||
name = nil,
|
||||
modules = modpol.copy_table(modpol.modules),
|
||||
modules = modpol.util.copy_table(modpol.modules),
|
||||
processes = {},
|
||||
pending = {},
|
||||
members = {},
|
||||
@ -98,7 +98,7 @@ function modpol.orgs.init_instance()
|
||||
|
||||
local instance = temp_org()
|
||||
instance.id = 1
|
||||
instance.name = "root"
|
||||
instance.name = "Root"
|
||||
|
||||
setmetatable(instance, modpol.orgs)
|
||||
|
||||
@ -175,7 +175,7 @@ function modpol.orgs:add_org(name, user)
|
||||
child_org.name = name
|
||||
child_org.parent = self.id
|
||||
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)
|
||||
|
||||
|
@ -1,9 +1,19 @@
|
||||
--- @function modpol.copy_table
|
||||
-- Returns a copy of the table inputted
|
||||
function modpol.copy_table(t)
|
||||
function modpol.util.copy_table(t)
|
||||
local t2 = {}
|
||||
for k,v in pairs(t) do
|
||||
t2[k] = v
|
||||
end
|
||||
return t2
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user