Skip to content

Commit

Permalink
[TfL] Add extra data to all report on dashboard
Browse files Browse the repository at this point in the history
TfL would like to be able to see the extra data for a category
on the 'All report' on the dashboard as well as on the specifically
selected category.

https://mysocietysupport.freshdesk.com/a/tickets/2556
  • Loading branch information
MorayMySoc authored and dracos committed Oct 24, 2023
1 parent 65f72af commit ebfea82
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 9 additions & 1 deletion perllib/FixMyStreet/Cobrand/TfL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,23 @@ sub dashboard_export_problems_add_columns {
);
$csv->splice_csv_column('fixed', action_scheduled => 'Action scheduled');

my @contacts = $csv->body->contacts->search(undef, { order_by => [ 'category' ] } )->all;

if ($csv->category) {
my @contacts = $csv->body->contacts->search(undef, { order_by => [ 'category' ] } )->all;
my ($contact) = grep { $_->category eq $csv->category } @contacts;
if ($contact) {
foreach (@{$contact->get_metadata_for_storage}) {
next if $_->{code} eq 'safety_critical';
$csv->add_csv_columns( "extra.$_->{code}" => $_->{description} );
}
}
} else {
foreach my $contact (@contacts) {

Check warning on line 248 in perllib/FixMyStreet/Cobrand/TfL.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/TfL.pm#L247-L248

Added lines #L247 - L248 were not covered by tests
foreach (@{$contact->get_metadata_for_storage}) {
next if $_->{code} eq 'safety_critical';

Check warning on line 250 in perllib/FixMyStreet/Cobrand/TfL.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/TfL.pm#L250

Added line #L250 was not covered by tests
$csv->add_csv_columns( "extra.$_->{code}" => $_->{description} );
}
}
}

$csv->csv_extra_data(sub {
Expand Down
7 changes: 5 additions & 2 deletions t/cobrand/tfl.t
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ $contact1->set_extra_fields(
description => 'Stop number',
datatype => 'string',
automated => 'hidden_field',
}
},
);
$contact1->update;
my $contact2 = $mech->create_contact_ok(
Expand Down Expand Up @@ -483,11 +483,14 @@ subtest 'Dashboard CSV extra columns' => sub {
$mech->content_contains($dt . ',,,confirmed,51.4021');
$mech->content_contains(',,,yes,[email protected],,' . $dt . ',"Council User"');

$report->set_extra_fields({ name => 'Question', value => '12345' });
$report->set_extra_fields({ name => 'stop_code', value => '98756' }, { name => 'Question', value => '12345' });
$report->update;

$mech->get_ok('/dashboard?export=1');
$mech->content_contains(',12345,,no,[email protected],,', "Bike number added to csv");
$mech->content_contains('"Council User",,98756', "Stop code added to csv for all categories report");
$mech->get_ok('/dashboard?export=1&category=Bus+stops');
$mech->content_contains('"Council User",,98756', "Stop code added to csv for bus stop category report");
};

subtest 'Inspect form state choices' => sub {
Expand Down

0 comments on commit ebfea82

Please sign in to comment.