Explorar o código

Added modpol.interactions.display and display_processes module, as well as a bunch of bugfixes

Nathan Schneider %!s(int64=2) %!d(string=hai) anos
pai
achega
7ef0626357

+ 1 - 0
modpol_core/api.lua

@@ -17,6 +17,7 @@ dofile (localdir .. "/modules/change_modules.lua")
 dofile (localdir .. "/modules/consent.lua")
 dofile (localdir .. "/modules/create_token.lua")
 dofile (localdir .. "/modules/defer_consent.lua")
+dofile (localdir .. "/modules/display_processes.lua")
 dofile (localdir .. "/modules/join_org_consent.lua")
 dofile (localdir .. "/modules/leave_org.lua")
 dofile (localdir .. "/modules/message_org.lua")

+ 14 - 5
modpol_core/interactions/interactions.lua

@@ -168,6 +168,7 @@ 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
@@ -261,18 +262,26 @@ 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, message, completion)
+function modpol.interactions.display(user, title, message, completion)
    local output = ""
-   if type(message) == table then
+   output = "\n-=< "..title.." >=-\n\n"
+   if type(message) == "table" then
       output = table.concat(message,"\n")
-   elseif type(message) == string then
+   elseif type(message) == "string" then
       output = message
-   elseif type(message) == number then
+   elseif type(message) == "number" then
       output = message
    else
-      return nil, "Error: message not typed for display"
+      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")

+ 61 - 0
modpol_core/modules/display_processes.lua

@@ -0,0 +1,61 @@
+--- display_processes
+-- @module display_processes
+
+local display_processes = {
+    name = "Display processes",
+    slug = "display_processes",
+    desc = "Presents a detailed list of org processes",
+    hide = false;
+}
+
+--- (Required) Data for module
+-- Variables that module uses during the course of a process
+-- Can be blank
+display_processes.data = {
+}
+
+display_processes.config = {
+}
+
+--- (Required): initiate function
+-- @param result (optional) Callback if this module is embedded in other modules
+-- @function initiate
+function display_processes:initiate(result)
+   local display_table = {}
+   for k,v in pairs(self.org.processes) do
+      if v ~= "deleted" then
+         local input = v.id..": "..v.slug
+         table.insert(display_table, input)
+         input = "Org: "..v.org.name..
+            ", initiator: "..v.initiator
+         table.insert(display_table, input)
+         if v.config 
+            and modpol.util.num_pairs(v.config) > 0 then
+            table.insert(display_table, "Policies:")
+            for k2,v2 in pairs(v.config) do
+               input = k2..": "..v2
+               table.insert(display_table, input)
+            end
+         end
+         table.insert(display_table, "\n")
+      end
+   end
+   local output = table.concat(display_table,"\n")
+   if #display_table == 0 then
+      output = "No processes found"
+   end
+   modpol.interactions.display(
+      self.initiator,
+      "Processes in org "..self.org.name,
+      output,
+      function()
+         modpol.interactions.org_dashboard(
+            self.initiator, self.org.id)
+         if result then result() end
+         self.org:delete_process(self.id)
+      end
+   )
+end
+
+--- (Required) Add to module table
+modpol.modules.display_processes = display_processes

+ 3 - 1
modpol_core/modules/template.lua

@@ -43,10 +43,12 @@ function module_template:initiate(result)
    -- call interaction functions here!
 
    -- concluding functions:
-
+   -- first, where appropriate, return users to dashboards.
+   -- second, result:
    -- may need to put result in self.data.result
    -- call this when module is successful (not for abort):
    if result then result() end
+   -- third, delete the process
    -- call this wherever process might end:
    self.org:delete_process(self.id)
 end

+ 70 - 28
modpol_minetest/overrides/interactions.lua

@@ -49,7 +49,6 @@ function modpol.interactions.dashboard(user)
    local user_orgs = modpol.orgs.user_orgs(user)
    local all_users = modpol.instance:list_members()
    -- pending list
-   local user_pending = {"View..."}
    local user_pending_count = 0
    for k,v in ipairs(modpol.orgs.array) do
       if v.pending and v.pending[user] then
@@ -64,15 +63,15 @@ function modpol.interactions.dashboard(user)
     local formspec = {
        "formspec_version[4]",
        "size[10,8]",
-       "label[0.5,0.5;M O D P O L]",
+       "hypertext[0.5,0.5;9,1;title;<big>Org dashboard</big>]",
        "label[0.5,2;All orgs:]",
-       "dropdown[2,1.5;7,0.8;all_orgs;"..formspec_list(all_orgs)..";;]",
+       "dropdown[2,1.5;7,0.8;all_orgs;View...,"..formspec_list(all_orgs)..";;]",
        "label[0.5,3;Your orgs:]",
-       "dropdown[2,2.5;7,0.8;user_orgs;"..formspec_list(user_orgs)..";;]",
+       "dropdown[2,2.5;7,0.8;user_orgs;View...,"..formspec_list(user_orgs)..";;]",
        "label[0.5,4;All users:]",
-       "dropdown[2,3.5;7,0.8;all_users;"..formspec_list(all_users)..";;]",
+       "dropdown[2,3.5;7,0.8;all_users;View...,"..formspec_list(all_users)..";;]",
        "label[0.5,5;Pending ("..user_pending_count.."):]",
-       "dropdown[2,4.5;7,0.8;pending;"..formspec_list(user_pending)..";;]",
+       "dropdown[2,4.5;7,0.8;pending;View...,"..formspec_list(user_pending)..";;]",
        "button[0.5,7;1,0.8;refresh;Refresh]",
        "button_exit[8.5,7;1,0.8;close;Close]",
     }
@@ -90,7 +89,8 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
          elseif fields.refresh then
             modpol.interactions.dashboard(pname)
           -- Put all dropdowns at the end
-         elseif fields.all_users then
+         elseif fields.all_users
+            and fields.all_users ~= "View..." then
             modpol.interactions.user_dashboard(
                pname,
                fields.all_users,
@@ -100,7 +100,10 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
             )
          elseif fields.all_orgs or fields.user_orgs or fields.pending then
             local org_name = fields.all_orgs or fields.user_orgs or fields.pending
-            modpol.interactions.org_dashboard(pname, org_name)
+            if org_name ~= "View..." then
+               modpol.interactions.org_dashboard(
+                  pname, org_name)
+            end 
          end
       end
 end)
@@ -129,6 +132,9 @@ function modpol.interactions.org_dashboard(user, org_string)
    if parent then parent = parent.name
    else parent = "none" end
 
+   -- prepare members menu
+   local members = org.members
+   
    -- prepare children menu
    local children = {}
    for k,v in ipairs(org.children) do
@@ -136,7 +142,6 @@ function modpol.interactions.org_dashboard(user, org_string)
       table.insert(children, this_child.name)
    end
    table.sort(children)
-   table.insert(children,1,"View...")
 
    -- prepare modules menu
    local modules = {}
@@ -149,7 +154,6 @@ function modpol.interactions.org_dashboard(user, org_string)
       end
    end
    table.sort(modules)
-   table.insert(modules,1,"View...")
 
    -- prepare pending menu
    local pending = {}
@@ -163,7 +167,6 @@ function modpol.interactions.org_dashboard(user, org_string)
       end
    end
    table.sort(pending)
-   table.insert(pending,1,"View...")
 
    -- set player context
    local user_context = {}
@@ -173,17 +176,17 @@ function modpol.interactions.org_dashboard(user, org_string)
     local formspec = {
        "formspec_version[4]",
        "size[10,8]",
-       "label[0.5,0.5;Org: "..
-          minetest.formspec_escape(org.name)..membership_toggle(org.name).."]",
-       "label[0.5,1;Parent: "..parent..membership_toggle(parent).."]",
+       "hypertext[0.5,0.5;9,1;title;<big>Org: <b>"..
+          minetest.formspec_escape(org.name).."</b>"..membership_toggle(org.name).."</big>]",
+       "label[0.5,1.25;Parent: "..parent..membership_toggle(parent).."]",
        "label[0.5,2;Members:]",
-       "dropdown[2,1.5;7,0.8;members;"..formspec_list(org.members)..";;]",
+       "dropdown[2,1.5;7,0.8;members;View...,"..formspec_list(members)..";;]",
        "label[0.5,3;Child orgs:]",
-       "dropdown[2,2.5;7,0.8;children;"..formspec_list(children)..";;]",
+       "dropdown[2,2.5;7,0.8;children;View...,"..formspec_list(children)..";;]",
        "label[0.5,4;Modules:]",
-       "dropdown[2,3.5;7,0.8;modules;"..formspec_list(modules)..";;]",
+       "dropdown[2,3.5;7,0.8;modules;View...,"..formspec_list(modules)..";;]",
        "label[0.5,5;Pending ("..num_pending.."):]",
-       "dropdown[2,4.5;7,0.8;pending;"..formspec_list(pending)..";;]",
+       "dropdown[2,4.5;7,0.8;pending;View...,"..formspec_list(pending)..";;]",
        "button[0.5,7;1,0.8;refresh;Refresh]",
        "button[8.5,7;1,0.8;back;Back]",
     }
@@ -210,7 +213,8 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
             
          -- Put all dropdowns at the end
             -- Receiving modules
-         elseif fields.members then
+         elseif fields.members
+            and fields.members ~= "View..." then
             modpol.interactions.user_dashboard(
                pname,
                fields.members,
@@ -268,7 +272,6 @@ end)
 -- @param completion Optional function to call on Done button
 function modpol.interactions.user_dashboard(viewer, user, completion)
    local user_orgs = modpol.orgs.user_orgs(user)
-   table.insert(user_orgs,1,"View...")
 
    -- set player context
    local user_context = {}
@@ -280,9 +283,9 @@ function modpol.interactions.user_dashboard(viewer, user, completion)
     local formspec = {
        "formspec_version[4]",
        "size[10,8]",
-       "label[0.5,0.5;User: "..user.."]",
+       "hypertext[0.5,0.5;9,1;title;<big>User: <b>"..user.."</b></big>]",
        "label[0.5,2;User's orgs:]",
-       "dropdown[2,1.5;7,0.8;user_orgs;"..formspec_list(user_orgs)..";;]",
+       "dropdown[2,1.5;7,0.8;user_orgs;View...,"..formspec_list(user_orgs)..";;]",
        "button[0.5,7;1.5,0.8;message;Message]",
        "button_exit[8.5,7;1,0.8;close;Close]",
     }
@@ -350,10 +353,51 @@ 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
-
-
+-- @param completion Optional function for what happens when user is done
+function modpol.interactions.display(
+      user, title, message, completion)
+   -- set up contexts
+   _contexts[user]["completion"] = completion
+   -- set up output
+   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
+      modpol.interactions.message(
+         self.initiator, "Error: message not typed for display")
+      if completion then completion() else
+         modpol.intereactions.dashboard(user)
+      end
+      return
+   end
+   -- set up formspec   
+   local formspec = {
+      "formspec_version[4]",
+      "size[10,8]",
+      "label[0.5,0.5;"..title.."]",
+      "hypertext[0.5,1;9,5.5;display;<global background=black margin=10>"..output.."]",
+      "button_exit[8.5,7;1,0.8;done;Done]",
+    }
+    local formspec_string = table.concat(formspec, "")
+    -- present to player
+    minetest.show_formspec(user, "modpol:display", formspec_string)
+end
+-- receive fields
+minetest.register_on_player_receive_fields(function (player, formname, fields)
+      local pname = player:get_player_name()
+      if formname == "modpol:display" then
+         if fields.done and _contexts[pname].completion then
+            minetest.close_formspec(pname, formname)
+            _contexts[pname].completion()
+         end
+      end
+end)
 
 -- Function: modpol.interactions.text_query
 -- Overrides function at modpol/interactions.lua
@@ -399,14 +443,12 @@ 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]",
       "size[10,4]",
       "label[0.5,1;"..minetest.formspec_escape(label).."]",
-      "dropdown[0.5,1.25;9,0.8;input;"..formspec_list(options)..";;]",
+      "dropdown[0.5,1.25;9,0.8;input;View...,"..formspec_list(options)..";;]",
       "button[0.5,2.5;1,0.8;cancel;Cancel]",
    }
    local formspec_string = table.concat(formspec, "")