Skip to content

Commit

Permalink
Fix issue with categories with regex characters.
Browse files Browse the repository at this point in the history
As the templates were using `grep`, they failed to match on a category
such as "Footpaths (right of way)". Changing the stash variables to be
hashes instead of lists makes checking for a key simpler. Fixes #1688.
  • Loading branch information
dracos committed Apr 13, 2017
1 parent cfe97d7 commit 112ab20
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 10 deletions.
5 changes: 3 additions & 2 deletions perllib/FixMyStreet/App/Controller/Admin.pm
Expand Up @@ -733,7 +733,7 @@ sub report_edit : Path('report_edit') : Args(1) {
}
}

$c->stash->{categories} = $c->forward('categories_for_point');
$c->forward('categories_for_point');

if ( $c->cobrand->moniker eq 'zurich' ) {
my $done = $c->cobrand->admin_report_edit();
Expand Down Expand Up @@ -909,7 +909,8 @@ sub categories_for_point : Private {
# Remove the "Pick a category" option
shift @{$c->stash->{category_options}} if @{$c->stash->{category_options}};

return $c->stash->{category_options};
$c->stash->{categories} = $c->stash->{category_options};
$c->stash->{categories_hash} = { map { $_ => 1 } @{$c->stash->{category_options}} };
}

sub templates : Path('templates') : Args(0) {
Expand Down
6 changes: 3 additions & 3 deletions perllib/FixMyStreet/App/Controller/Around.pm
Expand Up @@ -182,7 +182,7 @@ sub display_location : Private {
my ( $on_map_all, $on_map, $nearby, $distance ) =
FixMyStreet::Map::map_features( $c,
latitude => $latitude, longitude => $longitude,
interval => $interval, categories => $c->stash->{filter_category},
interval => $interval, categories => [ keys %{$c->stash->{filter_category}} ],
states => $c->stash->{filter_problem_states},
order => $c->stash->{sort_order},
);
Expand Down Expand Up @@ -264,8 +264,8 @@ sub check_and_stash_category : Private {
my %categories_mapped = map { $_ => 1 } @categories;

my $categories = [ $c->get_param_list('filter_category', 1) ];
my @valid_categories = grep { $_ && $categories_mapped{$_} } @$categories;
$c->stash->{filter_category} = \@valid_categories;
my %valid_categories = map { $_ => 1 } grep { $_ && $categories_mapped{$_} } @$categories;
$c->stash->{filter_category} = \%valid_categories;
}

=head2 /ajax
Expand Down
2 changes: 1 addition & 1 deletion perllib/FixMyStreet/App/Controller/My.pm
Expand Up @@ -111,7 +111,7 @@ sub get_problems : Private {
my $categories = [ $c->get_param_list('filter_category', 1) ];
if ( @$categories ) {
$params->{category} = $categories;
$c->stash->{filter_category} = $categories;
$c->stash->{filter_category} = { map { $_ => 1 } @$categories };
}

my $rows = 50;
Expand Down
2 changes: 1 addition & 1 deletion perllib/FixMyStreet/App/Controller/Report.pm
Expand Up @@ -306,7 +306,7 @@ sub inspect : Private {
my $problem = $c->stash->{problem};
my $permissions = $c->stash->{_permissions};

$c->stash->{categories} = $c->forward('/admin/categories_for_point');
$c->forward('/admin/categories_for_point');
$c->stash->{report_meta} = { map { $_->{name} => $_ } @{ $c->stash->{problem}->get_extra_fields() } };

my %category_body = map { $_->category => $_->body_id } map { $_->contacts->all } values %{$problem->bodies};
Expand Down
2 changes: 1 addition & 1 deletion perllib/FixMyStreet/App/Controller/Reports.pm
Expand Up @@ -137,7 +137,7 @@ sub ward : Path : Args(2) {
} )->all;
@categories = map { $_->category } @categories;
$c->stash->{filter_categories} = \@categories;
$c->stash->{filter_category} = [ $c->get_param_list('filter_category', 1) ];
$c->stash->{filter_category} = { map { $_ => 1 } $c->get_param_list('filter_category', 1) };

my $pins = $c->stash->{pins};

Expand Down
2 changes: 1 addition & 1 deletion templates/web/base/admin/report-category.html
@@ -1,5 +1,5 @@
<select class="form-control" name="category" id="category">
[% IF NOT problem.category OR NOT categories.grep(problem.category).size %]
[% IF NOT problem.category OR NOT categories_hash.${problem.category} %]
<optgroup label="[% loc('Existing category') %]">
<option selected value="[% problem.category | html %]">[% (problem.category OR '-') | html %]</option>
</optgroup>
Expand Down
2 changes: 1 addition & 1 deletion templates/web/base/reports/_list-filters.html
Expand Up @@ -19,7 +19,7 @@
[% IF filter_categories.size %]
<select class="form-control js-multiple" name="filter_category" id="filter_categories" multiple data-all="[% loc('Everything') %]">
[% FOR cat IN filter_categories %]
<option value="[% cat | html %]"[% ' selected' IF filter_category.grep(cat).size %]>
<option value="[% cat | html %]"[% ' selected' IF filter_category.$cat %]>
[% cat | html %]
</option>
[% END %]
Expand Down

0 comments on commit 112ab20

Please sign in to comment.