From bbd8c94897a49e37d6e2b517f611eddab52ab9b7 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Sat, 16 Sep 2023 06:26:14 +0000 Subject: [PATCH 01/14] Add table for weather --- ...20230916061712_add_weather_observations.rb | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 db/migrate/20230916061712_add_weather_observations.rb diff --git a/db/migrate/20230916061712_add_weather_observations.rb b/db/migrate/20230916061712_add_weather_observations.rb new file mode 100644 index 0000000000..4db34cb739 --- /dev/null +++ b/db/migrate/20230916061712_add_weather_observations.rb @@ -0,0 +1,21 @@ +class AddWeatherObservations < ActiveRecord::Migration[7.0] + def change + # See https://github.com/schemaorg/schemaorg/issues/362 + create_table :weather_observations do |t| + t.string :source + t.datetime :observation_at + t.integer :solar_uv_index + t.decimal :wind_speed_kmh + t.decimal :wind_gust_speed_kmh + t.string :wind_direction + t.decimal :air_temperature_centigrade + t.decimal :relative_humidity + t.decimal :precipitation_probability + t.decimal :dew_point_temperature_centigrade + t.decimal :pressure + t.string :visibility + t.string :weather_type + t.references :garden_id + end + end +end From 5ef4ca339a65b13da70c98115e1f906b3fcf7b4c Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Sat, 16 Sep 2023 07:49:38 +0000 Subject: [PATCH 02/14] Timestamps --- db/migrate/20230916061712_add_weather_observations.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/db/migrate/20230916061712_add_weather_observations.rb b/db/migrate/20230916061712_add_weather_observations.rb index 4db34cb739..b9665cf6f5 100644 --- a/db/migrate/20230916061712_add_weather_observations.rb +++ b/db/migrate/20230916061712_add_weather_observations.rb @@ -16,6 +16,7 @@ def change t.string :visibility t.string :weather_type t.references :garden_id + t.timestamps end end end From 8ee0881d0257261679da45c901d2925d61629e8c Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Sat, 16 Sep 2023 08:05:02 +0000 Subject: [PATCH 03/14] Rubocop --- db/migrate/20230916061712_add_weather_observations.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/db/migrate/20230916061712_add_weather_observations.rb b/db/migrate/20230916061712_add_weather_observations.rb index b9665cf6f5..b2280aba75 100644 --- a/db/migrate/20230916061712_add_weather_observations.rb +++ b/db/migrate/20230916061712_add_weather_observations.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddWeatherObservations < ActiveRecord::Migration[7.0] def change # See https://github.com/schemaorg/schemaorg/issues/362 From d0e3a8ff19929fe291104c63c142861e7d080981 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Sat, 16 Sep 2023 08:08:54 +0000 Subject: [PATCH 04/14] Add model --- app/models/garden.rb | 1 + app/models/weather_observation.rb | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 app/models/weather_observation.rb diff --git a/app/models/garden.rb b/app/models/garden.rb index b0be0f03c4..20c129df23 100644 --- a/app/models/garden.rb +++ b/app/models/garden.rb @@ -9,6 +9,7 @@ class Garden < ApplicationRecord has_many :plantings, dependent: :destroy has_many :crops, through: :plantings + has_many :weather_observations belongs_to :garden_type, optional: true diff --git a/app/models/weather_observation.rb b/app/models/weather_observation.rb new file mode 100644 index 0000000000..f1b3c501a5 --- /dev/null +++ b/app/models/weather_observation.rb @@ -0,0 +1,8 @@ +# A weather observation is intended to be a snapshot aligned to +# https://github.com/schemaorg/schemaorg/issues/362 +class WeatherObservation < ApplicationRecord + belongs_to :garden + + validates :source, presence: true + validates :observed_at, presence: true +end \ No newline at end of file From 7ed0d0d03692694e8c70d536c82883eca67ace1f Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Sat, 16 Sep 2023 08:16:58 +0000 Subject: [PATCH 05/14] Validations --- app/models/weather_observation.rb | 8 ++++++++ db/migrate/20230916061712_add_weather_observations.rb | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models/weather_observation.rb b/app/models/weather_observation.rb index f1b3c501a5..a91473a654 100644 --- a/app/models/weather_observation.rb +++ b/app/models/weather_observation.rb @@ -5,4 +5,12 @@ class WeatherObservation < ApplicationRecord validates :source, presence: true validates :observed_at, presence: true + + # Lowest temp on earth: -89.2°C (-128.6°F) + # Highest: 56.7°C + validates :dew_point_temperature_centigrade, min: -90, max: 60 + validates :air_temperature_centigrade, min: -90, max: 60 + validates :relative_humidity, min: 0, max: 100 + validates :wind_speed_kmh, min: 0, max: 450 # Highest 408 km/h + validates :wind_gust_speed_kmh, min: 0, max: 450 # Highest 408 km/h end \ No newline at end of file diff --git a/db/migrate/20230916061712_add_weather_observations.rb b/db/migrate/20230916061712_add_weather_observations.rb index b2280aba75..d70e94ec36 100644 --- a/db/migrate/20230916061712_add_weather_observations.rb +++ b/db/migrate/20230916061712_add_weather_observations.rb @@ -15,7 +15,7 @@ def change t.decimal :precipitation_probability t.decimal :dew_point_temperature_centigrade t.decimal :pressure - t.string :visibility + t.integer :visibility_distance_metres t.string :weather_type t.references :garden_id t.timestamps From 4596698f1b6ed097e07b4c38c39555e56331d703 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Sun, 7 Jan 2024 01:30:45 +0000 Subject: [PATCH 06/14] Fix warning --- app/models/garden.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/garden.rb b/app/models/garden.rb index 20c129df23..edfbcac439 100644 --- a/app/models/garden.rb +++ b/app/models/garden.rb @@ -9,7 +9,7 @@ class Garden < ApplicationRecord has_many :plantings, dependent: :destroy has_many :crops, through: :plantings - has_many :weather_observations + has_many :weather_observations, dependent: :destroy belongs_to :garden_type, optional: true From e9ec6f2ca9458845105d145c6a341a44117744cb Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Sun, 7 Jan 2024 01:31:28 +0000 Subject: [PATCH 07/14] Fix warning --- app/models/weather_observation.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/weather_observation.rb b/app/models/weather_observation.rb index a91473a654..6a3a032bdf 100644 --- a/app/models/weather_observation.rb +++ b/app/models/weather_observation.rb @@ -13,4 +13,4 @@ class WeatherObservation < ApplicationRecord validates :relative_humidity, min: 0, max: 100 validates :wind_speed_kmh, min: 0, max: 450 # Highest 408 km/h validates :wind_gust_speed_kmh, min: 0, max: 450 # Highest 408 km/h -end \ No newline at end of file +end From dee600053765b5715dab38249046df648158da86 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Sun, 7 Jan 2024 01:31:52 +0000 Subject: [PATCH 08/14] Fix warning --- app/models/weather_observation.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/weather_observation.rb b/app/models/weather_observation.rb index 6a3a032bdf..4b34cd11bd 100644 --- a/app/models/weather_observation.rb +++ b/app/models/weather_observation.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # A weather observation is intended to be a snapshot aligned to # https://github.com/schemaorg/schemaorg/issues/362 class WeatherObservation < ApplicationRecord From 775986d1dd6524b1f1108da90837ace6398ab27c Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Sun, 7 Jan 2024 01:33:22 +0000 Subject: [PATCH 09/14] Fix validators --- app/models/weather_observation.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/weather_observation.rb b/app/models/weather_observation.rb index 4b34cd11bd..d72d507b6b 100644 --- a/app/models/weather_observation.rb +++ b/app/models/weather_observation.rb @@ -10,9 +10,9 @@ class WeatherObservation < ApplicationRecord # Lowest temp on earth: -89.2°C (-128.6°F) # Highest: 56.7°C - validates :dew_point_temperature_centigrade, min: -90, max: 60 - validates :air_temperature_centigrade, min: -90, max: 60 - validates :relative_humidity, min: 0, max: 100 - validates :wind_speed_kmh, min: 0, max: 450 # Highest 408 km/h + validates :dew_point_temperature_centigrade, numericality: { min: -90, max: 60 } + validates :air_temperature_centigrade, numericality: { min: -90, max: 60 } + validates :relative_humidity, numericality: { min: 0, max: 100 } + validates :wind_speed_kmh, numericality: { min: 0, max: 450 } # Highest 408 km/h validates :wind_gust_speed_kmh, min: 0, max: 450 # Highest 408 km/h end From a081a8d2f541d1a1e36aaccc3de3d2af77faf84b Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Sun, 7 Jan 2024 01:39:58 +0000 Subject: [PATCH 10/14] Fix warnings --- app/models/weather_observation.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/models/weather_observation.rb b/app/models/weather_observation.rb index d72d507b6b..60375ff5b4 100644 --- a/app/models/weather_observation.rb +++ b/app/models/weather_observation.rb @@ -8,11 +8,15 @@ class WeatherObservation < ApplicationRecord validates :source, presence: true validates :observed_at, presence: true + attr_accessible :source, :observation_at, :solvar_uv_index, :dew_point_temperature_centigrade, + :air_temperature_centigrade, :relative_humidity, :wind_speed_kmh, :wind_gust_speed_kmh, :garden_id, :wind_direction, :precipitation_probability, :pressure, + :visibility_distance_metres, :weather_type + # Lowest temp on earth: -89.2°C (-128.6°F) # Highest: 56.7°C - validates :dew_point_temperature_centigrade, numericality: { min: -90, max: 60 } - validates :air_temperature_centigrade, numericality: { min: -90, max: 60 } - validates :relative_humidity, numericality: { min: 0, max: 100 } - validates :wind_speed_kmh, numericality: { min: 0, max: 450 } # Highest 408 km/h - validates :wind_gust_speed_kmh, min: 0, max: 450 # Highest 408 km/h + validates :dew_point_temperature_centigrade, numericality: { min: -90, max: 60 }, allow_nil: true + validates :air_temperature_centigrade, numericality: { min: -90, max: 60 }, allow_nil: true + validates :relative_humidity, numericality: { min: 0, max: 100 }, allow_nil: true + validates :wind_speed_kmh, numericality: { min: 0, max: 450 }, allow_nil: true # Highest 408 km/h + validates :wind_gust_speed_kmh, min: 0, max: 450, allow_nil: true # Highest 408 km/h end From a4cfb6086ab679bec31f1af04ab9c6e76d29d1a7 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Sun, 7 Jan 2024 01:46:10 +0000 Subject: [PATCH 11/14] Put observations at the owner level, rather than a specific garden --- app/models/weather_observation.rb | 4 ++-- db/migrate/20230916061712_add_weather_observations.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/weather_observation.rb b/app/models/weather_observation.rb index 60375ff5b4..39eae947e4 100644 --- a/app/models/weather_observation.rb +++ b/app/models/weather_observation.rb @@ -3,13 +3,13 @@ # A weather observation is intended to be a snapshot aligned to # https://github.com/schemaorg/schemaorg/issues/362 class WeatherObservation < ApplicationRecord - belongs_to :garden + belongs_to :owner validates :source, presence: true validates :observed_at, presence: true attr_accessible :source, :observation_at, :solvar_uv_index, :dew_point_temperature_centigrade, - :air_temperature_centigrade, :relative_humidity, :wind_speed_kmh, :wind_gust_speed_kmh, :garden_id, :wind_direction, :precipitation_probability, :pressure, + :air_temperature_centigrade, :relative_humidity, :wind_speed_kmh, :wind_gust_speed_kmh, :owner_id, :wind_direction, :precipitation_probability, :pressure, :visibility_distance_metres, :weather_type # Lowest temp on earth: -89.2°C (-128.6°F) diff --git a/db/migrate/20230916061712_add_weather_observations.rb b/db/migrate/20230916061712_add_weather_observations.rb index d70e94ec36..c8aed80c91 100644 --- a/db/migrate/20230916061712_add_weather_observations.rb +++ b/db/migrate/20230916061712_add_weather_observations.rb @@ -17,7 +17,7 @@ def change t.decimal :pressure t.integer :visibility_distance_metres t.string :weather_type - t.references :garden_id + t.references :owner t.timestamps end end From fca91a0a71aa87ce19db992e98d42e23bc4ffdb4 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Sun, 7 Jan 2024 01:46:51 +0000 Subject: [PATCH 12/14] Put observations at the owner level, rather than a specific garden --- .../weather_observations_controller.rb | 53 +++++++++++++++++++ config/routes.rb | 1 + 2 files changed, 54 insertions(+) create mode 100644 app/controllers/weather_observations_controller.rb diff --git a/app/controllers/weather_observations_controller.rb b/app/controllers/weather_observations_controller.rb new file mode 100644 index 0000000000..9b7ef44243 --- /dev/null +++ b/app/controllers/weather_observations_controller.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +class WeatherObservationsController < DataController + def index + @owner = Member.find_by(slug: params[:member_slug]) + @show_all = params[:all] == '1' + @show_jump_to = params[:member_slug].present? ? true : false + + # @weather_observations = @weather_observations.includes(:owner) + # @weather_observations = @weather_observations.active unless @show_all + # @weather_observations = @weather_observations.where(owner: @owner) if @owner.present? + # @weather_observations = @weather_observations.where.not(members: { confirmed_at: nil }) + # .order(:name).paginate(page: params[:page]) + respond_with(@weather_observations) + end + + def show + respond_with(@weather_observation) + end + + def new + @weather_observation = WeatherObservation.new + respond_with(@weather_observation) + end + + def edit + respond_with(@weather_observation) + end + + def create + @weather_observation.owner_id = current_member.id + flash[:notice] = I18n.t('weather_observations.created') if @weather_observation.save + respond_with(@weather_observation) + end + + def update + flash[:notice] = I18n.t('weather_observations.updated') if @weather_observation.update(weather_observation_params) + respond_with(@weather_observation) + end + + def destroy + @weather_observation.destroy + flash[:notice] = I18n.t('weather_observations.deleted') + redirect_to(member_weather_observations_path(@weather_observation.owner)) + end + + private + + def weather_observation_params + params.require(:weather_observation).permit! + end + end + \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index e21ada9be8..55c30e341a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -98,6 +98,7 @@ resources :plantings resources :harvests resources :posts + resources :weather_observations resources :follows get 'followers' => 'follows#followers' From bc089646fbec3cc5e66a849026fdfce587f9a298 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Sun, 7 Jan 2024 01:53:52 +0000 Subject: [PATCH 13/14] Add placehlder views --- .../weather_observations/_actions.html.haml | 18 +++ .../weather_observations/_form.html.haml | 40 ++++++ .../weather_observations/_overview.html.haml | 20 +++ .../weather_observations/_photo.html.haml | 3 + .../weather_observations/_previously.haml | 18 +++ app/views/weather_observations/edit.html.haml | 3 + .../weather_observations/index.html.haml | 65 ++++++++++ app/views/weather_observations/new.html.haml | 3 + app/views/weather_observations/show.html.haml | 117 ++++++++++++++++++ 9 files changed, 287 insertions(+) create mode 100644 app/views/weather_observations/_actions.html.haml create mode 100644 app/views/weather_observations/_form.html.haml create mode 100644 app/views/weather_observations/_overview.html.haml create mode 100644 app/views/weather_observations/_photo.html.haml create mode 100644 app/views/weather_observations/_previously.haml create mode 100644 app/views/weather_observations/edit.html.haml create mode 100644 app/views/weather_observations/index.html.haml create mode 100644 app/views/weather_observations/new.html.haml create mode 100644 app/views/weather_observations/show.html.haml diff --git a/app/views/weather_observations/_actions.html.haml b/app/views/weather_observations/_actions.html.haml new file mode 100644 index 0000000000..554d7e3fa7 --- /dev/null +++ b/app/views/weather_observations/_actions.html.haml @@ -0,0 +1,18 @@ +- if can?(:edit, garden) + .dropdown.garden-actions + %a#garden-actions-button.btn.dropdown-toggle{"aria-expanded" => "false", "aria-haspopup" => "true", "data-toggle" => "dropdown", type: "button", href: '#'} Actions + .dropdown-menu.dropdown-menu-xs{"aria-labelledby" => "garden-actions-button"} + - if can?(:edit, garden) + = garden_plant_something_button(garden, classes: 'dropdown-item') if garden.active + - if garden.active + = garden_mark_inactive_button(garden, classes: 'dropdown-item') + - else + = garden_mark_active_button(garden, classes: 'dropdown-item') + + = garden_edit_button(garden, classes: 'dropdown-item') + = add_photo_button(garden, classes: 'dropdown-item') + + - if can?(:destroy, garden) + .dropdown-divider + = delete_button(garden, classes: 'dropdown-item text-danger', + message: 'All plantings associated with this garden will also be deleted. Are you sure?') diff --git a/app/views/weather_observations/_form.html.haml b/app/views/weather_observations/_form.html.haml new file mode 100644 index 0000000000..8ab82bc9b4 --- /dev/null +++ b/app/views/weather_observations/_form.html.haml @@ -0,0 +1,40 @@ +.card.col-md-8.col-lg-7.mx-auto.float-none.white.z-depth-1.py-2.px-2 + = bootstrap_form_for(@garden) do |f| + - if content_for? :title + .card-header + %h1.h2-responsive.text-center + %strong=yield :title + .card-body + = required_field_help_text + - if @garden.errors.any? + #error_explanation.alert.alert-warning{:role => "alert"} + %h4.alert-heading + = pluralize(@garden.errors.size, "error") + prohibited this garden from being saved + %ul + - @garden.errors.full_messages.each do |msg| + %li= msg + + = f.text_field :name, maxlength: 255, required: true + = f.text_area :description, rows: 6 + = f.text_field :location, + value: @garden.location || current_member.location, + class: 'form-control', maxlength: 255 + %span.help-block + = t('.location_helper') + - if current_member.location.blank? + = link_to "Set your location now.", edit_member_registration_path + - else + = link_to "Change your location.", edit_member_registration_path + .row + .col-md-5.col-12= f.number_field :area, class: 'input-small', step: "any" + .col-md-7.col-12= f.select(:area_unit, Garden::AREA_UNITS_VALUES, { include_blank: false }) + .col-12= f.select(:garden_type_id, GardenType.all.order(:name).pluck(:name, :id), + selected: @garden.garden_type_id, include_blank: true) + .col-12 + = f.check_box :active, label: 'Active?' + %p + You can mark a garden as inactive if you no longer use it. + Note: this will mark all plantings in the garden as "finished". + .card-footer + .text-right= f.submit 'Save Garden' diff --git a/app/views/weather_observations/_overview.html.haml b/app/views/weather_observations/_overview.html.haml new file mode 100644 index 0000000000..ac6eb896fc --- /dev/null +++ b/app/views/weather_observations/_overview.html.haml @@ -0,0 +1,20 @@ +.panel.panel-success + .panel-heading + %h3.panel-title + = link_to garden.name, garden_path(garden) + .panel-body + .row + .col-md-2.col-xs-12.garden-info + %p= render 'gardens/photo', garden: garden + %p= display_garden_description(garden) + - if can?(:edit, garden) + = render 'gardens/actions', garden: garden + + .col-md-10 + - if garden.plantings.current.size.positive? + .row + - garden.plantings.current.order(created_at: :desc).includes(:crop, :photos).each do |planting| + .col-lg-2.col-sm-4.col-xs-6 + = render "plantings/thumbnail", planting: planting + - else + no plantings diff --git a/app/views/weather_observations/_photo.html.haml b/app/views/weather_observations/_photo.html.haml new file mode 100644 index 0000000000..b6d301d2e2 --- /dev/null +++ b/app/views/weather_observations/_photo.html.haml @@ -0,0 +1,3 @@ += link_to image_tag(garden_image_path(garden), + alt: garden.name, class: 'img-responsive'), + garden_path(garden) diff --git a/app/views/weather_observations/_previously.haml b/app/views/weather_observations/_previously.haml new file mode 100644 index 0000000000..c0c8d9968f --- /dev/null +++ b/app/views/weather_observations/_previously.haml @@ -0,0 +1,18 @@ +%h2 Previously planted in this garden + +- if @finished_plantings.any? + - year = nil + - @finished_plantings.where.not(planted_at: nil).order(planted_at: :desc).each do |planting| + - if year != planting.planted_at.year + - year = planting.planted_at.year + %h4= year + = render "plantings/tiny", planting: planting + + - if @finished_plantings.where(planted_at: nil).any? + %h4 Unknown year + - @finished_plantings.where(planted_at: nil).each do |planting| + = render "plantings/tiny", planting: planting +- else + .col-md-12 + %p Nothing has been planted here. + diff --git a/app/views/weather_observations/edit.html.haml b/app/views/weather_observations/edit.html.haml new file mode 100644 index 0000000000..49236a2ab1 --- /dev/null +++ b/app/views/weather_observations/edit.html.haml @@ -0,0 +1,3 @@ += content_for :title, "Edit garden" + += render "form" diff --git a/app/views/weather_observations/index.html.haml b/app/views/weather_observations/index.html.haml new file mode 100644 index 0000000000..478b18b800 --- /dev/null +++ b/app/views/weather_observations/index.html.haml @@ -0,0 +1,65 @@ +- content_for :title, @owner ? "#{@owner}'s weather_observations" : "Everyone's weather_observations" + +%h1= @owner ? "#{@owner}'s weather_observations" : "Everyone's weather_observations" + +- content_for :breadcrumbs do + - if @owner + %li.breadcrumb-item= link_to 'weather_observations', weather_observations_path + %li.breadcrumb-item.active= link_to "#{@owner}'s weather_observations", member_weather_observations_path(@owner) + - else + %li.breadcrumb-item.active= link_to 'weather_observations', weather_observations_path + +.row + .col-md-2 + = render 'layouts/nav', model: weather_observation + = link_to show_inactive_tickbox_path('weather_observations', owner: @owner, show_all: @show_all) do + = check_box_tag 'active', 'all', @show_all + include in-active + - if @owner.present? + %hr/ + = render @owner + + .col-md-10 + - if @weather_observations.empty? + %p There are no weather_observations to display. + - if can?(:create, weather_observation) && @owner == current_member + = link_to 'Add a weather_observation', new_weather_observation_path, class: 'btn btn-primary' + + - else + %section + %h2= page_entries_info @weather_observations + = will_paginate @weather_observations + + - if @show_jump_to == true + %section + .jump + jump to: + - @weather_observations.each do |weather_observation| + .badge.badge-primary + - if @owner.present? + = link_to weather_observation.weather_type, member_weather_observations_path(@owner, anchor: "weather_observation-#{weather_observation.id}") + - else + = link_to weather_observation.weather_type, weather_observations_path(anchor: "weather_observation-#{weather_observation.id}") + - @weather_observations.each do |weather_observation| + .card + .card-header + .row + .col-12.col-md-3 + %h2= link_to weather_observation.weather_type, weather_observation, name: "weather_observation-#{weather_observation.id}" + .row + .col-md-3 + - if @owner.blank? + owner: + = render 'members/tiny', member: weather_observation.owner + + .col-md-9 + %section + = render 'weather_observations/actions', weather_observation: weather_observation + + + + + + .row + .col-12= page_entries_info @weather_observations + .col-12= will_paginate @weather_observations diff --git a/app/views/weather_observations/new.html.haml b/app/views/weather_observations/new.html.haml new file mode 100644 index 0000000000..331f82d086 --- /dev/null +++ b/app/views/weather_observations/new.html.haml @@ -0,0 +1,3 @@ +- content_for :title, "New weather observation" + += render 'form' diff --git a/app/views/weather_observations/show.html.haml b/app/views/weather_observations/show.html.haml new file mode 100644 index 0000000000..98af8fb490 --- /dev/null +++ b/app/views/weather_observations/show.html.haml @@ -0,0 +1,117 @@ += content_for :title, "#{@weather_observation.owner}'s #{@weather_observation}" + +- content_for :opengraph do + - if @weather_observation.weather_type + = tag("meta", property: "og:description", content: og_description(@weather_observation. - if @weather_observation.weather_type)) + = tag("meta", property: "og:title", content: "#{@weather_observation.owner}'s #{@weather_observation}") + = tag("meta", property: "og:type", content: "website") + = tag("meta", property: "og:url", content: request.original_url) + = tag("meta", property: "og:site_name", content: ENV['GROWSTUFF_SITE_NAME']) + +- content_for :breadcrumbs do + %li.breadcrumb-item= link_to 'weather_observations', weather_observations_path + %li.breadcrumb-item.active= link_to @weather_observation.weather_type, weather_observations_path(@weather_observation) + +.row + .col-md-9.col-12 + %h2.h1 + %strong= @weather_observation + .col-md-3.col-12 + = render 'weather_observations/actions', weather_observation: @weather_observation +.row + %div + %p + :growstuff_markdown + #{strip_tags @weather_observation.weather_type} + - unless @weather_observation.description + .row-fluid + %p No description available yet. + + - if can? :edit, @weather_observation + %p + Why not + = link_to 'tell us more.', edit_weather_observation_path(@weather_observation) + + - if @weather_observation.plantings.where.not(planted_at: nil).any? + %section.card + %h2 weather_observation progress + .card-body + = render 'plantings/progress_list', plantings: @weather_observation.plantings.active + + %section + %h2 Current plantings in weather_observation + .index-cards + - if @current_plantings.size.positive? + - @current_plantings.each do |planting| + = render "plantings/card", planting: planting + - else + .col-md-12 + %p Nothing is currently planted here. + + %section.companions + %h2 Suggestioned companions + - @suggested_companions.each do |companion| + = render 'crops/tiny', crop: companion + + %section= render 'previously' + + .col-md-3 + .card + .card-image + = image_tag weather_observation_image_path(@weather_observation), class: 'img-card', alt: 'photo of this weather_observation' + .card-body + %h4 About this weather_observation + %p + %strong Owner: + = link_to @weather_observation.owner, @weather_observation.owner + - if @weather_observation.location.present? + %p + %strong Location: + = @weather_observation.location + - if @weather_observation.area.present? + %p + %strong Area: + = pluralize(@weather_observation.area, @weather_observation.area_unit) + - if @weather_observation.weather_observation_type.present? + %p + %strong weather_observation type: + = @weather_observation.weather_observation_type.name + + .card + .card-header + %h4 #{@weather_observation.owner}'s weather_observations + .card-body + %ul.list-group.list-group-flush + - @weather_observation.owner.weather_observations.active.order_by_name.each do |weather_observation| + %li.list-group-item.list-group-flush + = weather_observation_icon + - if @weather_observation == weather_observation + = @weather_observation + - else + = link_to weather_observation, weather_observation_path(weather_observation) + + - unless @weather_observation.owner.weather_observations.inactive.empty? + %h4 Inactive weather_observations + %ul + - @weather_observation.owner.weather_observations.inactive.order_by_name.each do |otherweather_observation| + %li + - if @weather_observation == otherweather_observation + = @weather_observation.name + - else + = link_to otherweather_observation, weather_observation_path(otherweather_observation) + + - if @weather_observation.owner == current_member + %p + = link_to new_weather_observation_path, class: 'btn btn-default btn-xs' do + Add New weather_observation + + - if can?(:edit, @weather_observation) && can?(:create, Photo) + %%p + = add_photo_button(@weather_observation) + + - if @weather_observation.photos.size.positive? + %section.photos + %h2= localize_plural(@weather_observation.photos, Photo) + .index-cards + - @weather_observation.photos.includes(:owner).each do |photo| + = render 'photos/thumbnail', photo: photo From ead197a59719c833f97b67973fd6b871d453127d Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Sun, 14 Jan 2024 03:01:12 +0000 Subject: [PATCH 14/14] Add schema --- db/schema.rb | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/db/schema.rb b/db/schema.rb index 3cd83979d2..3c2853bb66 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_03_13_015323) do +ActiveRecord::Schema[7.0].define(version: 2023_09_16_061712) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -567,6 +567,26 @@ t.index ["slug"], name: "index_seeds_on_slug", unique: true end + create_table "weather_observations", force: :cascade do |t| + t.string "source" + t.datetime "observation_at" + t.integer "solar_uv_index" + t.decimal "wind_speed_kmh" + t.decimal "wind_gust_speed_kmh" + t.string "wind_direction" + t.decimal "air_temperature_centigrade" + t.decimal "relative_humidity" + t.decimal "precipitation_probability" + t.decimal "dew_point_temperature_centigrade" + t.decimal "pressure" + t.integer "visibility_distance_metres" + t.string "weather_type" + t.bigint "owner_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["owner_id"], name: "index_weather_observations_on_owner_id" + end + add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" add_foreign_key "harvests", "plantings"