From a5a42ed1bf23da4a35b675ce00781fea99df2acd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Tue, 6 Nov 2012 17:01:19 +0100 Subject: [PATCH] CsvReport: Status mitspeichern --- SL/Controller/CsvImport.pm | 7 ++++- SL/DB/CsvImportReport.pm | 28 +++++++++++++++-- ...tRowStatus.pm => CsvImportReportStatus.pm} | 4 +-- SL/DB/Helper/Mappings.pm | 2 +- SL/DB/MetaSetup/CsvImportReportRowStatus.pm | 30 ------------------- SL/DB/MetaSetup/CsvImportReportStatus.pm | 24 +++++++++++++++ sql/Pg-upgrade2/csv_import_report_cache.sql | 5 ++-- templates/webpages/csv_import/report.html | 7 +++-- 8 files changed, 66 insertions(+), 41 deletions(-) rename SL/DB/{CsvImportReportRowStatus.pm => CsvImportReportStatus.pm} (75%) delete mode 100644 SL/DB/MetaSetup/CsvImportReportRowStatus.pm create mode 100644 SL/DB/MetaSetup/CsvImportReportStatus.pm diff --git a/SL/Controller/CsvImport.pm b/SL/Controller/CsvImport.pm index 5171576eb..830d5ff77 100644 --- a/SL/Controller/CsvImport.pm +++ b/SL/Controller/CsvImport.pm @@ -276,9 +276,11 @@ sub save_report { my $dbh = $::form->get_standard_dbh; $dbh->begin_work; - my $query = 'INSERT INTO csv_import_report_rows (csv_import_report_id, col, row, value) VALUES (?, ?, ?, ?)'; + my $query = 'INSERT INTO csv_import_report_rows (csv_import_report_id, col, row, value) VALUES (?, ?, ?, ?)'; + my $query2 = 'INSERT INTO csv_import_report_status (csv_import_report_id, row, type, value) VALUES (?, ?, ?, ?)'; my $sth = $dbh->prepare($query); + my $sth2 = $dbh->prepare($query2); # save headers my @headers = ( @@ -302,6 +304,9 @@ sub save_report { $sth->execute($report->id, $_, $row + 1, $data_row->{info_data}{ $info_methods[$_] }) for 0 .. $#info_methods; $sth->execute($report->id, $o1 + $_, $row + 1, $data_row->{object}->${ \ $methods[$_] }) for 0 .. $#methods; $sth->execute($report->id, $o2 + $_, $row + 1, $data_row->{raw_data}{ $raw_methods[$_] }) for 0 .. $#raw_methods; + + $sth2->execute($report->id, $row + 1, 'information', $_) for @{ $data_row->{information} || [] }; + $sth2->execute($report->id, $row + 1, 'errors', $_) for @{ $data_row->{errors} || [] }; } $dbh->commit; diff --git a/SL/DB/CsvImportReport.pm b/SL/DB/CsvImportReport.pm index 879c0404c..38d9e697e 100644 --- a/SL/DB/CsvImportReport.pm +++ b/SL/DB/CsvImportReport.pm @@ -13,6 +13,11 @@ __PACKAGE__->meta->add_relationships( class => 'SL::DB::CsvImportReportRow', column_map => { id => 'csv_import_report_id' }, }, + status => { + type => 'one to many', + class => 'SL::DB::CsvImportReportStatus', + column_map => { id => 'csv_import_report_id' }, + }, ); __PACKAGE__->meta->make_manager_class; @@ -26,16 +31,35 @@ sub folded_rows { return $self->{folded_rows}; } +sub folded_status { + my ($self) = @_; + + $self->_fold_status unless $self->{folded_status}; + + return $self->{folded_status}; +} + sub _fold_rows { my ($self) = @_; $self->{folded_rows} = []; for my $row_obj (@{ $self->rows }) { - $::lxdebug->dump(0, "adding", $row_obj->row . ' ' . $row_obj->col . ' ' . $row_obj->value); $self->{folded_rows}->[ $row_obj->row ] ||= []; $self->{folded_rows}->[ $row_obj->row ][ $row_obj->col ] = $row_obj->value; - $::lxdebug->dump(0, "now", $self->{folded_rows}); + } +} + +sub _fold_status { + my ($self) = @_; + + $self->{folded_status} = []; + + for my $status_obj (@{ $self->status }) { + $self->{folded_status}->[ $status_obj->row ] ||= {}; + $self->{folded_status}->[ $status_obj->row ]{information} ||= []; + $self->{folded_status}->[ $status_obj->row ]{errors} ||= []; + push @{ $self->{folded_status}->[ $status_obj->row ]{ $status_obj->type } }, $status_obj->value; } } diff --git a/SL/DB/CsvImportReportRowStatus.pm b/SL/DB/CsvImportReportStatus.pm similarity index 75% rename from SL/DB/CsvImportReportRowStatus.pm rename to SL/DB/CsvImportReportStatus.pm index 495169185..68a041b4c 100644 --- a/SL/DB/CsvImportReportRowStatus.pm +++ b/SL/DB/CsvImportReportStatus.pm @@ -1,11 +1,11 @@ # This file has been auto-generated only because it didn't exist. # Feel free to modify it at will; it will not be overwritten automatically. -package SL::DB::CsvImportReportRowStatus; +package SL::DB::CsvImportReportStatus; use strict; -use SL::DB::MetaSetup::CsvImportReportRowStatus; +use SL::DB::MetaSetup::CsvImportReportStatus; # Creates get_all, get_all_count, get_all_iterator, delete_all and update_all. __PACKAGE__->meta->make_manager_class; diff --git a/SL/DB/Helper/Mappings.pm b/SL/DB/Helper/Mappings.pm index 138807437..d04d05e1b 100644 --- a/SL/DB/Helper/Mappings.pm +++ b/SL/DB/Helper/Mappings.pm @@ -52,7 +52,7 @@ my %lxoffice_package_names = ( csv_import_profile_settings => 'csv_import_profile_setting', csv_import_reports => 'csv_import_report', csv_import_report_rows => 'csv_import_report_row', - csv_import_report_row_status => 'csv_import_report_row_status', + csv_import_report_status => 'csv_import_report_status', custom_variable_configs => 'custom_variable_config', custom_variables => 'custom_variable', custom_variables_validity => 'custom_variable_validity', diff --git a/SL/DB/MetaSetup/CsvImportReportRowStatus.pm b/SL/DB/MetaSetup/CsvImportReportRowStatus.pm deleted file mode 100644 index f0f55f797..000000000 --- a/SL/DB/MetaSetup/CsvImportReportRowStatus.pm +++ /dev/null @@ -1,30 +0,0 @@ -# This file has been auto-generated. Do not modify it; it will be overwritten -# by rose_auto_create_model.pl automatically. -package SL::DB::CsvImportReportRowStatus; - -use strict; - -use base qw(SL::DB::Object); - -__PACKAGE__->meta->setup( - table => 'csv_import_report_row_status', - - columns => [ - id => { type => 'serial', not_null => 1 }, - csv_import_report_row_id => { type => 'integer', not_null => 1 }, - type => { type => 'text', not_null => 1 }, - value => { type => 'text' }, - ], - - primary_key_columns => [ 'id' ], - - foreign_keys => [ - csv_import_report_row => { - class => 'SL::DB::CsvImportReportRow', - key_columns => { csv_import_report_row_id => 'id' }, - }, - ], -); - -1; -; diff --git a/SL/DB/MetaSetup/CsvImportReportStatus.pm b/SL/DB/MetaSetup/CsvImportReportStatus.pm new file mode 100644 index 000000000..ef9d30354 --- /dev/null +++ b/SL/DB/MetaSetup/CsvImportReportStatus.pm @@ -0,0 +1,24 @@ +# This file has been auto-generated. Do not modify it; it will be overwritten +# by rose_auto_create_model.pl automatically. +package SL::DB::CsvImportReportStatus; + +use strict; + +use base qw(SL::DB::Object); + +__PACKAGE__->meta->setup( + table => 'csv_import_report_status', + + columns => [ + id => { type => 'serial', not_null => 1 }, + csv_import_report_id => { type => 'integer', not_null => 1 }, + row => { type => 'integer', not_null => 1 }, + type => { type => 'text', not_null => 1 }, + value => { type => 'text' }, + ], + + primary_key_columns => [ 'id' ], +); + +1; +; diff --git a/sql/Pg-upgrade2/csv_import_report_cache.sql b/sql/Pg-upgrade2/csv_import_report_cache.sql index 440c34610..e401b8397 100644 --- a/sql/Pg-upgrade2/csv_import_report_cache.sql +++ b/sql/Pg-upgrade2/csv_import_report_cache.sql @@ -19,9 +19,10 @@ CREATE TABLE csv_import_report_rows ( value TEXT ); -CREATE TABLE csv_import_report_row_status ( +CREATE TABLE csv_import_report_status ( id SERIAL PRIMARY KEY, - csv_import_report_row_id INTEGER NOT NULL REFERENCES csv_import_report_rows(id), + csv_import_report_id INTEGER NOT NULL REFERENCES csv_import_reports(id), + row INTEGER NOT NULL, type TEXT NOT NULL, value TEXT ); diff --git a/templates/webpages/csv_import/report.html b/templates/webpages/csv_import/report.html index 7965b092f..e6c34b004 100644 --- a/templates/webpages/csv_import/report.html +++ b/templates/webpages/csv_import/report.html @@ -14,13 +14,14 @@ [%- LxERP.t8('Notes') %] [%- ELSE %] - + [% csv_import_report_errors = SELF.report.folded_status.${loop.index}.errors %] + [%- FOREACH value = row %] [%- value | html %] [%- END %] - [%- FOREACH error = row.errors %][%- HTML.escape(error) %][% UNLESS loop.last %]
[%- END %][%- END %] - [%- FOREACH info = row.information %][% IF !loop.first || row.errors.size %]
[%- END %][%- HTML.escape(info) %][%- END %] + [%- FOREACH error = csv_import_report_errors %][%- error | html %][% UNLESS loop.last %]
[%- END %][%- END %] + [%- FOREACH info = SELF.report.folded_status.${loop.index}.information %][% IF !loop.first || csv_import_report_errors.size %]
[%- END %][%- info | html %][%- END %] [%- END %] -- 2.20.1