diff options
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Reports.pm | 49 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/View/Web.pm | 12 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 16 | ||||
-rw-r--r-- | perllib/Utils.pm | 5 | ||||
-rw-r--r-- | templates/web/default/around/around_map_list_items.html | 2 | ||||
-rw-r--r-- | templates/web/default/around/on_map_list_items.html | 2 | ||||
-rw-r--r-- | templates/web/default/contact/index.html | 8 | ||||
-rw-r--r-- | templates/web/default/index.html | 2 | ||||
-rw-r--r-- | templates/web/default/my/my.html | 6 | ||||
-rw-r--r-- | templates/web/default/report/updates.html | 8 | ||||
-rwxr-xr-x | templates/web/default/reports/_list-entry.html | 4 | ||||
-rw-r--r-- | templates/web/fixmystreet/contact/index.html | 8 | ||||
-rw-r--r-- | templates/web/fixmystreet/my/my.html | 2 | ||||
-rw-r--r-- | templates/web/fixmystreet/report/_item.html | 12 | ||||
-rw-r--r-- | templates/web/zurich/report/_item.html | 13 | ||||
-rw-r--r-- | templates/web/zurich/report/_main.html | 2 | ||||
-rw-r--r-- | templates/web/zurich/report/updates.html | 2 |
17 files changed, 62 insertions, 91 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index f4093ef21..85a6e7c4d 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -372,53 +372,32 @@ sub load_and_group_problems : Private { my $problems = $c->cobrand->problems->search( $where, { - columns => [ - 'id', 'bodies_str', 'state', 'areas', 'latitude', 'longitude', 'title', 'cobrand', - #{ duration => { extract => "epoch from current_timestamp-lastupdate" } }, - #{ age => { extract => "epoch from current_timestamp-confirmed" } }, - { created => { extract => 'epoch from created' } }, - { confirmed => { extract => 'epoch from confirmed' } }, - { whensent => { extract => 'epoch from whensent' } }, - { lastupdate => { extract => 'epoch from lastupdate' } }, - 'photo', 'extra', - ], order_by => { -desc => 'lastupdate' }, rows => $c->cobrand->reports_per_page, } )->page( $page ); $c->stash->{pager} = $problems->pager; - $problems = $problems->cursor; # Raw DB cursor for speed my ( %problems, @pins ); - my @cols = ( 'id', 'bodies_str', 'state', 'areas', 'latitude', 'longitude', 'title', 'cobrand', 'created', 'confirmed', 'whensent', 'lastupdate', 'photo', 'extra' ); - while ( my @problem = $problems->next ) { - my %problem = zip @cols, @problem; - $problem{is_fixed} = FixMyStreet::DB::Result::Problem->fixed_states()->{$problem{state}}; - if ($problem{extra} && $c->cobrand->moniker eq 'zurich') { # Inflate - utf8::encode($problem{extra}) if utf8::is_utf8($problem{extra}); - $problem{extra} = RABX::unserialise($problem{extra}); - } - $c->log->debug( $problem{'cobrand'} . ', cobrand is ' . $c->cobrand->moniker ); + while ( my $problem = $problems->next ) { + $c->log->debug( $problem->cobrand . ', cobrand is ' . $c->cobrand->moniker ); if ( !$c->stash->{body}->id ) { # An external_body entry - add_row( \%problem, 0, \%problems, \@pins ); + add_row( $problem, 0, \%problems, \@pins ); next; } - if ( !$problem{bodies_str} ) { + if ( !$problem->bodies_str ) { # Problem was not sent to any body, add to all possible areas XXX - $problem{bodies} = 0; - while ($problem{areas} =~ /,(\d+)(?=,)/g) { - add_row( \%problem, $1, \%problems, \@pins ); + while ($problem->areas =~ /,(\d+)(?=,)/g) { + add_row( $problem, $1, \%problems, \@pins ); } } else { # Add to bodies it was sent to # XXX Assumes body ID matches "council ID" - (my $bodies = $problem{bodies_str}) =~ s/\|.*$//; - my @bodies = split( /,/, $bodies ); - $problem{bodies} = scalar @bodies; - foreach ( @bodies ) { + my $bodies = $problem->bodies_str_ids; + foreach ( @$bodies ) { next if $_ != $c->stash->{body}->id; - add_row( \%problem, $_, \%problems, \@pins ); + add_row( $problem, $_, \%problems, \@pins ); } } } @@ -452,11 +431,11 @@ sub add_row { my ( $problem, $body, $problems, $pins ) = @_; push @{$problems->{$body}}, $problem; push @$pins, { - latitude => $problem->{latitude}, - longitude => $problem->{longitude}, - colour => 'yellow', # FixMyStreet::DB::Result::Problem->fixed_states()->{$problem->{state}} ? 'green' : 'red', - id => $problem->{id}, - title => $problem->{title}, + latitude => $problem->latitude, + longitude => $problem->longitude, + colour => 'yellow', # FixMyStreet::DB::Result::Problem->fixed_states()->{$problem->state} ? 'green' : 'red', + id => $problem->id, + title => $problem->title, }; } diff --git a/perllib/FixMyStreet/App/View/Web.pm b/perllib/FixMyStreet/App/View/Web.pm index 42878be37..febeaf3c1 100644 --- a/perllib/FixMyStreet/App/View/Web.pm +++ b/perllib/FixMyStreet/App/View/Web.pm @@ -18,7 +18,7 @@ __PACKAGE__->config( ENCODING => 'utf8', render_die => 1, expose_methods => [ - 'loc', 'nget', 'tprintf', 'display_crosssell_advert', 'prettify_epoch', + 'loc', 'nget', 'tprintf', 'display_crosssell_advert', 'prettify_dt', 'add_links', 'version', ], FILTERS => { @@ -92,20 +92,20 @@ sub display_crosssell_advert { return CrossSell::display_advert( $c, $email, $name, %data ); } -=head2 Utils::prettify_epoch +=head2 Utils::prettify_dt - [% pretty = prettify_epoch( $epoch, $short_bool ) %] + [% pretty = prettify_dt( $dt, $short_bool ) %] -Return a pretty version of the epoch. +Return a pretty version of the DateTime object. $short_bool = 1; # 16:02, 29 Mar 2011 $short_bool = 0; # 16:02, Tuesday 29 March 2011 =cut -sub prettify_epoch { +sub prettify_dt { my ( $self, $c, $epoch, $short_bool ) = @_; - return Utils::prettify_epoch( $epoch, $short_bool ); + return Utils::prettify_dt( $epoch, $short_bool ); } =head2 add_links diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index 38326bfc7..ea6a0f231 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -397,6 +397,14 @@ sub confirm { return 1; } +sub bodies_str_ids { + my $self = shift; + return unless $self->bodies_str; + (my $bodies = $self->bodies_str) =~ s/\|.*$//; + my @bodies = split( /,/, $bodies ); + return \@bodies; +} + =head2 bodies Returns an arrayref of bodies to which a report was sent. @@ -406,9 +414,8 @@ Returns an arrayref of bodies to which a report was sent. sub bodies($) { my $self = shift; return {} unless $self->bodies_str; - (my $bodies = $self->bodies_str) =~ s/\|.*$//; - my @bodies = split( /,/, $bodies ); - @bodies = FixMyStreet::App->model('DB::Body')->search({ id => \@bodies })->all; + my $bodies = $self->bodies_str_ids; + my @bodies = FixMyStreet::App->model('DB::Body')->search({ id => $bodies })->all; return { map { $_->id => $_ } @bodies }; } @@ -493,8 +500,7 @@ meta data about the report. sub meta_line { my ( $problem, $c ) = @_; - my $date_time = - Utils::prettify_epoch( $problem->confirmed_local->epoch ); + my $date_time = Utils::prettify_dt( $problem->confirmed_local ); my $meta = ''; # FIXME Should be in cobrand diff --git a/perllib/Utils.pm b/perllib/Utils.pm index fa90620a0..1dd732283 100644 --- a/perllib/Utils.pm +++ b/perllib/Utils.pm @@ -221,12 +221,11 @@ sub cleanup_text { return $input; } -sub prettify_epoch { - my ( $epoch, $type ) = @_; +sub prettify_dt { + my ( $dt, $type ) = @_; $type ||= ''; $type = 'short' if $type eq '1'; - my $dt = DateTime->from_epoch( epoch => $epoch, time_zone => 'local' ); $dt->set_time_zone( FixMyStreet->config('TIME_ZONE') ) if FixMyStreet->config('TIME_ZONE'); diff --git a/templates/web/default/around/around_map_list_items.html b/templates/web/default/around/around_map_list_items.html index f598a9ba9..655d8bd25 100644 --- a/templates/web/default/around/around_map_list_items.html +++ b/templates/web/default/around/around_map_list_items.html @@ -5,7 +5,7 @@ <li> <a href="[% c.uri_for('/report', p.problem.id ) %]">[% p.problem.title | html %]</a> - <small>[% prettify_epoch( p.problem.confirmed_local.epoch, 1 ) %], [% dist %]km</small> + <small>[% prettify_dt( p.problem.confirmed_local, 1 ) %], [% dist %]km</small> [% IF p.problem.is_fixed %] <small>[% loc('(fixed)') %]</small> [% ELSIF p.problem.is_closed %] diff --git a/templates/web/default/around/on_map_list_items.html b/templates/web/default/around/on_map_list_items.html index e0f8eea08..1022c88a0 100644 --- a/templates/web/default/around/on_map_list_items.html +++ b/templates/web/default/around/on_map_list_items.html @@ -2,7 +2,7 @@ [% FOREACH p IN on_map %] <li> <a href="[% c.uri_for('/report', p.id ) %]">[% p.title | html %]</a> - <small>[% prettify_epoch( p.confirmed_local.epoch, 1 ) %]</small> + <small>[% prettify_dt( p.confirmed_local, 1 ) %]</small> [% IF p.is_fixed %] <small>[% loc('(fixed)') %]</small> [% ELSIF p.is_closed %] diff --git a/templates/web/default/contact/index.html b/templates/web/default/contact/index.html index a644ed952..cb87362ba 100644 --- a/templates/web/default/contact/index.html +++ b/templates/web/default/contact/index.html @@ -18,9 +18,9 @@ <blockquote> <p> [% IF update.anonymous %] - [% tprintf( loc('Update below added anonymously at %s'), prettify_epoch( update.confirmed_local.epoch ) ) %] + [% tprintf( loc('Update below added anonymously at %s'), prettify_dt( update.confirmed_local ) ) %] [% ELSE %] - [% tprintf( loc('Update below added by %s at %s'), update.name, prettify_epoch( update.confirmed_local.epoch ) ) | html %] + [% tprintf( loc('Update below added by %s at %s'), update.name, prettify_dt( update.confirmed_local ) ) | html %] [% END %] </p> @@ -42,9 +42,9 @@ <p> [% IF problem.anonymous %] - [% tprintf( loc('Reported anonymously at %s'), prettify_epoch( problem.confirmed_local.epoch ) ) %] + [% tprintf( loc('Reported anonymously at %s'), prettify_dt( problem.confirmed_local ) ) %] [% ELSE %] - [% tprintf( loc('Reported by %s at %s'), problem.user.name, prettify_epoch( problem.confirmed_local.epoch ) ) | html %] + [% tprintf( loc('Reported by %s at %s'), problem.user.name, prettify_dt( problem.confirmed_local ) ) | html %] [% END %] </p> diff --git a/templates/web/default/index.html b/templates/web/default/index.html index 3698d6494..3cfc07591 100644 --- a/templates/web/default/index.html +++ b/templates/web/default/index.html @@ -49,7 +49,7 @@ [% FOREACH p IN probs %] <li> <a href="/report/[% p.id %]">[% p.title | html %]</a> - <small>[% prettify_epoch( p.confirmed_local.epoch, 1 ) %]</small> + <small>[% prettify_dt( p.confirmed_local, 1 ) %]</small> </li> [% END %] </ul> diff --git a/templates/web/default/my/my.html b/templates/web/default/my/my.html index 3d418cda7..cb9b0dd99 100644 --- a/templates/web/default/my/my.html +++ b/templates/web/default/my/my.html @@ -53,7 +53,7 @@ END %] <li>“[% u.text | html %]” – <a href="[% c.uri_for( '/report', u.problem_id ) %]#update_[% u.id %]">[% u.problem.title | html %]</a>. <em class="council_sent_info"> - [% tprintf( loc("Added %s"), prettify_epoch( u.confirmed_local.epoch, 'date' ) ) %] + [% tprintf( loc("Added %s"), prettify_dt( u.confirmed_local, 'date' ) ) %] </em> </li> [% "</ul>" IF loop.last %] @@ -69,9 +69,9 @@ END %] <li><a href="[% c.uri_for( '/report', p.id ) %]">[% p.title | html %]</a> <em class="council_sent_info"> – [% IF p.whensent %] - [% tprintf( loc("Reported %s, to %s"), prettify_epoch( p.confirmed_local.epoch, 'date' ), p.body(c) ) %] + [% tprintf( loc("Reported %s, to %s"), prettify_dt( p.confirmed_local, 'date' ), p.body(c) ) %] [% ELSE %] - [% tprintf( loc("Reported %s"), prettify_epoch( p.confirmed_local.epoch, 'date' ) ) %] + [% tprintf( loc("Reported %s"), prettify_dt( p.confirmed_local, 'date' ) ) %] [% END %] </em> </li> diff --git a/templates/web/default/report/updates.html b/templates/web/default/report/updates.html index cfe2b3ab8..a892e0e69 100644 --- a/templates/web/default/report/updates.html +++ b/templates/web/default/report/updates.html @@ -6,21 +6,21 @@ [% IF update.whenanswered %] [%# A questionnaire update, currently saying report is still open %] - [% tprintf( loc( 'Still open, via questionnaire, %s' ), prettify_epoch( update.whenanswered_local.epoch ) ) %] + [% tprintf( loc( 'Still open, via questionnaire, %s' ), prettify_dt( update.whenanswered_local ) ) %] [% RETURN %] [% END %] [% IF update.anonymous || update.name == '' %] - [% tprintf( loc( 'Posted anonymously at %s' ), prettify_epoch( update.confirmed_local.epoch ) ) -%] + [% tprintf( loc( 'Posted anonymously at %s' ), prettify_dt( update.confirmed_local ) ) -%] [%- ELSIF update.user.from_body; user_name = update.user.name | html; body = update.user.body; IF body == 'Bromley Council'; body = "$body <img src='/cobrands/bromley/favicon.png' alt=''>"; END %] - [% tprintf( loc( 'Posted by %s (<strong>%s</strong>) at %s' ), user_name, body, prettify_epoch( update.confirmed_local.epoch ) ) -%] + [% tprintf( loc( 'Posted by %s (<strong>%s</strong>) at %s' ), user_name, body, prettify_dt( update.confirmed_local ) ) -%] [%- ELSE %] - [% tprintf( loc( 'Posted by %s at %s' ), update.name, prettify_epoch( update.confirmed_local.epoch ) ) | html -%] + [% tprintf( loc( 'Posted by %s at %s' ), update.name, prettify_dt( update.confirmed_local ) ) | html -%] [%- END -%] [%- ", " _ loc( 'marked as fixed' ) IF update.mark_fixed %] [%- ", " _ loc( 'reopened' ) IF update.mark_open OR update.problem_state == 'confirmed' %] diff --git a/templates/web/default/reports/_list-entry.html b/templates/web/default/reports/_list-entry.html index fa7dcee7b..445a5315f 100755 --- a/templates/web/default/reports/_list-entry.html +++ b/templates/web/default/reports/_list-entry.html @@ -1,6 +1,6 @@ <li><a href="[% c.uri_for('/report/' _ problem.id) %]">[% problem.title | html %]</a> - [% IF problem.bodies > 1 %] <small>[% loc('(sent to both)') %]</small> [% END %] + [% IF problem.bodies_str_ids.size > 1 %] <small>[% loc('(sent to both)') %]</small> [% END %] [% IF c.cobrand.moniker != 'emptyhomes' %] - [% IF problem.bodies == 0 %] <small>[% loc('(not sent to council)') %]</small> [% END %] + [% IF problem.bodies_str_ids.size == 0 %] <small>[% loc('(not sent to council)') %]</small> [% END %] [% END %] </li> diff --git a/templates/web/fixmystreet/contact/index.html b/templates/web/fixmystreet/contact/index.html index 368fb0628..450b6e2ef 100644 --- a/templates/web/fixmystreet/contact/index.html +++ b/templates/web/fixmystreet/contact/index.html @@ -19,9 +19,9 @@ <blockquote> <p> [% IF update.anonymous %] - [% tprintf( loc('Update below added anonymously at %s'), prettify_epoch( update.confirmed_local.epoch ) ) %] + [% tprintf( loc('Update below added anonymously at %s'), prettify_dt( update.confirmed_local ) ) %] [% ELSE %] - [% tprintf( loc('Update below added by %s at %s'), update.name, prettify_epoch( update.confirmed_local.epoch ) ) | html %] + [% tprintf( loc('Update below added by %s at %s'), update.name, prettify_dt( update.confirmed_local ) ) | html %] [% END %] </p> @@ -43,9 +43,9 @@ <p> [% IF problem.anonymous %] - [% tprintf( loc('Reported anonymously at %s'), prettify_epoch( problem.confirmed_local.epoch ) ) %] + [% tprintf( loc('Reported anonymously at %s'), prettify_dt( problem.confirmed_local ) ) %] [% ELSE %] - [% tprintf( loc('Reported by %s at %s'), problem.user.name, prettify_epoch( problem.confirmed_local.epoch ) ) | html %] + [% tprintf( loc('Reported by %s at %s'), problem.user.name, prettify_dt( problem.confirmed_local ) ) | html %] [% END %] </p> diff --git a/templates/web/fixmystreet/my/my.html b/templates/web/fixmystreet/my/my.html index 258f147c6..3134c335f 100644 --- a/templates/web/fixmystreet/my/my.html +++ b/templates/web/fixmystreet/my/my.html @@ -57,7 +57,7 @@ END %] <li>“[% u.text | html %]” – <a href="[% c.uri_for( '/report', u.problem_id ) %]#update_[% u.id %]">[% u.problem.title | html %]</a>. <p><small class="council_sent_info"> - [% tprintf( loc("Added %s"), prettify_epoch( u.confirmed_local.epoch, 'date' ) ) %] + [% tprintf( loc("Added %s"), prettify_dt( u.confirmed_local, 'date' ) ) %] </small></p> </li> [% "</ul>" IF loop.last %] diff --git a/templates/web/fixmystreet/report/_item.html b/templates/web/fixmystreet/report/_item.html index 894090f98..d8ab9ccb5 100644 --- a/templates/web/fixmystreet/report/_item.html +++ b/templates/web/fixmystreet/report/_item.html @@ -4,17 +4,13 @@ <img class="img" height="60" width="90" src="/photo/[% problem.id %].fp.jpeg" alt=""> [% END %] <h4>[% problem.title | html %]</h4> - <small>[% IF problem.confirmed_local %] - [%- prettify_epoch( problem.confirmed_local.epoch, 1 ) %] - [%- ELSE %] - [%- prettify_epoch( problem.confirmed, 1 ) %] - [%- END %] + <small>[% prettify_dt( problem.confirmed_local, 1 ) %] [%- IF dist %], [% dist %]km[% END %] - [%- IF include_lastupdate AND problem.confirmed != problem.lastupdate AND problem.whensent != problem.lastupdate %], last updated [% prettify_epoch( problem.lastupdate, 1 ) %] + [%- IF include_lastupdate AND problem.confirmed != problem.lastupdate AND problem.whensent != problem.lastupdate %], last updated [% prettify_dt( problem.lastupdate_local, 1 ) %] [%- END %] [% IF include_lastupdate %] - [% IF problem.bodies > 1 %] [% loc('(sent to both)') %] - [% ELSIF problem.bodies == 0 %] [% loc('(not sent to council)') %] + [% IF problem.bodies_str_ids.size > 1 %] [% loc('(sent to both)') %] + [% ELSIF problem.bodies_str_ids.size == 0 %] [% loc('(not sent to council)') %] [% END %] [% END %] [% IF NOT no_fixed AND problem.is_fixed %] diff --git a/templates/web/zurich/report/_item.html b/templates/web/zurich/report/_item.html index 4286eae1b..9c2d20551 100644 --- a/templates/web/zurich/report/_item.html +++ b/templates/web/zurich/report/_item.html @@ -8,19 +8,10 @@ [% ELSE %] <h4><em>[% loc('Awaiting moderation') %]</em></h4> [% END %] - <small>[% IF problem.created_local %] - [%- prettify_epoch( problem.created_local.epoch, 1 ) %] - [%- ELSE %] - [%- prettify_epoch( problem.created, 1 ) %] - [%- END %] + <small>[% prettify_dt( problem.created_local, 1 ) %] [%- IF dist %], [% dist %]km[% END %] - [%- IF include_lastupdate AND problem.created != problem.lastupdate AND problem.whensent != problem.lastupdate %], last updated [% prettify_epoch( problem.lastupdate, 1 ) %] + [%- IF include_lastupdate AND problem.created != problem.lastupdate AND problem.whensent != problem.lastupdate %], last updated [% prettify_dt( problem.lastupdate_local, 1 ) %] [%- END %] - [% IF include_lastupdate %] - [% IF problem.bodies > 1 %] [% loc('(sent to both)') %] - [% ELSIF problem.bodies == 0 %] [% loc('(not sent to council)') %] - [% END %] - [% END %] [% IF NOT no_fixed AND problem.is_fixed %] [% loc('(fixed)') %] [% ELSIF NOT no_fixed AND problem.is_closed %] diff --git a/templates/web/zurich/report/_main.html b/templates/web/zurich/report/_main.html index 9a3e56b27..fb24c6d96 100644 --- a/templates/web/zurich/report/_main.html +++ b/templates/web/zurich/report/_main.html @@ -1,7 +1,7 @@ <div class="problem-header cf"> <h1>[% tprintf( loc('Reported in the %s category'), problem.category ) %]</h1> <p class="sub"> - [% prettify_epoch( problem.created_local.epoch ) %] + [% prettify_dt( problem.created_local ) %] [%- IF !problem.used_map %]<br>[% loc('there is no pin shown as the user did not use the map') %][% END %] </p> diff --git a/templates/web/zurich/report/updates.html b/templates/web/zurich/report/updates.html index 0f9afbf68..462817043 100644 --- a/templates/web/zurich/report/updates.html +++ b/templates/web/zurich/report/updates.html @@ -4,7 +4,7 @@ <li> <div class="update-wrap"> <div class="update-text"> - <p class="meta-2">[% prettify_epoch( problem.lastupdate_local.epoch ) %]</p> + <p class="meta-2">[% prettify_dt( problem.lastupdate_local ) %]</p> [% IF problem.state == 'fixed - council' %] [% add_links( problem.extra.public_response ) | html_para %] [% ELSIF problem.state == 'closed' AND problem.external_body %] |