31855.patch

Felix Schäfer, 2019-08-06 22:03

Download (1.79 KB)

View differences:

app/helpers/workflows_helper.rb
74 74
    select_tag("permissions[#{status.id}][#{name}]", options_for_select(options, selected), html_options)
75 75
  end
76 76

  
77
  def transition_tag(workflows, old_status, new_status, name)
78
    w = workflows.select {|w| w.old_status == old_status && w.new_status == new_status}.size
77
  def transition_tag(transition_count, old_status, new_status, name)
78
    w = transition_count
79 79

  
80 80
    tag_name = "transitions[#{ old_status.try(:id) || 0 }][#{new_status.id}][#{name}]"
81 81
    if old_status == new_status
app/views/workflows/_form.html.erb
21 21
    <% end %>
22 22
  </tr>
23 23
</thead>
24
<% transition_counts = workflows.each_with_object(Hash.new(0)) {|w,memo| memo[[w.old_status, w.new_status]] += 1} %>
24 25
<tbody>
25 26
  <% for old_status in [nil] + @statuses %>
26 27
  <% next if old_status.nil? && name != 'always' %>
......
38 39
      <% end %>
39 40
    </td>
40 41
    <% for new_status in @statuses -%>
41
    <% checked = (old_status == new_status) || workflows.detect {|w| w.old_status == old_status && w.new_status == new_status} %>
42
    <% checked = (old_status == new_status) || (transition_counts[[old_status, new_status]] > 0) %>
42 43
    <td class="<%= checked ? 'enabled' : '' %>" title="<%= old_status_name %> &#187; <%= new_status.name %>">
43
      <%= transition_tag workflows, old_status, new_status, name %>
44
      <%= transition_tag transition_counts[[old_status, new_status]], old_status, new_status, name %>
44 45
    </td>
45 46
    <% end -%>
46 47
  </tr>