diff options
author | Dave Arter <davea@mysociety.org> | 2016-11-16 11:36:48 +0000 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2016-12-13 16:14:56 +0000 |
commit | e6a01721c87b7e3463093e64e97e08ed96f54bce (patch) | |
tree | 0f088aa26f2fe406699d075f90bb91b8b2ae2abb | |
parent | ca578e7c4150fab167f1a4ab422e23d0b1f09789 (diff) |
If a problem has duplicates, display them on its detail page
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 12 | ||||
-rw-r--r-- | t/app/controller/report_inspect.t | 6 | ||||
-rw-r--r-- | t/app/model/problem.t | 11 | ||||
-rw-r--r-- | templates/web/base/report/_inspect.html | 52 |
4 files changed, 58 insertions, 23 deletions
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index bb21fcc11..b7573d994 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -181,6 +181,7 @@ use namespace::clean -except => [ 'meta' ]; use Utils; use FixMyStreet::Map::FMS; use LWP::Simple qw($ua); +use RABX; my $IM = eval { require Image::Magick; @@ -1044,4 +1045,15 @@ has duplicate_of => ( }, ); +has duplicates => ( + is => 'ro', + lazy => 1, + default => sub { + my $self = shift; + my $rabx_id = RABX::serialise( $self->id ); + my @duplicates = $self->result_source->schema->resultset('Problem')->search({ extra => { like => "\%duplicate_of,$rabx_id%" } })->all; + return \@duplicates; + }, +); + 1; diff --git a/t/app/controller/report_inspect.t b/t/app/controller/report_inspect.t index 9a62b1eb7..b4d6636b9 100644 --- a/t/app/controller/report_inspect.t +++ b/t/app/controller/report_inspect.t @@ -93,7 +93,7 @@ FixMyStreet::override_config { $mech->content_lacks('Invalid location'); }; - subtest "test duplicate report is shown" => sub { + subtest "test duplicate reports are shown" => sub { my ($report2) = $mech->create_problems_for_body(1, $oxon->id, 'The other report is a duplicate of this one', { category => $report->category, cobrand => 'fixmystreet', areas => ',2237,2420', whensent => \'current_timestamp', @@ -107,6 +107,10 @@ FixMyStreet::override_config { $mech->get_ok("/report/$report_id"); $mech->content_contains($report2->title); + my $report2_id = $report2->id; + $mech->get_ok("/report/$report2_id"); + $mech->content_contains($report->title); + $report->unset_extra_metadata('duplicate_of'); $report->state($old_state); $report->update; diff --git a/t/app/model/problem.t b/t/app/model/problem.t index bd7d0e55c..1130078c0 100644 --- a/t/app/model/problem.t +++ b/t/app/model/problem.t @@ -763,6 +763,17 @@ subtest 'check response templates' => sub { is $problem->response_templates, 2, 'Global and pothole templates returned'; }; +subtest 'check duplicate reports' => sub { + my ($problem1, $problem2) = $mech->create_problems_for_body(2, $body_ids{2651}, 'TITLE'); + $problem1->set_extra_metadata(duplicate_of => $problem2->id); + $problem1->state('duplicate'); + $problem1->update; + + is $problem1->duplicate_of->title, $problem2->title, 'problem1 returns correct problem from duplicate_of'; + is scalar @{ $problem2->duplicates }, 1, 'problem2 has correct number of duplicates'; + is $problem2->duplicates->[0]->title, $problem1->title, 'problem2 includes problem1 in duplicates'; +}; + END { $problem->comments->delete if $problem; $problem->delete if $problem; diff --git a/templates/web/base/report/_inspect.html b/templates/web/base/report/_inspect.html index d5df3d42e..3479058c3 100644 --- a/templates/web/base/report/_inspect.html +++ b/templates/web/base/report/_inspect.html @@ -64,28 +64,36 @@ [% END %] [% IF permissions.report_inspect %] - <p> - <label for="state">[% loc('State') %]</label> - [%# XXX this is duplicated from admin/report_edit.html, should be refactored %] - <select name="state" id="state" class="form-control"> - [% FOREACH group IN state_groups %] - <optgroup label="[% group.0 %]"> - [% FOREACH state IN group.1 %] - <option [% 'selected ' IF state == problem.state %] value="[% state %]">[% state_pretty.$state %]</option> - [% END %] - </optgroup> - [% END %] - </select> - </p> - <div id="js-duplicate-reports" class="[% "hidden" UNLESS problem.duplicate_of %]"> - <input type="hidden" name="duplicate_of" value="[% problem.duplicate_of.id %]"> - Which report is it a duplicate of? - <ul> - [% IF problem.duplicate_of %] - [% INCLUDE 'report/_item.html' no_fixed = 1 item_extra_class = 'item-list__item--with-pin item-list--reports__item--selected' problem = problem.duplicate_of %] - [% END %] - </ul> - </div> + <p> + <label for="state">[% loc('State') %]</label> + [%# XXX this is duplicated from admin/report_edit.html, should be refactored %] + <select name="state" id="state" class="form-control"> + [% FOREACH group IN state_groups %] + <optgroup label="[% group.0 %]"> + [% FOREACH state IN group.1 %] + <option [% 'selected ' IF state == problem.state %] value="[% state %]">[% state_pretty.$state %]</option> + [% END %] + </optgroup> + [% END %] + </select> + </p> + <div id="js-duplicate-reports" class="[% "hidden" UNLESS problem.duplicate_of %]"> + <input type="hidden" name="duplicate_of" value="[% problem.duplicate_of.id %]"> + [% loc('Which report is it a duplicate of?') %] + <ul> + [% IF problem.duplicate_of %] + [% INCLUDE 'report/_item.html' item_extra_class = 'item-list__item--with-pin item-list--reports__item--selected' problem = problem.duplicate_of %] + [% END %] + </ul> + </div> + [% IF problem.duplicates.size %] + <p><strong>[% loc('Duplicates') %]</strong></p> + <ul> + [% FOR duplicate IN problem.duplicates %] + [% INCLUDE 'report/_item.html' problem = duplicate %] + [% END %] + </ul> + [% END %] [% END %] </div> |