Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision a5a42ed1

Von Sven Schöling vor mehr als 11 Jahren hinzugefügt

  • ID a5a42ed1bf23da4a35b675ce00781fea99df2acd
  • Vorgänger 67643d03
  • Nachfolger 5d74fd02

CsvReport: Status mitspeichern

Unterschiede anzeigen:

SL/Controller/CsvImport.pm
276 276
  my $dbh = $::form->get_standard_dbh;
277 277
  $dbh->begin_work;
278 278

  
279
  my $query = 'INSERT INTO csv_import_report_rows (csv_import_report_id, col, row, value) VALUES (?, ?, ?, ?)';
279
  my $query  = 'INSERT INTO csv_import_report_rows (csv_import_report_id, col, row, value) VALUES (?, ?, ?, ?)';
280
  my $query2 = 'INSERT INTO csv_import_report_status (csv_import_report_id, row, type, value) VALUES (?, ?, ?, ?)';
280 281

  
281 282
  my $sth = $dbh->prepare($query);
283
  my $sth2 = $dbh->prepare($query2);
282 284

  
283 285
  # save headers
284 286
  my @headers = (
......
302 304
    $sth->execute($report->id,       $_, $row + 1, $data_row->{info_data}{ $info_methods[$_] }) for 0 .. $#info_methods;
303 305
    $sth->execute($report->id, $o1 + $_, $row + 1, $data_row->{object}->${ \ $methods[$_] })    for 0 .. $#methods;
304 306
    $sth->execute($report->id, $o2 + $_, $row + 1, $data_row->{raw_data}{ $raw_methods[$_] })   for 0 .. $#raw_methods;
307

  
308
    $sth2->execute($report->id, $row + 1, 'information', $_) for @{ $data_row->{information} || [] };
309
    $sth2->execute($report->id, $row + 1, 'errors', $_)      for @{ $data_row->{errors}      || [] };
305 310
  }
306 311

  
307 312
  $dbh->commit;
SL/DB/CsvImportReport.pm
13 13
    class        => 'SL::DB::CsvImportReportRow',
14 14
    column_map   => { id => 'csv_import_report_id' },
15 15
  },
16
  status => {
17
    type         => 'one to many',
18
    class        => 'SL::DB::CsvImportReportStatus',
19
    column_map   => { id => 'csv_import_report_id' },
20
  },
16 21
);
17 22

  
18 23
__PACKAGE__->meta->make_manager_class;
......
26 31
  return $self->{folded_rows};
27 32
}
28 33

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

  
37
  $self->_fold_status unless $self->{folded_status};
38

  
39
  return $self->{folded_status};
40
}
41

  
29 42
sub _fold_rows {
30 43
  my ($self) = @_;
31 44

  
32 45
  $self->{folded_rows} = [];
33 46

  
34 47
  for my $row_obj (@{ $self->rows }) {
35
    $::lxdebug->dump(0,  "adding", $row_obj->row . ' ' . $row_obj->col . ' ' . $row_obj->value);
36 48
    $self->{folded_rows}->[ $row_obj->row ] ||= [];
37 49
    $self->{folded_rows}->[ $row_obj->row ][ $row_obj->col ] = $row_obj->value;
38
    $::lxdebug->dump(0,  "now", $self->{folded_rows});
50
  }
51
}
52

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

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

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

  
SL/DB/CsvImportReportRowStatus.pm
1
# This file has been auto-generated only because it didn't exist.
2
# Feel free to modify it at will; it will not be overwritten automatically.
3

  
4
package SL::DB::CsvImportReportRowStatus;
5

  
6
use strict;
7

  
8
use SL::DB::MetaSetup::CsvImportReportRowStatus;
9

  
10
# Creates get_all, get_all_count, get_all_iterator, delete_all and update_all.
11
__PACKAGE__->meta->make_manager_class;
12

  
13
1;
SL/DB/CsvImportReportStatus.pm
1
# This file has been auto-generated only because it didn't exist.
2
# Feel free to modify it at will; it will not be overwritten automatically.
3

  
4
package SL::DB::CsvImportReportStatus;
5

  
6
use strict;
7

  
8
use SL::DB::MetaSetup::CsvImportReportStatus;
9

  
10
# Creates get_all, get_all_count, get_all_iterator, delete_all and update_all.
11
__PACKAGE__->meta->make_manager_class;
12

  
13
1;
SL/DB/Helper/Mappings.pm
52 52
  csv_import_profile_settings    => 'csv_import_profile_setting',
53 53
  csv_import_reports             => 'csv_import_report',
54 54
  csv_import_report_rows         => 'csv_import_report_row',
55
  csv_import_report_row_status   => 'csv_import_report_row_status',
55
  csv_import_report_status       => 'csv_import_report_status',
56 56
  custom_variable_configs        => 'custom_variable_config',
57 57
  custom_variables               => 'custom_variable',
58 58
  custom_variables_validity      => 'custom_variable_validity',
SL/DB/MetaSetup/CsvImportReportRowStatus.pm
1
# This file has been auto-generated. Do not modify it; it will be overwritten
2
# by rose_auto_create_model.pl automatically.
3
package SL::DB::CsvImportReportRowStatus;
4

  
5
use strict;
6

  
7
use base qw(SL::DB::Object);
8

  
9
__PACKAGE__->meta->setup(
10
  table   => 'csv_import_report_row_status',
11

  
12
  columns => [
13
    id                       => { type => 'serial', not_null => 1 },
14
    csv_import_report_row_id => { type => 'integer', not_null => 1 },
15
    type                     => { type => 'text', not_null => 1 },
16
    value                    => { type => 'text' },
17
  ],
18

  
19
  primary_key_columns => [ 'id' ],
20

  
21
  foreign_keys => [
22
    csv_import_report_row => {
23
      class       => 'SL::DB::CsvImportReportRow',
24
      key_columns => { csv_import_report_row_id => 'id' },
25
    },
26
  ],
27
);
28

  
29
1;
30
;
SL/DB/MetaSetup/CsvImportReportStatus.pm
1
# This file has been auto-generated. Do not modify it; it will be overwritten
2
# by rose_auto_create_model.pl automatically.
3
package SL::DB::CsvImportReportStatus;
4

  
5
use strict;
6

  
7
use base qw(SL::DB::Object);
8

  
9
__PACKAGE__->meta->setup(
10
  table   => 'csv_import_report_status',
11

  
12
  columns => [
13
    id                   => { type => 'serial', not_null => 1 },
14
    csv_import_report_id => { type => 'integer', not_null => 1 },
15
    row                  => { type => 'integer', not_null => 1 },
16
    type                 => { type => 'text', not_null => 1 },
17
    value                => { type => 'text' },
18
  ],
19

  
20
  primary_key_columns => [ 'id' ],
21
);
22

  
23
1;
24
;
sql/Pg-upgrade2/csv_import_report_cache.sql
19 19
  value                TEXT
20 20
);
21 21

  
22
CREATE TABLE csv_import_report_row_status (
22
CREATE TABLE csv_import_report_status (
23 23
  id                   SERIAL PRIMARY KEY,
24
  csv_import_report_row_id INTEGER NOT NULL REFERENCES csv_import_report_rows(id),
24
  csv_import_report_id INTEGER NOT NULL REFERENCES csv_import_reports(id),
25
  row                  INTEGER NOT NULL,
25 26
  type                 TEXT NOT NULL,
26 27
  value                TEXT
27 28
);
templates/webpages/csv_import/report.html
14 14
   <th>[%- LxERP.t8('Notes') %]</th>
15 15
  </tr>
16 16
 [%- ELSE %]
17
  <tr class="[% IF row.errors.size %]redrow[% ELSE %]listrow[% END %][% loop.count % 2 %]">
17
  [% csv_import_report_errors = SELF.report.folded_status.${loop.index}.errors %]
18
  <tr class="[% IF csv_import_report_errors.size %]redrow[% ELSE %]listrow[% END %][% loop.count % 2 %]">
18 19
  [%- FOREACH value = row %]
19 20
   <td>[%- value | html  %]</td>
20 21
  [%- END %]
21 22
   <td>
22
    [%- FOREACH error = row.errors %][%- HTML.escape(error) %][% UNLESS loop.last %]<br>[%- END %][%- END %]
23
    [%- FOREACH info  = row.information %][% IF !loop.first || row.errors.size %]<br>[%- END %][%- HTML.escape(info) %][%- END %]
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 25
   </td>
25 26
  </tr>
26 27
 [%- END %]

Auch abrufbar als: Unified diff