diff options
author | Struan Donald <struan@exo.org.uk> | 2011-06-30 16:56:12 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2011-06-30 16:56:12 +0100 |
commit | 0e6bb3e802c0614d64366bd19732b37a574dc12c (patch) | |
tree | 01b5d111754a0acef3f8a71da526ce1fbe59de55 /perllib/FixMyStreet/App | |
parent | b756440e4b5c0b356ee0d65d1647124317535c95 (diff) | |
parent | fb78afe61194ea9b6fbec9596d69627e315ab97f (diff) |
Merge branch 'master' of ssh://git.mysociety.org/data/git/public/fixmystreet into new_statuses
Conflicts:
perllib/FixMyStreet/App/Controller/Reports.pm
Diffstat (limited to 'perllib/FixMyStreet/App')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Around.pm | 23 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Auth.pm | 6 | ||||
-rwxr-xr-x | perllib/FixMyStreet/App/Controller/Questionnaire.pm | 23 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Reports.pm | 69 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Tokens.pm | 14 |
6 files changed, 86 insertions, 53 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index ec1fde4e4..4ca559fad 100644 --- a/perllib/FixMyStreet/App/Controller/Around.pm +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -196,6 +196,7 @@ sub display_location : Private { } @$on_map_all, @$around_map; } + $c->stash->{page} = 'around'; # So the map knows to make clickable pins, update on pan FixMyStreet::Map::display_map( $c, latitude => $latitude, @@ -234,31 +235,19 @@ the map. sub ajax : Path('/ajax') { my ( $self, $c ) = @_; - # Our current X/Y middle of visible map - my $x = ( $c->req->param('x') || 0 ) + 0; - my $y = ( $c->req->param('y') || 0 ) + 0; - - # Where we started as that's the (0,0) we have to work to - my $sx = ( $c->req->param('sx') || 0 ) + 0; - my $sy = ( $c->req->param('sy') || 0 ) + 0; - # how far back should we go? my $all_pins = $c->req->param('all_pins') ? 1 : undef; my $interval = $all_pins ? undef : $c->cobrand->on_map_default_max_pin_age; # extract the data from the map my ( $pins, $on_map, $around_map, $dist ) = - FixMyStreet::Map::map_pins( $c, $x, $y, $sx, $sy, $interval ); + FixMyStreet::Map::map_pins( $c, $interval ); # render templates to get the html - # my $on_map_list_html = $c->forward( - # "View::Web", "render", my $on_map_list_html = $c->view('Web') ->render( $c, 'around/on_map_list_items.html', { on_map => $on_map } ); - # my $around_map_list_html = $c->forward( - # "View::Web", "render", my $around_map_list_html = $c->view('Web')->render( $c, 'around/around_map_list_items.html', @@ -278,8 +267,12 @@ sub ajax : Path('/ajax') { $c->res->content_type('text/javascript; charset=utf-8'); $c->res->header( 'Cache_Control' => 'max-age=0' ); - # Set the body - note that the js needs the surrounding brackets. - $c->res->body("($body)"); + if ( $c->req->param('bbox') ) { + $c->res->body($body); + } else { + # The JS needs the surrounding brackets for Tilma + $c->res->body("($body)"); + } } __PACKAGE__->meta->make_immutable; diff --git a/perllib/FixMyStreet/App/Controller/Auth.pm b/perllib/FixMyStreet/App/Controller/Auth.pm index 8aed746ec..ebb3510d0 100644 --- a/perllib/FixMyStreet/App/Controller/Auth.pm +++ b/perllib/FixMyStreet/App/Controller/Auth.pm @@ -71,7 +71,11 @@ sub sign_in : Private { return 1; } - $c->stash->{sign_in_error} = 1; + $c->stash( + sign_in_error => 1, + email => $email, + remember_me => $remember_me, + ); return; } diff --git a/perllib/FixMyStreet/App/Controller/Questionnaire.pm b/perllib/FixMyStreet/App/Controller/Questionnaire.pm index a146b85ce..90674b294 100755 --- a/perllib/FixMyStreet/App/Controller/Questionnaire.pm +++ b/perllib/FixMyStreet/App/Controller/Questionnaire.pm @@ -19,24 +19,17 @@ Deals with report questionnaires. =cut -=head2 load_questionnaire +=head2 check_questionnaire -Loads the questionnaire from the database, and checks it still needs answering -and is in the right state. Also finds out if this user has answered the -"ever reported" question before. +Checks the questionnaire still needs answering and is in the right state. Also +finds out if this user has answered the "ever reported" question before. =cut -sub load_questionnaire : Private { +sub check_questionnaire : Private { my ( $self, $c ) = @_; - my $questionnaire = $c->model('DB::Questionnaire')->find( - { id => $c->stash->{id} }, - { prefetch => 'problem' } - ); - $c->detach('missing_problem') unless $questionnaire; - - $c->stash->{questionnaire} = $questionnaire; + my $questionnaire = $c->stash->{questionnaire}; my $problem_id = $questionnaire->problem_id; @@ -155,8 +148,8 @@ sub submit_creator_fixed : Private { sub submit_standard : Private { my ( $self, $c ) = @_; - $c->forward( '/tokens/load_questionnaire_id', [ $c->req->params->{token} ] ); - $c->forward( 'load_questionnaire' ); + $c->forward( '/tokens/load_questionnaire', [ $c->req->params->{token} ] ); + $c->forward( 'check_questionnaire' ); $c->forward( 'process_questionnaire' ); my $problem = $c->stash->{problem}; @@ -270,7 +263,7 @@ sub process_questionnaire : Private { # Sent here from email token action. Simply load and display questionnaire. sub index : Private { my ( $self, $c ) = @_; - $c->forward( 'load_questionnaire' ); + $c->forward( 'check_questionnaire' ); $c->forward( 'display' ); } diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 4488ce8cd..3a7d18a1c 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -71,10 +71,6 @@ phone partial -=head2 can be ignored - -all_pins: related to map display - not relevant to creation of a new report - =cut sub report_new : Path : Args(0) { diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index fc8c4cd0e..9cec0fdfe 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -93,10 +93,36 @@ sub ward : Path : Args(2) { $c->forward( 'load_and_group_problems' ); $c->forward( 'sort_problems' ); - $c->stash->{rss_url} = '/rss/reports/' - . $c->cobrand->short_name( $c->stash->{council}, $c->stash->{areas_info} ); + my $council_short = $c->cobrand->short_name( $c->stash->{council}, $c->stash->{areas_info} ); + $c->stash->{rss_url} = '/rss/reports/' . $council_short; $c->stash->{rss_url} .= '/' . $c->cobrand->short_name( $c->stash->{ward} ) if $c->stash->{ward}; + + $c->stash->{council_url} = '/reports/' . $council_short; + + my $pins = $c->stash->{pins}; + + # Even though front end doesn't yet have it, have it on this page, it's better! + FixMyStreet::Map::set_map_class( 'FMS' ); + FixMyStreet::Map::display_map( + $c, + latitude => @$pins ? $pins->[0]{latitude} : 0, + longitude => @$pins ? $pins->[0]{longitude} : 0, + area => $c->stash->{ward} ? $c->stash->{ward}->{id} : $c->stash->{council}->{id}, + pins => $pins, + any_zoom => 1, + ); + + # List of wards + unless ($c->stash->{ward}) { + my $children = mySociety::MaPit::call('area/children', $c->stash->{council}->{id} ); + foreach (values %$children) { + $_->{url} = $c->uri_for( $c->stash->{council_url} + . '/' . $c->cobrand->short_name( $_ ) + ); + } + $c->stash->{children} = $children; + } } sub rss_council : Regex('^rss/(reports|area)$') : Args(1) { @@ -258,41 +284,41 @@ sub load_parent : Private { sub load_and_group_problems : Private { my ( $self, $c ) = @_; + my $page = $c->req->params->{p} || 1; + my $where = { state => [ FixMyStreet::DB::Result::Problem->visible_states() ] }; - my @extra_cols = (); if ($c->stash->{ward}) { $where->{areas} = { 'like', '%' . $c->stash->{ward}->{id} . '%' }; # FIXME Check this is secure - push @extra_cols, 'title', 'detail'; } elsif ($c->stash->{council}) { $where->{areas} = { 'like', '%' . $c->stash->{council}->{id} . '%' }; - push @extra_cols, 'title', 'detail'; } my $problems = $c->cobrand->problems->search( $where, { columns => [ - 'id', 'council', 'state', 'areas', + 'id', 'council', 'state', 'areas', 'latitude', 'longitude', 'title', { duration => { extract => "epoch from current_timestamp-lastupdate" } }, { age => { extract => "epoch from current_timestamp-confirmed" } }, - @extra_cols, ], - order_by => { -desc => 'id' }, + order_by => { -desc => 'lastupdate' }, + rows => 100, } - ); + )->page( $page ); + $c->stash->{pager} = $problems->pager; $problems = $problems->cursor; # Raw DB cursor for speed - my ( %fixed, %open ); + my ( %fixed, %open, @pins ); my $re_councils = join('|', keys %{$c->stash->{areas_info}}); - my @cols = ( 'id', 'council', 'state', 'areas', 'duration', 'age', 'title', 'detail' ); + my @cols = ( 'id', 'council', 'state', 'areas', 'latitude', 'longitude', 'title', 'duration', 'age' ); while ( my @problem = $problems->next ) { my %problem = zip @cols, @problem; if ( !$problem{council} ) { # Problem was not sent to any council, add to possible councils $problem{councils} = 0; while ($problem{areas} =~ /,($re_councils)(?=,)/g) { - add_row( \%problem, $1, \%fixed, \%open ); + add_row( \%problem, $1, \%fixed, \%open, \@pins ); } } else { # Add to councils it was sent to @@ -301,13 +327,16 @@ sub load_and_group_problems : Private { $problem{councils} = scalar @council; foreach ( @council ) { next if $c->stash->{council} && $_ != $c->stash->{council}->{id}; - add_row( \%problem, $_, \%fixed, \%open ); + add_row( \%problem, $_, \%fixed, \%open, \@pins ); } } } - $c->stash->{fixed} = \%fixed; - $c->stash->{open} = \%open; + $c->stash( + fixed => \%fixed, + open => \%open, + pins => \@pins, + ); return 1; } @@ -348,7 +377,7 @@ sub redirect_area : Private { my $fourweeks = 4*7*24*60*60; sub add_row { - my ( $problem, $council, $fixed, $open ) = @_; + my ( $problem, $council, $fixed, $open, $pins ) = @_; my $duration_str = ( $problem->{duration} > 2 * $fourweeks ) ? 'old' : 'new'; my $type = ( $problem->{duration} > 2 * $fourweeks ) ? 'unknown' @@ -359,6 +388,14 @@ sub add_row { # Open problems are either unknown, older, or new push @{$open->{$council}{$type}}, $problem if exists FixMyStreet::DB::Result::Problem->open_states->{$problem->{state}}; + + push @$pins, { + latitude => $problem->{latitude}, + longitude => $problem->{longitude}, + colour => $problem->{state} eq 'fixed' ? 'green' : 'red', + id => $problem->{id}, + title => $problem->{title}, + }; } =head1 AUTHOR diff --git a/perllib/FixMyStreet/App/Controller/Tokens.pm b/perllib/FixMyStreet/App/Controller/Tokens.pm index c9c9f3ab7..1fef0f07e 100644 --- a/perllib/FixMyStreet/App/Controller/Tokens.pm +++ b/perllib/FixMyStreet/App/Controller/Tokens.pm @@ -154,7 +154,7 @@ sub confirm_update : Path('/C') { return 1; } -sub load_questionnaire_id : Private { +sub load_questionnaire : Private { my ( $self, $c, $token_code ) = @_; # Set up error handling @@ -164,11 +164,21 @@ sub load_questionnaire_id : Private { my $auth_token = $c->forward( 'load_auth_token', [ $token_code, 'questionnaire' ] ); $c->stash->{id} = $auth_token->data; $c->stash->{token} = $token_code; + + my $questionnaire = $c->model('DB::Questionnaire')->find( + { id => $c->stash->{id} }, + { prefetch => 'problem' } + ); + $c->detach('/questionnaire/missing_problem') unless $questionnaire; + $c->stash->{questionnaire} = $questionnaire; } sub questionnaire : Path('/Q') : Args(1) { my ( $self, $c, $token_code ) = @_; - $c->forward( 'load_questionnaire_id', [ $token_code ] ); + $c->forward( 'load_questionnaire', [ $token_code ] ); + + $c->authenticate( { email => $c->stash->{questionnaire}->problem->user->email }, 'no_password' ); + $c->set_session_cookie_expire(0); $c->forward( '/questionnaire/index'); } |