diff options
-rwxr-xr-x | perllib/FixMyStreet/App/Controller/FakeMapit.pm | 11 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report.pm | 32 | ||||
-rw-r--r-- | t/app/controller/report_inspect.t | 23 | ||||
-rw-r--r-- | templates/web/base/report/_inspect.html | 2 | ||||
-rw-r--r-- | templates/web/base/report/_main.html | 12 | ||||
-rw-r--r-- | templates/web/base/report/inspect.html | 3 | ||||
-rw-r--r-- | web/js/map-OpenLayers.js | 59 |
7 files changed, 90 insertions, 52 deletions
diff --git a/perllib/FixMyStreet/App/Controller/FakeMapit.pm b/perllib/FixMyStreet/App/Controller/FakeMapit.pm index a4adadd09..0ec13ebfa 100755 --- a/perllib/FixMyStreet/App/Controller/FakeMapit.pm +++ b/perllib/FixMyStreet/App/Controller/FakeMapit.pm @@ -2,6 +2,7 @@ package FixMyStreet::App::Controller::FakeMapit; use Moose; use namespace::autoclean; use JSON::MaybeXS; +use LWP::Simple; BEGIN { extends 'Catalyst::Controller'; } @@ -21,6 +22,16 @@ world is one area, with ID 161 and name "Everywhere". my $area = { "name" => "Everywhere", "type" => "ZZZ", "id" => 161 }; +# The user should have the web server proxying this, +# but for development we can also do it on the server. +sub proxy : Path('/mapit') { + my ($self, $c) = @_; + (my $path = $c->req->uri->path_query) =~ s{^/mapit/}{}; + my $url = FixMyStreet->config('MAPIT_URL') . $path; + my $kml = LWP::Simple::get($url); + $c->response->body($kml); +} + sub output : Private { my ( $self, $c, $data ) = @_; my $body = encode_json($data); diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index db3b16dcd..f69bdc8c0 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -78,6 +78,13 @@ sub _display : Private { $c->forward( 'load_problem_or_display_error', [ $id ] ); $c->forward( 'load_updates' ); $c->forward( 'format_problem_for_display' ); + + my $permissions = $c->stash->{_permissions} = $c->forward( 'check_has_permission_to', + [ qw/report_inspect report_edit_category report_edit_priority/ ] ); + if (any { $_ } values %$permissions) { + $c->stash->{template} = 'report/inspect.html'; + $c->forward('inspect'); + } } sub support : Path('support') : Args(0) { @@ -292,23 +299,15 @@ e.g. /report/1/inspect sub action_router : Path('') : Args(2) { my ( $self, $c, $id, $action ) = @_; - $c->go( 'inspect', [ $id ] ) if $action eq 'inspect'; $c->go( 'map', [ $id ] ) if $action eq 'map'; $c->detach( '/page_error_404_not_found', [] ); } sub inspect : Private { - my ( $self, $c, $id ) = @_; - - $c->forward('/auth/get_csrf_token'); - $c->forward( 'load_problem_or_display_error', [ $id ] ); - my $permissions = $c->forward( 'check_has_permission_to', - [ qw/report_inspect report_edit_category report_edit_priority/ ] ); - $c->forward( 'load_updates' ); - $c->forward( 'format_problem_for_display' ); - + my ( $self, $c ) = @_; my $problem = $c->stash->{problem}; + my $permissions = $c->stash->{_permissions}; $c->stash->{categories} = $c->forward('/admin/categories_for_point'); $c->stash->{report_meta} = { map { $_->{name} => $_ } @{ $c->stash->{problem}->get_extra_fields() } }; @@ -347,7 +346,7 @@ sub inspect : Private { $problem->get_photoset->delete_cached; } if ( $problem->state ne $old_state ) { - $c->forward( '/admin/log_edit', [ $id, 'problem', 'state_change' ] ); + $c->forward( '/admin/log_edit', [ $problem->id, 'problem', 'state_change' ] ); } } @@ -391,7 +390,7 @@ sub inspect : Private { anonymous => 0, } ); } - $c->res->redirect( $c->uri_for( '/report', $problem->id, 'inspect' ) ); + $c->res->redirect( $c->uri_for( '/report', $problem->id ) ); } } }; @@ -416,14 +415,9 @@ to the current Problem in $c->stash->{problem}. Shows the 403 page if not. sub check_has_permission_to : Private { my ( $self, $c, @permissions ) = @_; - + return {} unless $c->user_exists; my $bodies = $c->stash->{problem}->bodies_str_ids; - - my %permissions = map { $_ => $c->user->has_permission_to($_, $bodies) } @permissions - if $c->user_exists; - $c->detach('/page_error_403_access_denied', [ _("Sorry, you don't have permission to do that.") ] ) - unless $c->user_exists && any { $_ } values %permissions; - + my %permissions = map { $_ => $c->user->has_permission_to($_, $bodies) } @permissions; return \%permissions; }; diff --git a/t/app/controller/report_inspect.t b/t/app/controller/report_inspect.t index f6dcf5e70..f2047b8e5 100644 --- a/t/app/controller/report_inspect.t +++ b/t/app/controller/report_inspect.t @@ -31,18 +31,21 @@ FixMyStreet::override_config { }, sub { subtest "test inspect page" => sub { $mech->get_ok("/report/$report_id"); - $mech->content_lacks('Inspect'); - $mech->content_lacks('Manage'); + $mech->content_lacks('Save changes'); + $mech->content_lacks('Priority'); + $mech->content_lacks('Traffic management'); $user->user_body_permissions->create({ body => $oxon, permission_type => 'report_edit_priority' }); $mech->get_ok("/report/$report_id"); - $mech->content_contains('Manage'); - $mech->follow_link_ok({ text => 'Manage' }); + $mech->content_contains('Save changes'); + $mech->content_contains('Priority'); + $mech->content_lacks('Traffic management'); $user->user_body_permissions->create({ body => $oxon, permission_type => 'report_inspect' }); $mech->get_ok("/report/$report_id"); - $mech->content_contains('Inspect'); - $mech->follow_link_ok({ text => 'Inspect' }); + $mech->content_contains('Save changes'); + $mech->content_contains('Priority'); + $mech->content_contains('Traffic management'); }; subtest "test basic inspect submission" => sub { @@ -56,7 +59,7 @@ FixMyStreet::override_config { $report->unset_extra_metadata('inspected'); $report->update; my $reputation = $report->user->get_extra_metadata("reputation") || 0; - $mech->get_ok("/report/$report_id/inspect"); + $mech->get_ok("/report/$report_id"); $mech->submit_form_ok({ button => 'save', with_fields => { public_update => "This is a public update.", save_inspected => "1" } }); $report->discard_changes; is $report->comments->first->text, "This is a public update.", 'Update was created'; @@ -68,7 +71,7 @@ FixMyStreet::override_config { $report->unset_extra_metadata('inspected'); $report->update; $report->comments->delete_all; - $mech->get_ok("/report/$report_id/inspect"); + $mech->get_ok("/report/$report_id"); $mech->submit_form_ok({ button => 'save', with_fields => { public_update => undef, save_inspected => "1" } }); is_deeply $mech->page_errors, [ "Please provide a public update for this report." ], 'errors match'; $report->discard_changes; @@ -77,7 +80,7 @@ FixMyStreet::override_config { }; subtest "test location changes" => sub { - $mech->get_ok("/report/$report_id/inspect"); + $mech->get_ok("/report/$report_id"); $mech->submit_form_ok({ button => 'save', with_fields => { latitude => 55, longitude => -2 } }); $mech->content_contains('Invalid location'); $mech->submit_form_ok({ button => 'save', with_fields => { latitude => 51.754926, longitude => -1.256179 } }); @@ -92,7 +95,7 @@ FixMyStreet::override_config { subtest "test $test->{type} permission" => sub { $user->user_body_permissions->delete; $user->user_body_permissions->create({ body => $oxon, permission_type => $test->{type} }); - $mech->get_ok("/report/$report_id/inspect"); + $mech->get_ok("/report/$report_id"); $mech->contains_or_lacks($test->{priority}, 'Priority'); $mech->contains_or_lacks($test->{priority}, 'High'); $mech->contains_or_lacks($test->{category}, 'Category'); diff --git a/templates/web/base/report/_inspect.html b/templates/web/base/report/_inspect.html index 34a7ea96c..b85fec0bb 100644 --- a/templates/web/base/report/_inspect.html +++ b/templates/web/base/report/_inspect.html @@ -4,7 +4,7 @@ <div id="side-inspect"> [% INCLUDE 'errors.html' %] - <form id="report_inspect_form" method="post" action="[% c.uri_for( '/report', problem.id, 'inspect' ) %]"> + <form id="report_inspect_form" method="post" action="[% c.uri_for( '/report', problem.id ) %]"> <div class="inspect-section"> <p> diff --git a/templates/web/base/report/_main.html b/templates/web/base/report/_main.html index 0a4056da7..4de26535c 100644 --- a/templates/web/base/report/_main.html +++ b/templates/web/base/report/_main.html @@ -119,24 +119,12 @@ [% IF (permissions.moderate) OR - (!hide_inspect_button AND - permissions.keys.grep('report_inspect|report_edit_category|report_edit_priority').size) - OR (c.user.has_permission_to('planned_reports', problem.bodies_str_ids)) %] <div class="moderate-display segmented-control" role="menu"> [% IF permissions.moderate %] <a class="js-moderate btn" role="menuitem" aria-label="[% loc('Moderate this report') %]">[% loc('Moderate') %]</a> [% END %] - [% IF !hide_inspect_button AND permissions.keys.grep('report_inspect|report_edit_category|report_edit_priority').size %] - <a class="btn" href="/report/[% problem.id %]/inspect#side-inspect" role="menuitem"> - [%~ IF permissions.report_inspect ~%] - [%~ loc('Inspect') ~%] - [%~ ELSE ~%] - [%~ loc('Manage') ~%] - [%~ END ~%] - </a> - [% END %] [% IF c.user.has_permission_to('planned_reports', problem.bodies_str_ids) %] [%~ IF c.user.is_planned_report(problem) ~%] <label class="btn" for="shortlist-report" role="menuitem" aria-label="[% loc('Remove from shortlist') %]">[% loc('Shortlisted') %]</label> diff --git a/templates/web/base/report/inspect.html b/templates/web/base/report/inspect.html index f4a9e4c46..7f02374e2 100644 --- a/templates/web/base/report/inspect.html +++ b/templates/web/base/report/inspect.html @@ -2,6 +2,5 @@ SET bodyclass = 'mappage with-actions'; SET two_column_sidebar = 1; PROCESS 'report/_inspect.html'; - SET shown_form = 1 UNLESS problem.get_extra_metadata('inspected'); - INCLUDE 'report/display.html', hide_inspect_button = 1; + INCLUDE 'report/display.html' %] diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js index afe47b4e7..02a0d7727 100644 --- a/web/js/map-OpenLayers.js +++ b/web/js/map-OpenLayers.js @@ -333,8 +333,26 @@ var fixmystreet = fixmystreet || {}; function onload() { if ( fixmystreet.area.length ) { + var extent = new OpenLayers.Bounds(); + var lr = new OpenLayers.Geometry.LinearRing([ + new OpenLayers.Geometry.Point(20E6,20E6), + new OpenLayers.Geometry.Point(10E6,20E6), + new OpenLayers.Geometry.Point(0,20E6), + new OpenLayers.Geometry.Point(-10E6,20E6), + new OpenLayers.Geometry.Point(-20E6,20E6), + new OpenLayers.Geometry.Point(-20E6,0), + new OpenLayers.Geometry.Point(-20E6,-20E6), + new OpenLayers.Geometry.Point(-10E6,-20E6), + new OpenLayers.Geometry.Point(0,-20E6), + new OpenLayers.Geometry.Point(10E6,-20E6), + new OpenLayers.Geometry.Point(20E6,-20E6), + new OpenLayers.Geometry.Point(20E6,0) + ]); + var loaded = 0; + var new_geometry = new OpenLayers.Geometry.Polygon(lr); for (var i=0; i<fixmystreet.area.length; i++) { var area = new OpenLayers.Layer.Vector("KML", { + renderers: ['SVGBig', 'VML', 'Canvas'], strategies: [ new OpenLayers.Strategy.Fixed() ], protocol: new OpenLayers.Protocol.HTTP({ url: "/mapit/area/" + fixmystreet.area[i] + ".kml?simplify_tolerance=0.0001", @@ -342,14 +360,34 @@ var fixmystreet = fixmystreet || {}; }) }); fixmystreet.map.addLayer(area); - if ( fixmystreet.area.length == 1 ) { - area.events.register('loadend', null, function(a,b,c) { - if ( fixmystreet.area_format ) { - area.styleMap.styles['default'].defaultStyle = fixmystreet.area_format; - } - zoomToBounds( area.getDataExtent() ); - }); - } + area.events.register('loadend', area, function(a,b,c) { + loaded++; + var style = this.styleMap.styles['default']; + if ( fixmystreet.area_format ) { + style.defaultStyle = fixmystreet.area_format; + } else { + $.extend(style.defaultStyle, { fillColor: 'black', strokeColor: 'black' }); + } + var geometry = this.features[0].geometry; + if (geometry.CLASS_NAME == 'OpenLayers.Geometry.Collection') { + $.each(geometry.components, function(i, polygon) { + new_geometry.addComponents(polygon.components) + extent.extend(polygon.getBounds()); + }); + } else if (geometry.CLASS_NAME == 'OpenLayers.Geometry.Polygon') { + new_geometry.addComponents(geometry.components); + extent.extend(this.getDataExtent()); + } + if (loaded == fixmystreet.area.length) { + var f = this.features[0].clone(); + f.geometry = new_geometry; + this.removeAllFeatures(); + this.addFeatures([f]); + zoomToBounds(extent); + } else { + fixmystreet.map.removeLayer(this); + } + }); } } @@ -845,3 +883,8 @@ OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, { } }); +OpenLayers.Renderer.SVGBig = OpenLayers.Class(OpenLayers.Renderer.SVG, { + MAX_PIXEL: 15E7, + CLASS_NAME: "OpenLayers.Renderer.SVGBig" + +}); |