Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 638e0b03

Von Sven Schöling vor fast 12 Jahren hinzugefügt

  • ID 638e0b031a49d9864395e8600077306b91a45252
  • Vorgänger d001c791
  • Nachfolger e5a690f9

report paginaten

Unterschiede anzeigen:

SL/Controller/CsvImport.pm
6 6
use SL::DB::CsvImportProfile;
7 7
use SL::DB::CsvImportReport;
8 8
use SL::DB::Unit;
9
use SL::DB::Helper::Paginated ();
9 10
use SL::Helper::Flash;
10 11
use SL::SessionFile;
11 12
use SL::Controller::CsvImport::Contact;
......
17 18
use SL::System::TaskServer;
18 19

  
19 20
use List::MoreUtils qw(none);
21
use List::Util qw(min);
20 22

  
21 23
use parent qw(SL::Controller::Base);
22 24

  
......
123 125
sub action_report {
124 126
  my ($self, %params) = @_;
125 127

  
126
  $self->{report} = SL::DB::Manager::CsvImportReport->find_by(id => $params{report_id} || $::form->{id});
128
  my $report_id = $params{report_id} || $::form->{id};
129

  
130
  $self->{report}      = SL::DB::Manager::CsvImportReport->find_by(id => $report_id);
131
  my $num_rows         = SL::DB::Manager::CsvImportReportRow->get_all_count(query => [ csv_import_report_id => $report_id ]);
132
  my $num_cols         = SL::DB::Manager::CsvImportReportRow->get_all_count(query => [ csv_import_report_id => $report_id, row => 0 ]);
133

  
134
  # manual paginating, yuck
135
  my $page = $::form->{page} || 1;
136
  my $pages = {};
137
  $pages->{per_page}        = $::form->{per_page} || 20;
138
  $pages->{max}             = SL::DB::Helper::Paginated::ceil($num_rows / ($num_cols || 1), $pages->{per_page}) || 1;
139
  $pages->{cur}             = $page < 1 ? 1
140
                            : $page > $pages->{max} ? $pages->{max}
141
                            : $page;
142
  $pages->{common}          = SL::DB::Helper::Paginated::make_common_pages($pages->{cur}, $pages->{max});
143

  
144
  $self->{display_rows} = [
145
    0,
146
    $pages->{per_page} * ($pages->{cur}-1) + 1
147
      ..
148
    min($pages->{per_page} * $pages->{cur}, $num_rows / ($num_cols || 1) - 1)
149
  ];
150

  
151
  my @query = (
152
    csv_import_report_id => $report_id,
153
    or => [
154
      row => 0,
155
      and => [
156
        row => { gt => $pages->{per_page} * ($pages->{cur}-1) },
157
        row => { le => $pages->{per_page} * $pages->{cur} },
158
      ]
159
    ]
160
  );
161

  
162
  my $rows             = SL::DB::Manager::CsvImportReportRow->get_all(query => \@query);
163
  my $status           = SL::DB::Manager::CsvImportReportStatus->get_all(query => \@query);
164

  
165
  $self->{report_rows}   = $self->{report}->folded_rows(rows => $rows);
166
  $self->{report_status} = $self->{report}->folded_status(status => $status);
167
  $self->{pages} = $pages;
168

  
169
  my $base_url = $self->url_for(action => 'report', id => $report_id);
127 170

  
128
  $self->render('csv_import/report', { no_layout => $params{no_layout} });
171
  $self->render('csv_import/report', { no_layout => $params{no_layout} }, base_url => $base_url);
129 172
}
130 173

  
131 174

  
SL/DB/CsvImportReport.pm
25 25
__PACKAGE__->meta->initialize;
26 26

  
27 27
sub folded_rows {
28
  my ($self) = @_;
29

  
30
  $self->_fold_rows unless $self->{folded_rows};
28
  my ($self, %params) = @_;
31 29

  
32
  return $self->{folded_rows};
33
}
30
  my $folded_rows = {};
34 31

  
35
sub folded_status {
36
  my ($self) = @_;
37

  
38
  $self->_fold_status unless $self->{folded_status};
32
  for my $row_obj (@{ $params{rows} || $self->rows }) {
33
    $folded_rows->{ $row_obj->row } ||= [];
34
    $folded_rows->{ $row_obj->row }[ $row_obj->col ] = $row_obj->value;
35
  }
39 36

  
40
  return $self->{folded_status};
37
  $folded_rows;
41 38
}
42 39

  
43
sub _fold_rows {
44
  my ($self) = @_;
40
sub folded_status {
41
  my ($self, %params) = @_;
45 42

  
46
  $self->{folded_rows} = [];
43
  my $folded_status = {};
47 44

  
48
  for my $row_obj (@{ $self->rows }) {
49
    $self->{folded_rows}->[ $row_obj->row ] ||= [];
50
    $self->{folded_rows}->[ $row_obj->row ][ $row_obj->col ] = $row_obj->value;
45
  for my $status_obj (@{ $params{status} || $self->status }) {
46
    $folded_status->{ $status_obj->row } ||= {};
47
    $folded_status->{ $status_obj->row }{information} ||= [];
48
    $folded_status->{ $status_obj->row }{errors} ||= [];
49
    push @{ $folded_status->{ $status_obj->row }{ $status_obj->type } }, $status_obj->value;
51 50
  }
52
}
53 51

  
54
sub _fold_status {
55
  my ($self) = @_;
56

  
57
  $self->{folded_status} = [];
58

  
59
  for my $status_obj (@{ $self->status }) {
60
    $self->{folded_status}->[ $status_obj->row ] ||= {};
61
    $self->{folded_status}->[ $status_obj->row ]{information} ||= [];
62
    $self->{folded_status}->[ $status_obj->row ]{errors} ||= [];
63
    push @{ $self->{folded_status}->[ $status_obj->row ]{ $status_obj->type } }, $status_obj->value;
64
  }
52
  $folded_status;
65 53
}
66 54

  
67 55
# implementes cascade delete as per documentation
templates/webpages/csv_import/report.html
5 5
 <h3>[%- LxERP.t8('Import result') %]</h3>
6 6

  
7 7
 <table>
8
[%- FOREACH row = SELF.report.folded_rows %]
8
[%- FOREACH rownum = SELF.display_rows %]
9 9
 [%- IF loop.first %]
10 10
  <tr class="listheading">
11
  [%- FOREACH value = row %]
11
  [%- FOREACH value = SELF.report_rows.${rownum} %]
12 12
   <th>[% value | html %]</th>
13 13
  [%- END  %]
14 14
   <th>[%- LxERP.t8('Notes') %]</th>
15 15
  </tr>
16 16
 [%- ELSE %]
17
  [% csv_import_report_errors = SELF.report.folded_status.${loop.index}.errors %]
17
  [% csv_import_report_errors = SELF.report_status.${rownum}.errors %]
18 18
  <tr class="[% IF csv_import_report_errors.size %]redrow[% ELSE %]listrow[% END %][% 1 - loop.count % 2 %]">
19
  [%- FOREACH value = row %]
19
  [%- FOREACH value = SELF.report_rows.${rownum} %]
20 20
   <td>[%- value | html  %]</td>
21 21
  [%- END %]
22 22
   <td>
23 23
    [%- FOREACH error = csv_import_report_errors %][%- error | html %][% UNLESS loop.last %]<br>[%- END %][%- END %]
24
    [%- FOREACH info  = SELF.report.folded_status.${loop.index}.information %][% IF !loop.first || csv_import_report_errors.size %]<br>[%- END %][%- info | html %][%- END %]
24
    [%- FOREACH info  = SELF.report_status.${rownum}.information %][% IF !loop.first || csv_import_report_errors.size %]<br>[%- END %][%- info | html %][%- END %]
25 25
   </td>
26 26
  </tr>
27 27
 [%- END %]
......
29 29

  
30 30
 </table>
31 31

  
32
[%- PROCESS 'common/paginate.html' pages=SELF.pages %]
33

  
32 34
<script type='text/javascript'>
33 35
  $(function(){ $('#action_import').show() });
34 36
</script>

Auch abrufbar als: Unified diff