Feature #22913 » 22913_auto_mapping.patch
| app/controllers/imports_controller.rb | ||
|---|---|---|
|
def mapping
|
||
|
@custom_fields = @import.mappable_custom_fields
|
||
|
if @import.mapping.empty?
|
||
|
@import.settings['mapping'] = {}
|
||
|
headers = @import.headers
|
||
|
# Core fields
|
||
|
core_fields =
|
||
|
case @import
|
||
|
when IssueImport
|
||
|
%w(tracker subject description status priority category assigned_to fixed_version is_private parent_issue_id start_date due_date estimated_hours done_ratio)
|
||
|
when TimeEntryImport
|
||
|
%w(activity user_id issue_id spent_on hours comments)
|
||
|
else
|
||
|
[]
|
||
|
end
|
||
|
core_fields.each do |field|
|
||
|
label = l(:"field_#{field.gsub(/\_id$/, '')}")
|
||
|
@import.mapping[field] = headers.index(label)
|
||
|
end
|
||
|
# Custom fields
|
||
|
@custom_fields.each do |field|
|
||
|
@import.mapping["cf_#{field.id}"] = headers.index(field.name)
|
||
|
end
|
||
|
end
|
||
|
if request.post?
|
||
|
respond_to do |format|
|
||
| app/views/imports/_issues_fields_mapping.html.erb | ||
|---|---|---|
|
:id => 'import_mapping_project_id' %>
|
||
|
</p>
|
||
|
<p>
|
||
|
<label for="import_mapping_tracker"><%= l(:label_tracker) %></label>
|
||
|
<label for="import_mapping_tracker"><%= l(:field_tracker) %></label>
|
||
|
<%= mapping_select_tag @import, 'tracker', :required => true,
|
||
|
:values => @import.allowed_target_trackers.sorted.map {|t| [t.name, t.id]} %>
|
||
|
</p>
|
||
| ... | ... | |
|
</p>
|
||
|
</div>
|
||
|
</div>
|
||
| test/fixtures/files/import_auto_mapping.csv | ||
|---|---|---|
|
Column 0;Column 1;Column 2;Subject;Column 4;Database;Column 6
|
||
|
0;1;2;3;4;5;6
|
||
| test/fixtures/files/import_time_entries_auto_mapping.csv | ||
|---|---|---|
|
Column 0;Column 1;Activity;Column 3;Overtime;Column 5;Column 6
|
||
|
0;1;2;3;4;5;6
|
||
| test/functional/imports_controller_test.rb | ||
|---|---|---|
|
end
|
||
|
end
|
||
|
def test_get_mapping_should_auto_select_by_column_name
|
||
|
import = generate_import('import_auto_mapping.csv')
|
||
|
import.settings = {'separator' => ';', 'wrapper'=> '"', 'encoding' => 'ISO-8859-1'}
|
||
|
import.save!
|
||
|
get :mapping, :params => {
|
||
|
:id => import.to_param
|
||
|
}
|
||
|
assert_response :success
|
||
|
assert_select 'select[name=?]', 'import_settings[mapping][subject]' do
|
||
|
assert_select 'option[value="3"][selected="selected"]', :text => 'Subject'
|
||
|
end
|
||
|
assert_select 'select[name=?]', 'import_settings[mapping][cf_1]' do
|
||
|
assert_select 'option[value="5"][selected="selected"]', :text => 'Database'
|
||
|
end
|
||
|
end
|
||
|
def test_post_mapping_should_update_mapping
|
||
|
import = generate_import('import_iso8859-1.csv')
|
||
| ... | ... | |
|
assert_select 'select[name=?]', 'import_settings[mapping][user_id]', 0
|
||
|
end
|
||
|
def test_get_mapping_time_entry_should_auto_select_by_column_name
|
||
|
import = generate_time_entry_import('import_time_entries_auto_mapping.csv')
|
||
|
import.settings = {'separator' => ";", 'wrapper' => '"', 'encoding' => "ISO-8859-1"}
|
||
|
import.save!
|
||
|
get :mapping, :params => {
|
||
|
:id => import.to_param
|
||
|
}
|
||
|
assert_response :success
|
||
|
assert_select 'select[name=?]', 'import_settings[mapping][activity]' do
|
||
|
assert_select 'option[value="2"][selected="selected"]', :text => 'Activity'
|
||
|
end
|
||
|
assert_select 'select[name=?]', 'import_settings[mapping][cf_10]' do
|
||
|
assert_select 'option[value="4"][selected="selected"]', :text => 'Overtime'
|
||
|
end
|
||
|
end
|
||
|
def test_get_run
|
||
|
import = generate_import_with_mapping
|
||