diff options
author | Matthew Somerville <matthew@mysociety.org> | 2011-06-24 17:45:58 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2011-06-28 15:01:03 +0100 |
commit | 85a3050d6e5e0f7f0bd9d3c827533f5d84d0b396 (patch) | |
tree | 542f579cb076f7b70d30848afe92313450d964e4 | |
parent | 9c662a2c3ba48a75e114ba4cff9826438441a949 (diff) |
Sort problems, and have a map, maybe.
-rw-r--r-- | perllib/FixMyStreet/App/Controller/My.pm | 25 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 10 | ||||
-rw-r--r-- | perllib/Utils.pm | 23 | ||||
-rw-r--r-- | t/app/controller/auth.t | 3 | ||||
-rw-r--r-- | templates/web/default/my/my.html | 53 |
5 files changed, 92 insertions, 22 deletions
diff --git a/perllib/FixMyStreet/App/Controller/My.pm b/perllib/FixMyStreet/App/Controller/My.pm index 79d5c5681..8cb807e09 100644 --- a/perllib/FixMyStreet/App/Controller/My.pm +++ b/perllib/FixMyStreet/App/Controller/My.pm @@ -22,7 +22,32 @@ Catalyst Controller. sub my : Path : Args(0) { my ( $self, $c ) = @_; + $c->detach( '/auth/redirect' ) unless $c->user; + + my $pins = []; + my $problems = {}; + foreach my $problem ( $c->user->problems ) { + push @$pins, { + latitude => $problem->latitude, + longitude => $problem->longitude, + colour => $problem->state eq 'fixed' ? 'green' : 'red', + id => $problem->id, + title => $problem->title, + }; + push @{ $problems->{$problem->state} }, $problem; + } + + $c->stash->{problems} = $problems; + + FixMyStreet::Map::display_map( + $c, + latitude => $pins->[0]{latitude}, + longitude => $pins->[0]{longitude}, + pins => $pins, + any_zoom => 1, + ) + if @$pins; } __PACKAGE__->meta->make_immutable; diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index da23802c3..ff730958a 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -364,8 +364,7 @@ sub meta_line { return $meta; } -# TODO Some/much of this could be moved to the template -sub duration_string { +sub body { my ( $problem, $c ) = @_; my $body; if ($problem->external_body) { @@ -387,6 +386,13 @@ sub duration_string { } @councils ); } + return $body; +} + +# TODO Some/much of this could be moved to the template +sub duration_string { + my ( $problem, $c ) = @_; + my $body = $problem->body( $c ); return sprintf(_('Sent to %s %s later'), $body, Utils::prettify_duration($problem->whensent_local->epoch - $problem->confirmed_local->epoch, 'minute') ); diff --git a/perllib/Utils.pm b/perllib/Utils.pm index 44234607f..39c251876 100644 --- a/perllib/Utils.pm +++ b/perllib/Utils.pm @@ -210,20 +210,25 @@ sub cleanup_text { } sub prettify_epoch { - my ($s, $short) = @_; + my ( $s, $type ) = @_; + $type = 'short' if $type eq '1'; + my @s = localtime($s); - my $tt = strftime('%H:%M', @s); + my $tt = ''; + $tt = strftime('%H:%M', @s) unless $type eq 'date'; my @t = localtime(); if (strftime('%Y%m%d', @s) eq strftime('%Y%m%d', @t)) { - $tt = "$tt " . _('today'); - } elsif (strftime('%Y %U', @s) eq strftime('%Y %U', @t)) { - $tt = "$tt, " . decode_utf8(strftime('%A', @s)); - } elsif ($short) { - $tt = "$tt, " . decode_utf8(strftime('%e %b %Y', @s)); + return "$tt " . _('today'); + } + $tt .= ', ' unless $type eq 'date'; + if (strftime('%Y %U', @s) eq strftime('%Y %U', @t)) { + $tt .= decode_utf8(strftime('%A', @s)); + } elsif ($type eq 'short') { + $tt .= decode_utf8(strftime('%e %b %Y', @s)); } elsif (strftime('%Y', @s) eq strftime('%Y', @t)) { - $tt = "$tt, " . decode_utf8(strftime('%A %e %B %Y', @s)); + $tt .= decode_utf8(strftime('%A %e %B %Y', @s)); } else { - $tt = "$tt, " . decode_utf8(strftime('%a %e %B %Y', @s)); + $tt .= decode_utf8(strftime('%a %e %B %Y', @s)); } return $tt; } diff --git a/t/app/controller/auth.t b/t/app/controller/auth.t index 67dfa1869..1a16457f9 100644 --- a/t/app/controller/auth.t +++ b/t/app/controller/auth.t @@ -128,8 +128,7 @@ $mech->not_logged_in_ok; $mech->get_ok($link); is $mech->uri->path, '/faq', "redirected to the Help page"; - $mech->get_ok('/my'); - $mech->follow_link_ok( { url => '/auth/change_password' } ); + $mech->get_ok('/auth/change_password'); ok my $form = $mech->form_name('change_password'), "found change password form"; diff --git a/templates/web/default/my/my.html b/templates/web/default/my/my.html index 03b180a3a..4393316c5 100644 --- a/templates/web/default/my/my.html +++ b/templates/web/default/my/my.html @@ -1,18 +1,53 @@ -[% INCLUDE 'header.html', title => loc('My Reports') %] +[% + pre_map = '<h2>' _ loc('Your latest problem') _ '</h2>'; + PROCESS "maps/${map.type}.html" IF c.user.problems; + INCLUDE 'header.html', title = loc('Your Reports') +%] + +[% IF c.user.problems %] + [% map_html %] + </div> + <div id="side"> +[% ELSE %] + <div id="skipped-map"> +[% END %] <h1>[% loc('Your Reports') %]</h1> -[% FOREACH p = c.user.problems %] - [% "<ul>" IF loop.first %] - - <li><a href="[% c.uri_for( '/report', p.id ) %]">[% p.title | html %]</a> ([% loc(p.state) %])</li> +[% FOREACH p = problems.confirmed %] + [% IF loop.first %]<h2>[% loc('Open reports') %]</h2>[% END %] + [% INCLUDE problem %] +[% END %] - [% "</ul>" IF loop.last %] +[% FOREACH p = problems.fixed %] + [% IF loop.first %]<h2>[% loc('Fixed reports') %]</h2>[% END %] + [% INCLUDE problem %] [% END %] +[%# FOREACH p = problems.unconfirmed; + IF loop.first; + '<h2>' _ loc('Unconfirmed reports') _ '</h2>'; + END; + INCLUDE problem; +END %] + +</div> -[%# FIXME - put in blurb here %] +[% INCLUDE 'footer.html' %] -<a href="/auth/change_password">change password</a> +[% BLOCK problem %] + [% "<ul>" IF loop.first %] + + <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) ) %] + [% ELSE %] + [% tprintf( loc("Reported %s"), prettify_epoch( p.confirmed_local.epoch, 'date' ) ) %] + [% END %] + </em> + </li> + + [% "</ul>" IF loop.last %] +[% END %] -[% INCLUDE 'footer.html' %]
\ No newline at end of file |