Skip to content

Add overall_rating to Plantings #4062

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

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion app/controllers/plantings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def planting_params
:crop_id, :description, :garden_id, :planted_at,
:parent_seed_id,
:quantity, :sunniness, :planted_from, :finished,
:finished_at
:finished_at, :overall_rating
)
end

Expand Down
3 changes: 3 additions & 0 deletions app/models/planting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ class Planting < ApplicationRecord
validates :planted_from, allow_blank: true, inclusion: {
in: PLANTED_FROM_VALUES, message: "%<value>s is not a valid planting method"
}
validates :overall_rating, allow_blank: true, numericality: {
only_integer: true, greater_than_or_equal_to: 1, less_than_or_equal_to: 5
}

def planting_slug
[
Expand Down
5 changes: 5 additions & 0 deletions app/views/harvests/_planting.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@
- @matching_plantings.each do |planting|
= f.radio_button :planting_id, planting.id, label: planting
= f.submit "save", class: 'btn btn-sm'

- if @harvest.planting.present? && @harvest.planting.overall_rating.blank?
.alert.alert-info{role: "alert"}
This harvest is from a planting that hasn't been rated yet.
= link_to "Rate this planting", edit_planting_path(@harvest.planting), class: 'alert-link'
6 changes: 6 additions & 0 deletions app/views/plantings/_facts.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- if planting.overall_rating.present?
.card.my-3
.card-body
%h5.card-title Overall Rating
%p.card-text
%strong= "#{planting.overall_rating}/5"
2 changes: 2 additions & 0 deletions app/views/plantings/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
= f.select(:sunniness, Planting::SUNNINESS_VALUES, { include_blank: '', label: 'Sun or shade?' } )
.col-md-4
= f.number_field :quantity, label: 'How many?', min: 1
.col-md-4
= f.select :overall_rating, options_for_select((1..5).to_a, @planting.overall_rating), { include_blank: 'Leave blank', label: 'Overall Rating' }
= f.text_area :description, rows: 6, label: 'Tell us more about it'

.row
Expand Down
9 changes: 9 additions & 0 deletions app/views/plantings/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
= 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'])
- if @planting.overall_rating.present?
%script{type: "application/ld+json"}
:plain
{
"@context": "http://schema.org",
"@type": "Rating",
"ratingValue": "#{@planting.overall_rating}",
"bestRating": "5"
}

- content_for :breadcrumbs do
%li.breadcrumb-item= link_to 'Plantings', plantings_path
Expand Down
Loading