display_processes.lua 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. display_processes.data = {
  10. }
  11. display_processes.config = {
  12. }
  13. --- Initiate function
  14. -- @function display_processes:initiate
  15. -- @param result Callback if this module is embedded in other modules
  16. function display_processes:initiate(result)
  17. local display_table = {}
  18. for k,v in pairs(self.org.processes) do
  19. if v ~= "deleted" then
  20. local input = v.id..": "..v.slug
  21. table.insert(display_table, input)
  22. input = "Org: "..v.org.name..
  23. ", initiator: "..v.initiator
  24. table.insert(display_table, input)
  25. if v.config
  26. and modpol.util.num_pairs(v.config) > 0 then
  27. table.insert(display_table, "Policies:")
  28. for k2,v2 in pairs(v.config) do
  29. local v2_string = ""
  30. if type(v2) ~= "string"
  31. and type(v2) ~= "table" then
  32. v2_string = tostring(v2)
  33. elseif type(v2) == "table" then
  34. v2_string = tostring(v2)
  35. else
  36. v2_string = "Could not render"
  37. end
  38. input = k2..": "..v2_string
  39. table.insert(display_table, input)
  40. end
  41. end
  42. table.insert(display_table, "\n")
  43. end
  44. end
  45. local output = table.concat(display_table,"\n")
  46. if #display_table == 0 then
  47. output = "No processes found"
  48. end
  49. modpol.interactions.display(
  50. self.initiator,
  51. "Processes in org "..self.org.name,
  52. output,
  53. function()
  54. modpol.interactions.org_dashboard(
  55. self.initiator, self.org.id)
  56. if result then result() end
  57. self.org:delete_process(self.id)
  58. end
  59. )
  60. end
  61. modpol.modules.display_processes = display_processes