aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2016-10-04 11:46:29 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2016-10-04 11:58:06 +0100
commit505aa9bcba1fe2f419e95cfa5122fab83b6f6ae0 (patch)
tree9a2118ee5dc352d7a037626a101f1697c40d5210 /perllib/FixMyStreet
parentead4a7ebbd33ac3e6e2c6bf3cb0302189eae99d1 (diff)
parentd8fdbf5d353238d9e4c334f06de251987f7e60cf (diff)
Merge branch 'issues/forcouncils/36-mobile-inspector-improvements'
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r--perllib/FixMyStreet/App/Controller/Report.pm13
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm54
-rw-r--r--perllib/FixMyStreet/TestMech.pm10
3 files changed, 52 insertions, 25 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm
index d56521fde..db3b16dcd 100644
--- a/perllib/FixMyStreet/App/Controller/Report.pm
+++ b/perllib/FixMyStreet/App/Controller/Report.pm
@@ -311,8 +311,9 @@ sub inspect : Private {
my $problem = $c->stash->{problem};
$c->stash->{categories} = $c->forward('/admin/categories_for_point');
+ $c->stash->{report_meta} = { map { $_->{name} => $_ } @{ $c->stash->{problem}->get_extra_fields() } };
- if ( $c->get_param('save') || $c->get_param('save_inspected') ) {
+ if ( $c->get_param('save') ) {
$c->forward('/auth/check_csrf_token');
my $valid = 1;
@@ -320,7 +321,7 @@ sub inspect : Private {
my $reputation_change = 0;
if ($permissions->{report_inspect}) {
- foreach (qw/detailed_location detailed_information traffic_information/) {
+ foreach (qw/detailed_information traffic_information/) {
$problem->set_extra_metadata( $_ => $c->get_param($_) );
}
@@ -363,6 +364,14 @@ sub inspect : Private {
if ($permissions->{report_inspect} || $permissions->{report_edit_category}) {
$c->forward( '/admin/report_edit_category', [ $problem ] );
+
+ # The new category might require extra metadata (e.g. pothole size), so
+ # we need to update the problem with the new values.
+ my $param_prefix = lc $problem->category;
+ $param_prefix =~ s/[^a-z]//g;
+ $param_prefix = "category_" . $param_prefix . "_";
+ my @contacts = grep { $_->category eq $problem->category } @{$c->stash->{contacts}};
+ $c->forward('/report/new/set_report_extras', [ \@contacts, $param_prefix ]);
}
if ($valid) {
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index f26120829..7766e08a1 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -849,33 +849,11 @@ sub process_report : Private {
$report->bodies_missing($missing);
}
- my @extra;
- foreach my $contact (@contacts) {
- my $metas = $contact->get_metadata_for_input;
- foreach my $field ( @$metas ) {
- if ( lc( $field->{required} ) eq 'true' ) {
- unless ( $c->get_param($field->{code}) ) {
- $c->stash->{field_errors}->{ $field->{code} } = _('This information is required');
- }
- }
- push @extra, {
- name => $field->{code},
- description => $field->{description},
- value => $c->get_param($field->{code}) || '',
- };
- }
- }
+ $c->forward('set_report_extras', [ \@contacts ]);
if ( $c->stash->{non_public_categories}->{ $report->category } ) {
$report->non_public( 1 );
}
-
- $c->cobrand->process_open311_extras( $c, $contacts[0]->body_id, \@extra );
-
- if ( @extra ) {
- $c->stash->{report_meta} = { map { $_->{name} => $_ } @extra };
- $report->set_extra_fields( @extra );
- }
} elsif ( @{ $c->stash->{bodies_to_list} } ) {
# There was an area with categories, but we've not been given one. Bail.
@@ -927,6 +905,36 @@ sub contacts_to_bodies : Private {
}
}
+sub set_report_extras : Private {
+ my ($self, $c, $contacts, $param_prefix) = @_;
+
+ $param_prefix ||= "";
+ my @extra;
+ foreach my $contact (@$contacts) {
+ my $metas = $contact->get_metadata_for_input;
+ foreach my $field ( @$metas ) {
+ if ( lc( $field->{required} ) eq 'true' ) {
+ unless ( $c->get_param($param_prefix . $field->{code}) ) {
+ $c->stash->{field_errors}->{ $field->{code} } = _('This information is required');
+ }
+ }
+ push @extra, {
+ name => $field->{code},
+ description => $field->{description},
+ value => $c->get_param($param_prefix . $field->{code}) || '',
+ };
+ }
+ }
+
+ $c->cobrand->process_open311_extras( $c, @$contacts[0]->body_id, \@extra )
+ if ( scalar @$contacts );
+
+ if ( @extra ) {
+ $c->stash->{report_meta} = { map { $_->{name} => $_ } @extra };
+ $c->stash->{report}->set_extra_fields( @extra );
+ }
+}
+
=head2 check_for_errors
Examine the user and the report for errors. If found put them on stash and
diff --git a/perllib/FixMyStreet/TestMech.pm b/perllib/FixMyStreet/TestMech.pm
index 54c39ffb9..122a5d0c9 100644
--- a/perllib/FixMyStreet/TestMech.pm
+++ b/perllib/FixMyStreet/TestMech.pm
@@ -282,6 +282,16 @@ sub get_first_email {
return $email_as_string;
}
+=head2 contains_or_lacks
+
+Based upon boolean FLAG, checks that content contains or lacks TEXT.
+
+=cut
+
+sub contains_or_lacks {
+ my ($mech, $flag, $text) = @_;
+ $flag ? $mech->content_contains($text) : $mech->content_lacks($text);
+}
=head2 page_errors