aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2018-05-02 17:05:43 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2018-05-08 15:32:12 +0100
commit505953fc71a6142826e1e5743a0a3dc18e306748 (patch)
tree79bb4371dee529c70a98ef8160da3d412a161d0f
parentba16e095260993d814e6fb603a7d405d08a4ecb9 (diff)
Remove needless category mappings.
Both filter categories and new report category lists went through mappings to different data structures, which doesn't seem to be needed.
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm2
-rw-r--r--perllib/FixMyStreet/App/Controller/Around.pm5
-rw-r--r--perllib/FixMyStreet/App/Controller/My.pm1
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm13
-rw-r--r--perllib/FixMyStreet/App/Controller/Reports.pm1
-rw-r--r--perllib/FixMyStreet/Cobrand/Zurich.pm2
-rw-r--r--t/app/controller/admin/report_edit.t1
-rw-r--r--templates/web/base/admin/report-category.html2
-rw-r--r--templates/web/base/report/_inspect.html2
-rw-r--r--templates/web/base/report/new/category.html6
-rw-r--r--templates/web/base/reports/_list-filters.html4
-rw-r--r--templates/web/zurich/admin/report_edit.html2
-rw-r--r--templates/web/zurich/admin/stats/index.html2
13 files changed, 20 insertions, 23 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index a923a3407..535a8d08e 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -1088,7 +1088,7 @@ sub categories_for_point : Private {
# Remove the "Pick a category" option
shift @{$c->stash->{category_options}} if @{$c->stash->{category_options}};
- $c->stash->{categories_hash} = { map { $_->{name} => 1 } @{$c->stash->{category_options}} };
+ $c->stash->{categories_hash} = { map { $_->category => 1 } @{$c->stash->{category_options}} };
}
sub templates : Path('templates') : Args(0) {
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm
index bdf381294..184d61f4f 100644
--- a/perllib/FixMyStreet/App/Controller/Around.pm
+++ b/perllib/FixMyStreet/App/Controller/Around.pm
@@ -228,7 +228,7 @@ sub check_and_stash_category : Private {
my @bodies = $c->model('DB::Body')->active->for_areas(keys %$all_areas)->all;
my %bodies = map { $_->id => $_ } @bodies;
- my @contacts = $c->model('DB::Contact')->not_deleted->search(
+ my @categories = $c->model('DB::Contact')->not_deleted->search(
{
body_id => [ keys %bodies ],
},
@@ -238,9 +238,8 @@ sub check_and_stash_category : Private {
distinct => 1
}
)->all;
- my @categories = map { { name => $_->category, value => $_->category_display } } @contacts;
$c->stash->{filter_categories} = \@categories;
- my %categories_mapped = map { $_->{name} => 1 } @categories;
+ my %categories_mapped = map { $_->category => 1 } @categories;
my $categories = [ $c->get_param_list('filter_category', 1) ];
my %valid_categories = map { $_ => 1 } grep { $_ && $categories_mapped{$_} } @$categories;
diff --git a/perllib/FixMyStreet/App/Controller/My.pm b/perllib/FixMyStreet/App/Controller/My.pm
index 1693766ba..f6ba9a6ee 100644
--- a/perllib/FixMyStreet/App/Controller/My.pm
+++ b/perllib/FixMyStreet/App/Controller/My.pm
@@ -163,7 +163,6 @@ sub setup_page_data : Private {
distinct => 1,
order_by => [ 'category' ],
} )->all;
- @categories = map { { name => $_->category, value => $_->category_display } } @categories;
$c->stash->{filter_categories} = \@categories;
$c->stash->{page} = 'my';
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index 3a8362b5b..574ef0390 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -666,7 +666,7 @@ sub setup_categories_and_bodies : Private {
$bodies_to_list{ $contact->body_id } = $contact->body;
unless ( $seen{$contact->category} ) {
- push @category_options, { name => $contact->category, value => $contact->category_display, group => $contact->get_extra_metadata('group') || '' };
+ push @category_options, $contact;
my $metas = $contact->get_metadata_for_input;
$category_extras{$contact->category} = $metas if @$metas;
@@ -679,15 +679,15 @@ sub setup_categories_and_bodies : Private {
$non_public_categories{ $contact->category } = 1 if $contact->non_public;
}
- $seen{$contact->category} = $contact->category_display;
+ $seen{$contact->category} = $contact;
}
if (@category_options) {
# If there's an Other category present, put it at the bottom
@category_options = (
- { name => _('-- Pick a category --'), value => _('-- Pick a category --'), group => '' },
- grep { $_->{name} ne _('Other') } @category_options );
- push @category_options, { name => _('Other'), value => $seen{_('Other')}, group => _('Other') } if $seen{_('Other')};
+ { category => _('-- Pick a category --'), category_display => _('-- Pick a category --'), group => '' },
+ grep { $_->category ne _('Other') } @category_options );
+ push @category_options, $seen{_('Other')} if $seen{_('Other')};
}
$c->cobrand->call_hook(munge_category_list => \@category_options, \@contacts, \%category_extras);
@@ -711,7 +711,8 @@ sub setup_categories_and_bodies : Private {
if ( $c->cobrand->call_hook('enable_category_groups') ) {
my %category_groups = ();
for my $category (@category_options) {
- push @{$category_groups{$category->{group}}}, $category;
+ my $group = $category->{group} // $category->get_extra_metadata('group') // '';
+ push @{$category_groups{$group}}, $category;
}
my @category_groups = ();
diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm
index 3aa24c2db..3b9ceaebc 100644
--- a/perllib/FixMyStreet/App/Controller/Reports.pm
+++ b/perllib/FixMyStreet/App/Controller/Reports.pm
@@ -160,7 +160,6 @@ sub ward : Path : Args(2) {
distinct => 1,
order_by => [ 'category' ],
} )->all;
- @categories = map { { name => $_->category, value => $_->category_display } } @categories;
$c->stash->{filter_categories} = \@categories;
$c->stash->{filter_category} = { map { $_ => 1 } $c->get_param_list('filter_category', 1) };
diff --git a/perllib/FixMyStreet/Cobrand/Zurich.pm b/perllib/FixMyStreet/Cobrand/Zurich.pm
index 453300cd5..1acbdaf71 100644
--- a/perllib/FixMyStreet/Cobrand/Zurich.pm
+++ b/perllib/FixMyStreet/Cobrand/Zurich.pm
@@ -499,7 +499,7 @@ sub category_options {
my ($self, $c) = @_;
my @categories = $c->model('DB::Contact')->not_deleted->all;
$c->stash->{category_options} = [ map { {
- name => $_->category, value => $_->category,
+ category => $_->category, category_display => $_->category,
abbreviation => $_->get_extra_metadata('abbreviation'),
} } @categories ];
}
diff --git a/t/app/controller/admin/report_edit.t b/t/app/controller/admin/report_edit.t
index 34277ca74..0a4e702bb 100644
--- a/t/app/controller/admin/report_edit.t
+++ b/t/app/controller/admin/report_edit.t
@@ -558,7 +558,6 @@ subtest "Test setting a report from unconfirmed to something else doesn't cause
};
subtest "Test display of report extra data" => sub {
- $report->unset_extra_metadata;
$mech->get_ok("/admin/report_edit/$report_id");
$mech->content_contains('Extra data: No');
$report->set_extra_metadata('extra_field', 'this is extra data');
diff --git a/templates/web/base/admin/report-category.html b/templates/web/base/admin/report-category.html
index 2d9ffcdb1..0416d71c0 100644
--- a/templates/web/base/admin/report-category.html
+++ b/templates/web/base/admin/report-category.html
@@ -7,7 +7,7 @@
[% IF category_options.size %]
<optgroup label="[% loc('Available categories') %]">
[% FOREACH cat IN category_options %]
- <option value="[% cat.name | html %]"[% ' selected' IF problem.category == cat.name %]>[% cat.value | html %]</option>
+ <option value="[% cat.category | html %]"[% ' selected' IF problem.category == cat.category %]>[% cat.category_display | html %]</option>
[% END %]
</optgroup>
[% END %]
diff --git a/templates/web/base/report/_inspect.html b/templates/web/base/report/_inspect.html
index 8708b08de..a81510f22 100644
--- a/templates/web/base/report/_inspect.html
+++ b/templates/web/base/report/_inspect.html
@@ -67,7 +67,7 @@
</p>
[% FOREACH category IN category_options %]
- [% cat_name = category.name;
+ [% cat_name = category.category;
cat_prefix = cat_name | lower | replace('[^a-z]', '');
cat_prefix = "category_" _ cat_prefix _ "_" %]
<p data-category="[% cat_name | html %]"
diff --git a/templates/web/base/report/new/category.html b/templates/web/base/report/new/category.html
index 94d5479a6..96b14e75b 100644
--- a/templates/web/base/report/new/category.html
+++ b/templates/web/base/report/new/category.html
@@ -1,8 +1,8 @@
[% IF category_options.size OR category_groups.size ~%]
[%~ BLOCK category_option ~%]
- [% cat_op_lc = cat_op.name | lower =%]
- <option value='[% cat_op.name | html %]'[% ' selected' IF report.category == cat_op.name || category_lc == cat_op_lc || (category_options.size == 2 AND loop.last) ~%]
- >[% IF loop.first %][% cat_op.value %][% ELSE %][% cat_op.value | html %][% END %]</option>
+ [% cat_op_lc = cat_op.category | lower =%]
+ <option value='[% cat_op.category | html %]'[% ' selected' IF report.category == cat_op.category || category_lc == cat_op_lc || (category_options.size == 2 AND loop.last) ~%]
+ >[% IF loop.first %][% cat_op.category_display %][% ELSE %][% cat_op.category_display | html %][% END %]</option>
[%~ END ~%]
[% IF category;
diff --git a/templates/web/base/reports/_list-filters.html b/templates/web/base/reports/_list-filters.html
index ab8ac06f7..ba6becb80 100644
--- a/templates/web/base/reports/_list-filters.html
+++ b/templates/web/base/reports/_list-filters.html
@@ -38,8 +38,8 @@
[% 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.name | html %]"[% ' selected' IF filter_category.${cat.name} %]>
- [% cat.value | html %]
+ <option value="[% cat.category | html %]"[% ' selected' IF filter_category.${cat.category} %]>
+ [% cat.category_display | html %]
</option>
[% END %]
</select>
diff --git a/templates/web/zurich/admin/report_edit.html b/templates/web/zurich/admin/report_edit.html
index ad14b2d45..58cf9d2a4 100644
--- a/templates/web/zurich/admin/report_edit.html
+++ b/templates/web/zurich/admin/report_edit.html
@@ -171,7 +171,7 @@
<select class="form-control" name="category" id="category">
<option value="">--</option>
[% FOREACH cat IN category_options %]
- <option value="[% cat.name %]">[% cat.value ~%]
+ <option value="[% cat.category %]">[% cat.category_display ~%]
[% ' (' _ cat.abbreviation _ ')' IF cat.abbreviation %]</option>
[% END %]
</select>
diff --git a/templates/web/zurich/admin/stats/index.html b/templates/web/zurich/admin/stats/index.html
index 9f2906d0a..4e2c568a0 100644
--- a/templates/web/zurich/admin/stats/index.html
+++ b/templates/web/zurich/admin/stats/index.html
@@ -27,7 +27,7 @@
<select class="form-control" name="category" id="category">
<option value="">--</option>
[% FOREACH cat IN category_options %]
- <option value="[% cat.name %]"[% ' selected' IF cat.name == category %]>[% cat.value ~%]
+ <option value="[% cat.category %]"[% ' selected' IF cat.category == category %]>[% cat.category_display ~%]
[% ' (' _ cat.abbreviation _ ')' IF cat.abbreviation %]</option>
[% END %]
</select>