Skip to content

Commit

Permalink
Merge pull request #661 from weather-gov/eg-592-alert-desc-formatting
Browse files Browse the repository at this point in the history
Weather alert area description formatting
  • Loading branch information
eric-gade committed Jan 19, 2024
2 parents 7736401 + 87488cd commit 4c2ab34
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ final class TryParsingDescriptionTextTest extends Base
{
$rawDescription =
"* WHAT...Snow expected. Total snow accumulations of 5 to 10\ninches.\n\n";
$rawDescription .= "* WHERE...Eastern San Juan Mountains Above 10000 Feet.\n\n";
$rawDescription .= "* WHEN...From 11 PM this evening to 11 PM MST Thursday.\n\n";
$rawDescription .=
"* WHERE...Eastern San Juan Mountains Above 10000 Feet.\n\n";
$rawDescription .=
"* WHEN...From 11 PM this evening to 11 PM MST Thursday.\n\n";
$rawDescription .= "* IMPACTS...Travel could be very difficult. The hazardous
conditions may impact travel over Wolf Creek Pass.";
$parsedDescription = WeatherAlertTrait::tryParsingDescriptionText(
Expand All @@ -41,7 +43,8 @@ conditions may impact travel over Wolf Creek Pass.";
{
$rawDescription =
"* This is an alert with\n\nmultiple newlines, but it has nothing ";
$rawDescription .= "to do with the what WHERE WHEN\n format we are concerned with.";
$rawDescription .=
"to do with the what WHERE WHEN\n format we are concerned with.";
$parsedDescription = WeatherAlertTrait::tryParsingDescriptionText(
$rawDescription,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class WeatherAlertTraitTest extends Base

$this->expected = [
(object) [
"areaDesc" => "place 2",
"areaDesc" => ["place 2"],
"event" => "Tsunami Warning",
"geometry" => [],
"description" =>
Expand Down Expand Up @@ -53,7 +53,7 @@ final class WeatherAlertTraitTest extends Base
"usesParsedDescription" => true,
],
(object) [
"areaDesc" => "place 1",
"areaDesc" => ["place 1"],
"event" => "Wind advisory",
"description" =>
"There is a warning for:\n\nPlaces listed\n\nYou should prepare.",
Expand Down
6 changes: 6 additions & 0 deletions web/modules/weather_data/src/Service/WeatherAlertTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,13 @@ public function getAlertsForLatLon($lat, $lon)
$output->instruction = self::fixupNewlines(
$output->instruction ?? false,
);

$output->areaDesc = self::fixupNewlines($output->areaDesc ?? false);
if ($output->areaDesc) {
$output->areaDesc = array_map(function ($description) {
return trim($description);
}, explode(";", $output->areaDesc));
}

$output->onset = self::turnToDate(
$output->onset ?? false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
</p>
{% endif %}
<h3>Areas impacted</h3>
<p>
{{ alert.areaDesc | nl2br }}
</p>
<ul class="usa-list" style="columns:2;">
{% for areaName in alert.areaDesc %}
<li class="">{{ areaName }}</li>
{% endfor %}
</ul>
</div>
</div>
{% endfor %}
Expand Down

0 comments on commit 4c2ab34

Please sign in to comment.