From 36bad1cda0fd3ae44ea73a66f02408aa9cec4340 Mon Sep 17 00:00:00 2001 From: Brenda Date: Sun, 23 Feb 2020 11:42:07 +1300 Subject: [PATCH] Fix mobile display of member profiles --- app/assets/stylesheets/_harvests.scss | 18 ++++++--- app/assets/stylesheets/_plantings.scss | 7 ---- app/assets/stylesheets/mobile.scss | 2 +- app/controllers/members_controller.rb | 7 ++++ app/views/harvests/_thumbnail.html.haml | 17 ++++---- app/views/members/_full_summary.html.haml | 20 ++++++++-- app/views/plantings/_badges.html.haml | 1 - app/views/plantings/_thumbnail.html.haml | 9 +++-- spec/features/members/profile_spec.rb | 48 +++++++++++++++++++++++ 9 files changed, 99 insertions(+), 30 deletions(-) diff --git a/app/assets/stylesheets/_harvests.scss b/app/assets/stylesheets/_harvests.scss index 560983965..b8c317ea5 100644 --- a/app/assets/stylesheets/_harvests.scss +++ b/app/assets/stylesheets/_harvests.scss @@ -2,21 +2,29 @@ .text { color: $white; margin: 0; - opacity: .9; + opacity: .8; position: absolute; text-align: center; - top: 50%; + top: 30%; width: 100%; + color: $white; + + h3, + h4, + h5 { + margin: 0 + } h3 { background-color: $green; - font-size: 1em; + } + + h4 { + background-color: $black; } h5 { background-color: $brown; - color: $white; - font-size: .7em; } a { diff --git a/app/assets/stylesheets/_plantings.scss b/app/assets/stylesheets/_plantings.scss index 52e204082..a65aeb75c 100755 --- a/app/assets/stylesheets/_plantings.scss +++ b/app/assets/stylesheets/_plantings.scss @@ -1,5 +1,4 @@ .planting { - .planting-badges { font-size: 1em; position: absolute; @@ -23,12 +22,6 @@ } } - .planting-full-badges { - .badge { - font-size: 200%; - } - } - .planting-name { position: relative; text-align: center; diff --git a/app/assets/stylesheets/mobile.scss b/app/assets/stylesheets/mobile.scss index c62904e37..95a1a568d 100644 --- a/app/assets/stylesheets/mobile.scss +++ b/app/assets/stylesheets/mobile.scss @@ -1,6 +1,6 @@ // Overrides applying only to mobile view. This must be at the end of the overrides file. // Extra small devices (portrait phones, less than 576px) -@include media-breakpoint-down(xs) { +@include media-breakpoint-down(md) { #maincontainer { width: 100%; diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index c63172709..51ca424cc 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -42,6 +42,13 @@ class MembersController < ApplicationController end end + @harvests = Harvest.search( + where: {owner_id: @member.id}, + boost_by: [:created_at], + limit: 16, + load: false + ) + respond_to do |format| format.html # show.html.haml format.json { render json: @member.to_json(only: member_json_fields) } diff --git a/app/views/harvests/_thumbnail.html.haml b/app/views/harvests/_thumbnail.html.haml index 5dfe125c3..016d40650 100644 --- a/app/views/harvests/_thumbnail.html.haml +++ b/app/views/harvests/_thumbnail.html.haml @@ -1,10 +1,11 @@ - cache harvest do - .card.harvest-thumbnail - = link_to image_tag(harvest_image_path(harvest), - alt: harvest, - class: 'img img-card'), - harvest + = link_to harvest_path(slug: harvest.slug) do + .card.harvest-thumbnail + = image_tag(harvest.thumbnail_url ? harvest.thumbnail_url : placeholder_image, + alt: harvest.crop_name, + class: 'img img-card') - .text - %h3.harvest-plant-part= link_to harvest.plant_part, harvest - %h5.harvest-crop= harvest.crop + .text + %h3.harvest-crop #{harvest.crop_name} harvest + %h4.harvest-plant-part= harvest.plant_part_name + %h5.harvest-date= harvest.harvested_at diff --git a/app/views/members/_full_summary.html.haml b/app/views/members/_full_summary.html.haml index 3ed78bd3b..d855d74cb 100644 --- a/app/views/members/_full_summary.html.haml +++ b/app/views/members/_full_summary.html.haml @@ -4,10 +4,18 @@ .index-cards - @harvesting.each do |planting| = render 'plantings/thumbnail', planting: planting + +- if @harvests.any? + %section.havests + %h2 Recent Harvests + .index-cards + - @harvests.each do |harvest| + = render 'harvests/thumbnail', harvest: harvest + - if @others.size.positive? %section.planting-progress %h2 Progress report - %p Still growing + %p Still growing and not ready for harvesting. .list-group - @others.each do |planting| .list-group-item @@ -19,17 +27,21 @@ %p These plantings are at the end of their lifecycle. - if member_signed_in? && @member == current_member - When you have removed the planting from your garden, mark the planting as finished in Growstuff. + %strong When you have removed the planting from your garden, mark the planting as finished in Growstuff. .index-cards - @late.each do |planting| = render 'plantings/thumbnail', planting: planting -- if @super_late.size.positive? +- if @super_late.any? %section.superlate %h2 Super late %p - We suspect the following plantings finished long ago and no longer need tracking. You can mark them as finished to stop tracking. + We suspect the following plantings finished long ago and no longer need tracking. + - if member_signed_in? && current_member == @member + %strong You can mark these plantings as finished to stop tracking. %ul - @super_late.each do |planting| %li = link_to planting.crop_name, planting_url(slug: planting.slug) planted on #{planting.planted_at.to_date} + + diff --git a/app/views/plantings/_badges.html.haml b/app/views/plantings/_badges.html.haml index 8402aaf36..e01d72d5f 100644 --- a/app/views/plantings/_badges.html.haml +++ b/app/views/plantings/_badges.html.haml @@ -4,7 +4,6 @@ - if planting.finish_is_predicatable? - if planting.super_late? %span.badge.badge-info.badge-super-late= t('.super_late') - = planting_finish_button(planting) - elsif planting.late? %span.badge.badge-info.badge-late= t('.late_finishing') diff --git a/app/views/plantings/_thumbnail.html.haml b/app/views/plantings/_thumbnail.html.haml index 60bf071cf..3e105961b 100644 --- a/app/views/plantings/_thumbnail.html.haml +++ b/app/views/plantings/_thumbnail.html.haml @@ -1,11 +1,12 @@ -.card.thumbnail +.card.planting.thumbnail .planting-thumbnail-image = link_to image_tag(planting_image_path(planting), alt: planting.crop, class: 'img-card'), planting .card-body - %h5.card-title + %h4 = crop_icon(planting.crop) = link_to planting.crop, planting - %h6.card-subtitle.text-muted=planting.finished_at - = render 'plantings/badges', planting: planting + planting + - if planting.finished_at.present? + %h6.card-subtitle.text-muted=planting.finished_at diff --git a/spec/features/members/profile_spec.rb b/spec/features/members/profile_spec.rb index 08438efda..e668f28cc 100644 --- a/spec/features/members/profile_spec.rb +++ b/spec/features/members/profile_spec.rb @@ -150,6 +150,54 @@ describe "member profile", js: true do it { expect(page).to have_link href: photo_path(photo) } it { expect(page).to have_link href: planting_path(planting) } end + + context 'plantings' do + let(:crop) { FactoryBot.create :crop } + before 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 + + growing_planting + harvesting_planting + super_late_planting + + visit member_path(member) + end + + let(:growing_planting) do + FactoryBot.create :planting, + crop: crop, + owner: member, + planted_at: Time.zone.today + end + + let(:harvesting_planting) do + FactoryBot.create :planting, + crop: crop, + owner: member, + planted_at: 51.days.ago + end + + let(:super_late_planting) do + FactoryBot.create :planting, + crop: crop, owner: member, + planted_at: 260.days.ago + end + + it { expect(page).to have_link(href: planting_path(growing_planting)) } + it { expect(page).to have_link(href: planting_path(harvesting_planting)) } + it { expect(page).to have_link(href: planting_path(super_late_planting)) } + end end context "not signed in" do