[#6441] Refactor logic in view to helpers

This commit is contained in:
Eric Davis
2011-08-08 14:12:06 -07:00
parent 953587ce46
commit 07c3c42ca8
3 changed files with 14 additions and 4 deletions
+10
View File
@@ -17,6 +17,16 @@ module ContractsHelper
grouped_contracts["closed"] ||= []
grouped_contracts
end
def deliverable_options(project)
project.contracts.inject([]) do |data, contract|
data << [contract.name, deliverable_options_for_contract(contract)]
end
end
def deliverable_options_for_contract(contract)
contract.deliverables.collect {|d| [d.title, d.id]}
end
# Simple helper to show the values of a field on an object in a standard format
#
+1 -4
View File
@@ -1,9 +1,6 @@
<% if project.module_enabled?(:contracts) && User.current.allowed_to?(:assign_deliverable_to_issue, project) %>
<p>
<% options = project.contracts.inject([]) {|data, contract|
data << [contract.name, contract.deliverables.collect {|d| [d.title, d.id]} ]
} %>
<%= form.select(:deliverable_id, grouped_options_for_select(options, issue.deliverable_id), {:include_blank => true}) %>
<%= form.select(:deliverable_id, grouped_options_for_select(deliverable_options(project), issue.deliverable_id), {:include_blank => true}) %>
</p>
<% end %>
+3
View File
@@ -102,6 +102,9 @@ Dispatcher.to_prepare :redmine_contracts do
unless Query.available_columns.collect(&:name).include?(:contract_name)
Query.add_available_column(QueryColumn.new(:contract_name, :sortable => "#{Contract.table_name}.name", :groupable => 'contracts.name'))
end
require_dependency 'application_controller'
ApplicationController.send(:helper, :contracts)
end
require 'redmine_contracts/hooks/view_layouts_base_html_head_hook'