diff --git a/app/helpers/workflows_helper.rb b/app/helpers/workflows_helper.rb index c09310acd..f9c545e5a 100644 --- a/app/helpers/workflows_helper.rb +++ b/app/helpers/workflows_helper.rb @@ -74,8 +74,8 @@ module WorkflowsHelper select_tag("permissions[#{status.id}][#{name}]", options_for_select(options, selected), html_options) end - def transition_tag(workflows, old_status, new_status, name) - w = workflows.select {|w| w.old_status == old_status && w.new_status == new_status}.size + def transition_tag(transition_count, old_status, new_status, name) + w = transition_count tag_name = "transitions[#{ old_status.try(:id) || 0 }][#{new_status.id}][#{name}]" if old_status == new_status diff --git a/app/views/workflows/_form.html.erb b/app/views/workflows/_form.html.erb index 542db4e35..32639753c 100644 --- a/app/views/workflows/_form.html.erb +++ b/app/views/workflows/_form.html.erb @@ -21,6 +21,7 @@ <% end %> +<% transition_counts = workflows.each_with_object(Hash.new(0)) {|w,memo| memo[[w.old_status, w.new_status]] += 1} %> <% for old_status in [nil] + @statuses %> <% next if old_status.nil? && name != 'always' %> @@ -38,9 +39,9 @@ <% end %> <% for new_status in @statuses -%> - <% checked = (old_status == new_status) || workflows.detect {|w| w.old_status == old_status && w.new_status == new_status} %> + <% checked = (old_status == new_status) || (transition_counts[[old_status, new_status]] > 0) %> - <%= transition_tag workflows, old_status, new_status, name %> + <%= transition_tag transition_counts[[old_status, new_status]], old_status, new_status, name %> <% end -%>