generated from dxw/rails-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from dxw/94-implement-air-quality-alerts-in-st…
…yled-forecasts-view Implement air quality alerts in styled forecasts view
- Loading branch information
Showing
21 changed files
with
626 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<%= tag.div class: "tab py-4 flex-1 #{@day} mx-2 px-1 text-center #{classes}", | ||
data: { | ||
date: @forecast.date.to_s, | ||
controller: "tab", | ||
"tab-active-class": "active", | ||
"tab-inactive-class": "inactive", | ||
"tab-target": "dayPrediction" | ||
} do | ||
%> | ||
<%= link_to update_styled_forecast_path(day: @day, format: :turbo_stream), | ||
data: { | ||
action: "click->tab#switch_tab" | ||
} do %> | ||
<div class="day" data-tab-target="day"> | ||
<%= @forecast.date == Date.today ? 'Today' : @forecast.date.strftime('%A') %> | ||
</div> | ||
<div class="date"> | ||
<%= @forecast.date.strftime("%d %B") %> | ||
</div> | ||
<div class="daqi-symbol flex justify-center items-center daqi-marker text-4xl py-2 h-14"> | ||
<div class="size-9 rounded-full <%= daqi_indicator_colour_class %>"></div> | ||
<% if @forecast.air_pollution.value > 3 %> | ||
<%= render partial: "shared/icons/exclamation_triangle", locals: {forecast: @forecast} %> | ||
<% end %> | ||
</div> | ||
<div class="daqi-label text-base"> | ||
<%= @forecast.air_pollution.label.capitalize %> | ||
</div> | ||
<div class="daqi-value font-normal" data-tab-target="daqiValue"> | ||
Index <%= @forecast.air_pollution.value %>/10 | ||
</div> | ||
<% end %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
class DayTabComponent < ViewComponent::Base | ||
def initialize(forecast:, day:) | ||
@forecast = forecast | ||
@day = day | ||
end | ||
|
||
TAG_COLOURS = { | ||
1 => "bg-lime-400", | ||
2 => "bg-green-400", | ||
3 => "bg-lime-600", | ||
4 => "bg-yellow-300", | ||
5 => "bg-amber-200", | ||
6 => "bg-yellow-500", | ||
7 => "bg-orange-500", | ||
8 => "bg-red-500", | ||
9 => "bg-red-800", | ||
10 => "bg-stone-700" | ||
} | ||
|
||
def daqi_indicator_colour_class | ||
TAG_COLOURS.fetch(@forecast.air_pollution.value) | ||
end | ||
|
||
def classes | ||
if @day == :today | ||
"active daqi-level-#{@forecast.air_pollution.value}-today" | ||
else | ||
"inactive after-today" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke=<%=forecast.air_pollution.value > 6 ? "white" : "black"%> class="size-8 -ml-[2.125rem]"> | ||
<path stroke-linecap="round" stroke-linejoin="round" d="M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126ZM12 15.75h.007v.008H12v-.008Z" /> | ||
</svg> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<%= turbo_frame_tag "alert_guidance" do %> | ||
<% if air_pollution_prediction.air_quality_alert %> | ||
<div class="alert-guidance bg-<%= air_pollution_prediction.air_quality_alert.daqi_label.parameterize %>-alert-guidance-panel m-5 p-10"> | ||
<p class="font-semibold mb-4"> | ||
<%= t("air_quality_alert.#{air_pollution_prediction.air_quality_alert.daqi_level}.guidance.title") %> | ||
</p> | ||
<div class="text-xs"> | ||
<%= t("air_quality_alert.#{air_pollution_prediction.air_quality_alert.daqi_level}.guidance.detail_html") %> | ||
</div> | ||
</div> | ||
<% end %> | ||
<% end %> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<%= turbo_stream.replace("day_predictions", partial: "predictions", locals: {forecast: @day_forecast}) %> | ||
<%= turbo_stream.replace("alert_guidance", partial: "alert_guidance", locals: {air_pollution_prediction: @day_forecast}) %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.