Compare commits

...

21 Commits

Author SHA1 Message Date
Daniel O'Connor
a2c0c314a7 Merge branch 'dev' into add-garden-attributes 2026-04-24 00:18:58 +09:30
Daniel O'Connor
49a248e8dd Merge branch 'dev' into add-garden-attributes 2025-08-31 13:17:59 +09:30
Daniel O'Connor
703c119e28 Merge branch 'dev' into add-garden-attributes 2024-07-14 13:52:14 +09:30
Daniel O'Connor
699fdb8859 Merge branch 'dev' into add-garden-attributes 2024-01-27 00:42:44 +10:30
Daniel O'Connor
ead197a597 Add schema 2024-01-14 03:01:12 +00:00
Daniel O'Connor
02a3776698 Merge branch 'dev' into add-garden-attributes 2024-01-09 18:27:17 +10:30
Daniel O'Connor
bc089646fb Add placehlder views 2024-01-07 01:53:52 +00:00
Daniel O'Connor
fca91a0a71 Put observations at the owner level, rather than a specific garden 2024-01-07 01:46:51 +00:00
Daniel O'Connor
a4cfb6086a Put observations at the owner level, rather than a specific garden 2024-01-07 01:46:10 +00:00
Daniel O'Connor
a081a8d2f5 Fix warnings 2024-01-07 01:39:58 +00:00
Daniel O'Connor
775986d1dd Fix validators 2024-01-07 01:33:22 +00:00
Daniel O'Connor
dee6000537 Fix warning 2024-01-07 01:31:52 +00:00
Daniel O'Connor
e9ec6f2ca9 Fix warning 2024-01-07 01:31:28 +00:00
Daniel O'Connor
4596698f1b Fix warning 2024-01-07 01:30:45 +00:00
Daniel O'Connor
99d5b08898 Merge branch 'dev' into add-garden-attributes 2024-01-07 11:51:39 +10:30
Daniel O'Connor
7ed0d0d036 Validations 2023-09-16 08:16:58 +00:00
Daniel O'Connor
d0e3a8ff19 Add model 2023-09-16 08:08:54 +00:00
Daniel O'Connor
8ee0881d02 Rubocop 2023-09-16 08:05:02 +00:00
Daniel O'Connor
3087443794 Merge branch 'rubocop-todo' into add-garden-attributes 2023-09-16 08:03:28 +00:00
Daniel O'Connor
5ef4ca339a Timestamps 2023-09-16 07:49:38 +00:00
Daniel O'Connor
bbd8c94897 Add table for weather 2023-09-16 06:26:14 +00:00
15 changed files with 408 additions and 0 deletions

View File

@@ -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

View File

@@ -10,6 +10,7 @@ class Garden < ApplicationRecord
has_many :plantings, dependent: :destroy
has_many :crops, through: :plantings
has_many :weather_observations, dependent: :destroy
has_many :activities, dependent: :destroy
has_many :garden_collaborators, dependent: :destroy

View File

@@ -0,0 +1,22 @@
# 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
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, :owner_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 }, 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

View File

@@ -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?')

View File

@@ -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'

View File

@@ -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

View File

@@ -0,0 +1,3 @@
= link_to image_tag(garden_image_path(garden),
alt: garden.name, class: 'img-responsive'),
garden_path(garden)

View File

@@ -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.

View File

@@ -0,0 +1,3 @@
= content_for :title, "Edit garden"
= render "form"

View File

@@ -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

View File

@@ -0,0 +1,3 @@
- content_for :title, "New weather observation"
= render 'form'

View File

@@ -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

View File

@@ -117,6 +117,7 @@ Rails.application.routes.draw do
resources :plantings
resources :harvests
resources :posts
resources :weather_observations
resources :activities
resources :follows

View File

@@ -0,0 +1,24 @@
# frozen_string_literal: true
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.integer :visibility_distance_metres
t.string :weather_type
t.references :owner
t.timestamps
end
end
end

View File

@@ -970,6 +970,26 @@ ActiveRecord::Schema[7.2].define(version: 2025_12_01_045000) do
t.index ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id"
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"