diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-09-24 14:08:05 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-10-03 16:41:28 +0100 |
commit | c50a525da9c8ec5267c4ba9498e4334b87fe851b (patch) | |
tree | d0cb4fcadcd49618d1ab23bb23434c4189606c84 | |
parent | 4186ebbc258326d05915bef0ffb15cd364f6be67 (diff) |
Add two fields to dashboard CSV export.
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Dashboard.pm | 7 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/BathNES.pm | 8 | ||||
-rw-r--r-- | t/app/controller/dashboard.t | 4 | ||||
-rw-r--r-- | t/cobrand/bathnes.t | 62 |
4 files changed, 42 insertions, 39 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Dashboard.pm b/perllib/FixMyStreet/App/Controller/Dashboard.pm index aadd913ca..7dc09186b 100644 --- a/perllib/FixMyStreet/App/Controller/Dashboard.pm +++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm @@ -300,6 +300,8 @@ sub export_as_csv : Private { 'Easting', 'Northing', 'Report URL', + 'Site Used', + 'Reported As', ], columns => [ 'id', @@ -319,6 +321,8 @@ sub export_as_csv : Private { 'local_coords_x', 'local_coords_y', 'url', + 'site_used', + 'reported_as', ], filename => do { my %where = ( @@ -398,6 +402,9 @@ sub generate_csv : Private { $report->local_coords; $hashref->{url} = join '', $c->cobrand->base_url_for_report($report), $report->url; + $hashref->{site_used} = $report->service || $report->cobrand; + $hashref->{reported_as} = $report->get_extra_metadata('contributed_as') || ''; + if (my $fn = $c->stash->{csv}->{extra_data}) { my $extra = $fn->($report); $hashref = { %$hashref, %$extra }; diff --git a/perllib/FixMyStreet/Cobrand/BathNES.pm b/perllib/FixMyStreet/Cobrand/BathNES.pm index c02c9328c..d69853881 100644 --- a/perllib/FixMyStreet/Cobrand/BathNES.pm +++ b/perllib/FixMyStreet/Cobrand/BathNES.pm @@ -216,39 +216,31 @@ sub dashboard_export_add_columns { @{ $c->stash->{csv}->{headers} }, "User Email", "User Phone", - "Reported As", "Staff User", "Attribute Data", - "Site Used", ]; $c->stash->{csv}->{columns} = [ @{ $c->stash->{csv}->{columns} }, "user_email", "user_phone", - "reported_as", "staff_user", "attribute_data", - "site_used", ]; $c->stash->{csv}->{extra_data} = sub { my $report = shift; - my $reported_as = $report->get_extra_metadata('contributed_as') || ''; my $staff_user = ''; if ( my $contributed_by = $report->get_extra_metadata('contributed_by') ) { $staff_user = $c->model('DB::User')->find({ id => $contributed_by })->email; } - my $site_used = $report->service || $report->cobrand || ''; my $attribute_data = join "; ", map { $_->{name} . " = " . $_->{value} } @{ $report->get_extra_fields }; return { user_email => $report->user->email || '', user_phone => $report->user->phone || '', - reported_as => $reported_as, staff_user => $staff_user, attribute_data => $attribute_data, - site_used => $site_used, }; }; } diff --git a/t/app/controller/dashboard.t b/t/app/controller/dashboard.t index b53056968..598898e9f 100644 --- a/t/app/controller/dashboard.t +++ b/t/app/controller/dashboard.t @@ -154,7 +154,7 @@ FixMyStreet::override_config { } is scalar @rows, 19, '1 (header) + 18 (reports) = 19 lines'; - is scalar @{$rows[0]}, 18, '18 columns present'; + is scalar @{$rows[0]}, 20, '20 columns present'; is_deeply $rows[0], [ @@ -176,6 +176,8 @@ FixMyStreet::override_config { 'Easting', 'Northing', 'Report URL', + 'Site Used', + 'Reported As', ], 'Column headers look correct'; diff --git a/t/cobrand/bathnes.t b/t/cobrand/bathnes.t index e0ad07c16..0a16fc96e 100644 --- a/t/cobrand/bathnes.t +++ b/t/cobrand/bathnes.t @@ -72,7 +72,7 @@ subtest 'extra CSV columns are absent if permission not granted' => sub { } is scalar @rows, 5, '1 (header) + 4 (reports) = 5 lines'; - is scalar @{$rows[0]}, 18, '18 columns present'; + is scalar @{$rows[0]}, 20, '20 columns present'; is_deeply $rows[0], [ @@ -94,6 +94,8 @@ subtest 'extra CSV columns are absent if permission not granted' => sub { 'Easting', 'Northing', 'Report URL', + 'Site Used', + 'Reported As', ], 'Column headers look correct'; }; @@ -153,42 +155,42 @@ subtest 'extra CSV columns are present if permission granted' => sub { 'Easting', 'Northing', 'Report URL', + 'Site Used', + 'Reported As', 'User Email', 'User Phone', - 'Reported As', 'Staff User', 'Attribute Data', - 'Site Used', ], 'Column headers look correct'; - is $rows[1]->[18], 'normaluser@example.com', 'User email is correct'; - is $rows[1]->[19], '+447123456789', 'User phone number is correct'; - is $rows[1]->[20], '', 'Reported As is empty if not made on behalf of another user/body'; - is $rows[1]->[21], '', 'Staff User is empty if not made on behalf of another user'; - is $rows[1]->[22], 'width = 10cm; depth = 25cm', 'Attribute Data is correct'; - is $rows[1]->[23], 'iOS', 'Site Used shows whether report made via app'; - - is $rows[2]->[18], 'counciluser@example.com', 'User email is correct'; - is $rows[2]->[19], '', 'User phone number is correct'; - is $rows[2]->[20], 'body', 'Reported As is correct if made on behalf of body'; - is $rows[2]->[21], '', 'Staff User is empty if not made on behalf of another user'; - is $rows[2]->[22], '', 'Attribute Data is correct'; - is $rows[2]->[23], 'bathnes', 'Site Used shows correct cobrand'; - - is $rows[3]->[18], 'normaluser@example.com', 'User email is correct'; - is $rows[3]->[19], '+447123456789', 'User phone number is correct'; - is $rows[3]->[20], 'another_user', 'Reported As is set if reported on behalf of another user'; - is $rows[3]->[21], 'counciluser@example.com', 'Staff User is correct if made on behalf of another user'; - is $rows[3]->[22], '', 'Attribute Data is correct'; - is $rows[3]->[23], 'bathnes', 'Site Used shows correct cobrand'; - - is $rows[4]->[18], 'counciluser@example.com', 'User email is correct'; - is $rows[4]->[19], '', 'User phone number is correct'; - is $rows[4]->[20], 'anonymous_user', 'Reported As is set if reported on behalf of another user'; - is $rows[4]->[21], '', 'Staff User is empty if not made on behalf of another user'; - is $rows[4]->[22], '', 'Attribute Data is correct'; - is $rows[4]->[23], 'bathnes', 'Site Used shows correct cobrand'; + is $rows[1]->[18], 'iOS', 'Site Used shows whether report made via app'; + is $rows[1]->[19], '', 'Reported As is empty if not made on behalf of another user/body'; + is $rows[1]->[20], 'normaluser@example.com', 'User email is correct'; + is $rows[1]->[21], '+447123456789', 'User phone number is correct'; + is $rows[1]->[22], '', 'Staff User is empty if not made on behalf of another user'; + is $rows[1]->[23], 'width = 10cm; depth = 25cm', 'Attribute Data is correct'; + + is $rows[2]->[18], 'bathnes', 'Site Used shows correct cobrand'; + is $rows[2]->[19], 'body', 'Reported As is correct if made on behalf of body'; + is $rows[2]->[20], 'counciluser@example.com', 'User email is correct'; + is $rows[2]->[21], '', 'User phone number is correct'; + is $rows[2]->[22], '', 'Staff User is empty if not made on behalf of another user'; + is $rows[2]->[23], '', 'Attribute Data is correct'; + + is $rows[3]->[18], 'bathnes', 'Site Used shows correct cobrand'; + is $rows[3]->[19], 'another_user', 'Reported As is set if reported on behalf of another user'; + is $rows[3]->[20], 'normaluser@example.com', 'User email is correct'; + is $rows[3]->[21], '+447123456789', 'User phone number is correct'; + is $rows[3]->[22], 'counciluser@example.com', 'Staff User is correct if made on behalf of another user'; + is $rows[3]->[23], '', 'Attribute Data is correct'; + + is $rows[4]->[18], 'bathnes', 'Site Used shows correct cobrand'; + is $rows[4]->[19], 'anonymous_user', 'Reported As is set if reported on behalf of another user'; + is $rows[4]->[20], 'counciluser@example.com', 'User email is correct'; + is $rows[4]->[21], '', 'User phone number is correct'; + is $rows[4]->[22], '', 'Staff User is empty if not made on behalf of another user'; + is $rows[4]->[23], '', 'Attribute Data is correct'; }; |