From 5992c974c77c906014834fbe224fbbfc09397162 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 19 Mar 2018 17:04:30 +1300 Subject: [PATCH 01/82] Adding codeclimate coverage --- .travis.yml | 19 ++++++++++++------- script/install_codeclimate.sh | 4 ++++ script/install_elasticsearch.sh | 9 +++++++++ 3 files changed, 25 insertions(+), 7 deletions(-) create mode 100755 script/install_codeclimate.sh create mode 100755 script/install_elasticsearch.sh diff --git a/.travis.yml b/.travis.yml index 5d94d6a86..c53367de6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,17 +15,13 @@ env: - RAILS_SECRET_TOKEN='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' - secure: "Z5TpM2jEX4UCvNePnk/LwltQX48U2u9BRc+Iypr1x9QW2o228QJhPIOH39a8RMUrepGnkQIq9q3ZRUn98RfrJz1yThtlNFL3NmzdQ57gKgjGwfpa0e4Dwj/ZJqV2D84tDGjvdVYLP7zzaYZxQcwk/cgNpzKf/jq97HLNP7CYuf4=" before_install: - - ./script/install_phantomjs; + - ./script/install_phantomjs - export PATH=$PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64/bin:$PATH # Force Travis to use Elastic Search 2.4.0 - > if [ "${GROWSTUFF_ELASTICSEARCH}" = "true" ]; then - sudo dpkg -r elasticsearch; - curl -O https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.4.0/elasticsearch-2.4.0.deb; - sudo dpkg -i --force-confnew elasticsearch-2.4.0.deb; - sudo service elasticsearch start; - sleep 10; - curl localhost:9200; + ./scripts/install_elasticsearch.sh; + ./scripts/install_codeclimate.sh; fi before_script: - set -e @@ -36,6 +32,10 @@ before_script: RAILS_ENV=test bundle exec rake db:create db:migrate; bundle exec rake assets:precompile; fi + - > + if [ "${GROWSTUFF_ELASTICSEARCH}" = "true" ]; then + ./cc-test-reporter before-build; + fi - set +e script: - set -e @@ -48,6 +48,11 @@ script: bundle exec rake jasmine:ci; fi; - set +e +after_script: + - > + if [ "${GROWSTUFF_ELASTICSEARCH}" = "true" ]; then + ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT; + fi before_deploy: - bundle exec script/heroku_maintenance.rb on deploy: diff --git a/script/install_codeclimate.sh b/script/install_codeclimate.sh new file mode 100755 index 000000000..5a30249fb --- /dev/null +++ b/script/install_codeclimate.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter +chmod +x ./cc-test-reporter \ No newline at end of file diff --git a/script/install_elasticsearch.sh b/script/install_elasticsearch.sh new file mode 100755 index 000000000..bd1a1c52d --- /dev/null +++ b/script/install_elasticsearch.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -euv + +sudo dpkg -r elasticsearch; +curl -O https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.4.0/elasticsearch-2.4.0.deb +sudo dpkg -i --force-confnew elasticsearch-2.4.0.deb +sudo service elasticsearch start +sleep 10 +curl localhost:9200 \ No newline at end of file From 6089198f5c5cf43f96dea7ff8bedd3515133955e Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 19 Mar 2018 17:52:25 +1300 Subject: [PATCH 02/82] fixed path to scripts --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 18ddd6f07..c777f40d1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,8 +18,8 @@ before_install: - ./script/install_phantomjs.sh - export PATH=$PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64/bin:$PATH # Force Travis to use Elastic Search 2.4.0 - - ./scripts/install_codeclimate.sh - - ./scripts/install_linters.sh + - ./script/install_codeclimate.sh + - ./script/install_linters.sh before_script: - RAILS_ENV=test bundle exec rake db:create db:migrate - bundle exec rake assets:precompile From a178d3d42a76f4af52c0dcb7c26ea062c2471191 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 19 Mar 2018 18:02:26 +1300 Subject: [PATCH 03/82] Fix ES install on travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index c777f40d1..835b976bc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,6 +19,7 @@ before_install: - export PATH=$PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64/bin:$PATH # Force Travis to use Elastic Search 2.4.0 - ./script/install_codeclimate.sh + - ./script/install_elasticsearch.sh - ./script/install_linters.sh before_script: - RAILS_ENV=test bundle exec rake db:create db:migrate From 7f24927dc9a9803f8e444c28a5eb32f8efa1d0ee Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Tue, 20 Mar 2018 11:06:37 +1300 Subject: [PATCH 04/82] Clean up errors on undefined shell vars --- .travis.yml | 4 ++-- script/install_codeclimate.sh | 2 +- script/install_elasticsearch.sh | 4 ++-- script/install_linters.sh | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 835b976bc..5373a72a0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,8 +7,8 @@ cache: - tmp/cache/assets/test/sprockets env: matrix: - - GROWSTUFF_ELASTICSEARCH='true' RSPEC_TAG=elasticsearch STATIC_CHECKS=false COVERAGE=true - - GROWSTUFF_ELASTICSEARCH='false' RSPEC_TAG=~elasticsearch + - ELASTICSEARCH=true RSPEC_TAG=elasticsearch COVERAGE=true + - ELASTICSEARCH=false RSPEC_TAG=~elasticsearch COVERAGE=false - STATIC_CHECKS=true global: - GROWSTUFF_SITE_NAME="Growstuff (travis)" diff --git a/script/install_codeclimate.sh b/script/install_codeclimate.sh index 0ba36c7ba..f48091a9a 100755 --- a/script/install_codeclimate.sh +++ b/script/install_codeclimate.sh @@ -1,7 +1,7 @@ #!/bin/bash -set -euv if [ "${COVERAGE}" = "true" ]; then + set -euv curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter; chmod +x ./cc-test-reporter; fi diff --git a/script/install_elasticsearch.sh b/script/install_elasticsearch.sh index 892a82842..0f2f24c48 100755 --- a/script/install_elasticsearch.sh +++ b/script/install_elasticsearch.sh @@ -1,7 +1,7 @@ #!/bin/bash -set -euv -if [ "${GROWSTUFF_ELASTICSEARCH}" = "true" ]; then +if [ "${ELASTICSEARCH}" = "true" ]; then + set -euv sudo dpkg -r elasticsearch curl -O https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.4.0/elasticsearch-2.4.0.deb sudo dpkg -i --force-confnew elasticsearch-2.4.0.deb diff --git a/script/install_linters.sh b/script/install_linters.sh index a753a7943..679a6b64a 100755 --- a/script/install_linters.sh +++ b/script/install_linters.sh @@ -1,7 +1,7 @@ #!/bin/bash -set -euv if [ "${STATIC_CHECKS}" = "true" ]; then + set -euv gem install --update overcommit rubocop haml-lint bundler-audit; npm install; pip install yamllint --user; From a1e33ae36eb8edf18211b099acc9b7cd6b4dae26 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Tue, 20 Mar 2018 11:13:11 +1300 Subject: [PATCH 05/82] Only set up database and assets in test run, not linter run --- .travis.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5373a72a0..838b697ae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,20 +17,19 @@ env: before_install: - ./script/install_phantomjs.sh - export PATH=$PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64/bin:$PATH - # Force Travis to use Elastic Search 2.4.0 - ./script/install_codeclimate.sh - - ./script/install_elasticsearch.sh - ./script/install_linters.sh -before_script: - - RAILS_ENV=test bundle exec rake db:create db:migrate - - bundle exec rake assets:precompile + # Force Travis to use Elastic Search 2.4.0 + - ./script/install_elasticsearch.sh script: - set -e - > if [ "${STATIC_CHECKS}" = "true" ]; then ./script/check_static.rb else - bundle exec rake db:migrate --trace; + set +e; + RAILS_ENV=test bundle exec rake db:create db:migrate; + bundle exec rake assets:precompile; bundle exec rspec --tag $RSPEC_TAG spec/; bundle exec rake jasmine:ci; fi; From 00ea96a73eb75e7c72c8d82c38e17e0bdff40cff Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Tue, 20 Mar 2018 11:35:01 +1300 Subject: [PATCH 06/82] Can't rename GROWSTUFF_ELASTICSEARCH --- .travis.yml | 4 ++-- script/install_elasticsearch.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 838b697ae..a93298a55 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,8 +7,8 @@ cache: - tmp/cache/assets/test/sprockets env: matrix: - - ELASTICSEARCH=true RSPEC_TAG=elasticsearch COVERAGE=true - - ELASTICSEARCH=false RSPEC_TAG=~elasticsearch COVERAGE=false + - GROWSTUFF_ELASTICSEARCH=true RSPEC_TAG=elasticsearch COVERAGE=true + - GROWSTUFF_ELASTICSEARCH=false RSPEC_TAG=~elasticsearch COVERAGE=false - STATIC_CHECKS=true global: - GROWSTUFF_SITE_NAME="Growstuff (travis)" diff --git a/script/install_elasticsearch.sh b/script/install_elasticsearch.sh index 0f2f24c48..1543a71bc 100755 --- a/script/install_elasticsearch.sh +++ b/script/install_elasticsearch.sh @@ -1,6 +1,6 @@ #!/bin/bash -if [ "${ELASTICSEARCH}" = "true" ]; then +if [ "${GROWSTUFF_ELASTICSEARCH}" = "true" ]; then set -euv sudo dpkg -r elasticsearch curl -O https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.4.0/elasticsearch-2.4.0.deb From f1afe1ca792a2a741aa62012931a7dc6351c0874 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sun, 1 Apr 2018 12:44:59 +1200 Subject: [PATCH 07/82] Expanding layout to use full screen --- app/assets/stylesheets/overrides.sass | 5 ++++ app/models/crop.rb | 6 ++-- app/models/planting.rb | 2 +- app/views/harvests/_list.html.haml | 7 ++--- app/views/home/_blurb.html.haml | 29 +++++++++---------- app/views/home/_crops.html.haml | 5 ++-- app/views/home/_harvests.html.haml | 2 +- app/views/home/_plantings.html.haml | 2 +- app/views/home/_seeds.html.haml | 2 +- app/views/home/index.html.haml | 6 ++-- app/views/layouts/application.html.haml | 2 +- .../plantings/_image_with_popover.html.haml | 2 +- app/views/plantings/_list.html.haml | 11 ++----- app/views/plantings/_popover.html.haml | 18 +++++++----- 14 files changed, 49 insertions(+), 50 deletions(-) diff --git a/app/assets/stylesheets/overrides.sass b/app/assets/stylesheets/overrides.sass index 338a2dbc5..25ade49a6 100644 --- a/app/assets/stylesheets/overrides.sass +++ b/app/assets/stylesheets/overrides.sass @@ -146,6 +146,7 @@ p.stats border: none text-align: center margin-bottom: 1.5em + max-width: 160px .member-thumbnail text-align: left @@ -221,6 +222,7 @@ footer #maincontainer min-height: 80% + padding: 50px 50px 50px 50px html, body height: 100% @@ -334,3 +336,6 @@ ul.thumbnail-buttons height: 180px .seed-thumbnail height: 220px + + #maincontainer + padding: 10px \ No newline at end of file diff --git a/app/models/crop.rb b/app/models/crop.rb index 682610436..490a35d71 100644 --- a/app/models/crop.rb +++ b/app/models/crop.rb @@ -26,13 +26,11 @@ class Crop < ActiveRecord::Base ## Scopes scope :recent, -> { approved.order(created_at: :desc) } scope :toplevel, -> { approved.where(parent_id: nil) } - scope :popular, -> { approved.reorder("plantings_count desc, lower(name) asc") } - # ok on sqlite and psql, but not on mysql - scope :randomized, -> { approved.reorder('random()') } + scope :popular, -> { approved.order("plantings_count desc, lower(name) asc") } scope :pending_approval, -> { where(approval_status: "pending") } scope :approved, -> { where(approval_status: "approved") } scope :rejected, -> { where(approval_status: "rejected") } - scope :interesting, -> { approved.has_photos.randomized } + scope :interesting, -> { approved.has_photos } scope :has_photos, -> { includes(:photos).where.not(photos: { id: nil }) } ## diff --git a/app/models/planting.rb b/app/models/planting.rb index e358a6bb4..715a494f7 100644 --- a/app/models/planting.rb +++ b/app/models/planting.rb @@ -17,7 +17,7 @@ class Planting < ActiveRecord::Base before_save :calculate_lifespan belongs_to :garden - belongs_to :owner, class_name: 'Member', counter_cache: true + belongs_to :owner, class_name: 'Member', foreign_key: 'owner_id', counter_cache: true belongs_to :crop, counter_cache: true has_many :harvests, dependent: :destroy diff --git a/app/views/harvests/_list.html.haml b/app/views/harvests/_list.html.haml index bb0178238..8e4e1a7a1 100644 --- a/app/views/harvests/_list.html.haml +++ b/app/views/harvests/_list.html.haml @@ -1,11 +1,10 @@ - harvests.each do |h| - cache h do .row - .col-md-3.col-xs-4{ style: 'padding-bottom: 6px' } + .col-lg-6.col-md-3.col-xs-4.homepage-listing = render 'harvests/image_with_popover', harvest: h - .col-md-9.col-xs-4 + .col-lg-3.col-md-9.col-xs-4 = link_to h.crop, crop_path(h.crop) %br/ %small - %i - = h.owner.location + %i= h.owner.location diff --git a/app/views/home/_blurb.html.haml b/app/views/home/_blurb.html.haml index 0459d1095..81e65510f 100644 --- a/app/views/home/_blurb.html.haml +++ b/app/views/home/_blurb.html.haml @@ -1,16 +1,13 @@ -.col-md-12 - -%h1= ENV['GROWSTUFF_SITE_NAME'] - -.row - .col-md-8.info - %p= t('.intro', site_name: ENV['GROWSTUFF_SITE_NAME']) - - = render partial: 'stats' - .col-md-4.signup - %p= t('.perks') - %p= link_to(t('.sign_up'), new_member_registration_path, class: 'btn btn-primary btn-lg') - %p - %small - = t('.already_html', sign_in: link_to(t('.sign_in_linktext'), new_member_session_path)) - +.container + .row + .col-md-12 + %h1= ENV['GROWSTUFF_SITE_NAME'] + .col-md-8.info + %p= t('.intro', site_name: ENV['GROWSTUFF_SITE_NAME']) + = render partial: 'stats' + .col-md-4.signup + %p= t('.perks') + %p= link_to(t('.sign_up'), new_member_registration_path, class: 'btn btn-primary btn-lg') + %p + %small + = t('.already_html', sign_in: link_to(t('.sign_in_linktext'), new_member_session_path)) diff --git a/app/views/home/_crops.html.haml b/app/views/home/_crops.html.haml index bfcbc9a71..8cffe4b78 100644 --- a/app/views/home/_crops.html.haml +++ b/app/views/home/_crops.html.haml @@ -1,5 +1,6 @@ - cache cache_key_for(Crop, 'interesting'), expires_in: 1.day do .row %h2= t('.our_crops') - - Crop.interesting.includes(:scientific_names, :photos).limit(8).each do |c| - .col-md-4.col-sm-3.col-xs-6= render 'crops/thumbnail', crop: c + - Crop.interesting.includes(:scientific_names, :photos).shuffle.first(12).each do |c| + .col-lg-2.col-md-4.col-sm-3.col-xs-6 + = render 'crops/thumbnail', crop: c diff --git a/app/views/home/_harvests.html.haml b/app/views/home/_harvests.html.haml index d4c2a1117..2229eae63 100644 --- a/app/views/home/_harvests.html.haml +++ b/app/views/home/_harvests.html.haml @@ -1,3 +1,3 @@ - cache cache_key_for(Harvest) do %h2 Recently Harvested - = render 'harvests/list', harvests: Harvest.includes(:crop, :owner, :photos).has_photos.recent.first(5) + = render 'harvests/list', harvests: Harvest.includes(:crop, :owner, :photos).has_photos.recent.first(6) diff --git a/app/views/home/_plantings.html.haml b/app/views/home/_plantings.html.haml index 595ad4586..dd631d2ff 100644 --- a/app/views/home/_plantings.html.haml +++ b/app/views/home/_plantings.html.haml @@ -1,3 +1,3 @@ - cache cache_key_for(Planting, 'home'), expires_in: 1.day do %h2= t('.recently_planted') - = render 'plantings/list', plantings: Planting.includes(:crop, garden: :owner).has_photos.recent.limit(5) + = render 'plantings/list', plantings: Planting.includes(:crop, garden: :owner).has_photos.recent.limit(6) diff --git a/app/views/home/_seeds.html.haml b/app/views/home/_seeds.html.haml index d53759738..4a28f9590 100644 --- a/app/views/home/_seeds.html.haml +++ b/app/views/home/_seeds.html.haml @@ -1,7 +1,7 @@ - cache cache_key_for(Seed, 'interesting'), expires_in: 1.day do %h2= t('.title') .row - - Seed.current.tradable.order(created_at: :desc).limit(6).each do |seed| + - Seed.current.tradable.includes(:owner, :crop).order(created_at: :desc).limit(6).each do |seed| .col-md-2.col-sm-2.col-xs-6 .thumbnail.seed-thumbnail - cache cache_key_for(Crop, seed.id) do diff --git a/app/views/home/index.html.haml b/app/views/home/index.html.haml index c28a8985b..d05d6a37a 100644 --- a/app/views/home/index.html.haml +++ b/app/views/home/index.html.haml @@ -19,11 +19,11 @@ = render 'blurb' .row - .col-md-6.col-sm-12 + .col-lg-8.col-md-6.col-sm-12 = render 'crops' - .col-md-3.col-sm-6 + .col-lg-2.col-md-3.col-sm-6 = render 'plantings' - .col-md-3.col-sm-6 + .col-lg-2.col-md-3.col-sm-6 = render 'harvests' .col-md-12 - cache cache_key_for(Crop, 'recent') do diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 2c0f6b9bb..6b9cfd40f 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -5,7 +5,7 @@ %body = render partial: "layouts/header" - .container#maincontainer + #maincontainer .row .col-md-12 - if content_for?(:title) diff --git a/app/views/plantings/_image_with_popover.html.haml b/app/views/plantings/_image_with_popover.html.haml index 70bfc1836..740562fda 100644 --- a/app/views/plantings/_image_with_popover.html.haml +++ b/app/views/plantings/_image_with_popover.html.haml @@ -5,6 +5,6 @@ planting, rel: "popover", 'data-trigger': 'hover', - 'data-title': planting.to_s, + 'data-title': planting.crop.name, 'data-content': render('plantings/popover', planting: planting), 'data-html': true diff --git a/app/views/plantings/_list.html.haml b/app/views/plantings/_list.html.haml index aa7dcf9fa..21be75416 100644 --- a/app/views/plantings/_list.html.haml +++ b/app/views/plantings/_list.html.haml @@ -1,15 +1,10 @@ - plantings.each do |p| - cache p do .row - .col-md-3.col-xs-4.homepage-listing + .col-lg-6.col-md-3.col-xs-4.homepage-listing = render 'plantings/image_with_popover', planting: p - .col-md-9.col-xs-4 + .col-lg-3.col-md-9.col-xs-4 = link_to p.crop, p.crop - in - = succeed "'s" do - = link_to p.garden.owner, p.garden.owner - = link_to display_garden_name(p.garden), p.garden %br/ %small - %i - = p.location + %i= p.location diff --git a/app/views/plantings/_popover.html.haml b/app/views/plantings/_popover.html.haml index d7a83f616..44fd1744f 100644 --- a/app/views/plantings/_popover.html.haml +++ b/app/views/plantings/_popover.html.haml @@ -1,7 +1,11 @@ -%p - %small - Quantity: - = planting.quantity ? planting.quantity : 'unknown' - %br/ - Planted on: - = planting.planted_at.to_s +- if planting.quantity.present? + %p + %small + Quantity: + = planting.quantity + +- if planting.planted_at.present? + %p + %small + Planted: + = planting.planted_at.to_s From b7f78d5dc9f645d5181e93855d6eb9b300c735c6 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sun, 1 Apr 2018 13:04:08 +1200 Subject: [PATCH 08/82] Fix ordering of recent plantings on crops#show --- app/views/crops/_plantings.html.haml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/views/crops/_plantings.html.haml b/app/views/crops/_plantings.html.haml index 351c6ba4c..ca05632a3 100644 --- a/app/views/crops/_plantings.html.haml +++ b/app/views/crops/_plantings.html.haml @@ -4,9 +4,9 @@ Nobody has planted this crop yet. - else %ul - - crop.plantings.take(3).each do |planting| + - crop.plantings.order(planted_at: :desc).limit(3).each do |planting| %li - = link_to display_planting(planting), planting_path(planting) + = link_to planting, planting_path(planting) = render partial: 'members/location', locals: { member: planting.owner } %small = distance_of_time_in_words(planting.created_at, Time.zone.now) @@ -18,4 +18,3 @@ %p= link_to "Plant #{crop.name}", new_planting_path(crop_id: crop.id) - else = render partial: 'shared/signin_signup', locals: { to: "track your #{crop.name} plantings" } - From b64a2942455fe4920cb615493a283ab919727aef Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sun, 1 Apr 2018 18:45:35 +1200 Subject: [PATCH 09/82] Removed duplicate margins in css --- app/assets/stylesheets/overrides.sass | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/stylesheets/overrides.sass b/app/assets/stylesheets/overrides.sass index 25ade49a6..6a97975fb 100644 --- a/app/assets/stylesheets/overrides.sass +++ b/app/assets/stylesheets/overrides.sass @@ -222,7 +222,7 @@ footer #maincontainer min-height: 80% - padding: 50px 50px 50px 50px + padding: 50px html, body height: 100% @@ -338,4 +338,4 @@ ul.thumbnail-buttons height: 220px #maincontainer - padding: 10px \ No newline at end of file + padding: 10px From 1fb3c4e0f96c9afadba2c2d92a9e6e750f337c58 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 2 Apr 2018 09:47:04 +1200 Subject: [PATCH 10/82] Regnerated and secured code climate key --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a93298a55..b51a53277 100644 --- a/.travis.yml +++ b/.travis.yml @@ -61,4 +61,5 @@ after_deploy: - bundle exec script/heroku_maintenance.rb off addons: code_climate: - repo_token: 462e015bbdaabfb20910fc07f2fea253410ecb131444e00f97dbf32dc6789ca6 + repo_token: + secure: "PfhLGBKRgNqhKuYCJsK+VPhdAzcgWFGeeOyxC/eS8gtlvIISVdgyZE+r30uIei0DFI6zEiN62eW4d+xtT4j7/e2ZcAcx7U52mza/SnQNuu3nCGQDJB8VOvV5NbnwXfi8vfr4e889Mt7k3ocd2c4gqB4UtRqrzhygj7HN+B/GfEk=" From e3bb43477b8ee06386edc930aebe837144c1d780 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 2 Apr 2018 10:13:19 +1200 Subject: [PATCH 11/82] Adding counter caches and ownable concern --- app/models/concerns/ownable.rb | 7 +++++++ app/models/forum.rb | 2 +- app/models/garden.rb | 2 +- app/models/harvest.rb | 2 +- app/models/photo.rb | 2 +- app/models/planting.rb | 2 +- app/models/seed.rb | 3 +-- db/migrate/20180401220637_add_member_count_caches.rb | 6 ++++++ db/schema.rb | 4 +++- 9 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 app/models/concerns/ownable.rb create mode 100644 db/migrate/20180401220637_add_member_count_caches.rb diff --git a/app/models/concerns/ownable.rb b/app/models/concerns/ownable.rb new file mode 100644 index 000000000..b9f229973 --- /dev/null +++ b/app/models/concerns/ownable.rb @@ -0,0 +1,7 @@ +module Ownable + extend ActiveSupport::Concern + + included do + belongs_to :owner, class_name: 'Member', foreign_key: 'owner_id', counter_cache: true + end +end diff --git a/app/models/forum.rb b/app/models/forum.rb index 7cbc0d43d..34afad592 100644 --- a/app/models/forum.rb +++ b/app/models/forum.rb @@ -1,10 +1,10 @@ class Forum < ActiveRecord::Base extend FriendlyId + include Ownable validates :name, presence: true friendly_id :name, use: %i(slugged finders) has_many :posts - belongs_to :owner, class_name: "Member" def to_s name diff --git a/app/models/garden.rb b/app/models/garden.rb index 0c3378b00..682796674 100644 --- a/app/models/garden.rb +++ b/app/models/garden.rb @@ -2,9 +2,9 @@ class Garden < ActiveRecord::Base extend FriendlyId include Geocodable include PhotoCapable + include Ownable friendly_id :garden_slug, use: %i(slugged finders) - belongs_to :owner, class_name: 'Member', foreign_key: 'owner_id', counter_cache: true has_many :plantings, dependent: :destroy has_many :crops, through: :plantings diff --git a/app/models/harvest.rb b/app/models/harvest.rb index 9bc4195b4..2b0a5a3a1 100644 --- a/app/models/harvest.rb +++ b/app/models/harvest.rb @@ -2,6 +2,7 @@ class Harvest < ActiveRecord::Base include ActionView::Helpers::NumberHelper extend FriendlyId include PhotoCapable + include Ownable friendly_id :harvest_slug, use: %i(slugged finders) @@ -33,7 +34,6 @@ class Harvest < ActiveRecord::Base ## ## Relationships belongs_to :crop - belongs_to :owner, class_name: 'Member', counter_cache: true belongs_to :plant_part belongs_to :planting diff --git a/app/models/photo.rb b/app/models/photo.rb index 07531672b..75a35b10a 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -1,5 +1,5 @@ class Photo < ActiveRecord::Base - belongs_to :owner, class_name: 'Member' + include Ownable PHOTO_CAPABLE = %w(Garden Planting Harvest Seed).freeze diff --git a/app/models/planting.rb b/app/models/planting.rb index e358a6bb4..3dff4c006 100644 --- a/app/models/planting.rb +++ b/app/models/planting.rb @@ -2,6 +2,7 @@ class Planting < ActiveRecord::Base extend FriendlyId include PhotoCapable include Finishable + include Ownable friendly_id :planting_slug, use: %i(slugged finders) # Constants @@ -17,7 +18,6 @@ class Planting < ActiveRecord::Base before_save :calculate_lifespan belongs_to :garden - belongs_to :owner, class_name: 'Member', counter_cache: true belongs_to :crop, counter_cache: true has_many :harvests, dependent: :destroy diff --git a/app/models/seed.rb b/app/models/seed.rb index 63c88a47c..e83747b77 100644 --- a/app/models/seed.rb +++ b/app/models/seed.rb @@ -2,6 +2,7 @@ class Seed < ActiveRecord::Base extend FriendlyId include PhotoCapable include Finishable + include Ownable friendly_id :seed_slug, use: %i(slugged finders) TRADABLE_TO_VALUES = %w(nowhere locally nationally internationally).freeze @@ -12,8 +13,6 @@ class Seed < ActiveRecord::Base # # Relationships belongs_to :crop - belongs_to :owner, class_name: 'Member', foreign_key: 'owner_id', counter_cache: true - belongs_to :parent_planting, class_name: 'Planting', foreign_key: 'parent_planting_id' # parent has_many :child_plantings, class_name: 'Planting', foreign_key: 'parent_seed_id', dependent: :nullify # children diff --git a/db/migrate/20180401220637_add_member_count_caches.rb b/db/migrate/20180401220637_add_member_count_caches.rb new file mode 100644 index 000000000..151f19fcd --- /dev/null +++ b/db/migrate/20180401220637_add_member_count_caches.rb @@ -0,0 +1,6 @@ +class AddMemberCountCaches < ActiveRecord::Migration + def change + add_column :members, :photos_count, :integer + add_column :members, :forums_count, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 7e9cad2e0..71338e4a2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180213005731) do +ActiveRecord::Schema.define(version: 20180401220637) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -318,6 +318,8 @@ ActiveRecord::Schema.define(version: 20180213005731) do t.integer "harvests_count" t.integer "seeds_count" t.datetime "deleted_at" + t.integer "photos_count" + t.integer "forums_count" end add_index "members", ["confirmation_token"], name: "index_members_on_confirmation_token", unique: true, using: :btree From 106d187e675458896f42bcb4ca85c52f3f4d3e7a Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 2 Apr 2018 10:29:10 +1200 Subject: [PATCH 12/82] Add dependent clauses on crop model --- app/models/crop.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/crop.rb b/app/models/crop.rb index 682610436..6264991bb 100644 --- a/app/models/crop.rb +++ b/app/models/crop.rb @@ -11,15 +11,15 @@ class Crop < ActiveRecord::Base has_many :scientific_names, after_add: :update_index, after_remove: :update_index, dependent: :destroy accepts_nested_attributes_for :scientific_names, allow_destroy: true, reject_if: :all_blank has_many :alternate_names, after_add: :update_index, after_remove: :update_index, dependent: :destroy - has_many :plantings + has_many :plantings, dependent: :destroy + has_many :seeds, dependent: :destroy + has_many :harvests, dependent: :destroy has_many :photos, through: :plantings - has_many :seeds - has_many :harvests has_many :plant_parts, -> { uniq.reorder("plant_parts.name") }, through: :harvests belongs_to :creator, class_name: 'Member' belongs_to :requester, class_name: 'Member' belongs_to :parent, class_name: 'Crop' - has_many :varieties, class_name: 'Crop', foreign_key: 'parent_id' + has_many :varieties, class_name: 'Crop', foreign_key: 'parent_id', dependent: :nullify has_and_belongs_to_many :posts # rubocop:disable Rails/HasAndBelongsToMany ## From 43813d1318b8842325cc2b8652358b9699c51e9e Mon Sep 17 00:00:00 2001 From: jenkr55 Date: Sat, 7 Apr 2018 14:58:07 -0500 Subject: [PATCH 13/82] Fixing various wrapping issues --- CONTRIBUTORS.md | 1 + app/assets/stylesheets/overrides.sass | 8 +++++++- app/views/seeds/index.html.haml | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 568137391..4b79a82a7 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -83,6 +83,7 @@ submit the change with your pull request. - Jeff Kingswood / [ancyentmariner](https://github.com/ancyentmariner) - Logan Gingerich / [logangingerich](https://github.com/logangingerich) - Mark Taffman / [mftaff](https://github.com/mftaff) +- Jennifer Kruse / [mftaff](https://github.com/mftaff) ## Bots diff --git a/app/assets/stylesheets/overrides.sass b/app/assets/stylesheets/overrides.sass index 6a97975fb..71dc96630 100644 --- a/app/assets/stylesheets/overrides.sass +++ b/app/assets/stylesheets/overrides.sass @@ -73,10 +73,16 @@ p.stats display: flex flex: none flex-wrap: wrap - justify-content: space-between + +.seeds-row + display: grid + grid-template-columns: 50% 50% + grid-gap: 25px + grid-row-gap: 5px .member-thumbnail padding: .25em + margin: 1em div width: 5em diff --git a/app/views/seeds/index.html.haml b/app/views/seeds/index.html.haml index e7e1ec3e3..0be394edf 100644 --- a/app/views/seeds/index.html.haml +++ b/app/views/seeds/index.html.haml @@ -24,10 +24,10 @@ = page_entries_info @seeds = will_paginate @seeds -.row +.seeds-row - unless @seeds.empty? - @seeds.each do |seed| - .col-md-6 + .seedcard = render 'seeds/card', seed: seed .pagination From efa8c513eaacedf89fa6f91a3e6b36dd1019179d Mon Sep 17 00:00:00 2001 From: jenkr55 Date: Sat, 7 Apr 2018 14:59:14 -0500 Subject: [PATCH 14/82] Adding myself as a contributor --- CONTRIBUTORS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 4b79a82a7..87b153b17 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -83,7 +83,7 @@ submit the change with your pull request. - Jeff Kingswood / [ancyentmariner](https://github.com/ancyentmariner) - Logan Gingerich / [logangingerich](https://github.com/logangingerich) - Mark Taffman / [mftaff](https://github.com/mftaff) -- Jennifer Kruse / [mftaff](https://github.com/mftaff) +- Jennifer Kruse / [jenkr55](https://github.com/jenkr55) ## Bots From 3e2b4f4183fc7a4ab7b5698586210a3cddb0f02a Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sun, 8 Apr 2018 09:56:19 +1200 Subject: [PATCH 15/82] Pick the first photo --- app/helpers/photos_helper.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/helpers/photos_helper.rb b/app/helpers/photos_helper.rb index b77f35bd9..618e0ac93 100644 --- a/app/helpers/photos_helper.rb +++ b/app/helpers/photos_helper.rb @@ -17,7 +17,7 @@ module PhotosHelper def planting_image_path(planting) if planting.photos.present? - planting.photos.first.thumbnail_url + planting.photos.order(date_taken: :desc).first.thumbnail_url else placeholder_image end @@ -25,9 +25,9 @@ module PhotosHelper def harvest_image_path(harvest) if harvest.photos.present? - harvest.photos.first.thumbnail_url - elsif harvest.planting.present? && harvest.planting.photos.present? - harvest.planting.photos.first.thumbnail_url + harvest.photos.order(date_taken: :desc).first.thumbnail_url + elsif harvest.planting.present? + planting_image_path(harvest.planting) else placeholder_image end From 6b68e9ee4d58b11c21205e96f7292014fd5ac805 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sun, 8 Apr 2018 10:04:43 +1200 Subject: [PATCH 16/82] Style fix --- app/helpers/photos_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/photos_helper.rb b/app/helpers/photos_helper.rb index 618e0ac93..6087a9c74 100644 --- a/app/helpers/photos_helper.rb +++ b/app/helpers/photos_helper.rb @@ -27,7 +27,7 @@ module PhotosHelper if harvest.photos.present? harvest.photos.order(date_taken: :desc).first.thumbnail_url elsif harvest.planting.present? - planting_image_path(harvest.planting) + planting_image_path(harvest.planting) else placeholder_image end From d38167fd14de267a221c76ca69b8775f34adb2f4 Mon Sep 17 00:00:00 2001 From: jenkr55 Date: Sun, 8 Apr 2018 09:47:15 -0500 Subject: [PATCH 17/82] Only show planting suggestion if theres a match --- app/views/harvests/_planting.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/harvests/_planting.haml b/app/views/harvests/_planting.haml index 085f24c7c..c58f5f6f4 100644 --- a/app/views/harvests/_planting.haml +++ b/app/views/harvests/_planting.haml @@ -3,7 +3,7 @@ planting_path(@harvest.planting) in = link_to @harvest.planting.garden, garden_path(@harvest.planting.garden) -- elsif @matching_plantings && @harvest.owner == current_member +- elsif @matching_plantings.any? && @harvest.owner == current_member Is this from one of these plantings? = form_for(@harvest) do |f| - @matching_plantings.each do |planting| From 9c0ddb61e7406a042dadf1b1ac751156a0f24fce Mon Sep 17 00:00:00 2001 From: jenkr55 Date: Sun, 8 Apr 2018 10:17:06 -0500 Subject: [PATCH 18/82] Prevent error when @matching_plantings is nil --- app/views/harvests/_planting.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/harvests/_planting.haml b/app/views/harvests/_planting.haml index c58f5f6f4..6e6ba03c2 100644 --- a/app/views/harvests/_planting.haml +++ b/app/views/harvests/_planting.haml @@ -3,7 +3,7 @@ planting_path(@harvest.planting) in = link_to @harvest.planting.garden, garden_path(@harvest.planting.garden) -- elsif @matching_plantings.any? && @harvest.owner == current_member +- elsif @matching_plantings && @matching_plantings.any? && @harvest.owner == current_member Is this from one of these plantings? = form_for(@harvest) do |f| - @matching_plantings.each do |planting| From d1603a6e7fe08a647c0de82b8ed8408fd6c4a0e4 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 16 Apr 2018 07:18:15 +1200 Subject: [PATCH 19/82] Badges showing finished and harvest status --- app/assets/stylesheets/overrides.sass | 3 ++ app/helpers/plantings_helper.rb | 10 +++++ app/models/planting.rb | 47 ++++++++++++++++++++++++ app/views/gardens/_overview.html.haml | 7 +--- app/views/plantings/_badges.html.haml | 15 ++++++++ app/views/plantings/_thumbnail.html.haml | 13 ++++--- 6 files changed, 84 insertions(+), 11 deletions(-) create mode 100644 app/views/plantings/_badges.html.haml diff --git a/app/assets/stylesheets/overrides.sass b/app/assets/stylesheets/overrides.sass index 71dc96630..293e8aea7 100644 --- a/app/assets/stylesheets/overrides.sass +++ b/app/assets/stylesheets/overrides.sass @@ -100,6 +100,9 @@ p.stats dd margin-left: auto +.planting-badges + position: absolute + #placesmap, #cropmap height: 500px diff --git a/app/helpers/plantings_helper.rb b/app/helpers/plantings_helper.rb index f71dc8158..b5dac192a 100644 --- a/app/helpers/plantings_helper.rb +++ b/app/helpers/plantings_helper.rb @@ -32,4 +32,14 @@ module PlantingsHelper def plantings_active_tickbox_path(owner, show_all) show_inactive_tickbox_path('plantings', owner, show_all) end + + def days_from_now_to_finished(planting) + return unless planting.finish_predicted_at.present? && planting.finish_predicted_at > Time.zone.today + (planting.finish_predicted_at - Time.zone.today).to_i + end + + def days_from_now_to_first_harvest(planting) + return unless planting.planted_at.present? && planting.first_harvest_predicted_at.present? + (planting.first_harvest_predicted_at - Time.zone.today).to_i + end end diff --git a/app/models/planting.rb b/app/models/planting.rb index 3dff4c006..0ac677abf 100644 --- a/app/models/planting.rb +++ b/app/models/planting.rb @@ -89,6 +89,16 @@ class Planting < ActiveRecord::Base planted_at + crop.median_lifespan.days if crop.median_lifespan.present? && planted_at.present? end + def first_harvest_predicted_at + return unless crop.median_days_to_first_harvest.present? && planted_at.present? + planted_at + crop.median_days_to_first_harvest.days + end + + def last_harvest_predicted_at + return unless crop.median_days_to_last_harvest.present? && planted_at.present? + planted_at + crop.median_days_to_last_harvest.days + end + def calculate_lifespan self.lifespan = (planted_at.present? && finished_at.present? ? finished_at - planted_at : nil) end @@ -130,6 +140,43 @@ class Planting < ActiveRecord::Base harvests_with_dates.maximum(:harvested_at) end + def zombie? + crop.annual? && !finished && + planted_at.present? && + finish_predicted_at.present? && + (finish_predicted_at + 60.days) < Time.zone.today + end + + def living_past_predicted_finished? + crop.annual? && !finished && + planted_at.present? && + finish_predicted_at.present? && + finish_predicted_at > Time.zone.today + end + + def harvest_time? + return false if crop.perennial || finished + + # We have harvests but haven't finished + harvests.size.positive? || + + # or, we don't have harvests, but we predict we should by now + (first_harvest_predicted_at.present? && + harvests.empty? && + first_harvest_predicted_at < Time.zone.today) + end + + def before_harvest_time? + first_harvest_predicted_at.present? && + harvests.empty? && + first_harvest_predicted_at.present? && + first_harvest_predicted_at > Time.zone.today + end + + def age_in_days + (Time.zone.today - planted_at).to_i if planted_at.present? + end + private def harvests_with_dates diff --git a/app/views/gardens/_overview.html.haml b/app/views/gardens/_overview.html.haml index b8f9ce54a..978a6abbf 100644 --- a/app/views/gardens/_overview.html.haml +++ b/app/views/gardens/_overview.html.haml @@ -13,12 +13,9 @@ .col-md-10 .row - if garden.plantings.current.size.positive? - - garden.plantings.current.includes(:crop).each do |planting| + - garden.plantings.current.includes(:crop, :photos).each do |planting| .col-md-2.col-sm-6.col-xs-6 - .hover-wrapper - .text - = render 'plantings/actions', planting: planting - = render partial: "plantings/thumbnail", locals: { planting: planting } + = render "plantings/thumbnail", planting: planting - else .col-md-2.col-sm-6.col-xs-6 no plantings - if can?(:edit, garden) diff --git a/app/views/plantings/_badges.html.haml b/app/views/plantings/_badges.html.haml new file mode 100644 index 000000000..2e0c078b7 --- /dev/null +++ b/app/views/plantings/_badges.html.haml @@ -0,0 +1,15 @@ +// Finish times +- if planting.zombie? + %span.badge.badge-danger zombie +- elsif planting.living_past_predicted_finished? + %span.badge.badge-light + = days_from_now_to_finished(planting) + days until finished + +// Harvest times +- if planting.harvest_time? + %span.badge.badge-light harvest time +- elsif planting.before_harvest_time? + %span.badge.badge-light + = days_from_now_to_first_harvest(planting) + days until harvest diff --git a/app/views/plantings/_thumbnail.html.haml b/app/views/plantings/_thumbnail.html.haml index e34c653da..6d52308cd 100644 --- a/app/views/plantings/_thumbnail.html.haml +++ b/app/views/plantings/_thumbnail.html.haml @@ -1,9 +1,10 @@ -.thumbnail - .planting-thumbnail - - if planting - = link_to image_tag(planting_image_path(planting), - alt: planting.crop.name, class: 'img'), - planting +.planting-badges + = render 'plantings/badges', planting: planting +.hover-wrapper + .text= render 'plantings/actions', planting: planting + .thumbnail + .planting-thumbnail + = link_to image_tag(planting_image_path(planting), alt: planting.crop.name, class: 'img'), planting_path(planting) .plantinginfo .planting-name = render 'plantings/progress', planting: planting, show_explanation: false From d043613bde97bfdc7ef86f0d5803fb4c4b4c9e11 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 16 Apr 2018 21:14:47 +1200 Subject: [PATCH 20/82] Model specs for harvest time and zombies --- spec/models/planting_spec.rb | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/spec/models/planting_spec.rb b/spec/models/planting_spec.rb index 6948caa75..404d50e69 100644 --- a/spec/models/planting_spec.rb +++ b/spec/models/planting_spec.rb @@ -97,8 +97,10 @@ describe Planting do it { expect(planting.expected_lifespan).to eq(nil) } end context 'lots of data' do + let(:crop) { FactoryBot.create :crop } + # this is a method so it creates a new one each time def one_hundred_day_old_planting - FactoryBot.create(:planting, crop: planting.crop, planted_at: 100.days.ago) + FactoryBot.create(:planting, crop: crop, planted_at: 100.days.ago) end before do # 50 days to harvest @@ -110,19 +112,35 @@ describe Planting do # 10 days to harvest FactoryBot.create(:harvest, harvested_at: 90.days.ago, crop: planting.crop, planting: one_hundred_day_old_planting) + planting.crop.plantings.each(&:update_harvest_days) planting.crop.update_lifespan_medians planting.crop.update_harvest_medians end - it { expect(planting.crop.median_days_to_first_harvest).to eq(20) } + it { expect(crop.median_days_to_first_harvest).to eq(20) } + describe 'sets median time to harvest' do + let(:planting) { FactoryBot.create :planting, crop: crop, planted_at: Time.zone.today } + it { expect(planting.first_harvest_predicted_at).to eq(Time.zone.today + 20.days) } + end + + describe 'harvest still growing' do + let(:planting) { FactoryBot.create :planting, crop: crop, planted_at: Time.zone.today } + it { expect(planting.before_harvest_time?).to eq true } + it { expect(planting.harvest_time?).to eq false } + end + describe 'harvesting ready now' do + let(:planting) { FactoryBot.create :planting, crop: crop, planted_at: 21.days.ago } + it { expect(planting.first_harvest_predicted_at).to eq(1.day.ago.to_date) } + it { expect(planting.before_harvest_time?).to eq false } + it { expect(planting.harvest_time?).to eq true } + end end describe 'planting has no harvests' do + let(:planting) { FactoryBot.create :planting } before do planting.update_harvest_days planting.crop.update_harvest_medians end - let(:planting) { FactoryBot.create :planting } - it { expect(planting.days_to_first_harvest).to eq(nil) } it { expect(planting.days_to_last_harvest).to eq(nil) } end From 934bd9adb8fd79a020af5d56e4ceb1e4d8e8e659 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 16 Apr 2018 22:11:36 +1200 Subject: [PATCH 21/82] Fixed bug in spec, wasn't really on member's garden#index --- spec/features/gardens/gardens_index_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/gardens/gardens_index_spec.rb b/spec/features/gardens/gardens_index_spec.rb index 39161d5c8..da8eeeac2 100644 --- a/spec/features/gardens/gardens_index_spec.rb +++ b/spec/features/gardens/gardens_index_spec.rb @@ -10,7 +10,7 @@ feature "Gardens#index", :js do context "with 10 gardens" do before do FactoryBot.create_list :garden, 10, owner: member - visit gardens_path(member: member) + visit gardens_path(owner: member.login_name) end it "displays each of the gardens" do From 3ee253743826be788b599bfae2a81ebd054e5a4c Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Tue, 17 Apr 2018 10:03:59 +1200 Subject: [PATCH 22/82] Only show time to finished if not finished --- app/views/plantings/_badges.html.haml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/views/plantings/_badges.html.haml b/app/views/plantings/_badges.html.haml index 2e0c078b7..a665b2a75 100644 --- a/app/views/plantings/_badges.html.haml +++ b/app/views/plantings/_badges.html.haml @@ -2,6 +2,8 @@ - if planting.zombie? %span.badge.badge-danger zombie - elsif planting.living_past_predicted_finished? + +- else %span.badge.badge-light = days_from_now_to_finished(planting) days until finished From 2a8c4d4829780f34d0fb5c5f8166931b1dfd05f1 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Tue, 17 Apr 2018 10:06:40 +1200 Subject: [PATCH 23/82] Add finished and finished_at to plantings factory --- spec/factories/planting.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/factories/planting.rb b/spec/factories/planting.rb index 5b7311025..f19d80145 100644 --- a/spec/factories/planting.rb +++ b/spec/factories/planting.rb @@ -6,6 +6,8 @@ FactoryBot.define do planted_at { Time.zone.local(2014, 7, 30) } quantity 33 description "This is a *really* good plant." + finished nil + finished_at nil factory :seed_planting do planted_from 'seed' From 634dc936f909dbd81d96ad1bc5addedd2f358f6c Mon Sep 17 00:00:00 2001 From: jenkr55 Date: Wed, 18 Apr 2018 19:32:24 -0500 Subject: [PATCH 24/82] Show second comment button when many comments --- app/views/posts/show.html.haml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/app/views/posts/show.html.haml b/app/views/posts/show.html.haml index 3a50106a5..e283412a0 100644 --- a/app/views/posts/show.html.haml +++ b/app/views/posts/show.html.haml @@ -29,15 +29,17 @@ .col-md-2 = render partial: 'crops/thumbnail', locals: { crop: c } -.col-md-11 +.col-md-11.post-actions - if can?(:edit, @post) || can?(:destroy, @post) - .post-actions - - if can? :edit, @post - = link_to 'Edit Post', edit_post_path(@post), class: 'btn btn-default btn-xs' - - if can? :destroy, @post - = link_to 'Delete Post', @post, method: :delete, - data: { confirm: 'Are you sure?' }, - class: 'btn btn-default btn-xs' + - if can? :edit, @post + = link_to 'Edit Post', edit_post_path(@post), class: 'btn btn-default btn-xs' + - if can? :destroy, @post + = link_to 'Delete Post', @post, method: :delete, + data: { confirm: 'Are you sure?' }, + class: 'btn btn-default btn-xs' + - if @post.comments.count > 10 && can?(:create, Comment) + = link_to 'Comment', new_comment_path(post_id: @post.id), + class: 'btn btn-default btn-xs' = render partial: "comments", locals: { post: @post } From 3ed90b8d046ea56f97d17619ed22af7a37f05fe0 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Thu, 19 Apr 2018 13:44:39 +1200 Subject: [PATCH 25/82] Moving predictions to own file --- app/models/concerns/predictable.rb | 109 +++++++++++++++++++++++++++++ app/models/planting.rb | 97 +------------------------ 2 files changed, 110 insertions(+), 96 deletions(-) create mode 100644 app/models/concerns/predictable.rb diff --git a/app/models/concerns/predictable.rb b/app/models/concerns/predictable.rb new file mode 100644 index 000000000..992b63d3b --- /dev/null +++ b/app/models/concerns/predictable.rb @@ -0,0 +1,109 @@ +module Predictable + extend ActiveSupport::Concern + + included do + ## Triggers + before_save :calculate_lifespan + + def calculate_lifespan + self.lifespan = (planted_at.present? && finished_at.present? ? finished_at - planted_at : nil) + end + + # dates + def first_harvest_date + harvests_with_dates.minimum(:harvested_at) + end + + def last_harvest_date + harvests_with_dates.maximum(:harvested_at) + end + + def finish_predicted_at + planted_at + crop.median_lifespan.days if crop.median_lifespan.present? && planted_at.present? + end + + def first_harvest_predicted_at + return unless crop.median_days_to_first_harvest.present? && planted_at.present? + planted_at + crop.median_days_to_first_harvest.days + end + + def last_harvest_predicted_at + return unless crop.median_days_to_last_harvest.present? && planted_at.present? + planted_at + crop.median_days_to_last_harvest.days + end + + # days + def age_in_days + (Time.zone.today - planted_at).to_i if planted_at.present? + end + + def expected_lifespan + if planted_at.present? && finished_at.present? + return (finished_at - planted_at).to_i + end + crop.median_lifespan + end + + def days_since_planted + (Time.zone.today - planted_at).to_i if planted_at.present? + end + + # progress + def percentage_grown + return 100 if finished + return if planted_at.blank? || expected_lifespan.blank? + p = (days_since_planted / expected_lifespan.to_f) * 100 + return p if p <= 100 + 100 + end + + # actions + def update_harvest_days! + days_to_first_harvest = nil + days_to_last_harvest = nil + if planted_at.present? && harvests_with_dates.size.positive? + days_to_first_harvest = (first_harvest_date - planted_at).to_i + days_to_last_harvest = (last_harvest_date - planted_at).to_i if finished? + end + update(days_to_first_harvest: days_to_first_harvest, days_to_last_harvest: days_to_last_harvest) + end + + # states + def finished_is_predicatable? + crop.annual? && planted_at.present? && finish_predicted_at.present? + end + + def zombie? + crop.annual? && !finished && + planted_at.present? && + finish_predicted_at.present? && + (finish_predicted_at + 60.days) < Time.zone.today + end + + def should_be_finished? + crop.annual? && !finished && + planted_at.present? && + finish_predicted_at.present? && + finish_predicted_at < Time.zone.today + end + + def harvest_time? + return false if crop.perennial || finished + + # We have harvests but haven't finished + harvests.size.positive? || + + # or, we don't have harvests, but we predict we should by now + (first_harvest_predicted_at.present? && + harvests.empty? && + first_harvest_predicted_at < Time.zone.today) + end + + def before_harvest_time? + first_harvest_predicted_at.present? && + harvests.empty? && + first_harvest_predicted_at.present? && + first_harvest_predicted_at > Time.zone.today + end + end +end diff --git a/app/models/planting.rb b/app/models/planting.rb index 0ac677abf..2aa50916e 100644 --- a/app/models/planting.rb +++ b/app/models/planting.rb @@ -3,6 +3,7 @@ class Planting < ActiveRecord::Base include PhotoCapable include Finishable include Ownable + include Predictable friendly_id :planting_slug, use: %i(slugged finders) # Constants @@ -13,10 +14,6 @@ class Planting < ActiveRecord::Base 'graft', 'layering' ].freeze - ## - ## Triggers - before_save :calculate_lifespan - belongs_to :garden belongs_to :crop, counter_cache: true has_many :harvests, dependent: :destroy @@ -85,98 +82,6 @@ class Planting < ActiveRecord::Base planted_at.present? && planted_at <= Date.current end - def finish_predicted_at - planted_at + crop.median_lifespan.days if crop.median_lifespan.present? && planted_at.present? - end - - def first_harvest_predicted_at - return unless crop.median_days_to_first_harvest.present? && planted_at.present? - planted_at + crop.median_days_to_first_harvest.days - end - - def last_harvest_predicted_at - return unless crop.median_days_to_last_harvest.present? && planted_at.present? - planted_at + crop.median_days_to_last_harvest.days - end - - def calculate_lifespan - self.lifespan = (planted_at.present? && finished_at.present? ? finished_at - planted_at : nil) - end - - def expected_lifespan - if planted_at.present? && finished_at.present? - return (finished_at - planted_at).to_i - end - crop.median_lifespan - end - - def days_since_planted - (Time.zone.today - planted_at).to_i if planted_at.present? - end - - def percentage_grown - return 100 if finished - return if planted_at.blank? || expected_lifespan.blank? - p = (days_since_planted / expected_lifespan.to_f) * 100 - return p if p <= 100 - 100 - end - - def update_harvest_days - days_to_first_harvest = nil - days_to_last_harvest = nil - if planted_at.present? && harvests_with_dates.size.positive? - days_to_first_harvest = (first_harvest_date - planted_at).to_i - days_to_last_harvest = (last_harvest_date - planted_at).to_i if finished? - end - update(days_to_first_harvest: days_to_first_harvest, days_to_last_harvest: days_to_last_harvest) - end - - def first_harvest_date - harvests_with_dates.minimum(:harvested_at) - end - - def last_harvest_date - harvests_with_dates.maximum(:harvested_at) - end - - def zombie? - crop.annual? && !finished && - planted_at.present? && - finish_predicted_at.present? && - (finish_predicted_at + 60.days) < Time.zone.today - end - - def living_past_predicted_finished? - crop.annual? && !finished && - planted_at.present? && - finish_predicted_at.present? && - finish_predicted_at > Time.zone.today - end - - def harvest_time? - return false if crop.perennial || finished - - # We have harvests but haven't finished - harvests.size.positive? || - - # or, we don't have harvests, but we predict we should by now - (first_harvest_predicted_at.present? && - harvests.empty? && - first_harvest_predicted_at < Time.zone.today) - end - - def before_harvest_time? - first_harvest_predicted_at.present? && - harvests.empty? && - first_harvest_predicted_at.present? && - first_harvest_predicted_at > Time.zone.today - end - - def age_in_days - (Time.zone.today - planted_at).to_i if planted_at.present? - end - private def harvests_with_dates From 279c922b34a3568b2fb6b7224b9e5c3cad712c3a Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Thu, 19 Apr 2018 13:45:29 +1200 Subject: [PATCH 26/82] Rename update predictions methods to have ! --- app/controllers/harvests_controller.rb | 2 +- app/controllers/plantings_controller.rb | 2 +- app/models/crop.rb | 2 +- db/migrate/20171105011017_set_prediction_data.rb | 2 +- spec/models/planting_spec.rb | 8 ++++---- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/controllers/harvests_controller.rb b/app/controllers/harvests_controller.rb index 2e7fbef3e..73aaafd86 100644 --- a/app/controllers/harvests_controller.rb +++ b/app/controllers/harvests_controller.rb @@ -92,7 +92,7 @@ class HarvestsController < ApplicationController # if this harvest is not linked to a planting, then do nothing return if @harvest.planting.nil? - @harvest.planting.update_harvest_days + @harvest.planting.update_harvest_days! @harvest.crop.update_harvest_medians end end diff --git a/app/controllers/plantings_controller.rb b/app/controllers/plantings_controller.rb index f6da9d076..5ee31ea2c 100644 --- a/app/controllers/plantings_controller.rb +++ b/app/controllers/plantings_controller.rb @@ -77,7 +77,7 @@ class PlantingsController < ApplicationController end def update_planting_medians - @planting.update_harvest_days + @planting.update_harvest_days! end def planting_params diff --git a/app/models/crop.rb b/app/models/crop.rb index bead8e89b..b1d492353 100644 --- a/app/models/crop.rb +++ b/app/models/crop.rb @@ -185,7 +185,7 @@ class Crop < ActiveRecord::Base end def update_medians - plantings.each(&:update_harvest_days) + plantings.each(&:update_harvest_days!) update_lifespan_medians update_harvest_medians end diff --git a/db/migrate/20171105011017_set_prediction_data.rb b/db/migrate/20171105011017_set_prediction_data.rb index 149001927..5f5590d37 100644 --- a/db/migrate/20171105011017_set_prediction_data.rb +++ b/db/migrate/20171105011017_set_prediction_data.rb @@ -1,7 +1,7 @@ class SetPredictionData < ActiveRecord::Migration def up say "Updating all plantings time to first harvest" - Planting.all.each(&:update_harvest_days) + Planting.all.each(&:update_harvest_days!) say "Updating crop median time to first harvest, and lifespan" Crop.all.each do |crop| crop.update_lifespan_medians diff --git a/spec/models/planting_spec.rb b/spec/models/planting_spec.rb index 404d50e69..146548f51 100644 --- a/spec/models/planting_spec.rb +++ b/spec/models/planting_spec.rb @@ -113,7 +113,7 @@ describe Planting do FactoryBot.create(:harvest, harvested_at: 90.days.ago, crop: planting.crop, planting: one_hundred_day_old_planting) - planting.crop.plantings.each(&:update_harvest_days) + planting.crop.plantings.each(&:update_harvest_days!) planting.crop.update_lifespan_medians planting.crop.update_harvest_medians end @@ -138,7 +138,7 @@ describe Planting do describe 'planting has no harvests' do let(:planting) { FactoryBot.create :planting } before do - planting.update_harvest_days + planting.update_harvest_days! planting.crop.update_harvest_medians end it { expect(planting.days_to_first_harvest).to eq(nil) } @@ -152,7 +152,7 @@ describe Planting do planting: planting, crop: planting.crop, harvested_at: 10.days.ago) - planting.update_harvest_days + planting.update_harvest_days! planting.crop.update_harvest_medians end it { expect(planting.days_to_first_harvest).to eq(90) } @@ -166,7 +166,7 @@ describe Planting do before do FactoryBot.create :harvest, planting: planting, crop: planting.crop, harvested_at: 90.days.ago FactoryBot.create :harvest, planting: planting, crop: planting.crop, harvested_at: 10.days.ago - planting.update_harvest_days + planting.update_harvest_days! planting.crop.update_harvest_medians end it { expect(planting.days_to_first_harvest).to eq(10) } From 5bf75fa36ff8f2dea14cb421333b994497b503ea Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Thu, 19 Apr 2018 13:45:47 +1200 Subject: [PATCH 27/82] Only show finish prediction badges if we have enough data --- app/views/plantings/_badges.html.haml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/views/plantings/_badges.html.haml b/app/views/plantings/_badges.html.haml index a665b2a75..a2ab4afec 100644 --- a/app/views/plantings/_badges.html.haml +++ b/app/views/plantings/_badges.html.haml @@ -1,12 +1,13 @@ // Finish times -- if planting.zombie? - %span.badge.badge-danger zombie -- elsif planting.living_past_predicted_finished? - -- else - %span.badge.badge-light - = days_from_now_to_finished(planting) - days until finished +- if planting.finished_is_predicatable? + - if planting.zombie? + %span.badge.badge-danger zombie + - elsif planting.should_be_finished? + %span.badge.badge-light days past finished + - else + %span.badge.badge-light + = days_from_now_to_finished(planting) + days until finished // Harvest times - if planting.harvest_time? From 7a112aeecf2245b77e8f27bf262a5725f3293a98 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Thu, 19 Apr 2018 13:49:54 +1200 Subject: [PATCH 28/82] Grammar correction in method name --- app/models/concerns/predictable.rb | 2 +- app/views/plantings/_badges.html.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/concerns/predictable.rb b/app/models/concerns/predictable.rb index 992b63d3b..0a0aa5a73 100644 --- a/app/models/concerns/predictable.rb +++ b/app/models/concerns/predictable.rb @@ -69,7 +69,7 @@ module Predictable end # states - def finished_is_predicatable? + def finish_is_predicatable? crop.annual? && planted_at.present? && finish_predicted_at.present? end diff --git a/app/views/plantings/_badges.html.haml b/app/views/plantings/_badges.html.haml index a2ab4afec..16e83a075 100644 --- a/app/views/plantings/_badges.html.haml +++ b/app/views/plantings/_badges.html.haml @@ -1,5 +1,5 @@ // Finish times -- if planting.finished_is_predicatable? +- if planting.finish_is_predicatable? - if planting.zombie? %span.badge.badge-danger zombie - elsif planting.should_be_finished? From b3962bc9bc91bc466c73c56dab2de66dda826ef0 Mon Sep 17 00:00:00 2001 From: jenkr55 Date: Thu, 19 Apr 2018 12:10:19 -0500 Subject: [PATCH 29/82] Comment button same style --- app/assets/stylesheets/overrides.sass | 3 +++ app/views/posts/show.html.haml | 20 +++++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/assets/stylesheets/overrides.sass b/app/assets/stylesheets/overrides.sass index 6a97975fb..f93aa4368 100644 --- a/app/assets/stylesheets/overrides.sass +++ b/app/assets/stylesheets/overrides.sass @@ -193,6 +193,9 @@ li.crop-hierarchy .navbar-bottom margin: 40px 0px 0px 0px !important +.post-actions + margin-bottom: 1rem + // footer footer #footer1, #footer2, #footer3 diff --git a/app/views/posts/show.html.haml b/app/views/posts/show.html.haml index e283412a0..cca0f813d 100644 --- a/app/views/posts/show.html.haml +++ b/app/views/posts/show.html.haml @@ -29,17 +29,19 @@ .col-md-2 = render partial: 'crops/thumbnail', locals: { crop: c } -.col-md-11.post-actions +.col-md-11 - if can?(:edit, @post) || can?(:destroy, @post) - - if can? :edit, @post - = link_to 'Edit Post', edit_post_path(@post), class: 'btn btn-default btn-xs' - - if can? :destroy, @post - = link_to 'Delete Post', @post, method: :delete, - data: { confirm: 'Are you sure?' }, - class: 'btn btn-default btn-xs' + .post-actions + - if can? :edit, @post + = link_to 'Edit Post', edit_post_path(@post), class: 'btn btn-default btn-xs' + - if can? :destroy, @post + = link_to 'Delete Post', @post, method: :delete, + data: { confirm: 'Are you sure?' }, + class: 'btn btn-default btn-xs' + - if @post.comments.count > 10 && can?(:create, Comment) - = link_to 'Comment', new_comment_path(post_id: @post.id), - class: 'btn btn-default btn-xs' + .post-actions + = link_to 'Comment', new_comment_path(post_id: @post.id), class: 'btn btn-primary' = render partial: "comments", locals: { post: @post } From 4120069e4c2e1a386a51a6aa992c36f4fc515d97 Mon Sep 17 00:00:00 2001 From: jenkr55 Date: Thu, 19 Apr 2018 12:17:36 -0500 Subject: [PATCH 30/82] Fixing trailing whitespace --- app/assets/stylesheets/overrides.sass | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/stylesheets/overrides.sass b/app/assets/stylesheets/overrides.sass index 42c42bbd1..dda6ecaef 100644 --- a/app/assets/stylesheets/overrides.sass +++ b/app/assets/stylesheets/overrides.sass @@ -201,7 +201,7 @@ li.crop-hierarchy .post-actions margin-bottom: 1rem - + // footer footer #footer1, #footer2, #footer3 From c2ff3790dbaece2cf2d62f81c8b8c988de67f2dd Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 21 Apr 2018 09:22:35 +1200 Subject: [PATCH 31/82] set finished false on planting factory some code+tests doesn't cope with nil --- spec/factories/planting.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/factories/planting.rb b/spec/factories/planting.rb index f19d80145..27a2b179d 100644 --- a/spec/factories/planting.rb +++ b/spec/factories/planting.rb @@ -6,7 +6,7 @@ FactoryBot.define do planted_at { Time.zone.local(2014, 7, 30) } quantity 33 description "This is a *really* good plant." - finished nil + finished false finished_at nil factory :seed_planting do From b7d4781aefb5f359e8cbbfb380041bd292d6e0fb Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 21 Apr 2018 10:18:18 +1200 Subject: [PATCH 32/82] Split the planting&harvest predictions into files --- .../{predictable.rb => predict_harvest.rb} | 66 +++---------------- app/models/concerns/predict_planting.rb | 57 ++++++++++++++++ app/models/planting.rb | 11 ++-- 3 files changed, 72 insertions(+), 62 deletions(-) rename app/models/concerns/{predictable.rb => predict_harvest.rb} (52%) create mode 100644 app/models/concerns/predict_planting.rb diff --git a/app/models/concerns/predictable.rb b/app/models/concerns/predict_harvest.rb similarity index 52% rename from app/models/concerns/predictable.rb rename to app/models/concerns/predict_harvest.rb index 0a0aa5a73..d5422ee35 100644 --- a/app/models/concerns/predictable.rb +++ b/app/models/concerns/predict_harvest.rb @@ -1,14 +1,7 @@ -module Predictable +module PredictHarvest extend ActiveSupport::Concern - included do - ## Triggers - before_save :calculate_lifespan - - def calculate_lifespan - self.lifespan = (planted_at.present? && finished_at.present? ? finished_at - planted_at : nil) - end - + included do # rubocop:disable Metrics/BlockLength # dates def first_harvest_date harvests_with_dates.minimum(:harvested_at) @@ -18,10 +11,6 @@ module Predictable harvests_with_dates.maximum(:harvested_at) end - def finish_predicted_at - planted_at + crop.median_lifespan.days if crop.median_lifespan.present? && planted_at.present? - end - def first_harvest_predicted_at return unless crop.median_days_to_first_harvest.present? && planted_at.present? planted_at + crop.median_days_to_first_harvest.days @@ -32,31 +21,6 @@ module Predictable planted_at + crop.median_days_to_last_harvest.days end - # days - def age_in_days - (Time.zone.today - planted_at).to_i if planted_at.present? - end - - def expected_lifespan - if planted_at.present? && finished_at.present? - return (finished_at - planted_at).to_i - end - crop.median_lifespan - end - - def days_since_planted - (Time.zone.today - planted_at).to_i if planted_at.present? - end - - # progress - def percentage_grown - return 100 if finished - return if planted_at.blank? || expected_lifespan.blank? - p = (days_since_planted / expected_lifespan.to_f) * 100 - return p if p <= 100 - 100 - end - # actions def update_harvest_days! days_to_first_harvest = nil @@ -68,25 +32,7 @@ module Predictable update(days_to_first_harvest: days_to_first_harvest, days_to_last_harvest: days_to_last_harvest) end - # states - def finish_is_predicatable? - crop.annual? && planted_at.present? && finish_predicted_at.present? - end - - def zombie? - crop.annual? && !finished && - planted_at.present? && - finish_predicted_at.present? && - (finish_predicted_at + 60.days) < Time.zone.today - end - - def should_be_finished? - crop.annual? && !finished && - planted_at.present? && - finish_predicted_at.present? && - finish_predicted_at < Time.zone.today - end - + # status def harvest_time? return false if crop.perennial || finished @@ -105,5 +51,11 @@ module Predictable first_harvest_predicted_at.present? && first_harvest_predicted_at > Time.zone.today end + + private + + def harvests_with_dates + harvests.where.not(harvested_at: nil) + end end end diff --git a/app/models/concerns/predict_planting.rb b/app/models/concerns/predict_planting.rb new file mode 100644 index 000000000..ca33a1d59 --- /dev/null +++ b/app/models/concerns/predict_planting.rb @@ -0,0 +1,57 @@ +module PredictPlanting + extend ActiveSupport::Concern + + included do # rubocop:disable Metrics/BlockLength + ## Triggers + before_save :calculate_lifespan + + def calculate_lifespan + self.lifespan = (planted_at.present? && finished_at.present? ? finished_at - planted_at : nil) + end + + # dates + def finish_predicted_at + planted_at + crop.median_lifespan.days if crop.median_lifespan.present? && planted_at.present? + end + + # days + def expected_lifespan + if planted_at.present? && finished_at.present? + return (finished_at - planted_at).to_i + end + crop.median_lifespan + end + + def days_since_planted + (Time.zone.today - planted_at).to_i if planted_at.present? + end + + # progress + def percentage_grown + return 100 if finished + return if planted_at.blank? || expected_lifespan.blank? + p = (days_since_planted / expected_lifespan.to_f) * 100 + return p if p <= 100 + 100 + end + + # states + def finish_is_predicatable? + crop.annual? && planted_at.present? && finish_predicted_at.present? + end + + def zombie? + crop.annual? && !finished && + planted_at.present? && + finish_predicted_at.present? && + (finish_predicted_at + 60.days) < Time.zone.today + end + + def should_be_finished? + crop.annual? && !finished && + planted_at.present? && + finish_predicted_at.present? && + finish_predicted_at < Time.zone.today + end + end +end diff --git a/app/models/planting.rb b/app/models/planting.rb index 2aa50916e..02dd7cff2 100644 --- a/app/models/planting.rb +++ b/app/models/planting.rb @@ -3,7 +3,8 @@ class Planting < ActiveRecord::Base include PhotoCapable include Finishable include Ownable - include Predictable + include PredictPlanting + include PredictHarvest friendly_id :planting_slug, use: %i(slugged finders) # Constants @@ -56,6 +57,10 @@ class Planting < ActiveRecord::Base in: PLANTED_FROM_VALUES, message: "%s is not a valid planting method" } + def age_in_days + (Time.zone.today - planted_at).to_i if planted_at.present? + end + def planting_slug [ owner.login_name, @@ -84,10 +89,6 @@ class Planting < ActiveRecord::Base private - def harvests_with_dates - harvests.where.not(harvested_at: nil) - end - # check that any finished_at date occurs after planted_at def finished_must_be_after_planted return unless planted_at && finished_at # only check if we have both From a5b84403bb9f94f322a7fb89f80d93e1068fbff6 Mon Sep 17 00:00:00 2001 From: Awesome Code Date: Fri, 20 Apr 2018 22:19:28 +0000 Subject: [PATCH 33/82] Auto corrected by following Style/ExpandPathArguments --- Rakefile | 2 +- config/application.rb | 2 +- config/boot.rb | 2 +- config/environment.rb | 2 +- script/rails | 4 ++-- spec/rails_helper.rb | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Rakefile b/Rakefile index 7e5e8eed3..25bd8aea0 100755 --- a/Rakefile +++ b/Rakefile @@ -3,6 +3,6 @@ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require 'rake/dsl_definition' -require File.expand_path('../config/application', __FILE__) +require File.expand_path('config/application', __dir__) Growstuff::Application.load_tasks diff --git a/config/application.rb b/config/application.rb index ae8d6e95f..9b11cc2a8 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,4 +1,4 @@ -require File.expand_path('../boot', __FILE__) +require File.expand_path('boot', __dir__) require 'rails/all' require 'openssl' diff --git a/config/boot.rb b/config/boot.rb index f2830ae31..24efefdb2 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,6 +1,6 @@ require 'rubygems' # Set up gems listed in the Gemfile. -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) diff --git a/config/environment.rb b/config/environment.rb index b175f6a30..b72677751 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,5 +1,5 @@ # Load the rails application -require File.expand_path('../application', __FILE__) +require File.expand_path('application', __dir__) # Initialize the rails application Growstuff::Application.initialize! diff --git a/script/rails b/script/rails index 9092f9f3c..754b05caa 100755 --- a/script/rails +++ b/script/rails @@ -2,6 +2,6 @@ # This command will automatically be run when you run "rails" # with Rails 3 gems installed from the root of your application. -APP_PATH = File.expand_path('../../config/application', __FILE__) -require File.expand_path('../../config/boot', __FILE__) +APP_PATH = File.expand_path('../config/application', __dir__) +require File.expand_path('../config/boot', __dir__) require 'rails/commands' diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index e28dd6e24..862b0316d 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -17,7 +17,7 @@ SimpleCov.start :rails do end require 'spec_helper' -require File.expand_path("../../config/environment", __FILE__) +require File.expand_path('../config/environment', __dir__) require 'rspec/rails' # Add additional requires below this line. Rails is not loaded until this point! Rails.application.eager_load! From cdde3994b2e423ca35baba2c5f57cd2d98a86f37 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 21 Apr 2018 10:35:28 +1200 Subject: [PATCH 34/82] Revert "Auto corrected by following Style/ExpandPathArguments" This reverts commit a5b84403bb9f94f322a7fb89f80d93e1068fbff6. --- Rakefile | 2 +- config/application.rb | 2 +- config/boot.rb | 2 +- config/environment.rb | 2 +- script/rails | 4 ++-- spec/rails_helper.rb | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Rakefile b/Rakefile index 25bd8aea0..7e5e8eed3 100755 --- a/Rakefile +++ b/Rakefile @@ -3,6 +3,6 @@ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require 'rake/dsl_definition' -require File.expand_path('config/application', __dir__) +require File.expand_path('../config/application', __FILE__) Growstuff::Application.load_tasks diff --git a/config/application.rb b/config/application.rb index 9b11cc2a8..ae8d6e95f 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,4 +1,4 @@ -require File.expand_path('boot', __dir__) +require File.expand_path('../boot', __FILE__) require 'rails/all' require 'openssl' diff --git a/config/boot.rb b/config/boot.rb index 24efefdb2..f2830ae31 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,6 +1,6 @@ require 'rubygems' # Set up gems listed in the Gemfile. -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) diff --git a/config/environment.rb b/config/environment.rb index b72677751..b175f6a30 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,5 +1,5 @@ # Load the rails application -require File.expand_path('application', __dir__) +require File.expand_path('../application', __FILE__) # Initialize the rails application Growstuff::Application.initialize! diff --git a/script/rails b/script/rails index 754b05caa..9092f9f3c 100755 --- a/script/rails +++ b/script/rails @@ -2,6 +2,6 @@ # This command will automatically be run when you run "rails" # with Rails 3 gems installed from the root of your application. -APP_PATH = File.expand_path('../config/application', __dir__) -require File.expand_path('../config/boot', __dir__) +APP_PATH = File.expand_path('../../config/application', __FILE__) +require File.expand_path('../../config/boot', __FILE__) require 'rails/commands' diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 862b0316d..e28dd6e24 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -17,7 +17,7 @@ SimpleCov.start :rails do end require 'spec_helper' -require File.expand_path('../config/environment', __dir__) +require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' # Add additional requires below this line. Rails is not loaded until this point! Rails.application.eager_load! From f8b76e9c846acabdb914268736594823de466f01 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 21 Apr 2018 11:12:25 +1200 Subject: [PATCH 35/82] Reducing complexity in planting predictions --- app/models/concerns/predict_planting.rb | 29 ++++++++++++++----------- app/models/planting.rb | 10 ++++++++- spec/models/planting_spec.rb | 3 +-- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/app/models/concerns/predict_planting.rb b/app/models/concerns/predict_planting.rb index ca33a1d59..65d101569 100644 --- a/app/models/concerns/predict_planting.rb +++ b/app/models/concerns/predict_planting.rb @@ -16,10 +16,12 @@ module PredictPlanting # days def expected_lifespan - if planted_at.present? && finished_at.present? - return (finished_at - planted_at).to_i - end - crop.median_lifespan + actual_lifespan.present? ? actual_lifespan : crop.median_lifespan + end + + def actual_lifespan + return unless planted_at.present? && finished_at.present? + (finished_at - planted_at).to_i end def days_since_planted @@ -28,11 +30,14 @@ module PredictPlanting # progress def percentage_grown - return 100 if finished - return if planted_at.blank? || expected_lifespan.blank? - p = (days_since_planted / expected_lifespan.to_f) * 100 - return p if p <= 100 - 100 + return 100 if finished? + return unless finish_is_predicatable? + if growing? + percent = (days_since_planted / expected_lifespan.to_f) * 100 + return 100 if percent > 100 + return percent + end + return 0 if planted? end # states @@ -41,14 +46,12 @@ module PredictPlanting end def zombie? - crop.annual? && !finished && - planted_at.present? && - finish_predicted_at.present? && + should_be_finished? && (finish_predicted_at + 60.days) < Time.zone.today end def should_be_finished? - crop.annual? && !finished && + crop.annual? && !finished? && planted_at.present? && finish_predicted_at.present? && finish_predicted_at < Time.zone.today diff --git a/app/models/planting.rb b/app/models/planting.rb index 02dd7cff2..bea6b9a8b 100644 --- a/app/models/planting.rb +++ b/app/models/planting.rb @@ -83,8 +83,16 @@ class Planting < ActiveRecord::Base photos.order(created_at: :desc).first end + def finished? + finished || (finished_at.present? && finished_at <= Time.zone.today) + end + def planted? - planted_at.present? && planted_at <= Date.current + planted_at.present? && planted_at <= Time.zone.today + end + + def growing? + planted? && !finished? end private diff --git a/spec/models/planting_spec.rb b/spec/models/planting_spec.rb index 146548f51..0bd36f19f 100644 --- a/spec/models/planting_spec.rb +++ b/spec/models/planting_spec.rb @@ -73,8 +73,7 @@ describe Planting do describe 'planting finished 10 days, but was never planted' do let(:planting) { FactoryBot.create :planting, planted_at: nil, finished_at: 10.days.ago } - - it { expect(planting.percentage_grown).to eq nil } + it { expect(planting.percentage_grown).to eq 100 } end describe 'planted 30 days ago, finished 10 days ago' do From 8ce0717c0f6ff49c234767de380979c280a889ce Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 21 Apr 2018 11:36:02 +1200 Subject: [PATCH 36/82] Fixing up planting helper predictions --- app/helpers/plantings_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/plantings_helper.rb b/app/helpers/plantings_helper.rb index b5dac192a..1bf216330 100644 --- a/app/helpers/plantings_helper.rb +++ b/app/helpers/plantings_helper.rb @@ -34,7 +34,7 @@ module PlantingsHelper end def days_from_now_to_finished(planting) - return unless planting.finish_predicted_at.present? && planting.finish_predicted_at > Time.zone.today + return unless planting.finish_is_predicatable? (planting.finish_predicted_at - Time.zone.today).to_i end From 9188bd384decac0fa8dd60640f766278c137c167 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 21 Apr 2018 11:36:48 +1200 Subject: [PATCH 37/82] Futher simplifying planting badges --- app/views/plantings/_badges.html.haml | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/app/views/plantings/_badges.html.haml b/app/views/plantings/_badges.html.haml index 16e83a075..103cf156a 100644 --- a/app/views/plantings/_badges.html.haml +++ b/app/views/plantings/_badges.html.haml @@ -2,17 +2,16 @@ - if planting.finish_is_predicatable? - if planting.zombie? %span.badge.badge-danger zombie - - elsif planting.should_be_finished? - %span.badge.badge-light days past finished - - else + - elsif !planting.should_be_finished? %span.badge.badge-light = days_from_now_to_finished(planting) days until finished // Harvest times -- if planting.harvest_time? - %span.badge.badge-light harvest time -- elsif planting.before_harvest_time? - %span.badge.badge-light - = days_from_now_to_first_harvest(planting) - days until harvest +- unless planting.zombie? + - if planting.harvest_time? + %span.badge.badge-light harvest time + - elsif planting.before_harvest_time? + %span.badge.badge-light + = days_from_now_to_first_harvest(planting) + days until harvest From 4fe8cd566b1168d5f2937e9621951839516d2bed Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 21 Apr 2018 12:37:00 +1200 Subject: [PATCH 38/82] USe finished not finished? because some plants have finished_at in the past but haven't had their .finished set to true yet --- app/models/concerns/predict_planting.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/concerns/predict_planting.rb b/app/models/concerns/predict_planting.rb index 65d101569..d670d78a2 100644 --- a/app/models/concerns/predict_planting.rb +++ b/app/models/concerns/predict_planting.rb @@ -51,10 +51,10 @@ module PredictPlanting end def should_be_finished? - crop.annual? && !finished? && + crop.annual? && !finished && planted_at.present? && finish_predicted_at.present? && - finish_predicted_at < Time.zone.today + finish_predicted_at <= Time.zone.today end end end From 935aebcb0d150bcacd7c67909b9680a07ee80df0 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 21 Apr 2018 12:38:32 +1200 Subject: [PATCH 39/82] Tidy up visual link between planting thumbnail and crop name --- app/assets/stylesheets/overrides.sass | 20 ++++++++++++++++---- app/views/plantings/_progress.html.haml | 3 ++- app/views/plantings/_thumbnail.html.haml | 19 ++++++++++--------- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/app/assets/stylesheets/overrides.sass b/app/assets/stylesheets/overrides.sass index 9651b2956..b5e9e06bd 100644 --- a/app/assets/stylesheets/overrides.sass +++ b/app/assets/stylesheets/overrides.sass @@ -93,17 +93,28 @@ p.stats padding-left: 1em width: 15em +.progress + border-radius: 0 + .planting + .planting-badges + position: absolute + + .planting-thumbnail + padding: 0 + border: 1px solid darken($beige, 10%) + border-radius: 4px + + .planting-name + position: relative + top: -1em + dl.planting-attributes dt text-align: left dd margin-left: auto -.planting-badges - position: absolute - - #placesmap, #cropmap height: 500px @@ -156,6 +167,7 @@ p.stats text-align: center margin-bottom: 1.5em max-width: 160px + max-height: 200px .member-thumbnail text-align: left diff --git a/app/views/plantings/_progress.html.haml b/app/views/plantings/_progress.html.haml index a594de75d..819cfe7af 100644 --- a/app/views/plantings/_progress.html.haml +++ b/app/views/plantings/_progress.html.haml @@ -1,5 +1,6 @@ - if planting.crop.perennial - %p Perennial + %p + %i perennial - elsif !planting.planted? - if show_explanation %p Progress: 0% - not planted yet diff --git a/app/views/plantings/_thumbnail.html.haml b/app/views/plantings/_thumbnail.html.haml index 6d52308cd..96bfeecbf 100644 --- a/app/views/plantings/_thumbnail.html.haml +++ b/app/views/plantings/_thumbnail.html.haml @@ -1,11 +1,12 @@ -.planting-badges - = render 'plantings/badges', planting: planting -.hover-wrapper - .text= render 'plantings/actions', planting: planting - .thumbnail - .planting-thumbnail - = link_to image_tag(planting_image_path(planting), alt: planting.crop.name, class: 'img'), planting_path(planting) - .plantinginfo +.planting + .planting-badges + = render 'plantings/badges', planting: planting + .hover-wrapper + .text + = render 'plantings/actions', planting: planting + .thumbnail + .planting-thumbnail + = link_to image_tag(planting_image_path(planting), alt: planting.crop.name, class: 'img'), planting_path(planting) + = render 'plantings/progress', planting: planting, show_explanation: false .planting-name - = render 'plantings/progress', planting: planting, show_explanation: false = link_to planting.crop.name, planting From 1b3e00fba0807019c23a64106f66849baa3c2728 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 21 Apr 2018 13:00:24 +1200 Subject: [PATCH 40/82] Colours for badges on plantings --- app/assets/stylesheets/custom_bootstrap/variables.sass | 4 ++-- app/assets/stylesheets/overrides.sass | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/custom_bootstrap/variables.sass b/app/assets/stylesheets/custom_bootstrap/variables.sass index f94f04106..f2fc82dda 100644 --- a/app/assets/stylesheets/custom_bootstrap/variables.sass +++ b/app/assets/stylesheets/custom_bootstrap/variables.sass @@ -1,7 +1,7 @@ // Use this file to override Twitter Bootstrap variables or define own variables. // Import original variables so they can be used in overrides -//@import 'bootstrap/variables.scss' +@import 'bootstrap/variables.scss' // Base colours @@ -10,7 +10,7 @@ $brown: #413f3b $green: #5f8e43 $blue: #2f4365 -$red: #8e4d43 +$red: #ff4d43 $orange: #ffa500 $yellow: #b2935c $white: #ffffff diff --git a/app/assets/stylesheets/overrides.sass b/app/assets/stylesheets/overrides.sass index b5e9e06bd..3f7bbdebb 100644 --- a/app/assets/stylesheets/overrides.sass +++ b/app/assets/stylesheets/overrides.sass @@ -96,6 +96,11 @@ p.stats .progress border-radius: 0 +.badge-zombie + background-color: $red +.badge-harvest + background-color: $blue + .planting .planting-badges position: absolute @@ -104,7 +109,8 @@ p.stats padding: 0 border: 1px solid darken($beige, 10%) border-radius: 4px - + .planting-actions + top: -8em .planting-name position: relative top: -1em From ca8dae4b78ec3e0b0d851b1e71f02987309580d6 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 21 Apr 2018 13:02:09 +1200 Subject: [PATCH 41/82] Moving the planting buttons lower --- app/views/plantings/_thumbnail.html.haml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/plantings/_thumbnail.html.haml b/app/views/plantings/_thumbnail.html.haml index 96bfeecbf..9d35f5c0f 100644 --- a/app/views/plantings/_thumbnail.html.haml +++ b/app/views/plantings/_thumbnail.html.haml @@ -2,11 +2,11 @@ .planting-badges = render 'plantings/badges', planting: planting .hover-wrapper - .text - = render 'plantings/actions', planting: planting .thumbnail .planting-thumbnail = link_to image_tag(planting_image_path(planting), alt: planting.crop.name, class: 'img'), planting_path(planting) = render 'plantings/progress', planting: planting, show_explanation: false .planting-name = link_to planting.crop.name, planting + .text + .planting-actions= render 'plantings/actions', planting: planting From a8509acd490f5cd6a8a6444a01a1490fa4a1bea9 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 21 Apr 2018 13:02:51 +1200 Subject: [PATCH 42/82] Zombie status needs 90 days --- app/models/concerns/predict_planting.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/concerns/predict_planting.rb b/app/models/concerns/predict_planting.rb index d670d78a2..e0086d959 100644 --- a/app/models/concerns/predict_planting.rb +++ b/app/models/concerns/predict_planting.rb @@ -47,7 +47,7 @@ module PredictPlanting def zombie? should_be_finished? && - (finish_predicted_at + 60.days) < Time.zone.today + (finish_predicted_at + 90.days) < Time.zone.today end def should_be_finished? From 87b04f60f7a1af430fd38be8a32d647fa7a778fb Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 21 Apr 2018 13:03:46 +1200 Subject: [PATCH 43/82] Order garden's plantings by planted_at --- app/views/gardens/_overview.html.haml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/gardens/_overview.html.haml b/app/views/gardens/_overview.html.haml index 978a6abbf..ed12d0cf5 100644 --- a/app/views/gardens/_overview.html.haml +++ b/app/views/gardens/_overview.html.haml @@ -13,8 +13,8 @@ .col-md-10 .row - if garden.plantings.current.size.positive? - - garden.plantings.current.includes(:crop, :photos).each do |planting| - .col-md-2.col-sm-6.col-xs-6 + - garden.plantings.current.order(created_at: :desc).includes(:crop, :photos).each do |planting| + .col-md-2.col-sm-4.col-xs-6 = render "plantings/thumbnail", planting: planting - else .col-md-2.col-sm-6.col-xs-6 no plantings From 9b16abd373f5d88cb1ec1cb56c2f6822d504ca80 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 21 Apr 2018 13:04:31 +1200 Subject: [PATCH 44/82] Render perenial progress bar the same as others --- app/views/plantings/_progress.html.haml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/views/plantings/_progress.html.haml b/app/views/plantings/_progress.html.haml index 819cfe7af..caa42bf2a 100644 --- a/app/views/plantings/_progress.html.haml +++ b/app/views/plantings/_progress.html.haml @@ -1,6 +1,5 @@ - if planting.crop.perennial - %p - %i perennial + = render "plantings/progress_bar", status: "perennial", progress: nil - elsif !planting.planted? - if show_explanation %p Progress: 0% - not planted yet From aae7688a0ee05d2090325c2c2e44dea809db63f0 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 21 Apr 2018 13:05:15 +1200 Subject: [PATCH 45/82] Classes for planting badge colours --- app/views/plantings/_badges.html.haml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/views/plantings/_badges.html.haml b/app/views/plantings/_badges.html.haml index 103cf156a..7ec837484 100644 --- a/app/views/plantings/_badges.html.haml +++ b/app/views/plantings/_badges.html.haml @@ -1,17 +1,18 @@ // Finish times - if planting.finish_is_predicatable? - if planting.zombie? - %span.badge.badge-danger zombie + %span.badge.badge-zombie zombie + = render 'shared/buttons/finish_planting', planting: planting - elsif !planting.should_be_finished? - %span.badge.badge-light + %span.badge = days_from_now_to_finished(planting) days until finished // Harvest times - unless planting.zombie? - if planting.harvest_time? - %span.badge.badge-light harvest time + %span.badge.badge-harvest harvesting now - elsif planting.before_harvest_time? - %span.badge.badge-light + %span.badge = days_from_now_to_first_harvest(planting) days until harvest From 9966eddd376fc49bc9223cf4da9bfeead0151b4f Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 21 Apr 2018 13:52:49 +1200 Subject: [PATCH 46/82] Giving gardens unique names to stop test collisions --- spec/factories/garden.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/factories/garden.rb b/spec/factories/garden.rb index 1f3d7461d..f93107361 100644 --- a/spec/factories/garden.rb +++ b/spec/factories/garden.rb @@ -1,6 +1,6 @@ FactoryBot.define do factory :garden do - name 'Springfield Community Garden' + name { Faker::Vehicle.vin } description "This is a **totally** cool garden" owner active true From 548fb3d3fd5a10049c37e8cc5ccea44f8467ae41 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 21 Apr 2018 14:00:00 +1200 Subject: [PATCH 47/82] Badges feature specs --- spec/features/gardens/gardens_index_spec.rb | 69 ++++++++++++++++++++- 1 file changed, 67 insertions(+), 2 deletions(-) diff --git a/spec/features/gardens/gardens_index_spec.rb b/spec/features/gardens/gardens_index_spec.rb index da8eeeac2..516796641 100644 --- a/spec/features/gardens/gardens_index_spec.rb +++ b/spec/features/gardens/gardens_index_spec.rb @@ -3,8 +3,7 @@ require 'custom_matchers' feature "Gardens#index", :js do context "Logged in as member" do - let(:member) { FactoryBot.create :member } - + let(:member) { FactoryBot.create :member, login_name: 'shadow' } background { login_as member } context "with 10 gardens" do @@ -67,4 +66,70 @@ feature "Gardens#index", :js do end end end + + describe 'badges' do + let(:garden) { member.gardens.first } + let(:member) { FactoryBot.create :member, login_name: 'robbieburns' } + let(:crop) { FactoryBot.create :crop } + before(:each) do + # time to harvest = 50 day + # time to finished = 90 days + FactoryBot.create(:harvest, + harvested_at: 50.days.ago, + crop: crop, + planting: FactoryBot.create(:planting, + crop: crop, + planted_at: 100.days.ago, + finished_at: 10.days.ago)) + crop.plantings.each(&:update_harvest_days!) + crop.update_lifespan_medians + crop.update_harvest_medians + + garden.update! name: 'super awesome garden' + assert planting + visit gardens_path(owner: member.login_name) + end + + describe 'harvest still growing' do + let!(:planting) do + FactoryBot.create :planting, + crop: crop, + owner: member, + garden: garden, + planted_at: Time.zone.today + end + it { expect(page).to have_link href: planting_path(planting) } + it { expect(page).to have_link href: garden_path(planting.garden) } + it { expect(page).to have_text '50 days until harvest' } + it { expect(page).to have_text '90 days until finished' } + it { expect(page).not_to have_text 'harvesting now' } + end + + describe 'harvesting now' do + let!(:planting) do + FactoryBot.create :planting, + crop: crop, + owner: member, garden: garden, + planted_at: 51.days.ago + end + it { expect(crop.median_days_to_first_harvest).to eq 50 } + it { expect(crop.median_lifespan).to eq 90 } + + it { expect(page).to have_text 'harvesting now' } + it { expect(page).to have_text '39 days until finished' } + it { expect(page).not_to have_text 'days until harvest' } + end + + describe 'zombie' do + let!(:planting) do + FactoryBot.create :planting, + crop: crop, owner: member, + garden: garden, planted_at: 260.days.ago + end + it { expect(page).to have_text 'zombie' } + it { expect(page).not_to have_text 'harvesting now' } + it { expect(page).not_to have_text 'days until harvest' } + it { expect(page).not_to have_text 'days until finished' } + end + end end From 2e4378f025c3bb6cefb8b97182a47572bc084ace Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 21 Apr 2018 14:17:50 +1200 Subject: [PATCH 48/82] Add css class to show finished/zombie/harvesting etc --- app/assets/stylesheets/overrides.sass | 4 ++++ app/helpers/plantings_helper.rb | 10 ++++++++++ app/views/plantings/_thumbnail.html.haml | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/overrides.sass b/app/assets/stylesheets/overrides.sass index 3f7bbdebb..5bde11d05 100644 --- a/app/assets/stylesheets/overrides.sass +++ b/app/assets/stylesheets/overrides.sass @@ -101,6 +101,10 @@ p.stats .badge-harvest background-color: $blue +.planting-zombie +.planting-predicted-finished + background-color: $beige + .planting .planting-badges position: absolute diff --git a/app/helpers/plantings_helper.rb b/app/helpers/plantings_helper.rb index 1bf216330..b57a1dc4a 100644 --- a/app/helpers/plantings_helper.rb +++ b/app/helpers/plantings_helper.rb @@ -42,4 +42,14 @@ module PlantingsHelper return unless planting.planted_at.present? && planting.first_harvest_predicted_at.present? (planting.first_harvest_predicted_at - Time.zone.today).to_i end + + def planting_classes(planting) + classes = [] + classes << 'planting-growing' if planting.growing? + classes << 'planting-finished' if planting.finished? + classes << 'planting-harvest-time' if planting.harvest_time? + classes << 'planting-predicted-finished' if planting.should_be_finished? + classes << 'planting-zombie' if planting.zombie? + classes.join(' ') + end end diff --git a/app/views/plantings/_thumbnail.html.haml b/app/views/plantings/_thumbnail.html.haml index 9d35f5c0f..6b8400b46 100644 --- a/app/views/plantings/_thumbnail.html.haml +++ b/app/views/plantings/_thumbnail.html.haml @@ -3,7 +3,7 @@ = render 'plantings/badges', planting: planting .hover-wrapper .thumbnail - .planting-thumbnail + .planting-thumbnail{class: planting_classes(planting)} = link_to image_tag(planting_image_path(planting), alt: planting.crop.name, class: 'img'), planting_path(planting) = render 'plantings/progress', planting: planting, show_explanation: false .planting-name From 948c32d1d5f2682dbdc1a8532069b1e36e0969d4 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 21 Apr 2018 14:19:40 +1200 Subject: [PATCH 49/82] test that expects a garden name, set to that name --- spec/models/planting_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/planting_spec.rb b/spec/models/planting_spec.rb index 0bd36f19f..86da90d9f 100644 --- a/spec/models/planting_spec.rb +++ b/spec/models/planting_spec.rb @@ -135,7 +135,7 @@ describe Planting do end end describe 'planting has no harvests' do - let(:planting) { FactoryBot.create :planting } + let(:planting) { FactoryBot.create :planting, name: 'Springfield Community Garden' } before do planting.update_harvest_days! planting.crop.update_harvest_medians From 5cc647ee9b2830e75e8eb340f4ac0ed45d48819b Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 21 Apr 2018 14:22:20 +1200 Subject: [PATCH 50/82] test that expects a garden name, set to that name --- spec/models/garden_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/garden_spec.rb b/spec/models/garden_spec.rb index f8e5a3311..839ef3445 100644 --- a/spec/models/garden_spec.rb +++ b/spec/models/garden_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' describe Garden do let(:owner) { FactoryBot.create(:member) } - let(:garden) { FactoryBot.create(:garden, owner: owner) } + let(:garden) { FactoryBot.create(:garden, owner: owner, name: 'Springfield Community Garden') } it "should have a slug" do garden.slug.should match(/member\d+-springfield-community-garden/) From 87d43f1eb23884ac4723d2199c67863537890474 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 21 Apr 2018 14:26:27 +1200 Subject: [PATCH 51/82] Move planting delete action into the bar --- app/views/plantings/_actions.html.haml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/plantings/_actions.html.haml b/app/views/plantings/_actions.html.haml index 87eddc8cf..6f5b1b93d 100644 --- a/app/views/plantings/_actions.html.haml +++ b/app/views/plantings/_actions.html.haml @@ -8,5 +8,5 @@ = render 'shared/buttons/harvest_planting', planting: planting = render 'shared/buttons/save_seeds', planting: planting - - if can? :destroy, planting - = render 'shared/buttons/delete', path: planting + - if can? :destroy, planting + = render 'shared/buttons/delete', path: planting From 34b6b546160736621687eb7eb975dfe65bfcc616 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 21 Apr 2018 14:33:39 +1200 Subject: [PATCH 52/82] Name goes on garden, not planting --- spec/models/planting_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/models/planting_spec.rb b/spec/models/planting_spec.rb index 86da90d9f..809ac845d 100644 --- a/spec/models/planting_spec.rb +++ b/spec/models/planting_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' describe Planting do let(:crop) { FactoryBot.create(:tomato) } let(:garden_owner) { FactoryBot.create(:member) } - let(:garden) { FactoryBot.create(:garden, owner: garden_owner) } + let(:garden) { FactoryBot.create(:garden, owner: garden_owner, name: 'Springfield Community Garden') } let(:planting) { FactoryBot.create(:planting, crop: crop, garden: garden, owner: garden.owner) } let(:finished_planting) do FactoryBot.create :planting, planted_at: 4.days.ago, finished_at: 2.days.ago, finished: true @@ -135,7 +135,7 @@ describe Planting do end end describe 'planting has no harvests' do - let(:planting) { FactoryBot.create :planting, name: 'Springfield Community Garden' } + let(:planting) { FactoryBot.create :planting } before do planting.update_harvest_days! planting.crop.update_harvest_medians From 6077d4da3472030d24b03147bd48fa2d6e7974fd Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 21 Apr 2018 15:01:33 +1200 Subject: [PATCH 53/82] Fixed bug in garden spec --- spec/features/harvests/harvesting_a_crop_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/harvests/harvesting_a_crop_spec.rb b/spec/features/harvests/harvesting_a_crop_spec.rb index e99c5e814..5f6d85fa2 100644 --- a/spec/features/harvests/harvesting_a_crop_spec.rb +++ b/spec/features/harvests/harvesting_a_crop_spec.rb @@ -130,7 +130,7 @@ feature "Harvesting a crop", :js, :elasticsearch do end scenario "linking to a planting" do - expect(page).to have_content planting.to_s + expect(page).to have_content existing_planting.to_s choose("harvest_planting_id_#{existing_planting.id}") click_button "save" expect(page).to have_link(href: planting_path(existing_planting)) From 4df3354020adf9b4819b8d417e78ae8ce0e62b2d Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 21 Apr 2018 15:17:17 +1200 Subject: [PATCH 54/82] Style fix up --- app/views/plantings/_thumbnail.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/plantings/_thumbnail.html.haml b/app/views/plantings/_thumbnail.html.haml index 6b8400b46..ccb3bb4b0 100644 --- a/app/views/plantings/_thumbnail.html.haml +++ b/app/views/plantings/_thumbnail.html.haml @@ -3,7 +3,7 @@ = render 'plantings/badges', planting: planting .hover-wrapper .thumbnail - .planting-thumbnail{class: planting_classes(planting)} + .planting-thumbnail{ class: planting_classes(planting) } = link_to image_tag(planting_image_path(planting), alt: planting.crop.name, class: 'img'), planting_path(planting) = render 'plantings/progress', planting: planting, show_explanation: false .planting-name From 4ad4dd0c7fb8bf3f522e4ddd87957f26092b4791 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 21 Apr 2018 15:17:51 +1200 Subject: [PATCH 55/82] Style fix up --- app/models/concerns/predict_planting.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/concerns/predict_planting.rb b/app/models/concerns/predict_planting.rb index e0086d959..8298455d7 100644 --- a/app/models/concerns/predict_planting.rb +++ b/app/models/concerns/predict_planting.rb @@ -16,7 +16,7 @@ module PredictPlanting # days def expected_lifespan - actual_lifespan.present? ? actual_lifespan : crop.median_lifespan + actual_lifespan.presence || crop.median_lifespan end def actual_lifespan From e103e6be35e1cb5fbdbe56da753d296793500e77 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 21 Apr 2018 15:32:04 +1200 Subject: [PATCH 56/82] Reducing complexity in planting predictions code --- app/models/concerns/predict_planting.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/models/concerns/predict_planting.rb b/app/models/concerns/predict_planting.rb index 8298455d7..52be89be6 100644 --- a/app/models/concerns/predict_planting.rb +++ b/app/models/concerns/predict_planting.rb @@ -32,12 +32,8 @@ module PredictPlanting def percentage_grown return 100 if finished? return unless finish_is_predicatable? - if growing? - percent = (days_since_planted / expected_lifespan.to_f) * 100 - return 100 if percent > 100 - return percent - end - return 0 if planted? + return calculate_percentage_grown if growing? + 0 if planted? end # states @@ -56,5 +52,12 @@ module PredictPlanting finish_predicted_at.present? && finish_predicted_at <= Time.zone.today end + + private + + def calculate_percentage_grown + percent = (days_since_planted / expected_lifespan.to_f) * 100 + (percent > 100 ? 100 : percent) + end end end From ef9bb01fc984c6e2ee5f12baf1707d38fd28d3bb Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 21 Apr 2018 15:34:18 +1200 Subject: [PATCH 57/82] Wrapped a long line --- app/views/plantings/_thumbnail.html.haml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/plantings/_thumbnail.html.haml b/app/views/plantings/_thumbnail.html.haml index ccb3bb4b0..a6b8349b8 100644 --- a/app/views/plantings/_thumbnail.html.haml +++ b/app/views/plantings/_thumbnail.html.haml @@ -4,7 +4,8 @@ .hover-wrapper .thumbnail .planting-thumbnail{ class: planting_classes(planting) } - = link_to image_tag(planting_image_path(planting), alt: planting.crop.name, class: 'img'), planting_path(planting) + = link_to image_tag(planting_image_path(planting), + alt: planting.crop.name, class: 'img'), planting_path(planting) = render 'plantings/progress', planting: planting, show_explanation: false .planting-name = link_to planting.crop.name, planting From 34145f7b640924d5d6b60d9aaf55d42d657b5a21 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 21 Apr 2018 16:19:51 +1200 Subject: [PATCH 58/82] Translation of string in haml --- app/views/plantings/_badges.html.haml | 8 ++++---- config/locales/en.yml | 11 +++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/views/plantings/_badges.html.haml b/app/views/plantings/_badges.html.haml index 7ec837484..b9e228e20 100644 --- a/app/views/plantings/_badges.html.haml +++ b/app/views/plantings/_badges.html.haml @@ -1,18 +1,18 @@ // Finish times - if planting.finish_is_predicatable? - if planting.zombie? - %span.badge.badge-zombie zombie + %span.badge.badge-zombie=t('.zombie') = render 'shared/buttons/finish_planting', planting: planting - elsif !planting.should_be_finished? %span.badge = days_from_now_to_finished(planting) - days until finished + = t('.days_until_finished') // Harvest times - unless planting.zombie? - if planting.harvest_time? - %span.badge.badge-harvest harvesting now + %span.badge.badge-harvest= t('.harvesting_now') - elsif planting.before_harvest_time? %span.badge = days_from_now_to_first_harvest(planting) - days until harvest + = t('.days_until_harvest') diff --git a/config/locales/en.yml b/config/locales/en.yml index d5d3364a6..d5a22d196 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -52,6 +52,11 @@ en: location_helper: If you have a location set in your profile, it will be used when you create a new garden. location: "%{owner}'s %{garden}" updated: Garden was successfully updated. + overview: + gardensphoto: gardens/photo + plantingsthumbnail: plantings/thumbnail + no_plantings: no plantings + gardensactions: gardens/actions harvests: created: Harvest was successfully created. index: @@ -189,6 +194,12 @@ en: default: Everyone's plantings owner_plantings: "%{owner} plantings" string: "%{crop} planting in %{garden} by %{owner}" + badges: + zombie: zombie + sharedbuttonsfinish_planting: shared/buttons/finish_planting + days_until_finished: days until finished + harvesting_now: harvesting now + days_until_harvest: days until harvest posts: index: title: From 78f021c2f28980ec51c68d3a50ae26931415ed66 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 21 Apr 2018 16:26:40 +1200 Subject: [PATCH 59/82] style fix up --- app/views/plantings/_badges.html.haml | 2 +- app/views/plantings/_progress.html.haml | 2 +- config/locales/en.yml | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/views/plantings/_badges.html.haml b/app/views/plantings/_badges.html.haml index b9e228e20..a75ccb3ee 100644 --- a/app/views/plantings/_badges.html.haml +++ b/app/views/plantings/_badges.html.haml @@ -1,7 +1,7 @@ // Finish times - if planting.finish_is_predicatable? - if planting.zombie? - %span.badge.badge-zombie=t('.zombie') + %span.badge.badge-zombie= t('.zombie') = render 'shared/buttons/finish_planting', planting: planting - elsif !planting.should_be_finished? %span.badge diff --git a/app/views/plantings/_progress.html.haml b/app/views/plantings/_progress.html.haml index caa42bf2a..5d94de1c3 100644 --- a/app/views/plantings/_progress.html.haml +++ b/app/views/plantings/_progress.html.haml @@ -2,7 +2,7 @@ = render "plantings/progress_bar", status: "perennial", progress: nil - elsif !planting.planted? - if show_explanation - %p Progress: 0% - not planted yet + %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 diff --git a/config/locales/en.yml b/config/locales/en.yml index d5a22d196..be173d985 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -200,6 +200,8 @@ en: days_until_finished: days until finished harvesting_now: harvesting now days_until_harvest: days until harvest + progress: + progress_0_not_planted_yet: 'Progress: 0% - not planted yet' posts: index: title: From e5cf8b6091e1c29624f8601e992f16f0f8e61fcc Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 21 Apr 2018 17:25:04 +1200 Subject: [PATCH 60/82] added spec for finished_predicted_at --- spec/models/planting_spec.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spec/models/planting_spec.rb b/spec/models/planting_spec.rb index 809ac845d..6d8e90605 100644 --- a/spec/models/planting_spec.rb +++ b/spec/models/planting_spec.rb @@ -60,9 +60,12 @@ describe Planting do describe 'planting 30 days ago, not finished' do let(:planting) { FactoryBot.create :planting, planted_at: 30.days.ago } - # 30 / 50 + # 30 / 50 = 60% it { expect(planting.percentage_grown).to eq 60.0 } + # planted 30 days ago it { expect(planting.days_since_planted).to eq 30 } + # means 20 days to go + it { expect(planting.finish_predicted_at).to eq Time.zone.today + 20.days } end describe 'planting not planted yet' do From 6677f8641f7643384d5f485af1035c0ad41024c7 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 21 Apr 2018 17:40:22 +1200 Subject: [PATCH 61/82] If not crop lifespan data, use parent data --- app/models/concerns/predict_planting.rb | 29 ++++++++++++++++++++----- spec/models/planting_spec.rb | 14 ++++++++++++ 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/app/models/concerns/predict_planting.rb b/app/models/concerns/predict_planting.rb index 52be89be6..006f51ed6 100644 --- a/app/models/concerns/predict_planting.rb +++ b/app/models/concerns/predict_planting.rb @@ -11,12 +11,24 @@ module PredictPlanting # dates def finish_predicted_at - planted_at + crop.median_lifespan.days if crop.median_lifespan.present? && planted_at.present? + if planted_at.blank? + nil + elsif crop.median_lifespan.present? + planted_at + crop.median_lifespan.days + elsif crop.parent.present? && crop.parent.median_lifespan.present? + planted_at + crop.parent.median_lifespan.days + end end # days def expected_lifespan - actual_lifespan.presence || crop.median_lifespan + if actual_lifespan.present? + actual_lifespan + elsif crop.median_lifespan.present? + crop.median_lifespan + elsif crop.parent.present? && crop.parent.median_lifespan.present? + crop.parent.median_lifespan + end end def actual_lifespan @@ -30,10 +42,15 @@ module PredictPlanting # progress def percentage_grown - return 100 if finished? - return unless finish_is_predicatable? - return calculate_percentage_grown if growing? - 0 if planted? + if finished? + 100 + elsif !finish_is_predicatable? + nil + elsif growing? + calculate_percentage_grown + elsif planted? + 0 + end end # states diff --git a/spec/models/planting_spec.rb b/spec/models/planting_spec.rb index 6d8e90605..6b49f1c0a 100644 --- a/spec/models/planting_spec.rb +++ b/spec/models/planting_spec.rb @@ -68,6 +68,20 @@ describe Planting do it { expect(planting.finish_predicted_at).to eq Time.zone.today + 20.days } end + describe 'child crop uses parent data' do + let(:child_crop) { FactoryBot.create :crop, parent: crop, name: 'child' } + let(:child_planting) { FactoryBot.create :planting, crop: child_crop, planted_at: 30.days.ago } + + # not data for this crop + it { expect(child_crop.median_lifespan).to eq nil } + # 30 / 50 = 60% + it { expect(child_planting.percentage_grown).to eq 60.0 } + # planted 30 days ago + it { expect(child_planting.days_since_planted).to eq 30 } + # means 20 days to go + it { expect(child_planting.finish_predicted_at).to eq Time.zone.today + 20.days } + end + describe 'planting not planted yet' do let(:planting) { FactoryBot.create :planting, planted_at: nil, finished_at: nil } From 86781f3491274d3714db88c078eb7d98d6428cfb Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 21 Apr 2018 21:14:18 +1200 Subject: [PATCH 62/82] Bundle upgrade --- Gemfile.lock | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 8f7585851..e19af5749 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -51,7 +51,7 @@ GEM public_suffix (>= 2.0.2, < 4.0) arel (6.0.4) ast (2.4.0) - autoprefixer-rails (8.2.0) + autoprefixer-rails (8.3.0) execjs bcrypt (3.1.11) better_errors (2.2.0) @@ -76,7 +76,7 @@ GEM activesupport (>= 3.0.0) uniform_notifier (~> 1.11.0) byebug (10.0.2) - cancancan (2.1.3) + cancancan (2.2.0) capybara (2.18.0) addressable mini_mime (>= 0.1.3) @@ -84,13 +84,13 @@ GEM rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (>= 2.0, < 4.0) - capybara-email (2.5.0) - capybara (~> 2.4) + capybara-email (3.0.1) + capybara (>= 2.4, < 4.0) mail - capybara-screenshot (1.0.18) - capybara (>= 1.0, < 3) + capybara-screenshot (1.0.19) + capybara (>= 1.0, < 4) launchy - chartkick (2.3.3) + chartkick (2.3.4) childprocess (0.9.0) ffi (~> 1.0, >= 1.0.11) climate_control (0.2.0) @@ -130,11 +130,11 @@ GEM term-ansicolor (~> 1.3) thor (~> 0.19.1) tins (~> 1.6) - crass (1.0.3) + crass (1.0.4) csv_shaper (1.3.0) activesupport (>= 3.0.0) - dalli (2.7.7) - database_cleaner (1.6.2) + dalli (2.7.8) + database_cleaner (1.7.0) debug_inspector (0.0.3) devise (4.4.3) bcrypt (~> 3.0) @@ -251,7 +251,7 @@ GEM parser (>= 2.2.3.0) term-ansicolor (>= 1.3.2) terminal-table (>= 1.5.1) - jquery-rails (4.3.1) + jquery-rails (4.3.3) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) @@ -326,7 +326,7 @@ GEM omniauth (1.8.1) hashie (>= 3.4.6, < 3.6.0) rack (>= 1.6.2, < 3) - omniauth-facebook (4.0.0) + omniauth-facebook (5.0.0) omniauth-oauth2 (~> 1.2) omniauth-flickr (0.0.19) multi_json (~> 1.11.0) @@ -348,7 +348,7 @@ GEM mimemagic (~> 0.3.0) terrapin (~> 0.6.0) parallel (1.12.1) - parser (2.5.0.5) + parser (2.5.1.0) ast (~> 2.4.0) pg (0.21.0) platform-api (2.1.0) @@ -469,9 +469,9 @@ GEM selenium-webdriver (3.11.0) childprocess (~> 0.5) rubyzip (~> 1.2) - sexp_processor (4.10.1) + sexp_processor (4.11.0) shellany (0.0.1) - sidekiq (5.1.2) + sidekiq (5.1.3) concurrent-ruby (~> 1.0) connection_pool (~> 2.2, >= 2.2.0) rack-protection (>= 1.5.0) @@ -481,8 +481,8 @@ GEM json (>= 1.8, < 3) simplecov-html (~> 0.10.0) simplecov-html (0.10.2) - sparkpost_rails (1.5.0) - rails (>= 4.0, < 5.2) + sparkpost_rails (1.5.1) + rails (>= 4.0, < 5.3) sprockets (3.7.1) concurrent-ruby (~> 1.0) rack (> 1, < 3) @@ -507,9 +507,9 @@ GEM trollop (1.16.2) tzinfo (1.2.5) thread_safe (~> 0.1) - uglifier (4.1.8) + uglifier (4.1.9) execjs (>= 0.3.0, < 3) - unicode-display_width (1.3.0) + unicode-display_width (1.3.2) unicorn (5.4.0) kgio (~> 2.6) raindrops (~> 0.7) From caa5bcec4b44a21b7fcadfea9ad8ca5ee9b90f90 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 21 Apr 2018 21:55:33 +1200 Subject: [PATCH 63/82] Only show finish button if can edit planting --- app/views/plantings/_badges.html.haml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/plantings/_badges.html.haml b/app/views/plantings/_badges.html.haml index a75ccb3ee..cb2019374 100644 --- a/app/views/plantings/_badges.html.haml +++ b/app/views/plantings/_badges.html.haml @@ -2,7 +2,8 @@ - if planting.finish_is_predicatable? - if planting.zombie? %span.badge.badge-zombie= t('.zombie') - = render 'shared/buttons/finish_planting', planting: planting + - if can? :edit, planting + = render 'shared/buttons/finish_planting', planting: planting - elsif !planting.should_be_finished? %span.badge = days_from_now_to_finished(planting) From 6310c518790c1ffbfb53d030368c711b8c7d11a3 Mon Sep 17 00:00:00 2001 From: jenkr55 Date: Sat, 21 Apr 2018 09:08:02 -0500 Subject: [PATCH 64/82] Only show data prompt when there are plantings --- app/views/plantings/_nav.haml | 1 - app/views/plantings/index.html.haml | 21 +++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/views/plantings/_nav.haml b/app/views/plantings/_nav.haml index bb81da701..396d6e021 100644 --- a/app/views/plantings/_nav.haml +++ b/app/views/plantings/_nav.haml @@ -15,4 +15,3 @@ = link_to 'Plant something', new_planting_path, class: 'btn btn-primary' - else = render partial: 'shared/signin_signup', locals: { to: "track what you've planted" } - diff --git a/app/views/plantings/index.html.haml b/app/views/plantings/index.html.haml index 8ad0277d2..b7b3e5785 100644 --- a/app/views/plantings/index.html.haml +++ b/app/views/plantings/index.html.haml @@ -19,13 +19,14 @@ = page_entries_info @plantings = will_paginate @plantings - %ul.list-inline - %li The data on this page is available in the following formats: - - if @owner - %li= link_to "CSV", plantings_by_owner_path(@owner, format: 'csv') - %li= link_to "JSON", plantings_by_owner_path(@owner, format: 'json') - %li= link_to "RSS", plantings_by_owner_path(@owner, format: 'rss') - - else - %li= link_to "CSV", plantings_path(format: 'csv') - %li= link_to "JSON", plantings_path(format: 'json') - %li= link_to "RSS", plantings_path(format: 'rss') + - if @plantings.length > 0 + %ul.list-inline + %li The data on this page is available in the following formats: + - if @owner + %li= link_to "CSV", plantings_by_owner_path(@owner, format: 'csv') + %li= link_to "JSON", plantings_by_owner_path(@owner, format: 'json') + %li= link_to "RSS", plantings_by_owner_path(@owner, format: 'rss') + - else + %li= link_to "CSV", plantings_path(format: 'csv') + %li= link_to "JSON", plantings_path(format: 'json') + %li= link_to "RSS", plantings_path(format: 'rss') From 585e45487a3c892075b14699f72b03d84ba93170 Mon Sep 17 00:00:00 2001 From: jenkr55 Date: Sat, 21 Apr 2018 09:16:17 -0500 Subject: [PATCH 65/82] Fixing button layout issue --- app/assets/stylesheets/overrides.sass | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/assets/stylesheets/overrides.sass b/app/assets/stylesheets/overrides.sass index dda6ecaef..4a4ec6411 100644 --- a/app/assets/stylesheets/overrides.sass +++ b/app/assets/stylesheets/overrides.sass @@ -100,6 +100,8 @@ p.stats dd margin-left: auto +.layout-actions + width: 100% #placesmap, #cropmap height: 500px From cb5d490b1c5774ee8567a6ceb1b3d21f2a454ed7 Mon Sep 17 00:00:00 2001 From: jenkr55 Date: Sat, 21 Apr 2018 10:26:19 -0500 Subject: [PATCH 66/82] Fixing params not being passed to plantings controller --- app/helpers/application_helper.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 639d27686..0b8339960 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -89,8 +89,11 @@ module ApplicationHelper plantings_by_owner_path(owner: owner.slug, all: all) if type == 'plantings' gardens_by_owner_path(owner: owner.slug, all: all) if type == 'gardens' else - plantings_path(all: all) if type == 'plantings' - gardens_path(all: all) if type == 'gardens' + if type == 'plantings' then + plantings_path(all: all) + elsif type == 'gardens' then + gardens_path(all: all) + end end end From 6cbf7d0bba0064980b50d7cf3e69d4b368ba445c Mon Sep 17 00:00:00 2001 From: jenkr55 Date: Sat, 21 Apr 2018 10:29:13 -0500 Subject: [PATCH 67/82] Fixing parmas issue for owner --- app/helpers/application_helper.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0b8339960..9259f38d2 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -86,8 +86,11 @@ module ApplicationHelper def show_inactive_tickbox_path(type, owner, show_all) all = show_all ? '' : 1 if owner - plantings_by_owner_path(owner: owner.slug, all: all) if type == 'plantings' - gardens_by_owner_path(owner: owner.slug, all: all) if type == 'gardens' + if type == 'plantings' then + plantings_by_owner_path(owner: owner.slug, all: all) + elsif type == 'gardens' then + gardens_by_owner_path(owner: owner.slug, all: all) + end else if type == 'plantings' then plantings_path(all: all) From e767ea6b38b6aee024d67e8cb560a5c45e6e86cf Mon Sep 17 00:00:00 2001 From: jenkr55 Date: Sat, 21 Apr 2018 10:36:33 -0500 Subject: [PATCH 68/82] Fixing planting wrapping issue --- app/assets/stylesheets/overrides.sass | 2 +- app/views/plantings/index.html.haml | 4 ++-- app/views/seeds/index.html.haml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/assets/stylesheets/overrides.sass b/app/assets/stylesheets/overrides.sass index 4a4ec6411..f61ec813a 100644 --- a/app/assets/stylesheets/overrides.sass +++ b/app/assets/stylesheets/overrides.sass @@ -74,7 +74,7 @@ p.stats flex: none flex-wrap: wrap -.seeds-row +.card-row display: grid grid-template-columns: 50% 50% grid-gap: 25px diff --git a/app/views/plantings/index.html.haml b/app/views/plantings/index.html.haml index b7b3e5785..c5161b9d1 100644 --- a/app/views/plantings/index.html.haml +++ b/app/views/plantings/index.html.haml @@ -9,10 +9,10 @@ = page_entries_info @plantings = will_paginate @plantings -.row +.card-row - unless @plantings.empty? - @plantings.each.with_index do |planting| - .col-xs-12.col-lg-6 + .card = render partial: "plantings/card", locals: { planting: planting } .pagination diff --git a/app/views/seeds/index.html.haml b/app/views/seeds/index.html.haml index 0be394edf..5e2eabece 100644 --- a/app/views/seeds/index.html.haml +++ b/app/views/seeds/index.html.haml @@ -24,7 +24,7 @@ = page_entries_info @seeds = will_paginate @seeds -.seeds-row +.card-row - unless @seeds.empty? - @seeds.each do |seed| .seedcard From 0b191049b2028c71f9226fb12de6157738324661 Mon Sep 17 00:00:00 2001 From: jenkr55 Date: Sat, 21 Apr 2018 10:46:27 -0500 Subject: [PATCH 69/82] Undo this --- app/views/plantings/index.html.haml | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/app/views/plantings/index.html.haml b/app/views/plantings/index.html.haml index c5161b9d1..3302bdacb 100644 --- a/app/views/plantings/index.html.haml +++ b/app/views/plantings/index.html.haml @@ -19,14 +19,13 @@ = page_entries_info @plantings = will_paginate @plantings - - if @plantings.length > 0 - %ul.list-inline - %li The data on this page is available in the following formats: - - if @owner - %li= link_to "CSV", plantings_by_owner_path(@owner, format: 'csv') - %li= link_to "JSON", plantings_by_owner_path(@owner, format: 'json') - %li= link_to "RSS", plantings_by_owner_path(@owner, format: 'rss') - - else - %li= link_to "CSV", plantings_path(format: 'csv') - %li= link_to "JSON", plantings_path(format: 'json') - %li= link_to "RSS", plantings_path(format: 'rss') + %ul.list-inline + %li The data on this page is available in the following formats: + - if @owner + %li= link_to "CSV", plantings_by_owner_path(@owner, format: 'csv') + %li= link_to "JSON", plantings_by_owner_path(@owner, format: 'json') + %li= link_to "RSS", plantings_by_owner_path(@owner, format: 'rss') + - else + %li= link_to "CSV", plantings_path(format: 'csv') + %li= link_to "JSON", plantings_path(format: 'json') + %li= link_to "RSS", plantings_path(format: 'rss') From ef74cc293d42569d5c67e9e9e6c98efcf079b30c Mon Sep 17 00:00:00 2001 From: jenkr55 Date: Sat, 21 Apr 2018 10:51:19 -0500 Subject: [PATCH 70/82] Rubocop --- app/helpers/application_helper.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 9259f38d2..7ef7bc02f 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -86,17 +86,15 @@ module ApplicationHelper def show_inactive_tickbox_path(type, owner, show_all) all = show_all ? '' : 1 if owner - if type == 'plantings' then + if type == 'plantings' plantings_by_owner_path(owner: owner.slug, all: all) - elsif type == 'gardens' then + elsif type == 'gardens' gardens_by_owner_path(owner: owner.slug, all: all) end - else - if type == 'plantings' then - plantings_path(all: all) - elsif type == 'gardens' then - gardens_path(all: all) - end + elsif type == 'plantings' + plantings_path(all: all) + elsif type == 'gardens' + gardens_path(all: all) end end From c94d08c816832ea43ded72217d78179a7a62bfac Mon Sep 17 00:00:00 2001 From: jenkr55 Date: Sat, 21 Apr 2018 20:09:23 -0500 Subject: [PATCH 71/82] Moving bio to be by other profile information --- app/views/members/show.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/members/show.html.haml b/app/views/members/show.html.haml index 478574b3b..74c61ebd7 100644 --- a/app/views/members/show.html.haml +++ b/app/views/members/show.html.haml @@ -27,10 +27,10 @@ .col-md-9 = render partial: "map", locals: { member: @member } - = render partial: "bio", locals: { member: @member } = render partial: "gardens", locals: { member: @member, gardens: @gardens } .col-md-3 = render partial: "avatar", locals: { member: @member } + = render partial: "bio", locals: { member: @member } = render partial: "roles", locals: { member: @member } = render partial: "stats", locals: { member: @member } = render partial: "contact", locals: { member: @member, From 7be10957ec4f527cdaec67c116189a8a7d02d6f5 Mon Sep 17 00:00:00 2001 From: jenkr55 Date: Sat, 21 Apr 2018 21:05:58 -0500 Subject: [PATCH 72/82] WIP different profile page --- app/assets/stylesheets/overrides.sass | 25 +++++++++++++++++++++++++ app/controllers/members_controller.rb | 1 + app/views/members/_avatar.html.haml | 2 +- app/views/members/_gardens.html.haml | 5 ++--- app/views/members/_harvests.html.haml | 4 ++++ app/views/members/_map.html.haml | 2 +- app/views/members/_stats.html.haml | 2 +- app/views/members/show.html.haml | 22 ++++++++++++++++------ 8 files changed, 51 insertions(+), 12 deletions(-) create mode 100644 app/views/members/_harvests.html.haml diff --git a/app/assets/stylesheets/overrides.sass b/app/assets/stylesheets/overrides.sass index f61ec813a..3de542b21 100644 --- a/app/assets/stylesheets/overrides.sass +++ b/app/assets/stylesheets/overrides.sass @@ -12,6 +12,10 @@ body .list-inline > li.first padding-left: 0px +.activity-list + list-style-type: none + padding: 0 + h2 font-size: 150% @@ -34,6 +38,20 @@ h3 max-width: 100% height: auto +.profile-img + border-radius: 50% + z-index: 2 + position: relative + width: 80% + +.profile-sidebar + margin-top: -5rem + +.profile-activity + background: white + padding: 2em + margin-top: 2em + .sidebar border-left: 1px solid darken($beige, 10%) margin-left: -1px @@ -80,6 +98,12 @@ p.stats grid-gap: 25px grid-row-gap: 5px +.card-row-short + display: grid + grid-template-columns: 47.5% 47.5% + grid-gap: 25px + grid-row-gap: 5px + .member-thumbnail padding: .25em margin: 1em @@ -108,6 +132,7 @@ p.stats #membermap height: 250px + z-index: 0 .location-not-set height: 250px diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index c346eb8e3..ae720e57b 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -20,6 +20,7 @@ class MembersController < ApplicationController @facebook_auth = @member.auth('facebook') @posts = @member.posts @gardens = @member.gardens.active.order(:name) + @harvests = @member.harvests # The garden form partial is called from the "New Garden" tab; # it requires a garden to be passed in @garden. diff --git a/app/views/members/_avatar.html.haml b/app/views/members/_avatar.html.haml index 421424256..9417f466f 100644 --- a/app/views/members/_avatar.html.haml +++ b/app/views/members/_avatar.html.haml @@ -1,5 +1,5 @@ - if member = link_to image_tag(avatar_uri(member, 150), alt: '', - class: 'img img-responsive avatar'), + class: 'img img-responsive avatar profile-img'), member_path(member) diff --git a/app/views/members/_gardens.html.haml b/app/views/members/_gardens.html.haml index 7e1bc61ca..ee41feb77 100644 --- a/app/views/members/_gardens.html.haml +++ b/app/views/members/_gardens.html.haml @@ -1,4 +1,3 @@ -%h2 #{member.login_name}'s gardens .tabbable %ul.nav.nav-tabs - first_garden = true @@ -45,10 +44,10 @@ = link_to "Add photo", new_photo_path(type: "garden", id: g.id), class: 'btn btn-primary' %h3 What's planted here? - .row + .card-row-short - unless g.featured_plantings.empty? - g.featured_plantings.each.with_index do |planting| - .col-xs-12.col-lg-6 + .card = render partial: "plantings/card", locals: { planting: planting } %p diff --git a/app/views/members/_harvests.html.haml b/app/views/members/_harvests.html.haml new file mode 100644 index 000000000..3a5a54a0a --- /dev/null +++ b/app/views/members/_harvests.html.haml @@ -0,0 +1,4 @@ +.card-row-short + - harvests.each do |harvest| + .card + = render partial: "harvests/card", locals: { harvest: harvest } diff --git a/app/views/members/_map.html.haml b/app/views/members/_map.html.haml index 253f3b3ec..711e4d9e0 100644 --- a/app/views/members/_map.html.haml +++ b/app/views/members/_map.html.haml @@ -1,6 +1,6 @@ - if member.latitude && member.longitude #membermap - %p + %p.pull-right See other members, plantings, seeds and more near = link_to member.location, place_path(member.location, anchor: "members") - else diff --git a/app/views/members/_stats.html.haml b/app/views/members/_stats.html.haml index a2ebab47d..2db447d4c 100644 --- a/app/views/members/_stats.html.haml +++ b/app/views/members/_stats.html.haml @@ -7,7 +7,7 @@ %h3 Activity -%ul.list-inline +%ul.activity-list %li - if !member.plantings.empty? = link_to localize_plural(member.plantings, Planting), plantings_by_owner_path(owner: member) diff --git a/app/views/members/show.html.haml b/app/views/members/show.html.haml index 74c61ebd7..7682fd49b 100644 --- a/app/views/members/show.html.haml +++ b/app/views/members/show.html.haml @@ -9,7 +9,7 @@ = tag("meta", property: "og:site_name", content: ENV['GROWSTUFF_SITE_NAME']) - content_for :buttonbar do - if can? :update, @member - = link_to 'Edit profile', edit_member_registration_path, class: 'btn btn-default' + = link_to 'Edit profile', edit_member_registration_path, class: 'btn btn-default pull-right' - if can?(:create, Notification) && current_member != @member = link_to 'Send message', new_notification_path(recipient_id: @member.id), class: 'btn btn-default' @@ -24,11 +24,8 @@ - content_for :member_rss_slug, @member.slug .row - - .col-md-9 - = render partial: "map", locals: { member: @member } - = render partial: "gardens", locals: { member: @member, gardens: @gardens } - .col-md-3 + = render partial: "map", locals: { member: @member } + .col-md-2.profile-sidebar = render partial: "avatar", locals: { member: @member } = render partial: "bio", locals: { member: @member } = render partial: "roles", locals: { member: @member } @@ -37,3 +34,16 @@ twitter_auth: @twitter_auth, flickr_auth: @flickr_auth, facebook_auth: @facebook_auth } + + .col-md-10 + %ul.nav.nav-pills.nav-justified + %li.active + %a{"data-toggle" => "tab", href: "#gardens"} Gardens + %li + %a{"data-toggle" => "tab", href: "#harvests"} Harvests + / Tab panes + .tab-content.profile-activity + #gardens.tab-pane.active + = render partial: "gardens", locals: { member: @member, gardens: @gardens } + #harvests.tab-pane + = render partial: "harvests", locals: { member: @member, harvests: @harvests } From 77978a76f2576496c0b19bbb5ec1e0b5a473e1a1 Mon Sep 17 00:00:00 2001 From: jenkr55 Date: Sat, 21 Apr 2018 21:27:40 -0500 Subject: [PATCH 73/82] Fixing notes display bug on harvest card --- app/views/harvests/_card.html.haml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/harvests/_card.html.haml b/app/views/harvests/_card.html.haml index 52cfb3627..c2f528cdc 100644 --- a/app/views/harvests/_card.html.haml +++ b/app/views/harvests/_card.html.haml @@ -21,8 +21,8 @@ %dd= display_quantity(harvest) %dt Harvest date : %dd= harvest.harvested_at - %dd Notes: - %dt=display_harvest_description(harvest) + %dt Notes: + %dd=display_harvest_description(harvest) - if harvest.planting.present? %dt Harvested from %dd= link_to(harvest.planting, planting_path(harvest.planting)) From fa28fe25b62a516836bdd4991c4d5eebfe6f270e Mon Sep 17 00:00:00 2001 From: jenkr55 Date: Sat, 21 Apr 2018 21:43:19 -0500 Subject: [PATCH 74/82] Fixing responsive design issues --- app/assets/stylesheets/overrides.sass | 19 +++++++------------ app/views/members/_gardens.html.haml | 2 +- app/views/members/_harvests.html.haml | 2 ++ app/views/members/show.html.haml | 7 +++---- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/app/assets/stylesheets/overrides.sass b/app/assets/stylesheets/overrides.sass index 3de542b21..c7cee0cc4 100644 --- a/app/assets/stylesheets/overrides.sass +++ b/app/assets/stylesheets/overrides.sass @@ -38,19 +38,20 @@ h3 max-width: 100% height: auto -.profile-img - border-radius: 50% - z-index: 2 - position: relative - width: 80% - .profile-sidebar margin-top: -5rem + .avatar + border-radius: 50% + border-radius: 50% + z-index: 2 + position: relative .profile-activity background: white padding: 2em margin-top: 2em + .container + width: 100% .sidebar border-left: 1px solid darken($beige, 10%) @@ -98,12 +99,6 @@ p.stats grid-gap: 25px grid-row-gap: 5px -.card-row-short - display: grid - grid-template-columns: 47.5% 47.5% - grid-gap: 25px - grid-row-gap: 5px - .member-thumbnail padding: .25em margin: 1em diff --git a/app/views/members/_gardens.html.haml b/app/views/members/_gardens.html.haml index ee41feb77..5872f4926 100644 --- a/app/views/members/_gardens.html.haml +++ b/app/views/members/_gardens.html.haml @@ -44,7 +44,7 @@ = link_to "Add photo", new_photo_path(type: "garden", id: g.id), class: 'btn btn-primary' %h3 What's planted here? - .card-row-short + .card-row - unless g.featured_plantings.empty? - g.featured_plantings.each.with_index do |planting| .card diff --git a/app/views/members/_harvests.html.haml b/app/views/members/_harvests.html.haml index 3a5a54a0a..248510c27 100644 --- a/app/views/members/_harvests.html.haml +++ b/app/views/members/_harvests.html.haml @@ -2,3 +2,5 @@ - harvests.each do |harvest| .card = render partial: "harvests/card", locals: { harvest: harvest } +- if !harvests.any? + #{member.login_name} hasn't harvested anything yet. diff --git a/app/views/members/show.html.haml b/app/views/members/show.html.haml index 7682fd49b..500ea039c 100644 --- a/app/views/members/show.html.haml +++ b/app/views/members/show.html.haml @@ -11,14 +11,14 @@ - if can? :update, @member = link_to 'Edit profile', edit_member_registration_path, class: 'btn btn-default pull-right' - if can?(:create, Notification) && current_member != @member - = link_to 'Send message', new_notification_path(recipient_id: @member.id), class: 'btn btn-default' + = link_to 'Send message', new_notification_path(recipient_id: @member.id), class: 'btn btn-default pull-right' - if current_member && current_member != @member # must be logged in, can't follow yourself - follow = current_member.get_follow(@member) - if !follow && can?(:create, Follow) # not already following - = link_to 'Follow', follows_path(followed_id: @member.id), method: :post, class: 'btn btn-default' + = link_to 'Follow', follows_path(followed_id: @member.id), method: :post, class: 'btn btn-default pull-right' - if follow && can?(:destroy, follow) # already following - = link_to 'Unfollow', follow_path(follow), method: :delete, class: 'btn btn-default' + = link_to 'Unfollow', follow_path(follow), method: :delete, class: 'btn btn-default pull-right' - content_for :member_rss_login_name, @member.login_name - content_for :member_rss_slug, @member.slug @@ -41,7 +41,6 @@ %a{"data-toggle" => "tab", href: "#gardens"} Gardens %li %a{"data-toggle" => "tab", href: "#harvests"} Harvests - / Tab panes .tab-content.profile-activity #gardens.tab-pane.active = render partial: "gardens", locals: { member: @member, gardens: @gardens } From 028c2a28a5cc6f32fcd29c5bd20056b905980ac0 Mon Sep 17 00:00:00 2001 From: jenkr55 Date: Sat, 21 Apr 2018 21:52:55 -0500 Subject: [PATCH 75/82] unneeded class --- app/views/members/_avatar.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/members/_avatar.html.haml b/app/views/members/_avatar.html.haml index 9417f466f..421424256 100644 --- a/app/views/members/_avatar.html.haml +++ b/app/views/members/_avatar.html.haml @@ -1,5 +1,5 @@ - if member = link_to image_tag(avatar_uri(member, 150), alt: '', - class: 'img img-responsive avatar profile-img'), + class: 'img img-responsive avatar'), member_path(member) From 25bba9c1267ade296ccb89d4f51b6340efc2cc67 Mon Sep 17 00:00:00 2001 From: jenkr55 Date: Sat, 21 Apr 2018 21:55:29 -0500 Subject: [PATCH 76/82] format fixes --- app/views/harvests/_card.html.haml | 2 +- app/views/members/show.html.haml | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/views/harvests/_card.html.haml b/app/views/harvests/_card.html.haml index c2f528cdc..02ad5d3e0 100644 --- a/app/views/harvests/_card.html.haml +++ b/app/views/harvests/_card.html.haml @@ -22,7 +22,7 @@ %dt Harvest date : %dd= harvest.harvested_at %dt Notes: - %dd=display_harvest_description(harvest) + %dd= display_harvest_description(harvest) - if harvest.planting.present? %dt Harvested from %dd= link_to(harvest.planting, planting_path(harvest.planting)) diff --git a/app/views/members/show.html.haml b/app/views/members/show.html.haml index 500ea039c..621f35c51 100644 --- a/app/views/members/show.html.haml +++ b/app/views/members/show.html.haml @@ -38,11 +38,11 @@ .col-md-10 %ul.nav.nav-pills.nav-justified %li.active - %a{"data-toggle" => "tab", href: "#gardens"} Gardens + %a{ "data-toggle" => "tab", href: "#gardens" } Gardens %li - %a{"data-toggle" => "tab", href: "#harvests"} Harvests + %a{ "data-toggle" => "tab", href: "#harvests" } Harvests .tab-content.profile-activity - #gardens.tab-pane.active + .tab-pane.active#gardens = render partial: "gardens", locals: { member: @member, gardens: @gardens } - #harvests.tab-pane + .tab-pane#harvests = render partial: "harvests", locals: { member: @member, harvests: @harvests } From eed0b257fa26fee23fd332771d9e19554acb2335 Mon Sep 17 00:00:00 2001 From: jenkr55 Date: Sat, 21 Apr 2018 22:03:31 -0500 Subject: [PATCH 77/82] Fixing test because I removed this line --- spec/features/member_profile_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/features/member_profile_spec.rb b/spec/features/member_profile_spec.rb index 9f1005894..db7d4f595 100644 --- a/spec/features/member_profile_spec.rb +++ b/spec/features/member_profile_spec.rb @@ -9,7 +9,6 @@ feature "member profile", js: true do expect(page).to have_css("h1", text: member.login_name) expect(page).to have_content member.bio expect(page).to have_content "Member since: #{member.created_at.to_s(:date)}" - expect(page).to have_content "#{member.login_name}'s gardens" expect(page).to have_link "More about this garden...", href: garden_path(member.gardens.first) end From db0c60be0df9c42486232cb4095eecdd229772b5 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 23 Apr 2018 13:33:38 +1200 Subject: [PATCH 78/82] Rename zombie to super_late --- app/assets/stylesheets/overrides.sass | 4 ++-- app/helpers/plantings_helper.rb | 2 +- app/models/concerns/predict_planting.rb | 3 ++- app/views/plantings/_badges.html.haml | 6 +++--- config/locales/en.yml | 2 +- spec/features/gardens/gardens_index_spec.rb | 4 ++-- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/app/assets/stylesheets/overrides.sass b/app/assets/stylesheets/overrides.sass index 920dbd5d4..3c44ffa62 100644 --- a/app/assets/stylesheets/overrides.sass +++ b/app/assets/stylesheets/overrides.sass @@ -115,12 +115,12 @@ p.stats .progress border-radius: 0 -.badge-zombie +.badge-super-late background-color: $red .badge-harvest background-color: $blue -.planting-zombie +.planting-super-late .planting-predicted-finished background-color: $beige diff --git a/app/helpers/plantings_helper.rb b/app/helpers/plantings_helper.rb index b57a1dc4a..dd96ce5fa 100644 --- a/app/helpers/plantings_helper.rb +++ b/app/helpers/plantings_helper.rb @@ -49,7 +49,7 @@ module PlantingsHelper classes << 'planting-finished' if planting.finished? classes << 'planting-harvest-time' if planting.harvest_time? classes << 'planting-predicted-finished' if planting.should_be_finished? - classes << 'planting-zombie' if planting.zombie? + classes << 'planting-super-late' if planting.super_late? classes.join(' ') end end diff --git a/app/models/concerns/predict_planting.rb b/app/models/concerns/predict_planting.rb index 006f51ed6..9cc0e5521 100644 --- a/app/models/concerns/predict_planting.rb +++ b/app/models/concerns/predict_planting.rb @@ -58,7 +58,8 @@ module PredictPlanting crop.annual? && planted_at.present? && finish_predicted_at.present? end - def zombie? + # Planting has live more then 90 days past predicted finish + def super_late? should_be_finished? && (finish_predicted_at + 90.days) < Time.zone.today end diff --git a/app/views/plantings/_badges.html.haml b/app/views/plantings/_badges.html.haml index cb2019374..561a22538 100644 --- a/app/views/plantings/_badges.html.haml +++ b/app/views/plantings/_badges.html.haml @@ -1,7 +1,7 @@ // Finish times - if planting.finish_is_predicatable? - - if planting.zombie? - %span.badge.badge-zombie= t('.zombie') + - if planting.super_late? + %span.badge.badge-super late= t('.super late') - if can? :edit, planting = render 'shared/buttons/finish_planting', planting: planting - elsif !planting.should_be_finished? @@ -10,7 +10,7 @@ = t('.days_until_finished') // Harvest times -- unless planting.zombie? +- unless planting.super_late? - if planting.harvest_time? %span.badge.badge-harvest= t('.harvesting_now') - elsif planting.before_harvest_time? diff --git a/config/locales/en.yml b/config/locales/en.yml index be173d985..3cc1a947a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -195,7 +195,7 @@ en: owner_plantings: "%{owner} plantings" string: "%{crop} planting in %{garden} by %{owner}" badges: - zombie: zombie + super late: super late sharedbuttonsfinish_planting: shared/buttons/finish_planting days_until_finished: days until finished harvesting_now: harvesting now diff --git a/spec/features/gardens/gardens_index_spec.rb b/spec/features/gardens/gardens_index_spec.rb index 516796641..0a973e305 100644 --- a/spec/features/gardens/gardens_index_spec.rb +++ b/spec/features/gardens/gardens_index_spec.rb @@ -120,13 +120,13 @@ feature "Gardens#index", :js do it { expect(page).not_to have_text 'days until harvest' } end - describe 'zombie' do + describe 'super late' do let!(:planting) do FactoryBot.create :planting, crop: crop, owner: member, garden: garden, planted_at: 260.days.ago end - it { expect(page).to have_text 'zombie' } + it { expect(page).to have_text 'super late' } it { expect(page).not_to have_text 'harvesting now' } it { expect(page).not_to have_text 'days until harvest' } it { expect(page).not_to have_text 'days until finished' } From fc46685ab97828930f6a96dc04132a871f71e4db Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 23 Apr 2018 13:44:53 +1200 Subject: [PATCH 79/82] Renamed should_be_finshed? to late? --- app/assets/stylesheets/overrides.sass | 2 +- app/helpers/plantings_helper.rb | 2 +- app/models/concerns/predict_planting.rb | 5 ++--- app/views/plantings/_badges.html.haml | 9 +++++---- app/views/shared/buttons/_finish_planting.html.haml | 2 +- config/locales/en.yml | 3 ++- 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/app/assets/stylesheets/overrides.sass b/app/assets/stylesheets/overrides.sass index 3c44ffa62..b255536ea 100644 --- a/app/assets/stylesheets/overrides.sass +++ b/app/assets/stylesheets/overrides.sass @@ -121,7 +121,7 @@ p.stats background-color: $blue .planting-super-late -.planting-predicted-finished +.planting-late background-color: $beige .planting diff --git a/app/helpers/plantings_helper.rb b/app/helpers/plantings_helper.rb index dd96ce5fa..4ea42f43e 100644 --- a/app/helpers/plantings_helper.rb +++ b/app/helpers/plantings_helper.rb @@ -48,7 +48,7 @@ module PlantingsHelper classes << 'planting-growing' if planting.growing? classes << 'planting-finished' if planting.finished? classes << 'planting-harvest-time' if planting.harvest_time? - classes << 'planting-predicted-finished' if planting.should_be_finished? + classes << 'planting-late' if planting.late? classes << 'planting-super-late' if planting.super_late? classes.join(' ') end diff --git a/app/models/concerns/predict_planting.rb b/app/models/concerns/predict_planting.rb index 9cc0e5521..ff66168d8 100644 --- a/app/models/concerns/predict_planting.rb +++ b/app/models/concerns/predict_planting.rb @@ -60,11 +60,10 @@ module PredictPlanting # Planting has live more then 90 days past predicted finish def super_late? - should_be_finished? && - (finish_predicted_at + 90.days) < Time.zone.today + late? && (finish_predicted_at + 90.days) < Time.zone.today end - def should_be_finished? + def late? crop.annual? && !finished && planted_at.present? && finish_predicted_at.present? && diff --git a/app/views/plantings/_badges.html.haml b/app/views/plantings/_badges.html.haml index 561a22538..2d690b914 100644 --- a/app/views/plantings/_badges.html.haml +++ b/app/views/plantings/_badges.html.haml @@ -1,10 +1,11 @@ // Finish times - if planting.finish_is_predicatable? - if planting.super_late? - %span.badge.badge-super late= t('.super late') - - if can? :edit, planting - = render 'shared/buttons/finish_planting', planting: planting - - elsif !planting.should_be_finished? + %span.badge.badge-super-late= t('.super_late') + = render 'shared/buttons/finish_planting', planting: planting + - elsif planting.late? + %span.badge.badge-late= t('.late_finishing') + - else %span.badge = days_from_now_to_finished(planting) = t('.days_until_finished') diff --git a/app/views/shared/buttons/_finish_planting.html.haml b/app/views/shared/buttons/_finish_planting.html.haml index 9a3b6ce75..7b1ba8319 100644 --- a/app/views/shared/buttons/_finish_planting.html.haml +++ b/app/views/shared/buttons/_finish_planting.html.haml @@ -1,4 +1,4 @@ -- unless planting.finished +- if can?(:edit, planting) && !planting.finished = link_to planting_path(planting, planting: { finished: 1 }), method: :put, class: 'btn btn-default btn-xs append-date' do %span.glyphicon.glyphicon-ok{ title: "Finished" } diff --git a/config/locales/en.yml b/config/locales/en.yml index 3cc1a947a..09d5687f8 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -195,7 +195,8 @@ en: owner_plantings: "%{owner} plantings" string: "%{crop} planting in %{garden} by %{owner}" badges: - super late: super late + late_finishing: late finishing + super_late: super late sharedbuttonsfinish_planting: shared/buttons/finish_planting days_until_finished: days until finished harvesting_now: harvesting now From 85eea897926679d68e0486273cb45f39b38141da Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 23 Apr 2018 15:40:56 +1200 Subject: [PATCH 80/82] i18n for plantings#index --- app/views/plantings/index.html.haml | 15 +++++---------- config/locales/en.yml | 2 ++ 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/app/views/plantings/index.html.haml b/app/views/plantings/index.html.haml index 3302bdacb..2dc58ccde 100644 --- a/app/views/plantings/index.html.haml +++ b/app/views/plantings/index.html.haml @@ -3,7 +3,7 @@ = render 'nav', owner: @owner, show_all: @show_all - if @owner - = link_to "View #{@owner}'s profile >>", member_path(@owner) + = link_to t('.view_owners_profile', owner: @owner), member_path(@owner) .pagination = page_entries_info @plantings @@ -20,12 +20,7 @@ = will_paginate @plantings %ul.list-inline - %li The data on this page is available in the following formats: - - if @owner - %li= link_to "CSV", plantings_by_owner_path(@owner, format: 'csv') - %li= link_to "JSON", plantings_by_owner_path(@owner, format: 'json') - %li= link_to "RSS", plantings_by_owner_path(@owner, format: 'rss') - - else - %li= link_to "CSV", plantings_path(format: 'csv') - %li= link_to "JSON", plantings_path(format: 'json') - %li= link_to "RSS", plantings_path(format: 'rss') + %li= t('.the_data_on_this_page_is_available_in_the_following_formats') + - ['csv', 'json', 'rss'].each do |format| + %li= link_to format.upcase, + (@owner ? plantings_by_owner_path(@owner, format: format) : plantings_path(format: format)) diff --git a/config/locales/en.yml b/config/locales/en.yml index d5d3364a6..b78d869ea 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -188,6 +188,8 @@ en: crop_plantings: Everyone's %{crop} plantings default: Everyone's plantings owner_plantings: "%{owner} plantings" + view_owners_profile: View %{owner}'s profile >> + the_data_on_this_page_is_available_in_the_following_formats: 'The data on this page is available in the following formats:' string: "%{crop} planting in %{garden} by %{owner}" posts: index: From 5b5eacb738e511ca185449a3037aa9f4e3320907 Mon Sep 17 00:00:00 2001 From: deppbot Date: Thu, 26 Apr 2018 09:23:58 +0800 Subject: [PATCH 81/82] Bundle Update on 2018-04-26 --- Gemfile.lock | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index e19af5749..1ca28af8d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -61,7 +61,9 @@ GEM binding_of_caller (0.8.0) debug_inspector (>= 0.0.1) bluecloth (2.2.0) - bonsai-elasticsearch-rails (0.0.4) + bonsai-elasticsearch-rails (0.2.0) + elasticsearch-model (~> 0) + elasticsearch-rails (~> 0) bootstrap-datepicker-rails (1.8.0.1) railties (>= 3.0) bootstrap-kaminari-views (0.0.5) @@ -152,11 +154,11 @@ GEM elasticsearch-transport (= 2.0.2) elasticsearch-api (2.0.2) multi_json - elasticsearch-model (5.0.0) + elasticsearch-model (0.1.9) activesupport (> 3) - elasticsearch (> 1) + elasticsearch (> 0.4) hashie - elasticsearch-rails (5.0.2) + elasticsearch-rails (0.1.9) elasticsearch-transport (2.0.2) faraday multi_json @@ -179,7 +181,7 @@ GEM font-awesome-sass (5.0.9) sass (>= 3.2) formatador (0.2.5) - friendly_id (5.2.3) + friendly_id (5.2.4) activerecord (>= 4.0.0) geocoder (1.4.7) gibbon (1.2.1) @@ -367,7 +369,7 @@ GEM public_suffix (3.0.2) quiet_assets (1.1.0) railties (>= 3.1, < 5.0) - rack (1.6.9) + rack (1.6.10) rack-protection (2.0.1) rack rack-test (0.6.3) @@ -507,7 +509,7 @@ GEM trollop (1.16.2) tzinfo (1.2.5) thread_safe (~> 0.1) - uglifier (4.1.9) + uglifier (4.1.10) execjs (>= 0.3.0, < 3) unicode-display_width (1.3.2) unicorn (5.4.0) @@ -619,6 +621,7 @@ DEPENDENCIES will_paginate xmlrpc + RUBY VERSION ruby 2.4.1p111 From aa9841dc7db47deb1f0cea7ae7a903b46e3cf692 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 28 Apr 2018 18:33:09 +1200 Subject: [PATCH 82/82] Pinned elastic search to 5.0.0. or later --- Gemfile | 4 ++-- Gemfile.lock | 17 +++++++---------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/Gemfile b/Gemfile index bc3d45a34..c55d5e70f 100644 --- a/Gemfile +++ b/Gemfile @@ -87,8 +87,8 @@ gem "chartkick" # elasticsearch we use # See https://github.com/elastic/elasticsearch-ruby#compatibility gem "elasticsearch-api", "~> 2.0.0" -gem "elasticsearch-model" -gem "elasticsearch-rails" +gem "elasticsearch-model", ">= 5.0.0" +gem "elasticsearch-rails", ">= 5.0.0" gem "hashie", ">= 3.5.3" gem 'rake', '>= 10.0.0' diff --git a/Gemfile.lock b/Gemfile.lock index 1ca28af8d..015c12fb6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -51,7 +51,7 @@ GEM public_suffix (>= 2.0.2, < 4.0) arel (6.0.4) ast (2.4.0) - autoprefixer-rails (8.3.0) + autoprefixer-rails (8.3.0.1) execjs bcrypt (3.1.11) better_errors (2.2.0) @@ -61,9 +61,7 @@ GEM binding_of_caller (0.8.0) debug_inspector (>= 0.0.1) bluecloth (2.2.0) - bonsai-elasticsearch-rails (0.2.0) - elasticsearch-model (~> 0) - elasticsearch-rails (~> 0) + bonsai-elasticsearch-rails (0.0.4) bootstrap-datepicker-rails (1.8.0.1) railties (>= 3.0) bootstrap-kaminari-views (0.0.5) @@ -154,11 +152,11 @@ GEM elasticsearch-transport (= 2.0.2) elasticsearch-api (2.0.2) multi_json - elasticsearch-model (0.1.9) + elasticsearch-model (5.0.0) activesupport (> 3) - elasticsearch (> 0.4) + elasticsearch (> 1) hashie - elasticsearch-rails (0.1.9) + elasticsearch-rails (5.0.2) elasticsearch-transport (2.0.2) faraday multi_json @@ -561,8 +559,8 @@ DEPENDENCIES database_cleaner devise elasticsearch-api (~> 2.0.0) - elasticsearch-model - elasticsearch-rails + elasticsearch-model (>= 5.0.0) + elasticsearch-rails (>= 5.0.0) factory_bot_rails faker figaro @@ -621,7 +619,6 @@ DEPENDENCIES will_paginate xmlrpc - RUBY VERSION ruby 2.4.1p111