-
Notifications
You must be signed in to change notification settings - Fork 214
Add table for weather observation (Stacked PR) #3452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
bbd8c94
5ef4ca3
3087443
8ee0881
d0e3a8f
7ed0d0d
99d5b08
4596698
e9ec6f2
dee6000
775986d
a081a8d
a4cfb60
fca91a0
bc08964
02a3776
ead197a
699fdb8
703c119
49a248e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
CloCkWeRX marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def show | ||
respond_with(@weather_observation) | ||
end | ||
|
||
CloCkWeRX marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def new | ||
@weather_observation = WeatherObservation.new | ||
respond_with(@weather_observation) | ||
end | ||
|
||
CloCkWeRX marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def edit | ||
respond_with(@weather_observation) | ||
end | ||
|
||
CloCkWeRX marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unexpected trailing spaces found. |
||
def update | ||
flash[:notice] = I18n.t('weather_observations.updated') if @weather_observation.update(weather_observation_params) | ||
respond_with(@weather_observation) | ||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unexpected trailing spaces found. |
||
def destroy | ||
@weather_observation.destroy | ||
flash[:notice] = I18n.t('weather_observations.deleted') | ||
redirect_to(member_weather_observations_path(@weather_observation.owner)) | ||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unexpected trailing spaces found. |
||
private | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unexpected trailing spaces found. |
||
def weather_observation_params | ||
params.require(:weather_observation).permit! | ||
Check warningCode scanning / Brakeman Specify exact keys allowed for mass assignment instead of using `permit!` which allows any keys.
Specify exact keys allowed for mass assignment instead of using `permit!` which allows any keys.
|
||
end | ||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Expected a newline at the end of the file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unexpected trailing spaces found. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
Check noticeCode scanning / Brakeman Potentially dangerous attribute available for mass assignment.
Potentially dangerous attribute available for mass assignment.
|
||
|
||
# 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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [167/120] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hash attribute should start with one space after the opening brace |
||
.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?') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
= link_to image_tag(garden_image_path(garden), | ||
alt: garden.name, class: 'img-responsive'), | ||
garden_path(garden) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
= content_for :title, "Edit garden" | ||
|
||
= render "form" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
Check noticeCode scanning / Brakeman Render path contains parameter value.
Render path contains parameter value.
|
||
|
||
.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 | ||
|
||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unexpected trailing spaces found. |
||
|
||
|
||
.row | ||
.col-12= page_entries_info @weather_observations | ||
.col-12= will_paginate @weather_observations |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
- content_for :title, "New weather observation" | ||
|
||
= render 'form' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The line was indented 2 levels deeper than the previous line. |
||
%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 |
Uh oh!
There was an error while loading. Please reload this page.