mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-25 09:19:15 -04:00
Compare commits
21 Commits
release82
...
add-garden
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a2c0c314a7 | ||
|
|
49a248e8dd | ||
|
|
703c119e28 | ||
|
|
699fdb8859 | ||
|
|
ead197a597 | ||
|
|
02a3776698 | ||
|
|
bc089646fb | ||
|
|
fca91a0a71 | ||
|
|
a4cfb6086a | ||
|
|
a081a8d2f5 | ||
|
|
775986d1dd | ||
|
|
dee6000537 | ||
|
|
e9ec6f2ca9 | ||
|
|
4596698f1b | ||
|
|
99d5b08898 | ||
|
|
7ed0d0d036 | ||
|
|
d0e3a8ff19 | ||
|
|
8ee0881d02 | ||
|
|
3087443794 | ||
|
|
5ef4ca339a | ||
|
|
bbd8c94897 |
53
app/controllers/weather_observations_controller.rb
Normal file
53
app/controllers/weather_observations_controller.rb
Normal 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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
22
app/models/weather_observation.rb
Normal file
22
app/models/weather_observation.rb
Normal 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
|
||||
18
app/views/weather_observations/_actions.html.haml
Normal file
18
app/views/weather_observations/_actions.html.haml
Normal 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?')
|
||||
40
app/views/weather_observations/_form.html.haml
Normal file
40
app/views/weather_observations/_form.html.haml
Normal 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'
|
||||
20
app/views/weather_observations/_overview.html.haml
Normal file
20
app/views/weather_observations/_overview.html.haml
Normal 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
|
||||
3
app/views/weather_observations/_photo.html.haml
Normal file
3
app/views/weather_observations/_photo.html.haml
Normal file
@@ -0,0 +1,3 @@
|
||||
= link_to image_tag(garden_image_path(garden),
|
||||
alt: garden.name, class: 'img-responsive'),
|
||||
garden_path(garden)
|
||||
18
app/views/weather_observations/_previously.haml
Normal file
18
app/views/weather_observations/_previously.haml
Normal 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.
|
||||
|
||||
3
app/views/weather_observations/edit.html.haml
Normal file
3
app/views/weather_observations/edit.html.haml
Normal file
@@ -0,0 +1,3 @@
|
||||
= content_for :title, "Edit garden"
|
||||
|
||||
= render "form"
|
||||
65
app/views/weather_observations/index.html.haml
Normal file
65
app/views/weather_observations/index.html.haml
Normal 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
|
||||
3
app/views/weather_observations/new.html.haml
Normal file
3
app/views/weather_observations/new.html.haml
Normal file
@@ -0,0 +1,3 @@
|
||||
- content_for :title, "New weather observation"
|
||||
|
||||
= render 'form'
|
||||
117
app/views/weather_observations/show.html.haml
Normal file
117
app/views/weather_observations/show.html.haml
Normal 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
|
||||
@@ -117,6 +117,7 @@ Rails.application.routes.draw do
|
||||
resources :plantings
|
||||
resources :harvests
|
||||
resources :posts
|
||||
resources :weather_observations
|
||||
resources :activities
|
||||
|
||||
resources :follows
|
||||
|
||||
24
db/migrate/20230916061712_add_weather_observations.rb
Normal file
24
db/migrate/20230916061712_add_weather_observations.rb
Normal 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
|
||||
20
db/schema.rb
20
db/schema.rb
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user