diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-02-15 12:04:40 +0000 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-02-16 19:04:09 +0000 |
commit | ac70eec9d5b76b8b11b5b1f47add60013ea7144c (patch) | |
tree | d172a98320459c832abf7751c76582aa0dc5e5bb | |
parent | e8a6506641403d14ce3d6d9dcbe9ebd20398781a (diff) |
Link update made during questionnaire to it.
This means we don't show separate 'Still open' messages
when an update was also left at the same time.
-rwxr-xr-x | perllib/FixMyStreet/App/Controller/Questionnaire.pm | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report.pm | 12 | ||||
-rw-r--r-- | t/app/controller/report_updates.t | 25 | ||||
-rw-r--r-- | templates/web/base/report/update.html | 3 | ||||
-rw-r--r-- | templates/web/base/report/updates.html | 2 |
5 files changed, 36 insertions, 7 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Questionnaire.pm b/perllib/FixMyStreet/App/Controller/Questionnaire.pm index 1ff57e920..dd180dff8 100755 --- a/perllib/FixMyStreet/App/Controller/Questionnaire.pm +++ b/perllib/FixMyStreet/App/Controller/Questionnaire.pm @@ -206,6 +206,7 @@ sub submit_standard : Private { anonymous => $problem->anonymous, } ); + $update->set_extra_metadata( questionnaire_id => $q->id ); if ( my $fileid = $c->stash->{upload_fileid} ) { $update->photo( $fileid ); } diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index b1cc5885a..2861f368a 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -169,11 +169,19 @@ sub load_updates : Private { ); my @combined; + my %questionnaires_with_updates; while (my $update = $updates->next) { push @combined, [ $update->confirmed, $update ]; + if (my $qid = $update->get_extra_metadata('questionnaire_id')) { + $questionnaires_with_updates{$qid} = $update; + } } - while (my $update = $questionnaires->next) { - push @combined, [ $update->whenanswered, $update ]; + while (my $q = $questionnaires->next) { + if (my $update = $questionnaires_with_updates{$q->id}) { + $update->set_extra_metadata('open_from_questionnaire', 1); + next; + } + push @combined, [ $q->whenanswered, $q ]; } @combined = map { $_->[1] } sort { $a->[0] <=> $b->[0] } @combined; $c->stash->{updates} = \@combined; diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 0b6d4ae3e..84f52eaa5 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -146,14 +146,22 @@ subtest "unconfirmed updates not displayed" => sub { }; subtest "several updates shown in correct order" => sub { - for my $fields ( { + my @qs; + for my $fields ( { # One with an associated update below problem_id => $report_id, whensent => '2011-03-10 12:23:16', whenanswered => '2011-03-10 12:23:16', old_state => 'confirmed', new_state => 'confirmed', }, - { + { # One with no associated update + problem_id => $report_id, + whensent => '2011-03-11 12:23:16', + whenanswered => '2011-03-11 12:23:16', + old_state => 'confirmed', + new_state => 'confirmed', + }, + { # One for the fixed update problem_id => $report_id, whensent => '2011-03-15 08:12:36', whenanswered => '2011-03-15 08:12:36', @@ -164,6 +172,7 @@ subtest "several updates shown in correct order" => sub { my $q = FixMyStreet::App->model('DB::Questionnaire')->find_or_create( $fields ); + push @qs, $q; } for my $fields ( { @@ -200,6 +209,14 @@ subtest "several updates shown in correct order" => sub { my $comment = FixMyStreet::App->model('DB::Comment')->find_or_create( $fields ); + if ($fields->{text} eq 'Second update') { + $comment->set_extra_metadata(questionnaire_id => $qs[0]->id); + $comment->update; + } + if ($fields->{text} eq 'Third update') { + $comment->set_extra_metadata(questionnaire_id => $qs[2]->id); + $comment->update; + } } $mech->get_ok("/report/$report_id"); @@ -207,8 +224,8 @@ subtest "several updates shown in correct order" => sub { my $meta = $mech->extract_update_metas; is scalar @$meta, 5, 'number of updates'; is $meta->[0], 'Posted by Other User at 12:23, Thu 10 March 2011', 'first update'; - is $meta->[1], 'Posted by Main User at 12:23, Thu 10 March 2011', 'second update'; - is $meta->[2], 'Still open, via questionnaire, 12:23, Thu 10 March 2011', 'questionnaire'; + is $meta->[1], 'Posted by Main User at 12:23, Thu 10 March 2011 Still open, via questionnaire', 'second update'; + is $meta->[2], 'Still open, via questionnaire, 12:23, Fri 11 March 2011', 'questionnaire'; is $meta->[3], 'State changed to: Fixed', 'third update, part 1'; is $meta->[4], 'Posted anonymously at 08:12, Tue 15 March 2011', 'third update, part 2'; $report->questionnaires->delete; diff --git a/templates/web/base/report/update.html b/templates/web/base/report/update.html index 100deb1ea..bd66c7b13 100644 --- a/templates/web/base/report/update.html +++ b/templates/web/base/report/update.html @@ -60,6 +60,9 @@ [% mlog = update.latest_moderation_log_entry(); IF mlog %] <br />[% tprintf(loc('Moderated by %s at %s'), mlog.admin_user, prettify_dt(mlog.whenedited)) %] [% END %] + [% IF update.get_extra_metadata('open_from_questionnaire') %] + <br />[% loc('Still open, via questionnaire') %] + [% END %] </p> </div> [% END %] diff --git a/templates/web/base/report/updates.html b/templates/web/base/report/updates.html index e8a2d4bd3..1d37c1d99 100644 --- a/templates/web/base/report/updates.html +++ b/templates/web/base/report/updates.html @@ -13,7 +13,7 @@ [% IF update.whenanswered %] [%# A questionnaire update, currently saying report is still open %] - [% tprintf( loc( 'Still open, via questionnaire, %s' ), prettify_dt( update.whenanswered ) ) %] + [% loc('Still open, via questionnaire') %], [% prettify_dt( update.whenanswered ) %] [% RETURN %] [% END %] |