Show target-runner relationships in a diagram.

Akinori MUSHA 10 years ago
parent
commit
0ae0f1a302
2 changed files with 22 additions and 3 deletions
  1. 11 1
      app/helpers/agent_helper.rb
  2. 11 2
      app/helpers/dot_helper.rb

+ 11 - 1
app/helpers/agent_helper.rb

@@ -15,4 +15,14 @@ module AgentHelper
15 15
   def agent_show_class(agent)
16 16
     agent.short_type.underscore.dasherize
17 17
   end
18
-end
18
+
19
+  def agent_schedule(agent, delimiter = ', ')
20
+    return 'n/a' unless agent.can_be_scheduled?
21
+
22
+    runners = agent.runners
23
+    [
24
+      *(CGI.escape_html(agent.schedule.humanize.titleize) unless agent.schedule == 'never' && agent.runners.count > 0),
25
+      *runners.map { |agent| link_to(agent.name, agent_path(agent)) },
26
+    ].join(delimiter).html_safe
27
+  end
28
+end

+ 11 - 2
app/helpers/dot_helper.rb

@@ -138,7 +138,9 @@ module DotHelper
138 138
       def agent_edge(agent, receiver)
139 139
         edge(agent_id[agent],
140 140
              agent_id[receiver],
141
-             style: ('dashed' unless receiver.propagate_immediately),
141
+             style: ('dashed' unless agent.can_run_other_agents? || !receiver.propagate_immediately?),
142
+             label: (' runs ' if agent.can_run_other_agents?),
143
+             arrowhead: ('empty' if agent.can_run_other_agents?),
142 144
              color: (@disabled if agent.disabled? || receiver.disabled?))
143 145
       end
144 146
 
@@ -151,10 +153,17 @@ module DotHelper
151 153
                   fontsize: 10,
152 154
                   fontname: ('Helvetica' if rich)
153 155
 
156
+        statement 'edge',
157
+                  fontsize: 10,
158
+                  fontname: ('Helvetica' if rich)
159
+
154 160
         agents.each.with_index { |agent, index|
155 161
           agent_node(agent)
156 162
 
157
-          agent.receivers.each { |receiver|
163
+          [
164
+            *agent.receivers,
165
+            *(agent.targets if agent.can_run_other_agents?)
166
+          ].each { |receiver|
158 167
             agent_edge(agent, receiver) if agents.include?(receiver)
159 168
           }
160 169
         }