Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions app/assets/stylesheets/_climate.scss
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,25 @@ $climate-soil-year: #6b4423;
.weather-invitation-body {
display: flex;
flex-direction: column;
gap: 1rem;
gap: 1.5rem;
padding: 1.25rem 1.5rem;
}

.weather-invitation-history {
display: flex;
flex-direction: column;
gap: 1rem;
min-width: 0;
}

.weather-invitation-forecast {
background: rgba($green, 0.035);
border: $figure-line;
border-radius: $card-radius;
min-width: 0;
padding: 1.1rem;
}

.weather-invitation-intro {
align-items: flex-start;
display: flex;
Expand All @@ -279,7 +294,7 @@ $climate-soil-year: #6b4423;
.weather-invitation-cards {
display: grid;
gap: 0.75rem;
grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr));
}

.weather-invitation-card {
Expand Down Expand Up @@ -342,5 +357,29 @@ $climate-soil-year: #6b4423;
display: flex;
flex-wrap: wrap;
gap: 0.75rem 1.25rem;
margin-top: auto;
}

@include media-breakpoint-up(xl) {
.weather-invitation-body--combined {
display: grid;
grid-template-columns: minmax(0, 1.8fr) minmax(18rem, 1fr);

.weather-invitation-cards {
grid-template-columns: repeat(3, minmax(0, 1fr));
}

.weather-invitation-card {
flex-direction: column;
}

.weather-invitation-title {
font-size: 1rem;
}

.weather-invitation-note {
font-size: 0.85rem;
}
}
}
}
174 changes: 174 additions & 0 deletions app/assets/stylesheets/_weather_forecast.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
// The home page's outlook. Jobs use the smaller inline summaries below.
.weather-forecast {
background: $white;
border: 1px solid #dfe8d4;
border-radius: $card-radius;
color: $body-color;
padding: 1.1rem;

.weather-forecast-title {
background: none;
box-shadow: none;
color: $green;
font-size: 1.15rem;
font-weight: 600;
margin: 0 0 0.35rem;
padding: 0;
}

.weather-forecast-period,
.weather-forecast-label,
.weather-forecast-note,
.weather-forecast-credit {
color: $ink-muted;
font-size: 0.85rem;
}

.weather-forecast-figures {
display: flex;
flex-wrap: wrap;
gap: 0.75rem 2rem;
margin-bottom: 0.75rem;

span,
strong {
display: block;
}

strong {
font-size: 1.2rem;
}
}

.weather-forecast-outlook {
margin-bottom: 0.75rem;
}

.weather-forecast-hazards {
background: #fff3cd;
border-left: 3px solid #9b6700;
border-radius: 2px;
color: #624500;
display: flex;
flex-wrap: wrap;
gap: 0.4rem 1rem;
list-style: none;
padding: 0.65rem 0.75rem;
}

.weather-forecast-days {
list-style: none;
margin: 0 0 1rem;
padding: 0;
}

.weather-forecast-day {
align-items: baseline;
border-top: 1px solid #e5e9e0;
display: grid;
font-size: 0.85rem;
gap: 0.2rem 0.75rem;
grid-template-columns: minmax(0, 1fr) auto;
padding: 0.6rem 0;

time {
font-weight: 600;
}
}

.weather-forecast-condition {
grid-column: 1;
grid-row: 2;

i {
color: $green;
margin-right: 0.25rem;
}
}

.weather-forecast-rain {
grid-column: 2;
grid-row: 2;
}

.weather-forecast-temperature {
grid-column: 2;
grid-row: 1;
}

.weather-forecast-credit {
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
margin-bottom: 0;
}
}

.weather-invitation .weather-forecast--summary {
background: transparent;
border: 0;
padding: 0;

.weather-forecast-figures {
gap: 0.75rem;

> div {
background: $white;
border: 1px solid #dfe8d4;
border-radius: $card-radius;
flex: 1;
padding: 0.6rem 0.75rem;
}
}

.weather-forecast-note {
font-size: 0.8rem;
line-height: 1.5;
margin-bottom: 0.6rem;
}

.weather-forecast-credit {
font-size: 0.75rem;
}
}

.notepad .notepad-heading {
flex-wrap: wrap;

.notepad-weather {
align-items: baseline;
color: $ink-muted;
display: inline-flex;
flex-wrap: wrap;
font-size: 0.8rem;
gap: 0.3rem 0.75rem;
justify-content: flex-end;
margin-left: auto;
text-align: right;
}

.notepad-weather-condition {
i {
margin-right: 0.2rem;
}
}

.notepad-weather-caution {
color: inherit;
}

@include media-breakpoint-down(sm) {
.notepad-weather {
flex-basis: 100%;
}
}
}

.notepad-forecast-credit {
color: $ink-muted;
display: flex;
flex-wrap: wrap;
font-size: 0.75rem;
gap: 0.5rem;
margin: 0.75rem 1.1rem;
}
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
@import "figures";
@import "frost";
@import "climate";
@import "weather_forecast";
@import "crop_picker";
@import "garden_cards";
@import "gardens_page";
Expand Down
10 changes: 9 additions & 1 deletion app/controllers/jobs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,21 @@ def render_notepad(status)

def render_groups(status)
response.set_header('X-Jobs-Done-This-Week', @done_this_week.to_s)
render partial: 'jobs/notepad_groups', locals: { groups: @job_groups, in_garden: garden.present? }, status:
render partial: 'jobs/notepad_groups',
locals: { groups: @job_groups, in_garden: garden.present?, forecast: @weather_forecast }, status:
end

def load_notepad
notepad = JobsNotepad.new(@owner, garden:, pinned: pinned_ids)
@job_groups = notepad.groups
@done_this_week = notepad.done_this_week
return if garden || !current_member || !WeatherInvitation.enabled?(current_member)

@weather_forecast = if request.xhr?
WeatherForecast.cached_for(current_member)
else
WeatherForecast.for(current_member)
end
end

# The garden a notepad on a garden's page is for, if it is.
Expand Down
50 changes: 50 additions & 0 deletions app/helpers/weather_forecast_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# frozen_string_literal: true

module WeatherForecastHelper
ICONS = {
heat: 'temperature-high', frost: 'snowflake', heavy_rain: 'cloud-showers-heavy', strong_wind: 'wind',
freezing_rain: 'icicles', snow: 'snowflake', thunderstorm: 'cloud-bolt', hail: 'cloud-bolt'
}.freeze

def forecast_condition_icon(condition)
icon('fas', ICONS.fetch(condition), 'aria-hidden': true)
end

def forecast_temperature(range)
return t('weather_forecast.missing') unless range

t('weather_forecast.temperature_range', low: range.first.round, high: range.last.round)
end

def forecast_rainfall(value)
return t('weather_forecast.missing') if value.nil?

t('weather_forecast.rainfall_amount', amount: number_with_precision(value, precision: 1, strip_insignificant_zeros: true))
end

def forecast_outlook(forecast)
forecast.conditions.map { |condition| t("weather_forecast.conditions.#{condition}") }.to_sentence
end

def forecast_for_job_group(forecast, group)
return unless forecast&.available? && %i(today week weekend next_weekend).include?(group.key)

last_day = group.to || group.from
days = forecast.days.select { |day| day[:date].between?(group.from, last_day) }
# Do not present part of a weekend (or week) as the whole period's outlook.
return unless days.pluck(:date).uniq.size == (last_day - group.from).to_i + 1

WeatherForecast.new(forecast.place_name, days)
end

def forecast_header_condition(forecast)
priority = %i(hail thunderstorm freezing_rain snow heat heavy_rain strong_wind frost)
priority.find { |condition| forecast.hazards.include?(condition) }
end

def forecast_header_details(forecast)
cautions = forecast.hazards.map { |hazard| t("weather_forecast.hazards.#{hazard}") }.to_sentence
[t('weather_forecast.title', place: forecast.place_name), forecast_outlook(forecast), cautions,
t('weather_forecast.caution')].compact_blank.join('. ')
end
end
14 changes: 14 additions & 0 deletions app/models/domesticated_animal.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

# Temporary compatibility stub for legacy jobs. There is no animal table in
# the current schema. Use an existing table only for Active Record's metadata,
# never return its rows, and prohibit writes until the legacy links are migrated.
class DomesticatedAnimal < ApplicationRecord
self.table_name = 'jobs'

default_scope { none }

def readonly?
true
end
end
Loading