diff options
author | Matthew Somerville <matthew@mysociety.org> | 2019-11-28 12:09:09 +0000 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2019-12-09 12:50:07 +0000 |
commit | 39b90de5867b7de66c10b74556a961e31f454104 (patch) | |
tree | f19ba00c1ae4d6f45320731429c0be68539697d8 | |
parent | e4a1090545dd80a8dd36d63747e001ee0f3e87ab (diff) |
[TfL] Include category extra fields in CSV export.
If a category is selected.
-rw-r--r-- | perllib/FixMyStreet/Cobrand/TfL.pm | 18 | ||||
-rw-r--r-- | t/cobrand/tfl.t | 19 |
2 files changed, 31 insertions, 6 deletions
diff --git a/perllib/FixMyStreet/Cobrand/TfL.pm b/perllib/FixMyStreet/Cobrand/TfL.pm index 6afa4b363..ba5d8b171 100644 --- a/perllib/FixMyStreet/Cobrand/TfL.pm +++ b/perllib/FixMyStreet/Cobrand/TfL.pm @@ -161,6 +161,17 @@ sub dashboard_export_problems_add_columns { "reassigned_by", ]; + if ($c->stash->{category}) { + my ($contact) = grep { $_->category eq $c->stash->{category} } @{$c->stash->{contacts}}; + if ($contact) { + foreach (@{$contact->get_metadata_for_storage}) { + next if $_->{code} eq 'safety_critical'; + push @{$c->stash->{csv}->{columns}}, "extra.$_->{code}"; + push @{$c->stash->{csv}->{headers}}, $_->{description}; + } + } + } + $c->stash->{csv}->{extra_data} = sub { my $report = shift; @@ -182,7 +193,7 @@ sub dashboard_export_problems_add_columns { $closure_email_at = DateTime->from_epoch( epoch => $closure_email_at, time_zone => FixMyStreet->local_time_zone ) if $closure_email_at; - return { + my $fields = { acknowledged => $report->whensent, agent_responsible => $agent ? $agent->name : '', category => $groups{$report->category}, @@ -194,6 +205,11 @@ sub dashboard_export_problems_add_columns { reassigned_at => $reassigned_at, reassigned_by => $reassigned_by, }; + foreach (@{$report->get_extra_fields}) { + next if $_->{name} eq 'safety_critical'; + $fields->{"extra.$_->{name}"} = $_->{value}; + } + return $fields; }; } diff --git a/t/cobrand/tfl.t b/t/cobrand/tfl.t index 0346ee2b7..4ae21cdaa 100644 --- a/t/cobrand/tfl.t +++ b/t/cobrand/tfl.t @@ -31,6 +31,11 @@ my $contact1 = $mech->create_contact_ok( email => 'busstops@example.com', ); $contact1->set_extra_metadata(group => [ 'Bus things' ]); +$contact1->set_extra_fields({ + code => 'leaning', + description => 'Is the pole leaning?', + datatype => 'string', +}); $contact1->update; my $contact2 = $mech->create_contact_ok( body_id => $body->id, @@ -179,16 +184,20 @@ subtest "reference number included in email" => sub { $mech->content_contains('FMS' . $report->id) or diag $mech->content; }; -subtest 'Dashboard extra columns' => sub { +subtest 'Dashboard CSV extra columns' => sub { + my $report = FixMyStreet::DB->resultset("Problem")->find({ title => 'Test Report 1'}); + $report->set_extra_fields({ name => 'leaning', value => 'Yes' }); + $report->update; + $mech->log_in_ok( $staffuser->email ); - $mech->get_ok('/dashboard?export=1'); + $mech->get_ok('/dashboard?export=1&category=Bus+stops'); $mech->content_contains('Category,Subcategory'); $mech->content_contains('Query,Borough'); - $mech->content_contains(',"Safety critical","Delivered to","Closure email at","Reassigned at","Reassigned by"'); + $mech->content_contains(',"Safety critical","Delivered to","Closure email at","Reassigned at","Reassigned by","Is the pole leaning?"'); $mech->content_contains('"Bus things","Bus stops"'); $mech->content_contains('"BR1 3UH",Bromley,'); - $mech->content_contains(',,,no'); - my $report = FixMyStreet::DB->resultset("Problem")->find({ title => 'Test Report 1'}); + $mech->content_contains(',,,no,busstops@example.com,,,,Yes'); + $report->set_extra_fields({ name => 'safety_critical', value => 'yes' }); $report->anonymous(1); $report->update; |