diff --git a/app/controllers/crops_controller.rb b/app/controllers/crops_controller.rb index 27c7b3755..6c0d8bace 100644 --- a/app/controllers/crops_controller.rb +++ b/app/controllers/crops_controller.rb @@ -51,7 +51,7 @@ class CropsController < ApplicationController def show @crop = Crop.includes(:scientific_names, plantings: :photos).find_by!(slug: params[:slug]) @posts = @crop.posts.order(created_at: :desc).paginate(page: params[:page]) - @photos = Photo.joins(:photographings).where(photographings: {crop: @crop}) + @photos = Photo.joins(:photographings).where(photographings: { crop: @crop }) # respond_with(@crop) respond_to do |format| format.html diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index 7af1b2a7d..b79c9bb48 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -6,14 +6,14 @@ class PhotosController < ApplicationController responders :flash def show - @crops = Crop.distinct.joins(:photographings).where(photographings: { photo: @photo}) + @crops = Crop.distinct.joins(:photographings).where(photographings: { photo: @photo }) respond_with(@photo) end def index if params[:crop_slug] @crop = Crop.find params[:crop_slug] - @photos = Photo.joins(:photographings).where(photographings: {crop: @crop}) + @photos = Photo.joins(:photographings).where(photographings: { crop: @crop }) else @photos = Photo.all end diff --git a/app/models/crop.rb b/app/models/crop.rb index d83b5b846..81eaf18aa 100644 --- a/app/models/crop.rb +++ b/app/models/crop.rb @@ -107,6 +107,7 @@ class Crop < ApplicationRecord def seed_photos Photo.joins(:seeds).where("seeds.crop_id": id) end + # update the Elasticsearch index (only if we're using it in this # environment) def update_index(_name_obj) diff --git a/app/models/photo.rb b/app/models/photo.rb index d9ff5217c..27ebae2ff 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -1,7 +1,6 @@ class Photo < ApplicationRecord include Ownable - PHOTO_CAPABLE = %w(Garden Planting Harvest Seed).freeze has_many :photographings, foreign_key: :photo_id, dependent: :destroy, inverse_of: :photo diff --git a/app/models/photographing.rb b/app/models/photographing.rb index 1769434b4..2693725a2 100644 --- a/app/models/photographing.rb +++ b/app/models/photographing.rb @@ -4,23 +4,21 @@ class Photographing < ApplicationRecord belongs_to :crop, optional: true validate :photo_and_item_have_same_owner - + ## ## Triggers before_save :set_crop def item - self.find_by!(photographable_id: photographable_id, photographable_type: photographable_type).photographable + find_by!(photographable_id: photographable_id, photographable_type: photographable_type).photographable end - + def self.item(item_id, item_type) find_by!(photographable_id: item_id, photographable_type: item_type).photographable end def set_crop - if ['Planting', 'Seed', 'Harvest'].include?(photographable_type) - self.crop_id = photographable.crop_id - end + self.crop_id = photographable.crop_id if %w(Planting Seed Harvest).include?(photographable_type) end private diff --git a/app/views/plantings/_progress.html.haml b/app/views/plantings/_progress.html.haml index 1978f8d19..e16b6c64f 100644 --- a/app/views/plantings/_progress.html.haml +++ b/app/views/plantings/_progress.html.haml @@ -1 +1,17 @@ +-# - if planting.crop.perennial +-# = render "plantings/progress_bar", status: "perennial", progress: nil +-# - elsif !planting.planted? +-# - if show_explanation +-# %p= t('.progress_0_not_planted_yet') +-# = render "plantings/progress_bar", status: "not planted", progress: 0 +-# - elsif planting.finished? +-# = render "plantings/progress_bar", status: 'finished', progress: 100 +-# - elsif planting.finish_predicted_at.nil? +-# - if show_explanation == true +-# %p Progress: Not enough data +-# = render "plantings/progress_bar", status: "unknown", progress: nil +-# - else +-# = render "plantings/progress_bar", status: 'growing', progress: planting.percentage_grown + + = render "plantings/progress_bar", status: planting_status(planting), progress: planting_progress(planting)