diff options
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Waste.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Bromley.pm | 37 | ||||
-rw-r--r-- | perllib/Integrations/Echo.pm | 40 | ||||
-rw-r--r-- | t/app/controller/waste.t | 7 | ||||
-rw-r--r-- | templates/web/bromley/waste/services.html | 14 | ||||
-rw-r--r-- | web/cobrands/sass/_waste.scss | 4 |
6 files changed, 102 insertions, 4 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Waste.pm b/perllib/FixMyStreet/App/Controller/Waste.pm index 7556781cf..7587795c8 100644 --- a/perllib/FixMyStreet/App/Controller/Waste.pm +++ b/perllib/FixMyStreet/App/Controller/Waste.pm @@ -136,7 +136,7 @@ sub construct_bin_request_form { my $field_list = []; foreach (@{$c->stash->{service_data}}) { - next unless $_->{next}; + next unless $_->{next} && !$_->{request_open}; my $name = $_->{service_name}; my $containers = $_->{request_containers}; my $max = $_->{request_max}; @@ -217,7 +217,7 @@ sub construct_bin_report_form { my $field_list = []; foreach (@{$c->stash->{service_data}}) { - next unless $_->{last} && $_->{report_allowed}; + next unless $_->{last} && $_->{report_allowed} && !$_->{report_open}; my $id = $_->{service_id}; my $name = $_->{service_name}; push @$field_list, "service-$id" => { diff --git a/perllib/FixMyStreet/Cobrand/Bromley.pm b/perllib/FixMyStreet/Cobrand/Bromley.pm index 263549e71..8b6924f2d 100644 --- a/perllib/FixMyStreet/Cobrand/Bromley.pm +++ b/perllib/FixMyStreet/Cobrand/Bromley.pm @@ -522,6 +522,9 @@ sub bin_services_for_address { my $result = $echo->GetServiceUnitsForObject($property->{uprn}); return [] unless @$result; + my $events = $echo->GetEventsForObject($property->{id}); + my $open = $self->_parse_open_events($events); + my @out; foreach (@$result) { next unless $_->{ServiceTasks}; @@ -532,12 +535,15 @@ sub bin_services_for_address { next unless $schedules->{next} or $schedules->{last}; my $containers = $service_to_containers{$_->{ServiceId}}; + my ($open_request) = grep { $_ } map { $open->{request}->{$_} } @$containers; my $row = { id => $_->{Id}, service_id => $_->{ServiceId}, service_name => $service_name_override{$_->{ServiceId}} || $_->{ServiceName}, report_allowed => within_working_days($schedules->{last}{date}, 2), + report_open => $open->{missed}->{$_->{ServiceId}}, request_allowed => $request_allowed{$_->{ServiceId}}, + request_open => $open_request, request_containers => $containers, request_max => $quantity_max{$_->{ServiceId}}, service_task_id => $servicetask->{Id}, @@ -553,6 +559,37 @@ sub bin_services_for_address { return \@out; } +sub _parse_open_events { + my $self = shift; + my $events = shift; + my $open; + foreach (@$events) { + next if $_->{ResolvedDate} || $_->{ResolutionCodeId}; # Is this the right field? + my $event_type = $_->{EventTypeId}; + my $service_id = $_->{ServiceId}; + if ($event_type == 2104) { # Request + my $data = $_->{Data}{ExtensibleDatum}; + my $container; + DATA: foreach (@$data) { + if ($_->{ChildData}) { + foreach (@{$_->{ChildData}{ExtensibleDatum}}) { + if ($_->{DatatypeName} eq 'Container Type') { + $container = $_->{Value}; + last DATA; + } + } + } + } + my $report = $self->problems->search({ external_id => $_->{Guid} })->first; + $open->{request}->{$container} = $report ? { report => $report } : 1; + } elsif (2095 <= $event_type && $event_type <= 2103) { # Missed collection + my $report = $self->problems->search({ external_id => $_->{Guid} })->first; + $open->{missed}->{$service_id} = $report ? { report => $report } : 1; + } + } + return $open; +} + sub _parse_schedules { my $servicetask = shift; my $schedules = $servicetask->{ServiceTaskSchedules}{ServiceTaskSchedule}; diff --git a/perllib/Integrations/Echo.pm b/perllib/Integrations/Echo.pm index 7dc2e6948..205e1178f 100644 --- a/perllib/Integrations/Echo.pm +++ b/perllib/Integrations/Echo.pm @@ -291,6 +291,46 @@ sub GetServiceTaskInstances { return force_arrayref($res, 'ServiceTaskInstances'); } +sub GetEventsForObject { + my ($self, $id, $type) = @_; + my $from = DateTime->now->set_time_zone(FixMyStreet->local_time_zone)->subtract(months => 3); + return [ { + # Missed collection for service 542 + EventTypeId => 2100, + ServiceId => 542, + }, { + # Request for a new paper container + EventTypeId => 2104, + Data => { ExtensibleDatum => [ + { Value => 2, DatatypeName => 'Source' }, + { + ChildData => { ExtensibleDatum => [ + { Value => 1, DatatypeName => 'Action' }, + { Value => 12, DatatypeName => 'Container Type' }, + ] }, + }, + ] }, + ServiceId => 535, + } ] if $self->sample_data; + # uncoverable statement + my $res = $self->call('GetEventsForObject', + objectRef => ixhash( + Key => 'Id', + Type => 'PointAddress', + Value => { 'msArray:anyType' => $id }, + ), + query => ixhash( + $type ? (EventTypeRef => ixhash( + Key => 'Id', + Type => 'EventType', + Value => { 'msArray:anyType' => $type }, + )) : (), + From => dt_to_hash($from), + ), + ); + return force_arrayref($res, 'Event'); +} + sub ixhash { tie (my %data, 'Tie::IxHash', @_); return \%data; diff --git a/t/app/controller/waste.t b/t/app/controller/waste.t index fe1b369d9..aac898da9 100644 --- a/t/app/controller/waste.t +++ b/t/app/controller/waste.t @@ -59,6 +59,9 @@ FixMyStreet::override_config { $mech->content_contains('2 Example Street'); $mech->content_contains('Food Waste'); }; + subtest 'Thing already requested' => sub { + $mech->content_contains('A food waste collection has been reported as missed'); + }; subtest 'Report a missed bin' => sub { $mech->content_contains('service-101', 'Can report, last collection was 27th'); $mech->content_contains('service-537', 'Can report, last collection was 27th'); @@ -135,6 +138,10 @@ FixMyStreet::override_config { is $report->get_extra_field_value('Quantity'), 2; is $report->get_extra_field_value('Container_Type'), 1; }; + subtest 'Thing already requested' => sub { + $mech->get_ok('/waste/uprn/1000000002'); + $mech->content_contains('A new paper & cardboard container request has been made'); + }; subtest 'General enquiry, bad data' => sub { $mech->get_ok('/waste/uprn/1000000002/enquiry'); is $mech->uri->path, '/waste/uprn/1000000002'; diff --git a/templates/web/bromley/waste/services.html b/templates/web/bromley/waste/services.html index 3f9f47753..41684ad8b 100644 --- a/templates/web/bromley/waste/services.html +++ b/templates/web/bromley/waste/services.html @@ -1,4 +1,9 @@ -[% IF unit.report_allowed %] +[% IF unit.report_open %] + <span class="waste-service-descriptor"> + A [% unit.service_name FILTER lower %] collection has been reported as missed + [% IF unit.report_open.report %] – <a href="[% unit.report_open.report.url %]" class="waste-service-link">check status</a>[% END %] + </span> +[% ELSIF unit.report_allowed %] [% any_report_allowed = 1 %] <form method="post" action="[% c.uri_for_action('waste/report', [ uprn ]) %]"> <input type="hidden" name="token" value="[% csrf_token %]"> @@ -9,7 +14,12 @@ <span class="waste-service-descriptor">Please note that missed collections can only be reported within 2 working days of your scheduled collection day.</span> [% END %] <a href="[% c.uri_for_action('waste/enquiry', [ uprn ]) %]?template=problem&service_id=[% unit.service_id %]" class="waste-service-link waste-service-descriptor">Report a problem with a [% unit.service_name FILTER lower %] collection</a> -[% IF unit.request_allowed %] +[% IF unit.request_open %] + <span class="waste-service-descriptor"> + A new [% unit.service_name FILTER lower %] container request has been made + [% IF unit.request_open.report %] – <a href="[% unit.request_open.report.url %]" class="waste-service-link">check status</a>[% END %] + </span> +[% ELSIF unit.request_allowed %] [% any_request_allowed = 1 %] <form method="post" action="[% c.uri_for_action('waste/request', [ uprn ]) %]"> <input type="hidden" name="token" value="[% csrf_token %]"> diff --git a/web/cobrands/sass/_waste.scss b/web/cobrands/sass/_waste.scss index 9ea957131..798335578 100644 --- a/web/cobrands/sass/_waste.scss +++ b/web/cobrands/sass/_waste.scss @@ -97,6 +97,7 @@ body.waste { transition: all 200ms ease-out; z-index: inherit; position: relative; + max-width: 100%; .js &.hidden-js { display: block; opacity: 0; @@ -136,6 +137,9 @@ input[type="submit"].waste-service-link { &:focus { text-decoration: underline; } + &:visited { + color: $link-color; + } } .waste-service-name-link { |