Resolved merge conflicts with master

This commit is contained in:
SkylarHew
2022-01-23 16:01:44 -07:00
31 changed files with 1525 additions and 291 deletions

View File

@ -38,8 +38,10 @@ 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
table.insert(user_pending, v.name)
user_pending_count = user_pending_count + 1
if modpol.util.num_pairs(v.pending[user]) ~= 0 then
table.insert(user_pending, v.name)
user_pending_count = user_pending_count + 1
end
end
end
@ -48,18 +50,53 @@ function modpol.interactions.dashboard(user)
print('All users: ' .. table.concat(all_users, ', '))
print()
print('Access which org id?')
print("Commands: (O)rg, (U)ser, (R)eset, (Q)uit")
local sel = io.read()
print()
if modpol.orgs.array[tonumber(sel)] then
local sel_org = modpol.orgs.array[tonumber(sel)].name
modpol.interactions.org_dashboard(user, sel_org)
else
print("Org id not found.")
end
if sel == "O" or sel == "o" then
print('Access which org id?')
sel = io.read()
print()
if modpol.orgs.array[tonumber(sel)] then
local sel_org = modpol.orgs.array[tonumber(sel)].name
modpol.interactions.org_dashboard(user, sel_org)
else
print("Org id not found")
modpol.interactions.dashboard(user)
end
elseif sel == "U" or sel == "u" then
print("Access which user?")
sel = io.read()
print()
if modpol.instance:has_member(sel) then
modpol.interactions.user_dashboard(
user, sel,
function()
modpol.interactions.dashboard(user)
end
)
else
print("User name not found")
modpol.interactions.dashboard(user)
end
elseif sel == "R" or sel == "r" then
modpol.instance.members = {}
modpol.orgs.reset()
print("Orgs and users reset")
modpol.interactions.dashboard(user)
elseif sel == "Q" or "q" then
return
else
print("Invalid input, try again")
modpol.interactions.dashboard(user)
end
end
--- Output: Displays a menu of org-specific commands to the user
-- @function modpol.interactions.org_dashboard
-- @param user (string)
@ -109,7 +146,7 @@ function modpol.interactions.org_dashboard(user, org_string)
print("Org: " .. org.name)
print("Parent: " .. parent)
print("Members: " .. table.concat(org.members, ", "))
print("Children: " .. table.concat(children, ", "))
print("Child orgs: " .. table.concat(children, ", "))
print("Modules: " .. table.concat(modules, ", "))
print("Pending: " .. process_msg)
print()
@ -132,25 +169,33 @@ function modpol.interactions.org_dashboard(user, org_string)
org:call_module(module_sel, user)
else
print("Error: Module not found.")
modpol.interactions.org_dashboard(user, org.id)
end
elseif sel == 'p' or sel == 'P' then
local processes = {}
print("All processes: (* indicates pending)")
for i,v in ipairs(org.processes) do
local active = ''
if org.pending[user] then
if org.pending[user][v.id] then
active = '*'
if v ~= "deleted" then
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("["..v.id.."] "..v.slug..active)
end
print()
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
if not process then
modpol.interactions.message(
user, "Not a pending process")
modpol.interactions.org_dashboard(user, org.id)
return
end
if org:has_pending_actions(user) then
if org.pending[user][process.id] then
org:interact(process.id, user)
@ -164,13 +209,46 @@ function modpol.interactions.org_dashboard(user, org_string)
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.user_dashboard
-- Displays a dashboard about a particular user
-- @param viewer Name of user viewing the dashboard (string)
-- @param user Name of user being viewed (string)
-- @param completion Optional function to call on Done button
function modpol.interactions.user_dashboard(viewer, user, completion)
local user_orgs = {}
local user_modules = {}
--- Output: Prints message to CLI
print("\n-=< USER DASHBOARD: "..user.." >=-")
print("User's orgs:")
for id, org in ipairs(modpol.orgs.array) do
if type(org) == "table" then
if org:has_member(user) then
print(org.name)
end
end
end
print()
print("Commands: (M)essage user, Enter when done")
local sel = io.read()
if sel == "M" or sel == "m" then
modpol.interactions.message_user(
viewer, user)
completion()
else
completion()
end
end
-- INTERACTION PRIMITIVES
-- ======================
--- Prints message to CLI.
-- Buttons: message, done
-- @function modpol.interactions.message
-- @param user (string)
-- @param message (string)
@ -178,11 +256,56 @@ function modpol.interactions.message(user, message)
print(user .. ": " .. message)
end
--- Output: Applies "func" to user input.
--- Function: modpol.interactions.message_user
-- Gets and sends a message from one user to another
-- @param sender Name of user sending (string)
-- @param recipient Name of user receiving (string)
function modpol.interactions.message_user(sender, recipient)
print("Enter your message for "..recipient..":")
local sel = io.read()
modpol.interactions.message(
recipient,
sel.." [from "..sender.."]")
end
--- Function: modpol.interactions.display
-- Displays complex data to a user
-- @param user Name of target user (string)
-- @param title Title of display (string)
-- @param message Content of message (string or table of strings)
-- @param done Optional function for what happens when user is done
function modpol.interactions.display(user, title, message, completion)
local output = ""
output = "\n-=< "..title.." >=-\n\n"
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")
modpol.interactions.message(
self.initiator, "Error: input not typed for display")
if completion then completion() else
modpol.intereactions.dashboard(user)
end
end
print(message)
print("\nEnter to continue")
io.read()
if completion then completion() else
modpol.intereactions.dashboard(user)
end
end
-- Applies "func" to user input
-- Func input: user input (string)
-- @function modpol.interactions.text_query
-- @param user (string)
-- @param query (string)
-- @param User (string)
-- @param Query (string)
-- @param func (function)
function modpol.interactions.text_query(user, query, func)
print(user .. ": " .. query)
@ -197,8 +320,6 @@ end
-- @param label (string)
-- @param options (table of strings)
-- @param func (choice) (function)
function modpol.interactions.dropdown_query(user, label, options, func)
-- set up options
local options_display = ""
@ -211,7 +332,7 @@ function modpol.interactions.dropdown_query(user, label, options, func)
options_display = options_display .. "Select number:"
if options_number == 0 then
print("Error: No options given for dropdown")
return nil
return nil
end
-- begin displaying
print(user .. ": " .. label)
@ -234,12 +355,60 @@ function modpol.interactions.dropdown_query(user, label, options, func)
end
end
--- Output: Applies "func" to user input.
-- Func input: user input (string: y/n)
-- @function modpol.binary_poll_user(user, question)
-- @param user (string)
-- @param question (string)
-- @param func (function)
--- Allows user to select from a set of options
-- @function modpol.interactions.checkbox_query
-- @param user Name of user (string)
-- @param label Query for user before options (string)
-- @param options Table of options and their checked status in the form {{"option_1_string", true}, {"option_2_string", false}}
-- @param func Function to be called with param "input", made up of the corrected table in the same format as the param options
function modpol.interactions.checkbox_query(
user, label, options, func)
-- set up options
local options_display = ""
local options_number = 0
for i,v in ipairs(options) do
local checked = false
if v[2] then checked = true end
if checked then
checked = "x"
else
checked = " "
end
options_display = options_display..i..". ["..
checked.."] "..v[1].."\n"
options_number = options_number + 1
end
if options_number == 0 then
print("Error: No options given for dropdown")
return nil
end
options_display = options_display..
"List comma-separated options to flip (e.g., 1,2,5):"
-- begin displaying
print(user .. ": " .. label)
print(options_display)
-- read input and produce output
local answer = io.read()
local answer_table = {}
for match in (answer..","):gmatch("(.-)"..",") do
table.insert(answer_table, tonumber(match))
end
local result_table = modpol.util.copy_table(options)
for i,v in ipairs(answer_table) do
if result_table[v] then
-- flip the boolean on selected options
result_table[v][2] = not result_table[v][2]
end
end
func(result_table)
end
-- Function: modpol.interactions.binary_poll_user
-- Params: user (string), question (string), func (function)
-- func input: user input (string: y/n)
-- Output: Applies "func" to user input
function modpol.interactions.binary_poll_user(user, question, func)
local query = "Poll for " .. user .. " (y/n): ".. question
local answer
@ -280,3 +449,9 @@ end
-- output: gets question from initiator, asks all org members, broadcasts answers
-- TESTING
--testing command
function modpol.msg(text)
modpol.interactions.message("TEST MSG",text)
end