Patch #22913

Auto-select fields mapping in Importing

Added by Haihan Ji over 3 years ago. Updated 2 days ago.

Status:NewStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:Importers
Target version:4.2.0

Description

I hate to select many times in import-mapping.
This patch can auto select by label before you select it.

auto_select_fields.patch Magnifier (1.14 KB) Haihan Ji, 2016-05-27 15:55

20160606_auto_select_fields_test.patch Magnifier (1.37 KB) Haihan Ji, 2016-06-06 12:28

22913_auto_mapping.patch Magnifier (4.47 KB) Yuichi HARADA, 2019-11-26 06:59

demo_auto_map_fields.patch Magnifier (2.35 KB) Marius BALTEANU, 2020-01-27 00:44


Related issues

Related to Redmine - Feature #28234: Add CSV Import for Time Entries Closed

History

#1 Updated by Sebastian Paluch over 3 years ago

+1

#2 Updated by Go MAEDA over 3 years ago

Very interesting feature.
Could you add tests? Tests are required to be merged into the core.

#3 Updated by Haihan Ji over 3 years ago

Append Unit Test Code.

#4 Updated by Go MAEDA over 3 years ago

  • Target version set to Candidate for next major release

#5 Updated by Go MAEDA about 3 years ago

  • Status changed from New to Needs feedback

I tried this patch but got the following error while processing ImportsController#mapping. Could you test the patch on the current trunk?

NameError (undefined local variable or method `issue' for #<ImportsController:0x007fc8be2479b0>
Did you mean?  issue_url):
  app/controllers/imports_controller.rb:72:in `mapping'
  lib/redmine/sudo_mode.rb:63:in `sudo_mode'

#6 Updated by Yuichi HARADA 2 months ago

I fixed auto_select_fields.patch and 20160606_auto_select_fields_test.patch to work with the current trunk(r19312).
I attach a fixed patch.

#7 Updated by Joshua Jobin 2 months ago

Yuichi HARADA wrote:

I fixed auto_select_fields.patch and 20160606_auto_select_fields_test.patch to work with the current trunk(r19312).
I attach a fixed patch.

This is great. Thank you!
Do you find that if custom fields are absent from the default tracker, that they will not match when you load a tracker with more custom fields? I implemented this exactly and found that to be the case.

#8 Updated by Go MAEDA about 1 month ago

Joshua Jobin wrote:

Do you find that if custom fields are absent from the default tracker, that they will not match when you load a tracker with more custom fields? I implemented this exactly and found that to be the case.

Could you show the steps to reproduce the problem?

I didn't see the problem you pointed out with Yuichi HARADA's patch applied. What I did is disable a custom field only in the first tracker.

#9 Updated by Go MAEDA 25 days ago

  • Status changed from Needs feedback to New
  • Target version changed from Candidate for next major release to 4.2.0

Setting the target version to 4.2.0.

#10 Updated by Marius BALTEANU 25 days ago

  • Assignee set to Marius BALTEANU

Go MAEDA wrote:

Setting the target version to 4.2.0.

The patch cannot be committed as it is, please let me review it.

#11 Updated by Marius BALTEANU 2 days ago

#12 Updated by Marius BALTEANU 2 days ago

Sorry for my late review on this.

My main concern with the proposed patch are the hardcoded fields from mapping method (ImportsController). Because of them, the "auto mapping" feature it won't be easily extended by plugins or other models (it is against the generalisation added in r18145).

I'm attaching a patch with another solution, where each subclass of the import have a class constant (AUTO_MAPPABLE_FIELDS in my patch) or a method that returns an array with the fields that can be auto-mapped. In ImportsController, the method auto_map_fields uses this constant and try to auto map the fields based on some conditions. This auto mapping uses only the "internal" name of the fields, not labels or translations.

To support labels and translations as well, I see two options:
1. We modify the AUTO_MAPPABLE_FIELDS to return a hash with each internal field and his label. For example:

  AUTO_MAPPABLE_FIELDS = [
    'tracker' => 'label_tracker',
    'status' => 'label_status',
    ...
  ]

and then inside the auto_map_fields method we use it.

2. We use Javascript where we have access to all the required information, we just need to iterate throw each select element. This solution can handle both cases.

Also available in: Atom PDF