agent_helper.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. module AgentHelper
  2. def agent_show_view(agent)
  3. name = agent.short_type.underscore
  4. if File.exist?(Rails.root.join("app", "views", "agents", "agent_views", name, "_show.html.erb"))
  5. File.join("agents", "agent_views", name, "show")
  6. end
  7. end
  8. def scenario_links(agent)
  9. agent.scenarios.map { |scenario|
  10. link_to(scenario.name, scenario, class: "label", style: style_colors(scenario))
  11. }.join(" ").html_safe
  12. end
  13. def agent_show_class(agent)
  14. agent.short_type.underscore.dasherize
  15. end
  16. def agent_schedule(agent, delimiter = ', ')
  17. return 'n/a' unless agent.can_be_scheduled?
  18. case agent.schedule
  19. when nil, 'never'
  20. agent_controllers(agent, delimiter) || 'Never'
  21. else
  22. [
  23. agent.schedule.humanize.titleize,
  24. *(agent_controllers(agent, delimiter))
  25. ].join(delimiter).html_safe
  26. end
  27. end
  28. def agent_controllers(agent, delimiter = ', ')
  29. if agent.controllers.present?
  30. agent.controllers.map { |agent|
  31. link_to(agent.name, agent_path(agent))
  32. }.join(delimiter).html_safe
  33. end
  34. end
  35. end