From: Sven Schöling Date: Fri, 16 Nov 2012 16:01:51 +0000 (+0100) Subject: report paginaten X-Git-Tag: release-3.1.0beta1~726 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=638e0b031a49d9864395e8600077306b91a45252;p=kivitendo-erp.git report paginaten --- diff --git a/SL/Controller/CsvImport.pm b/SL/Controller/CsvImport.pm index 681ebdd47..24c76ab3d 100644 --- a/SL/Controller/CsvImport.pm +++ b/SL/Controller/CsvImport.pm @@ -6,6 +6,7 @@ use SL::DB::Buchungsgruppe; use SL::DB::CsvImportProfile; use SL::DB::CsvImportReport; use SL::DB::Unit; +use SL::DB::Helper::Paginated (); use SL::Helper::Flash; use SL::SessionFile; use SL::Controller::CsvImport::Contact; @@ -17,6 +18,7 @@ use SL::BackgroundJob::CsvImport; use SL::System::TaskServer; use List::MoreUtils qw(none); +use List::Util qw(min); use parent qw(SL::Controller::Base); @@ -123,9 +125,50 @@ sub action_download_sample { sub action_report { my ($self, %params) = @_; - $self->{report} = SL::DB::Manager::CsvImportReport->find_by(id => $params{report_id} || $::form->{id}); + my $report_id = $params{report_id} || $::form->{id}; + + $self->{report} = SL::DB::Manager::CsvImportReport->find_by(id => $report_id); + my $num_rows = SL::DB::Manager::CsvImportReportRow->get_all_count(query => [ csv_import_report_id => $report_id ]); + my $num_cols = SL::DB::Manager::CsvImportReportRow->get_all_count(query => [ csv_import_report_id => $report_id, row => 0 ]); + + # manual paginating, yuck + my $page = $::form->{page} || 1; + my $pages = {}; + $pages->{per_page} = $::form->{per_page} || 20; + $pages->{max} = SL::DB::Helper::Paginated::ceil($num_rows / ($num_cols || 1), $pages->{per_page}) || 1; + $pages->{cur} = $page < 1 ? 1 + : $page > $pages->{max} ? $pages->{max} + : $page; + $pages->{common} = SL::DB::Helper::Paginated::make_common_pages($pages->{cur}, $pages->{max}); + + $self->{display_rows} = [ + 0, + $pages->{per_page} * ($pages->{cur}-1) + 1 + .. + min($pages->{per_page} * $pages->{cur}, $num_rows / ($num_cols || 1) - 1) + ]; + + my @query = ( + csv_import_report_id => $report_id, + or => [ + row => 0, + and => [ + row => { gt => $pages->{per_page} * ($pages->{cur}-1) }, + row => { le => $pages->{per_page} * $pages->{cur} }, + ] + ] + ); + + my $rows = SL::DB::Manager::CsvImportReportRow->get_all(query => \@query); + my $status = SL::DB::Manager::CsvImportReportStatus->get_all(query => \@query); + + $self->{report_rows} = $self->{report}->folded_rows(rows => $rows); + $self->{report_status} = $self->{report}->folded_status(status => $status); + $self->{pages} = $pages; + + my $base_url = $self->url_for(action => 'report', id => $report_id); - $self->render('csv_import/report', { no_layout => $params{no_layout} }); + $self->render('csv_import/report', { no_layout => $params{no_layout} }, base_url => $base_url); } diff --git a/SL/DB/CsvImportReport.pm b/SL/DB/CsvImportReport.pm index 5b7acd25b..b3cdf3bf3 100644 --- a/SL/DB/CsvImportReport.pm +++ b/SL/DB/CsvImportReport.pm @@ -25,43 +25,31 @@ __PACKAGE__->meta->add_relationships( __PACKAGE__->meta->initialize; sub folded_rows { - my ($self) = @_; - - $self->_fold_rows unless $self->{folded_rows}; + my ($self, %params) = @_; - return $self->{folded_rows}; -} + my $folded_rows = {}; -sub folded_status { - my ($self) = @_; - - $self->_fold_status unless $self->{folded_status}; + for my $row_obj (@{ $params{rows} || $self->rows }) { + $folded_rows->{ $row_obj->row } ||= []; + $folded_rows->{ $row_obj->row }[ $row_obj->col ] = $row_obj->value; + } - return $self->{folded_status}; + $folded_rows; } -sub _fold_rows { - my ($self) = @_; +sub folded_status { + my ($self, %params) = @_; - $self->{folded_rows} = []; + my $folded_status = {}; - for my $row_obj (@{ $self->rows }) { - $self->{folded_rows}->[ $row_obj->row ] ||= []; - $self->{folded_rows}->[ $row_obj->row ][ $row_obj->col ] = $row_obj->value; + for my $status_obj (@{ $params{status} || $self->status }) { + $folded_status->{ $status_obj->row } ||= {}; + $folded_status->{ $status_obj->row }{information} ||= []; + $folded_status->{ $status_obj->row }{errors} ||= []; + push @{ $folded_status->{ $status_obj->row }{ $status_obj->type } }, $status_obj->value; } -} -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; - } + $folded_status; } # implementes cascade delete as per documentation diff --git a/templates/webpages/csv_import/report.html b/templates/webpages/csv_import/report.html index 264bedafb..96fb0a547 100644 --- a/templates/webpages/csv_import/report.html +++ b/templates/webpages/csv_import/report.html @@ -5,23 +5,23 @@

[%- LxERP.t8('Import result') %]

-[%- FOREACH row = SELF.report.folded_rows %] +[%- FOREACH rownum = SELF.display_rows %] [%- IF loop.first %] - [%- FOREACH value = row %] + [%- FOREACH value = SELF.report_rows.${rownum} %] [%- END %] [%- ELSE %] - [% csv_import_report_errors = SELF.report.folded_status.${loop.index}.errors %] + [% csv_import_report_errors = SELF.report_status.${rownum}.errors %] - [%- FOREACH value = row %] + [%- FOREACH value = SELF.report_rows.${rownum} %] [%- END %] [%- END %] @@ -29,6 +29,8 @@
[% value | html %][%- LxERP.t8('Notes') %]
[%- value | html %] [%- 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 %] + [%- FOREACH info = SELF.report_status.${rownum}.information %][% IF !loop.first || csv_import_report_errors.size %]
[%- END %][%- info | html %][%- END %]
+[%- PROCESS 'common/paginate.html' pages=SELF.pages %] +