Feature #22913 » demo_auto_map_fields.patch
app/controllers/imports_controller.rb | ||
---|---|---|
66 | 66 |
def mapping |
67 | 67 |
@custom_fields = @import.mappable_custom_fields |
68 | 68 | |
69 |
auto_map_fields if @import.mapping.empty? |
|
70 | ||
69 | 71 |
if request.post? |
70 | 72 |
respond_to do |format| |
71 | 73 |
format.html { |
... | ... | |
159 | 161 |
type && type < Import ? type : nil |
160 | 162 |
end |
161 | 163 |
end |
164 | ||
165 |
def auto_map_fields |
|
166 |
@import.settings['mapping'] = {} |
|
167 | ||
168 |
headers = @import.headers.map { |string| string.parameterize.underscore } |
|
169 |
mappings = @import.mapping |
|
170 | ||
171 |
# Try to auto map core fields |
|
172 |
import_type::AUTO_MAPPABLE_FIELDS.each do |field| |
|
173 |
if !mappings.include?(field) && headers.include?(field) |
|
174 |
@import.mapping[field] = headers.index(field) |
|
175 |
end |
|
176 |
end |
|
177 | ||
178 |
# Try to auto map custom fields |
|
179 |
@custom_fields.each do |field| |
|
180 |
field_name = field.name.parameterize.underscore |
|
181 |
if headers.include?(field_name) |
|
182 |
@import.mapping["cf_#{field.id}"] = headers.index(field_name) |
|
183 |
end |
|
184 |
end |
|
185 |
end |
|
162 | 186 |
end |
app/models/import.rb | ||
---|---|---|
38 | 38 |
'%d-%m-%Y' |
39 | 39 |
] |
40 | 40 | |
41 |
AUTO_MAPPABLE_FIELDS = [] |
|
42 | ||
41 | 43 |
def self.menu_item |
42 | 44 |
nil |
43 | 45 |
end |
app/models/issue_import.rb | ||
---|---|---|
18 | 18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
19 | 19 | |
20 | 20 |
class IssueImport < Import |
21 | ||
22 |
AUTO_MAPPABLE_FIELDS = [ |
|
23 |
'tracker', |
|
24 |
'status', |
|
25 |
'unique_id', |
|
26 |
'subject', |
|
27 |
'description', |
|
28 |
'priority', |
|
29 |
'category', |
|
30 |
'assigned_to', |
|
31 |
'fixed_version', |
|
32 |
'is_private', |
|
33 |
'parent_issue_id', |
|
34 |
'start_date', |
|
35 |
'due_date', |
|
36 |
'estimated_hours', |
|
37 |
'done_ratio' |
|
38 |
] |
|
39 | ||
21 | 40 |
def self.menu_item |
22 | 41 |
:issues |
23 | 42 |
end |