display_processes.lua 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. --- display_processes
  2. -- @module display_processes
  3. local display_processes = {
  4. name = "Display processes",
  5. slug = "display_processes",
  6. desc = "Presents a detailed list of org processes",
  7. hide = false;
  8. }
  9. --- (Required) Data for module
  10. -- Variables that module uses during the course of a process
  11. -- Can be blank
  12. display_processes.data = {
  13. }
  14. display_processes.config = {
  15. }
  16. --- (Required): initiate function
  17. -- @param result (optional) Callback if this module is embedded in other modules
  18. -- @function initiate
  19. function display_processes:initiate(result)
  20. local display_table = {}
  21. for k,v in pairs(self.org.processes) do
  22. if v ~= "deleted" then
  23. local input = v.id..": "..v.slug
  24. table.insert(display_table, input)
  25. input = "Org: "..v.org.name..
  26. ", initiator: "..v.initiator
  27. table.insert(display_table, input)
  28. if v.config
  29. and modpol.util.num_pairs(v.config) > 0 then
  30. table.insert(display_table, "Policies:")
  31. for k2,v2 in pairs(v.config) do
  32. local v2_string = ""
  33. if type(v2) ~= "string"
  34. and type(v2) ~= "table" then
  35. v2_string = tostring(v2)
  36. elseif type(v2) == "table" then
  37. v2_string = table.concat(v2)
  38. else
  39. v2_string = "Could not render"
  40. end
  41. input = k2..": "..v2_string
  42. table.insert(display_table, input)
  43. end
  44. end
  45. table.insert(display_table, "\n")
  46. end
  47. end
  48. local output = table.concat(display_table,"\n")
  49. if #display_table == 0 then
  50. output = "No processes found"
  51. end
  52. modpol.interactions.display(
  53. self.initiator,
  54. "Processes in org "..self.org.name,
  55. output,
  56. function()
  57. modpol.interactions.org_dashboard(
  58. self.initiator, self.org.id)
  59. if result then result() end
  60. self.org:delete_process(self.id)
  61. end
  62. )
  63. end
  64. --- (Required) Add to module table
  65. modpol.modules.display_processes = display_processes