mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-25 01:13:03 -04:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
313e240eb9 | ||
|
|
14aa673440 | ||
|
|
cef23b8212 | ||
|
|
3b45dca6e2 | ||
|
|
9060c45aed | ||
|
|
d4401b402a | ||
|
|
372a5edc29 | ||
|
|
1f0777fda0 | ||
|
|
6503e2554c | ||
|
|
4fd544c0b8 | ||
|
|
f7e1aafc25 | ||
|
|
208720c46c | ||
|
|
370c8683fd | ||
|
|
e5aa2aaa1f | ||
|
|
4e91037f50 | ||
|
|
af74a2907f | ||
|
|
3804ae3333 |
@@ -1,6 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module CropsHelper
|
||||
|
||||
def crop_or_parent(crop, attribute)
|
||||
default = crop.send(attribute)
|
||||
return default if default.present?
|
||||
while parent = crop.parent do
|
||||
return parent.send(attribute) if parent&.send(attribute).present?
|
||||
end
|
||||
|
||||
# For scopes, arrays, etc return the empty value
|
||||
default
|
||||
end
|
||||
|
||||
def display_seed_availability(member, crop)
|
||||
seeds = member.seeds.where(crop:)
|
||||
total_quantity = seeds.where.not(quantity: nil).sum(:quantity)
|
||||
|
||||
@@ -162,7 +162,7 @@ class Crop < ApplicationRecord
|
||||
def all_companions
|
||||
return companions unless parent
|
||||
|
||||
(companions + parent.companions).uniq
|
||||
(companions + parent.all_companions).uniq
|
||||
end
|
||||
|
||||
before_destroy :destroy_reverse_companionships
|
||||
|
||||
@@ -41,14 +41,28 @@
|
||||
= f.radio_button(:perennial, true, label: "Perennial")
|
||||
%span.help-block Living more than two years
|
||||
|
||||
%h2 OpenFarm Data
|
||||
%h2 Data
|
||||
= f.text_area :description, label: 'Description'
|
||||
- if @crop.parent
|
||||
%span.help-block Parent: #{@crop.parent.description}
|
||||
= f.number_field :row_spacing, label: 'Row Spacing (cm)', min: 0
|
||||
- if @crop.parent
|
||||
%span.help-block Parent: #{@crop.parent.row_spacing}
|
||||
= f.number_field :spread, label: 'Spread (cm)', min: 0
|
||||
- if @crop.parent
|
||||
%span.help-block Parent: #{@crop.parent.spread}
|
||||
= f.number_field :height, label: 'Height (cm)', min: 0
|
||||
- if @crop.parent
|
||||
%span.help-block Parent: #{@crop.parent.height}
|
||||
= f.text_field :sowing_method
|
||||
- if @crop.parent
|
||||
%span.help-block Parent: #{@crop.parent.sowing_method}
|
||||
= f.text_field :sun_requirements
|
||||
- if @crop.parent
|
||||
%span.help-block Parent: #{@crop.parent.sun_requirements}
|
||||
= f.number_field :growing_degree_days, min: 0
|
||||
- if @crop.parent
|
||||
%span.help-block Parent: #{@crop.parent.growing_degree_days}
|
||||
|
||||
- unless @crop.approved?
|
||||
= link_to 'Search wikipedia', "https://en.wikipedia.org/w/index.php?search=#{@crop.name}", target: '_blank'
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
- unless @crop.approved?
|
||||
%badge.badge-warning=@crop.approval_status
|
||||
%small.text-muted= @crop.default_scientific_name
|
||||
- if @crop.sowing_method.present?
|
||||
- if crop_or_parent(@crop, :sowing_method).present?
|
||||
%p
|
||||
%strong How to sow #{@crop.name}:
|
||||
= @crop.sowing_method
|
||||
- if @crop.sun_requirements.present?
|
||||
= crop_or_parent(@crop, :sowing_method)
|
||||
- if crop_or_parent(@crop, :sun_requirements).present?
|
||||
%p
|
||||
%strong Sun requirement for #{@crop}:
|
||||
Plant in #{@crop.sun_requirements}
|
||||
Plant in #{crop_or_parent(@crop, :sun_requirements)}
|
||||
%p.text-muted
|
||||
- if !@crop.plantings.empty?
|
||||
#{@crop.name.titleize} has been planted
|
||||
@@ -21,8 +21,8 @@
|
||||
by #{ENV['GROWSTUFF_SITE_NAME']} members.
|
||||
- else
|
||||
Nobody is growing this yet. You could be the first!
|
||||
- if @crop.description.present?
|
||||
%p= simple_format @crop.description
|
||||
- if crop_or_parent(@crop, :description).present?
|
||||
%p= simple_format crop_or_parent(@crop, :description)
|
||||
.col-md-3
|
||||
= image_tag crop_image_path(@crop),
|
||||
class: 'img-responsive shadow rounded crop-hero-photo', alt: "Image of #{@crop.name}"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
%h2 #{photo_icon} Photos
|
||||
- [Crop, Planting, Harvest, Seed].each do |model_name|
|
||||
- if crop.photos.by_model(model_name).any?
|
||||
- if crop_or_parent(crop, :photos).by_model(model_name).any?
|
||||
%h3 #{@crop.name.capitalize} #{t("activerecord.models.#{model_name.to_s.downcase}.other")}
|
||||
= render 'photos/gallery', photos: crop.photos.by_model(model_name).includes(:owner).order(likes_count: :desc).limit(5)
|
||||
= render 'photos/gallery', photos: crop_or_parent(crop, :photos).by_model(model_name).includes(:owner).order(likes_count: :desc).limit(5)
|
||||
- if crop.photos.count.positive?
|
||||
= link_to 'more photos »', crop_photos_path(@crop), class: 'btn'
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
|
||||
- content_for :breadcrumbs do
|
||||
%li.breadcrumb-item= link_to 'Crops', crops_path
|
||||
- if @crop.parent
|
||||
%li.breadcrumb-item.active= link_to @crop.parent.name.capitalize, @crop.parent
|
||||
%li.breadcrumb-item.active= link_to @crop.name.capitalize, @crop
|
||||
|
||||
= render 'approval_status_message', crop: @crop
|
||||
@@ -30,11 +32,11 @@
|
||||
- @crop.all_companions.each do |companion|
|
||||
= render 'crops/tiny', crop: companion
|
||||
|
||||
- if @crop.en_youtube_url.present?
|
||||
- if crop_or_parent(@crop, :en_youtube_url).present?
|
||||
%section.youtube
|
||||
%h2 Video
|
||||
.embed-responsive.embed-responsive-16by9
|
||||
%iframe.embed-responsive-item{ src: "https://www.youtube.com/embed/#{youtube_video_id(@crop.en_youtube_url)}", allowfullscreen: true }
|
||||
%iframe.embed-responsive-item{ src: "https://www.youtube.com/embed/#{youtube_video_id(crop_or_parent(@crop, :en_youtube_url))}", allowfullscreen: true }
|
||||
|
||||
%section.photos
|
||||
= cute_icon
|
||||
|
||||
Reference in New Issue
Block a user