Forráskód Böngészése

Added user_dashboard and message_user in modpol_core, still have to add to modpol_minetest

Nathan Schneider 2 éve
szülő
commit
de8ad25b2f

+ 107 - 14
modpol_core/interactions/interactions.lua

@@ -49,18 +49,40 @@ function modpol.interactions.dashboard(user)
    print('All users: ' .. table.concat(all_users, ', '))
    print()
 
-   print('Access which org id?')
+   print("Commands: (O)rg, (U)ser, Enter to close")
+
    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
+   end
 end
-
+   
 
 -- Function: modpol.interactions.org_dashboard
 -- Params: user (string), org_string (string or id)
@@ -165,20 +187,91 @@ 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 = {}
 
+   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
+      print("Enter your message for "..user..":")
+      sel = io.read()
+      print("Sending message")
+      modpol.interactions.message_user(
+         viewer, user, sel)
+      completion()
+   else
+      completion()
+   end
+end
+
+
+-- buttons: message, done
+
+-- INTERACTION PRIMITIVES
+-- ======================
 
 -- Function: modpol.interactions.message
+-- Produces a brief message to a user
 -- input: user (string), message (string)
 -- output: prints message to CLI
 function modpol.interactions.message(user, message)
    print(user .. ": " .. message)
 end
 
+--- Function: modpol.interactions.message_user
+-- Sends a message from one user to another
+-- @param sender Name of user sending (string)
+-- @param recipient Name of user receiving (string)
+-- @param message Message to be sent (string)
+function modpol.interactions.message_user(sender, recipient, message)
+   modpol.interactions.message(
+      recipient,
+      message.." [from "..sender.."]")
+end
+
+--- Function: modpol.interactions.display
+-- Displays complex data to a user
+-- @param user Name of target user (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, message, completion)
+   local output = ""
+   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
+      return nil, "Error: message not typed for display"
+   end
+   print(message)
+   print("\nEnter to continue")
+   io.read()
+   if completion then completion() else
+      modpol.intereactions.dashboard(user)
+   end
+end
+
+
 -- Function: modpol.interactions.text_query
 -- input: User (string), Query (string), func (function)
 --   func input: user input (string)

+ 12 - 2
modpol_minetest/overrides/interactions.lua

@@ -257,10 +257,11 @@ function modpol.interactions.policy_dashboard(
 end
 
 
--- INTERACTION FUNCTIONS
--- =====================
+-- INTERACTION PRIMITIVES
+-- ======================
 
 -- Function: modpol.interactions.message
+-- Produces a brief message to a user
 -- input: user (string), message (string)
 -- output: displays message to specified user
 function modpol.interactions.message(user, message)
@@ -269,6 +270,15 @@ function modpol.interactions.message(user, message)
    end
 end
 
+
+--- Function: modpol.interactions.display
+-- Displays complex data to a user
+-- @param user Name of target user (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.text_query
 -- Overrides function at modpol/interactions.lua
 -- input: user (string), query (string), func (function)