Revision a0d9f09a
Von Sven Schöling vor mehr als 8 Jahren hinzugefügt
SL/Controller/CsvImport.pm | ||
---|---|---|
32 | 32 |
( |
33 | 33 |
scalar => [ qw(type profile file all_profiles all_charsets sep_char all_sep_chars quote_char all_quote_chars escape_char all_escape_chars all_buchungsgruppen all_units |
34 | 34 |
import_status errors headers raw_data_headers info_headers data num_importable displayable_columns file all_taxzones) ], |
35 |
'scalar --get_set_init' => [ qw(worker task_server num_imported) ], |
|
35 |
'scalar --get_set_init' => [ qw(worker task_server num_imported mappings) ],
|
|
36 | 36 |
'array' => [ |
37 | 37 |
progress_tracker => { }, |
38 | 38 |
add_progress_tracker => { interface => 'add', hash_key => 'progress_tracker' }, |
... | ... | |
213 | 213 |
$self->render('csv_import/report', { layout => !($params{no_layout} || $::form->{no_layout}) }); |
214 | 214 |
} |
215 | 215 |
|
216 |
sub action_add_empty_mapping_line { |
|
217 |
my ($self) = @_; |
|
218 |
|
|
219 |
$self->profile_from_form; |
|
220 |
$self->setup_help; |
|
221 |
|
|
222 |
$self->js |
|
223 |
->append('#csv_import_mappings', $self->render('csv_import/_mapping_item', { layout => 0, output => 0 })) |
|
224 |
->hide('#mapping_empty') |
|
225 |
->render; |
|
226 |
} |
|
227 |
|
|
228 |
sub action_add_mapping_from_upload { |
|
229 |
my ($self) = @_; |
|
230 |
|
|
231 |
$self->profile_from_form; |
|
232 |
$self->setup_help; |
|
233 |
|
|
234 |
my $file = SL::SessionFile->new($self->csv_file_name, mode => '<', encoding => $self->profile->get('charset')); |
|
235 |
if (!$file->fh) { |
|
236 |
$self->js |
|
237 |
->flash('error', t8('No file has been uploaded yet.')) |
|
238 |
->render; |
|
239 |
return; |
|
240 |
} |
|
241 |
|
|
242 |
my $csv = Text::CSV_XS->new({ |
|
243 |
binary => 1, |
|
244 |
sep_char => $self->profile->get('sep_char'), |
|
245 |
quote_char => $self->profile->get('quote_char'), |
|
246 |
escape_char => $self->profile->get('escape_char'), |
|
247 |
}); |
|
248 |
|
|
249 |
my $header = $csv->getline($file->fh) or do { |
|
250 |
$self->js |
|
251 |
->flash('error', t8('No header found')) |
|
252 |
->render; |
|
253 |
return; |
|
254 |
}; |
|
255 |
|
|
256 |
for my $field (@$header) { |
|
257 |
next if $self->mappings_for_profile->{$field}; |
|
258 |
$self->js->append( |
|
259 |
'#csv_import_mappings', |
|
260 |
$self->render('csv_import/_mapping_item', { layout => 0, output => 0 }, item => { from => $field }), |
|
261 |
); |
|
262 |
} |
|
263 |
|
|
264 |
$self->js |
|
265 |
->hide('#mapping_empty') |
|
266 |
->render; |
|
267 |
} |
|
268 |
|
|
216 | 269 |
|
217 | 270 |
# |
218 | 271 |
# filters |
... | ... | |
372 | 425 |
$profile ||= SL::DB::CsvImportProfile->new(type => $self->{type}, login => $::myconfig{login}); |
373 | 426 |
|
374 | 427 |
$self->profile($profile); |
428 |
$self->mappings(SL::JSON::from_json($self->profile->get('json_mappings'))) if $self->profile->get('json_mappings'); |
|
375 | 429 |
$self->worker->set_profile_defaults; |
376 | 430 |
$self->profile->set_defaults; |
377 | 431 |
} |
... | ... | |
416 | 470 |
$self->profile->assign_attributes(%{ $::form->{profile} }); |
417 | 471 |
$self->profile->settings(map({ { key => $_, value => $::form->{settings}->{$_} } } keys %{ $::form->{settings} }), |
418 | 472 |
@settings); |
473 |
|
|
474 |
$self->profile->set('json_mappings', JSON::to_json($self->mappings)); |
|
475 |
|
|
419 | 476 |
$self->profile->set_defaults; |
420 | 477 |
} |
421 | 478 |
|
... | ... | |
664 | 721 |
1; |
665 | 722 |
} |
666 | 723 |
|
724 |
sub mappings_for_profile { |
|
725 |
+{ map { $_->{from} => $_->{to} } @{ $_[0]->mappings } } |
|
726 |
} |
|
727 |
|
|
728 |
sub init_mappings { |
|
729 |
$::form->{mappings} || [] |
|
730 |
} |
|
731 |
|
|
667 | 732 |
1; |
Auch abrufbar als: Unified diff
CsvImport: Spaltenzuordnung für non multiplexed