From e7b0b6f18e9534d00e816dad92af15ea8873eccc Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Wed, 27 Mar 2019 21:04:56 +1300 Subject: [PATCH] Remove table display on plantings#show, replace with boxes --- app/assets/stylesheets/overrides.sass | 9 +- app/assets/stylesheets/plantings.sass | 18 ++- app/controllers/photos_controller.rb | 3 + app/controllers/plantings_controller.rb | 2 +- app/controllers/seeds_controller.rb | 2 + app/helpers/icons_helper.rb | 8 ++ app/helpers/plantings_helper.rb | 7 ++ app/models/harvest.rb | 2 +- app/views/harvests/show.html.haml | 17 ++- app/views/photos/_actions.html.haml | 2 +- app/views/photos/_photo.haml | 1 + app/views/photos/index.html.haml | 14 +-- app/views/photos/show.html.haml | 4 +- app/views/plantings/_card.html.haml | 89 +++++++-------- app/views/plantings/_descendants.html.haml | 8 +- app/views/plantings/_facts.haml | 95 ++++++++++++++++ app/views/plantings/_harvests.html.haml | 10 +- app/views/plantings/_owner.haml | 16 +++ app/views/plantings/_planting.haml | 6 + app/views/plantings/_thumbnail.html.haml | 2 +- app/views/plantings/index.html.haml | 6 +- app/views/plantings/show.html.haml | 104 +++++------------- .../20190326224347_add_harvests_count.rb | 9 ++ db/schema.rb | 3 +- 24 files changed, 280 insertions(+), 157 deletions(-) create mode 100644 app/views/photos/_photo.haml create mode 100644 app/views/plantings/_facts.haml create mode 100644 app/views/plantings/_owner.haml create mode 100644 app/views/plantings/_planting.haml create mode 100644 db/migrate/20190326224347_add_harvests_count.rb diff --git a/app/assets/stylesheets/overrides.sass b/app/assets/stylesheets/overrides.sass index 1b7d4d152..ac76458d2 100644 --- a/app/assets/stylesheets/overrides.sass +++ b/app/assets/stylesheets/overrides.sass @@ -38,12 +38,13 @@ h3 max-width: 100% height: auto +.avatar + border-radius: 50% + z-index: 2 + position: relative + .profile-sidebar margin-top: -5rem - .avatar - border-radius: 50% - z-index: 2 - position: relative .profile-activity background: white diff --git a/app/assets/stylesheets/plantings.sass b/app/assets/stylesheets/plantings.sass index a6d450b68..f2732b77d 100644 --- a/app/assets/stylesheets/plantings.sass +++ b/app/assets/stylesheets/plantings.sass @@ -25,7 +25,7 @@ font-size: 150% top: -0.5em .planting-quick-actions - position: absolute + position: absolute left: 142px top: 6px .planting-thumbnail-photo @@ -36,3 +36,19 @@ text-align: left dd margin-left: auto + + .fact + text-align: center + height: 180px + border: 1px solid lighten($green, 20%) + border-radius: 30% + background: $white + margin: 1em + strong + font-size: 3em + font-align: center + h3 + span + display: block + img + height: 50% diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index 1d9af2cfa..a38dc6130 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -14,6 +14,9 @@ class PhotosController < ApplicationController if params[:crop_slug] @crop = Crop.find params[:crop_slug] @photos = Photo.by_crop(@crop) + elsif params[:planting_id] + @planting = Planting.find params[:planting_id] + @photos = @planting.photos else @photos = Photo.all end diff --git a/app/controllers/plantings_controller.rb b/app/controllers/plantings_controller.rb index 449a919bd..0020547c5 100644 --- a/app/controllers/plantings_controller.rb +++ b/app/controllers/plantings_controller.rb @@ -22,7 +22,7 @@ class PlantingsController < ApplicationController @plantings = @plantings.joins(:owner, :crop, :garden) .order(created_at: :desc) - .includes(:crop, :owner, :garden) + .includes(:owner, :garden, crop: :parent) .paginate(page: params[:page]) @filename = "Growstuff-#{specifics}Plantings-#{Time.zone.now.to_s(:number)}.csv" diff --git a/app/controllers/seeds_controller.rb b/app/controllers/seeds_controller.rb index cbed89e5c..ba09fca61 100644 --- a/app/controllers/seeds_controller.rb +++ b/app/controllers/seeds_controller.rb @@ -10,9 +10,11 @@ class SeedsController < ApplicationController def index @owner = Member.find_by(slug: params[:member_slug]) if params[:member_slug].present? @crop = Crop.find_by(slug: params[:crop_slug]) if params[:crop_slug].present? + @planting = Planting.find_by(slug: params[:planting_id]) if params[:planting_id].present? @seeds = @seeds.where(owner: @owner) if @owner.present? @seeds = @seeds.where(crop: @crop) if @crop.present? + @seeds = @seeds.where(parent_planting: @planting) if @planting.present? @seeds = @seeds.order(created_at: :desc).includes(:owner, :crop).paginate(page: params[:page]) @filename = csv_filename diff --git a/app/helpers/icons_helper.rb b/app/helpers/icons_helper.rb index a42aaf5d8..9ff06e3d5 100644 --- a/app/helpers/icons_helper.rb +++ b/app/helpers/icons_helper.rb @@ -31,4 +31,12 @@ module IconsHelper def photo_icon icon('fas', 'camera-retro') end + + def planted_from_icon(planted_from) + planted_from + end + + def sunniness_icon(sunniness) + image_tag("sunniness_#{sunniness}.png", class: 'img') + end end diff --git a/app/helpers/plantings_helper.rb b/app/helpers/plantings_helper.rb index 34b76d2e2..fecbd8b59 100644 --- a/app/helpers/plantings_helper.rb +++ b/app/helpers/plantings_helper.rb @@ -45,6 +45,13 @@ module PlantingsHelper (planting.first_harvest_predicted_at - Time.zone.today).to_i end + def days_from_now_to_last_harvest(planting) + return unless planting.planted_at.present? && planting.last_harvest_predicted_at.present? + + (planting.last_harvest_predicted_at - Time.zone.today).to_i + end + + def planting_classes(planting) classes = [] classes << 'planting-growing' if planting.growing? diff --git a/app/models/harvest.rb b/app/models/harvest.rb index 94b71d7b4..6de58739d 100644 --- a/app/models/harvest.rb +++ b/app/models/harvest.rb @@ -35,7 +35,7 @@ class Harvest < ApplicationRecord ## Relationships belongs_to :crop belongs_to :plant_part - belongs_to :planting, optional: true + belongs_to :planting, optional: true, counter_cache: true ## ## Scopes diff --git a/app/views/harvests/show.html.haml b/app/views/harvests/show.html.haml index 69638706d..c2c5e88e4 100644 --- a/app/views/harvests/show.html.haml +++ b/app/views/harvests/show.html.haml @@ -39,9 +39,16 @@ .col-md-6 = render partial: "crops/index_card", locals: { crop: @harvest.crop } -%h2 Notes +- if @harvest.description.present? + %h2 Notes + :growstuff_markdown + #{ @harvest.description != "" ? strip_tags(@harvest.description) : "No description given." } -:growstuff_markdown - #{ @harvest.description != "" ? strip_tags(@harvest.description) : "No description given." } - -= render 'photos/item_photos', item: @harvest, type: 'harvest', photos: @photos +%hr/ +- if @harvest.photos.size.positive? + .row + .col-md-6= render @harvest.default_photo + .col-md-6 + = link_to 'View all photos >>', planting_photos_path(@harvest), class: 'pull-right' + - @harvest.photos.order(date_taken: :desc).limit(3).each do |photo| + = render('photos/thumbnail', photo: photo) \ No newline at end of file diff --git a/app/views/photos/_actions.html.haml b/app/views/photos/_actions.html.haml index 95d9de0d1..1b19a50a5 100644 --- a/app/views/photos/_actions.html.haml +++ b/app/views/photos/_actions.html.haml @@ -2,6 +2,6 @@ - if can?(:edit, @photo) && can?(:destroy, @photo) %p - if can?(:edit, @photo) - = edit_button(@photo) + = edit_button(edit_photo_path(@photo)) - if can?(:destroy, @photo) = delete_button(@photo) diff --git a/app/views/photos/_photo.haml b/app/views/photos/_photo.haml new file mode 100644 index 000000000..28aa3be64 --- /dev/null +++ b/app/views/photos/_photo.haml @@ -0,0 +1 @@ += image_tag(photo.fullsize_url, alt: photo.title, class: 'img img-responsive') diff --git a/app/views/photos/index.html.haml b/app/views/photos/index.html.haml index 6cdf7e2dd..7e4acc53c 100644 --- a/app/views/photos/index.html.haml +++ b/app/views/photos/index.html.haml @@ -1,15 +1,15 @@ -- content_for :title, "Photos" - -- if @crop - %h2= @crop.name - -%p Most recent photos added to #{ENV['GROWSTUFF_SITE_NAME']}. +- content_for :title do + - if @crop + Photos of #{@crop.name} + - elsif @planting.present? + Photos of #{@planting} + - else + Most recent photos added to #{ENV['GROWSTUFF_SITE_NAME']}. .pagination = page_entries_info @photos = will_paginate @photos - .row - @photos.each do |p| .col-md-2.six-across diff --git a/app/views/photos/show.html.haml b/app/views/photos/show.html.haml index 78f5074a4..2944e7f6b 100644 --- a/app/views/photos/show.html.haml +++ b/app/views/photos/show.html.haml @@ -9,7 +9,7 @@ .row .col-md-8 - %p= image_tag(@photo.fullsize_url, alt: @photo.title, class: 'img img-responsive') + %p= render @photo .col-md-4 = render 'photos/actions', photo: @photo @@ -27,7 +27,7 @@ %p= link_to "View on Flickr", @photo.link_url - if @photo.associations? = render "photo_associations", locals: { photo: @photo } - + - if @crops.size.positive? - @crops.each do |crop| = render 'crops/index_card', crop: crop diff --git a/app/views/plantings/_card.html.haml b/app/views/plantings/_card.html.haml index efdbd700b..09ba70be9 100644 --- a/app/views/plantings/_card.html.haml +++ b/app/views/plantings/_card.html.haml @@ -1,46 +1,47 @@ -.panel.panel-success.planting-thumbnail - .panel-heading - %h3.panel-title - = link_to planting.crop.name, planting_path(planting) - - if can? :edit, planting - %a.pull-right{ href: edit_planting_path(planting), role: "button", id: "edit_garden_glyphicon" } - %span.glyphicon.glyphicon-pencil{ title: "Edit" } - .panel-body - .row - .col-xs-12.col-md-4 - = link_to image_tag(planting_image_path(planting), - alt: planting.crop_id, class: 'img img-responsive'), - planting - .col-xs-12.col-md-8 - %dl.dl-horizontal.planting-attributes - %dt Owner: - %dd= link_to planting.owner.login_name, planting.owner - %dt Garden: - %dd= link_to planting.garden&.name, planting.garden - %dt Planted on: - %dd= planting.planted_at - - if planting.quantity - %dt Quantity: - %dd= display_planting_quantity(planting) - - if planting.finished? - %dt Finished on: - %dd= display_finished(planting) +.card + .panel.panel-success.planting-thumbnail + .panel-heading + %h3.panel-title + = link_to planting.crop.name, planting_path(planting) + - if can? :edit, planting + %a.pull-right{ href: edit_planting_path(planting), role: "button", id: "edit_garden_glyphicon" } + %span.glyphicon.glyphicon-pencil{ title: "Edit" } + .panel-body + .row + .col-xs-12.col-md-4 + = link_to image_tag(planting_image_path(planting), + alt: planting.crop_id, class: 'img img-responsive'), + planting + .col-xs-12.col-md-8 + %dl.dl-horizontal.planting-attributes + %dt Owner: + %dd= link_to planting.owner.login_name, planting.owner + %dt Garden: + %dd= link_to planting.garden&.name, planting.garden + %dt Planted on: + %dd= planting.planted_at + - if planting.quantity + %dt Quantity: + %dd= display_planting_quantity(planting) + - if planting.finished? + %dt Finished on: + %dd= display_finished(planting) - - unless planting.sunniness.blank? - %dt Sun/shade?: - %dd - - sunniness = planting.sunniness.blank? ? "not specified" : planting.sunniness - = image_tag("sunniness_#{sunniness}.png", size: "25x25", alt: sunniness, title: sunniness) - = " (#{sunniness})" - - - unless planting.planted_from.blank? - %dt Planted from: - %dd= display_planted_from(planting) + - unless planting.sunniness.blank? + %dt Sun/shade?: + %dd + - sunniness = planting.sunniness.blank? ? "not specified" : planting.sunniness + = image_tag("sunniness_#{sunniness}.png", size: "25x25", alt: sunniness, title: sunniness) + = " (#{sunniness})" + + - unless planting.planted_from.blank? + %dt Planted from: + %dd= display_planted_from(planting) - %dt Finish expected: - %dd= planting.finish_predicted_at if planting.finish_predicted_at.present? - %p= render 'plantings/progress', planting: planting, show_explanation: true - .row - .col-md-12 - = render 'plantings/actions', planting: planting - + %dt Finish expected: + %dd= planting.finish_predicted_at if planting.finish_predicted_at.present? + %p= render 'plantings/progress', planting: planting, show_explanation: true + .row + .col-md-12 + = render 'plantings/actions', planting: planting + diff --git a/app/views/plantings/_descendants.html.haml b/app/views/plantings/_descendants.html.haml index 27e81c6b8..3cecee084 100644 --- a/app/views/plantings/_descendants.html.haml +++ b/app/views/plantings/_descendants.html.haml @@ -1,4 +1,8 @@ %h2 Seeds saved from this planting +- if planting.active? && can?(:create, Seed) && can?(:edit, planting) + = link_to new_planting_seed_path(planting), class: 'btn btn-default' do + %span.glyphicon.glyphicon-heart{ title: "Add photo" } + Save seeds - if planting.child_seeds.size.positive? .row @@ -8,7 +12,3 @@ - else %p No seeds saved -- if planting.active? && can?(:create, Seed) && can?(:edit, planting) - = link_to new_planting_seed_path(planting), class: 'btn btn-primary' do - %span.glyphicon.glyphicon-heart{ title: "Add photo" } - Save seeds diff --git a/app/views/plantings/_facts.haml b/app/views/plantings/_facts.haml new file mode 100644 index 000000000..0fe0db90b --- /dev/null +++ b/app/views/plantings/_facts.haml @@ -0,0 +1,95 @@ +.planting + + - if planting.parent_seed + .fact.col-lg-2.col-md-3.col-sm-6.col-xs-12 + %h3 Parent seed + %strong + = link_to @planting.parent_seed, seed_path(@planting.parent_seed) + - if planting.finished + .fact.col-lg-2.col-md-3.col-sm-6.col-xs-12 + %h3 Planted + %strong=planting_icon + %span= planting.planted_at.to_formatted_s(:short) + + - if planting.planted_at.present? && ! planting.finished? + .fact.col-lg-2.col-md-3.col-sm-6.col-xs-12 + %h3 Planted + %strong #{planting.days_since_planted} + %span days ago + %span= planting.planted_at.to_formatted_s(:short) + + - unless planting.finished? + .fact.col-lg-2.col-md-3.col-sm-6.col-xs-12 + %h3 Growing + %strong + %i.fas.fa-seedling + %span= planting.planted_at.to_formatted_s(:short) + + - if planting.planted_from.present? + .fact.col-lg-2.col-md-3.col-sm-6.col-xs-12 + %h3 Grown from + %strong=planted_from_icon(planting.planted_from) + - if planting.quantity.to_i.positive? + %span #{pluralize((planting.quantity.to_i), planting.planted_from)} + + - if planting.sunniness.present? + .fact.col-lg-2.col-md-3.col-sm-6.col-xs-12 + %h3 Grown in + %strong + = link_to planting.garden do + = sunniness_icon(planting.sunniness) + %span= planting.sunniness + + + .fact.col-lg-2.col-md-3.col-sm-6.col-xs-12 + %h3 + - if planting.finished? + Harvests + - else + Harvesting + %strong + = link_to planting_harvests_path(planting) do + = harvest_icon + %span + = planting.first_harvest_date&.to_formatted_s(:short) || planting&.first_harvest_predicted_at&.to_formatted_s(:short) + %span #{planting.harvests.size} harvests + + - if planting.crop.perennial + .fact.col-lg-2.col-md-3.col-sm-6.col-xs-12 + %h3 Perennial + %strong + %i.fas.fa-tree + - else + - if !planting.finished? && planting.finish_is_predicatable? + .fact.col-lg-2.col-md-3.col-sm-6.col-xs-12 + - days = days_from_now_to_finished(planting) + - if days.positive? + %h3 Finishes + %strong #{days} + %span days to go + - else + %h3 Finish + %strong #{days * -1} + %span days ago + %span= planting.finish_predicted_at&.to_formatted_s(:short) + + - if planting.child_seeds.size.positive? + .fact.col-lg-2.col-md-3.col-sm-6.col-xs-12 + %h3 Seeds saved + %strong + = link_to planting_seeds_path(planting) do + = seed_icon + %span=planting.child_seeds&.first&.created_at&.to_date&.to_formatted_s(:short) + %span #{pluralize(planting.child_seeds.size, 'packet')} of seed + + + - if planting.finished? + .fact.col-lg-2.col-md-3.col-sm-6.col-xs-12 + %h3 Finished + %strong=finished_icon + %span=planting.finished_at&.to_formatted_s(:short) + + - elsif planting.percentage_grown + .fact.col-lg-2.col-md-3.col-sm-6.col-xs-12 + %h2 Progress + %strong #{sprintf '%.0f', planting.percentage_grown}% diff --git a/app/views/plantings/_harvests.html.haml b/app/views/plantings/_harvests.html.haml index a845e980e..33f6c6040 100644 --- a/app/views/plantings/_harvests.html.haml +++ b/app/views/plantings/_harvests.html.haml @@ -1,4 +1,8 @@ -%h2 Harvests +%h2 Harvests from this planting +- if planting.active? && can?(:edit, planting) + = link_to new_planting_harvest_path(planting), class: 'btn btn-default' do + %span.glyphicon.glyphicon-leaf{ title: "Harvest" } + Add Harvest - if planting.harvests.empty? %p No harvests - else @@ -7,7 +11,3 @@ .col-xs-6.col-sm-4.col-md-3 = render 'harvests/thumbnail', harvest: harvest -- if planting.active? && can?(:edit, planting) - = link_to new_planting_harvest_path(planting), class: 'btn btn-primary' do - %span.glyphicon.glyphicon-leaf{ title: "Harvest" } - Harvest diff --git a/app/views/plantings/_owner.haml b/app/views/plantings/_owner.haml new file mode 100644 index 000000000..9688edcbe --- /dev/null +++ b/app/views/plantings/_owner.haml @@ -0,0 +1,16 @@ +.row + .col-md-6 + %h4 + Planted by + = link_to @planting.owner, @planting.owner + = link_to "view all #{@planting.owner}'s plantings", member_gardens_path(@planting.owner) + + %p + Planted in + = link_to @planting.garden, @planting.garden + - if @planting.owner.location + %p + %small + View other plantings, members and more near + = link_to @planting.owner.location, place_path(@planting.owner.location, anchor: "plantings") + .col-md-6= render "members/avatar", member: @planting.owner \ No newline at end of file diff --git a/app/views/plantings/_planting.haml b/app/views/plantings/_planting.haml new file mode 100644 index 000000000..a85c3e9c3 --- /dev/null +++ b/app/views/plantings/_planting.haml @@ -0,0 +1,6 @@ +- if local_assigns[:full] + - cache planting do + = render 'plantings/card', planting: planting +- else + - cache planting do + = render 'plantings/thumbnail', planting: planting \ No newline at end of file diff --git a/app/views/plantings/_thumbnail.html.haml b/app/views/plantings/_thumbnail.html.haml index 2ce49fd94..976503c28 100644 --- a/app/views/plantings/_thumbnail.html.haml +++ b/app/views/plantings/_thumbnail.html.haml @@ -1,4 +1,4 @@ -.planting +.planting.col-md-2 .planting-thumbnail = render 'plantings/quick_actions', planting: planting = render 'plantings/badges', planting: planting diff --git a/app/views/plantings/index.html.haml b/app/views/plantings/index.html.haml index 8950082ec..fa66bd736 100644 --- a/app/views/plantings/index.html.haml +++ b/app/views/plantings/index.html.haml @@ -13,11 +13,7 @@ = page_entries_info @plantings = will_paginate @plantings -.card-row - - unless @plantings.empty? - - @plantings.each.with_index do |planting| - .card - = render partial: "plantings/card", locals: { planting: planting } +.row= render @plantings || "empty_list" .pagination = page_entries_info @plantings diff --git a/app/views/plantings/show.html.haml b/app/views/plantings/show.html.haml index 970aa43b7..7af0bf2ef 100644 --- a/app/views/plantings/show.html.haml +++ b/app/views/plantings/show.html.haml @@ -12,80 +12,34 @@ - content_for :buttonbar do = render 'plantings/actions', planting: @planting -.row.planting - .col-xs-12.col-sm-6 - %dl.dl-horizontal.planting-attributes - %dt Owner: - %dd - = link_to @planting.owner, @planting.owner - — - = link_to "view all #{@planting.owner}'s plantings", member_plantings_path(@planting.owner) +.planting + .row + .col-xs-12.col-sm-8 + .row + = render 'facts', planting: @planting + %hr/ + - if @planting.photos.size.positive? + .row + .col-sm-8 + = render 'plantings/badges', planting: @planting + = render @planting.default_photo + .col-sm-4 + = link_to 'View all photos >>', planting_photos_path(@planting), class: 'pull-right' + - @planting.photos.order(date_taken: :desc).limit(3).each do |photo| + = render('photos/thumbnail', photo: photo) - %dt Planted on: - %dd= @planting.planted_at ? @planting.planted_at : "not specified" + .col-xs-12.col-sm-4.pull-right + = render "crops/index_card", crop: @planting.crop + = render 'plantings/owner', planting: @planting - %dt Where: - %dd - = link_to "#{@planting.owner}'s", @planting.owner - = link_to @planting.garden, @planting.garden - - if @planting.owner.location.present? - (#{@planting.owner.location}) - %dt Quantity: - %dd= display_planting_quantity(@planting) - - %dt Planted from: - %dd - - if @planting.parent_seed - = link_to @planting.parent_seed, seed_path(@planting.parent_seed) - - else - = display_planted_from(@planting) - - %dt Sun or shade? - %dd - - sunniness = @planting.sunniness.blank? ? "not specified" : @planting.sunniness - = image_tag("sunniness_#{sunniness}.png", size: "25x25", alt: sunniness, title: sunniness) - = sunniness - - - unless @planting.crop.perennial - %dt Predicted finish: - %dd - - if @planting.finish_predicted_at.present? - = @planting.finish_predicted_at - - elsif @planting.planted_at.blank? - %strong Set planted date to get predictions - - if @planting.finished? - %dt Finished: - %dd= display_finished(@planting) - - if @planting.crop.median_lifespan.present? - %dt Expected Lifespan: - %dd #{@planting.crop.median_lifespan} days - - if @planting.lifespan.present? - %dt Actual Lifespan: - %dd #{@planting.lifespan} days - - if @planting.days_to_first_harvest.present? - %dt First Harvest: - %dd #{@planting.days_to_first_harvest} days after planting - - if @planting.days_to_last_harvest.present? - %dt Last Harvest: - %dd #{@planting.days_to_last_harvest} days after planting - - %dt Progress - %dd= render 'plantings/progress', planting: @planting, show_explanation: true - - .col-xs-12.col-sm-6 - = render partial: "crops/index_card", locals: { crop: @planting.crop } - - if @planting.owner.location - %p - %small - View other plantings, members and more near - = link_to @planting.owner.location, place_path(@planting.owner.location, anchor: "plantings") -.row - .col-md-6 - - if @planting.description - %h2 Notes - :growstuff_markdown - #{ @planting.description != "" ? strip_tags(@planting.description) : "No description given." } - = render 'plantings/harvests', planting: @planting - = render 'plantings/descendants', planting: @planting - .col-md-6 - = render 'photos/item_photos', item: @planting, type: 'planting', photos: @photos + .row + .col-md-12 + - if @planting.description + %h2 Notes + :growstuff_markdown + #{ @planting.description != "" ? strip_tags(@planting.description) : "No description given." } + .row + .col-md-6.col-sm-12 + = render 'plantings/harvests', planting: @planting + .col-md-6.col-sm-12 + = render 'plantings/descendants', planting: @planting diff --git a/db/migrate/20190326224347_add_harvests_count.rb b/db/migrate/20190326224347_add_harvests_count.rb new file mode 100644 index 000000000..8b2396713 --- /dev/null +++ b/db/migrate/20190326224347_add_harvests_count.rb @@ -0,0 +1,9 @@ +class AddHarvestsCount < ActiveRecord::Migration[5.2] + def change + add_column :plantings, :harvests_count, :integer, default: 0 + Planting.reset_column_information + Planting.pluck(:id).each do |planting_id| + Planting.reset_counters(planting_id, :harvests) + end + end +end diff --git a/db/schema.rb b/db/schema.rb index d0e1ac43e..d6cb3cbf4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2019_03_26_063855) do +ActiveRecord::Schema.define(version: 2019_03_26_224347) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -400,6 +400,7 @@ ActiveRecord::Schema.define(version: 2019_03_26_063855) do t.integer "days_to_first_harvest" t.integer "days_to_last_harvest" t.integer "parent_seed_id" + t.integer "harvests_count", default: 0 t.index ["slug"], name: "index_plantings_on_slug", unique: true end