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

Adding org_dashboard (but not yet tested)

Nathan Schneider 3 éve
szülő
commit
87bd3ecc89
1 módosított fájl, 58 hozzáadás és 12 törlés
  1. 58 12
      modpol_minetest/overrides/interactions/interactions.lua

+ 58 - 12
modpol_minetest/overrides/interactions/interactions.lua

@@ -36,21 +36,17 @@ local function formspec_list(array)
 end
 
 
--- MAIN MODPOL DASHBOARD
--- =====================
+-- DASHBOARDS
+-- ==========
 
 -- Function: modpol.interactions.dashboard(user)
 -- Params: user (string)
 -- Q: Should this return a menu of commands relevant to the specific user?
 -- Output: Displays a menu of commands to the user
--- TKTK currently a manually curated list---needs major improvement
+-- TODO currently a manually curated list---needs major improvement
 function modpol.interactions.dashboard(user)
    -- prepare data
-   -- to add: my orgs, nested orgs map
-   local commands = "Command list: "
-   for key,value in pairs(command_list) do
-      commands = commands .. "/" .. value .. " "
-   end
+   -- to add: nested orgs map
    local all_orgs = modpol.orgs.list_all()
    local user_orgs = modpol.orgs.user_orgs(user)
    local all_users = modpol.list_users()
@@ -60,13 +56,13 @@ function modpol.interactions.dashboard(user)
        "size[10,8]",
        "label[0.5,0.5;MODULAR POLITICS]",
        "label[0.5,2;All orgs:]",
-       "dropdown[2,1.5;5,0.8;user_orgs;"..formspec_list(all_orgs)..";;]",
+       "dropdown[2,1.5;5,0.8;all_orgs;"..formspec_list(all_orgs)..";;]",
        "label[0.5,3;Your orgs:]",
-       "dropdown[2,2.5;5,0.8;input;"..formspec_list(user_orgs)..";;]",
+       "dropdown[2,2.5;5,0.8;user_orgs;"..formspec_list(user_orgs)..";;]",
        "label[0.5,4;All users:]",
-       "dropdown[2,3.5;5,0.8;input;"..formspec_list(all_users)..";;]",
+       "dropdown[2,3.5;5,0.8;all_users;"..formspec_list(all_users)..";;]",
        "label[0.5,5;Processes:]",
-       "dropdown[2,4.5;5,0.8;input;TBA;;]",
+       "dropdown[2,4.5;5,0.8;processes;TBA;;]",
        "button[0.5,7;1,0.8;test_poll;Test poll]",
        "button[2,7;1,0.8;add_org;Add org]",
        "button[3.5,7;1.5,0.8;remove_org;Remove org]",
@@ -91,6 +87,56 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
 end)
 
 
+-- Function: modpol.interactions.org_dashboard
+-- Params: user (string), org_name (string)
+-- Output: Displays a menu of org-specific commands to the user
+function modpol.interactions.org_dashboard(user, org_name)
+   -- prepare data
+   local org = modpol.orgs.get_org(org_name)
+   if not org then return nil end
+   -- set player context
+   _contexts[user][current_org] = org
+   -- set up formspec
+    local formspec = {
+       "formspec_version[4]",
+       "size[10,8]",
+       "label[0.5,0.5;Org: "..
+          minetest.formspec_escape(org_name).."]",
+       "label[0.5,2;Members:]",
+       "dropdown[2,1.5;5,0.8;user_orgs;"..formspec_list(org.members)..";;]",
+       "label[0.5,3;Children:]",
+       "dropdown[2,2.5;5,0.8;children;"..formspec_list(org.children)..";;]",
+       "label[0.5,4;Policies:]",
+       "dropdown[2,3.5;5,0.8;policies;"..formspec_list(org.policies)..";;]",
+       "label[0.5,5;Processes:]",
+       "dropdown[2,4.5;5,0.8;processes;"..formspec_list(org.processes)..";;]",
+       "button[0.5,7;1,0.8;test_poll;Test poll]",
+       "button[2,7;1,0.8;add_org;Add child]",
+       "button[3.5,7;1.5,0.8;remove_org;Remove org]",
+       "button[8.5,7;1,0.8;back;Back]",
+    }
+    local formspec_string = table.concat(formspec, "")
+    -- present to player
+    minetest.show_formspec(user, "modpol:org_dashboard", formspec_string)
+end
+-- receive input
+minetest.register_on_player_receive_fields(function (player, formname, fields)
+      if formname == "modpol:org_dashboard" then
+         local pname = player:get_player_name()
+         if fields.test_poll then
+            modpol.interactions.binary_poll_org(pname, _contexts.pname.current_org.id, "Poll question (yes/no):")
+         elseif fields.add_org then
+            modpol.interactions.add_org(pname, _contexts.pname.current_org.id)
+         elseif fields.remove_org then
+            modpol.interactions.remove_org(pname)
+         elseif fields.back then
+            modpol.interactions.dashboard(pname)
+         end
+      end
+end)
+
+
+
 -- BASIC INTERACTION FUNCTIONS
 -- ===========================