Feature #22913 » demo_auto_map_fields.patch
| app/controllers/imports_controller.rb | ||
|---|---|---|
|
def mapping
|
||
|
@custom_fields = @import.mappable_custom_fields
|
||
|
auto_map_fields if @import.mapping.empty?
|
||
|
if request.post?
|
||
|
respond_to do |format|
|
||
|
format.html {
|
||
| ... | ... | |
|
type && type < Import ? type : nil
|
||
|
end
|
||
|
end
|
||
|
def auto_map_fields
|
||
|
@import.settings['mapping'] = {}
|
||
|
headers = @import.headers.map { |string| string.parameterize.underscore }
|
||
|
mappings = @import.mapping
|
||
|
# Try to auto map core fields
|
||
|
import_type::AUTO_MAPPABLE_FIELDS.each do |field|
|
||
|
if !mappings.include?(field) && headers.include?(field)
|
||
|
@import.mapping[field] = headers.index(field)
|
||
|
end
|
||
|
end
|
||
|
# Try to auto map custom fields
|
||
|
@custom_fields.each do |field|
|
||
|
field_name = field.name.parameterize.underscore
|
||
|
if headers.include?(field_name)
|
||
|
@import.mapping["cf_#{field.id}"] = headers.index(field_name)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
| app/models/import.rb | ||
|---|---|---|
|
'%d-%m-%Y'
|
||
|
]
|
||
|
AUTO_MAPPABLE_FIELDS = []
|
||
|
def self.menu_item
|
||
|
nil
|
||
|
end
|
||
| app/models/issue_import.rb | ||
|---|---|---|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
class IssueImport < Import
|
||
|
AUTO_MAPPABLE_FIELDS = [
|
||
|
'tracker',
|
||
|
'status',
|
||
|
'unique_id',
|
||
|
'subject',
|
||
|
'description',
|
||
|
'priority',
|
||
|
'category',
|
||
|
'assigned_to',
|
||
|
'fixed_version',
|
||
|
'is_private',
|
||
|
'parent_issue_id',
|
||
|
'start_date',
|
||
|
'due_date',
|
||
|
'estimated_hours',
|
||
|
'done_ratio'
|
||
|
]
|
||
|
def self.menu_item
|
||
|
:issues
|
||
|
end
|
||