diff options
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Dashboard.pm | 21 | ||||
-rw-r--r-- | t/app/controller/dashboard.t | 39 | ||||
-rw-r--r-- | templates/web/base/dashboard/index.html | 9 |
4 files changed, 69 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index a5224b3fd..5289a2be6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ a public update #1873 - Report field pre-filling for inspectors configurable #1854 - Admins can now unban users #1881 + - Council dashboard has date range for report generation #1885 - UK: - Use SVG logo, inlined on front page. #1887 - Inline critical CSS on front page. diff --git a/perllib/FixMyStreet/App/Controller/Dashboard.pm b/perllib/FixMyStreet/App/Controller/Dashboard.pm index f961660c0..7f4a4bb27 100644 --- a/perllib/FixMyStreet/App/Controller/Dashboard.pm +++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm @@ -157,6 +157,27 @@ sub index : Path : Args(0) { %$prob_where, 'me.confirmed' => { '>=', $dtf->format_datetime( $now->clone->subtract( days => 30 ) ) }, }; + + if ( $c->get_param('start_date') or $c->get_param('end_date') ) { + my @parts; + if ($c->get_param('start_date')) { + my $date = $dtf->parse_datetime( $c->get_param('start_date') ); + push @parts, { '>=', $dtf->format_datetime( $date ) }; + $c->stash->{start_date} = $c->get_param('start_date'); + } + if ($c->get_param('end_date')) { + my $date = $dtf->parse_datetime( $c->get_param('end_date') ); + push @parts, { '<=', $dtf->format_datetime( $date ) }; + $c->stash->{end_date} = $c->get_param('end_date'); + } + + if (scalar @parts == 2) { + $params->{'me.confirmed'} = [ -and => $parts[0], $parts[1] ]; + } else { + $params->{'me.confirmed'} = $parts[0]; + } + } + my $problems_rs = $c->cobrand->problems->to_body($body)->search( $params ); my @problems = $problems_rs->all; diff --git a/t/app/controller/dashboard.t b/t/app/controller/dashboard.t index 14bd76c41..3a22d4280 100644 --- a/t/app/controller/dashboard.t +++ b/t/app/controller/dashboard.t @@ -634,6 +634,45 @@ FixMyStreet::override_config { is $rows[5]->[15], '610591', 'Correct Easting conversion'; is $rows[5]->[16], '126573', 'Correct Northing conversion'; }; + + delete_problems(); + subtest 'check date restriction' => sub { + make_problem({ state => 'confirmed', conf_dt => DateTime->now->subtract( 'days' => 1 ) }); + make_problem({ state => 'confirmed', conf_dt => DateTime->now->subtract( 'days' => 50 ) }); + make_problem({ state => 'confirmed', conf_dt => DateTime->now->subtract( 'days' => 31 ) }); + + $mech->get_ok('/dashboard?export=1'); + open my $data_handle, '<', \$mech->content; + my $csv = Text::CSV->new( { binary => 1 } ); + my @rows; + while ( my $row = $csv->getline( $data_handle ) ) { + push @rows, $row; + } + + is scalar @rows, 2, '1 (header) + 1 (reports) = 2 lines'; + + $mech->get_ok('/dashboard?export=1&start_date=' . DateTime->now->subtract('days' => 32)->ymd); + + open $data_handle, '<', \$mech->content; + $csv = Text::CSV->new( { binary => 1 } ); + @rows = (); + while ( my $row = $csv->getline( $data_handle ) ) { + push @rows, $row; + } + + is scalar @rows, 3, '1 (header) + 2 (reports) = 3 lines'; + + $mech->get_ok('/dashboard?export=1&start_date=' . DateTime->now->subtract('days' => 51)->ymd . '&end_date=' . DateTime->now->subtract('days' => 49)->ymd ); + + open $data_handle, '<', \$mech->content; + $csv = Text::CSV->new( { binary => 1 } ); + @rows = (); + while ( my $row = $csv->getline( $data_handle ) ) { + push @rows, $row; + } + + is scalar @rows, 2, '1 (header) + 1 (reports) = 2 lines'; + }; }; restore_time; diff --git a/templates/web/base/dashboard/index.html b/templates/web/base/dashboard/index.html index e47798573..b3cf68e0a 100644 --- a/templates/web/base/dashboard/index.html +++ b/templates/web/base/dashboard/index.html @@ -133,7 +133,6 @@ <h2>[% loc('Reports') %]</h2> - </select> <p>[% loc('Report state:') %] <select class="form-control" name="state"> <option value=''>[% loc('All') %]</option> [% FOR group IN filter_states %] @@ -143,6 +142,14 @@ [% END %] [% END %] </select> +</p> +<p> +<label for="start_date">[% loc('Start Date') %]</label><input name="start_date" type="date" value="[% start_date | html %]"> +</p> + +<p> +<label for="end_date">[% loc('End Date') %]</label><input name="end_date" type="date" value="[% end_date | html %]"> +</p> <input type="submit" class="btn" value="[% loc('Look up') %]"> <a class="export_as_csv" href="[% c.req.uri_with({ export => 1 }) %]">[% loc('Export as CSV') %]</a> |