From a2859ad405025c8e929ff2c305b88af7cc9a7594 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Tue, 9 Oct 2018 18:33:27 +0100 Subject: [PATCH] Have body.url work in hashref lookup. body.url could still be in use by old-school /reports table index pages (though they were dropped in 2.1, so a cobrand would have to have overridden it since then) and the update to speed up body lists in #2248 broke it. This puts it back in minimal form. --- CHANGELOG.md | 1 + perllib/FixMyStreet/DB/Result/Body.pm | 11 +++++++++-- perllib/FixMyStreet/DB/Result/Problem.pm | 2 +- perllib/FixMyStreet/DB/ResultSet/Body.pm | 8 ++++++++ templates/web/base/admin/body.html | 2 +- 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b71e3081aa..ea022caed45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Bugfixes: - Add perl 5.26/5.28 support. - Fix subcategory issues when visiting /report/new directly #2276 + - Have body.url work in hashref lookup. #2284 - Internal things: - Move send-comments code to package for testing. diff --git a/perllib/FixMyStreet/DB/Result/Body.pm b/perllib/FixMyStreet/DB/Result/Body.pm index 74a38f225a4..d459d5f025b 100644 --- a/perllib/FixMyStreet/DB/Result/Body.pm +++ b/perllib/FixMyStreet/DB/Result/Body.pm @@ -138,10 +138,17 @@ use namespace::clean; with 'FixMyStreet::Roles::Translatable', 'FixMyStreet::Roles::Extra'; +sub _url { + my ( $obj, $cobrand, $args ) = @_; + my $uri = URI->new('/reports/' . $cobrand->short_name($obj)); + $uri->query_form($args) if $args; + return $uri; +} + sub url { my ( $self, $c, $args ) = @_; - # XXX $areas_info was used here for Norway parent - needs body parents, I guess - return $c->uri_for( '/reports/' . $c->cobrand->short_name( $self ), $args || {} ); + my $cobrand = $self->result_source->schema->cobrand; + return _url($self, $cobrand, $args); } __PACKAGE__->might_have( diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index 2192158d3a1..a222c78cde2 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -663,7 +663,7 @@ sub body { my @body_names = sort map { my $name = $_->name; if ($c and FixMyStreet->config('AREA_LINKS_FROM_PROBLEMS')) { - '' . $name . ''; + '' . $name . ''; } else { $name; } diff --git a/perllib/FixMyStreet/DB/ResultSet/Body.pm b/perllib/FixMyStreet/DB/ResultSet/Body.pm index 1855a45c1f6..4e9661d2edc 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Body.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Body.pm @@ -149,9 +149,17 @@ sub all_sorted { })->all; @bodies = sort { strcoll($a->{msgstr} || $a->{name}, $b->{msgstr} || $b->{name}) } @bodies; + my $cobrand = $rs->result_source->schema->cobrand; + foreach my $body (@bodies) { $body->{parent} = { id => $body->{parent}, name => $body->{parent_name} } if $body->{parent}; + # DEPRECATED: url(c, query_params) -> url + $body->{url} = sub { + my ($c, $args) = @_; + return FixMyStreet::DB::Result::Body::_url($body, $cobrand, $args); + }; + # DEPRECATED: get_column('area_count') -> area_count next unless defined $body->{area_count}; $body->{get_column} = sub { diff --git a/templates/web/base/admin/body.html b/templates/web/base/admin/body.html index 2d77f10cef1..37ab24496a3 100644 --- a/templates/web/base/admin/body.html +++ b/templates/web/base/admin/body.html @@ -28,7 +28,7 @@ [% END %] [% END %]
- [% loc('List all reported problems' ) %] | + [% loc('List all reported problems' ) %] | [% loc('Text only version') %]