From c5699610299d84c52957bd1621fc8f425f54ba76 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sun, 7 Jan 2018 19:25:05 +1300 Subject: [PATCH 1/2] Add timeline to gardens --- app/controllers/gardens_controller.rb | 11 +++++++++++ app/views/gardens/show.html.haml | 9 +++++++++ config/routes.rb | 4 +++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/app/controllers/gardens_controller.rb b/app/controllers/gardens_controller.rb index ede5c2602..d2aa8bfe0 100644 --- a/app/controllers/gardens_controller.rb +++ b/app/controllers/gardens_controller.rb @@ -58,6 +58,17 @@ class GardensController < ApplicationController redirect_to(gardens_by_owner_path(owner: @garden.owner)) end + def timeline + @data = [] + @garden = Garden.find(params[:garden_id]) + @garden.plantings.where.not(finished_at: nil) + .where.not(planted_at: nil) + .order(finished_at: :desc).each do |p| + @data << [p.crop.name, p.planted_at, p.finished_at] + end + render json: @data + end + private def garden_params diff --git a/app/views/gardens/show.html.haml b/app/views/gardens/show.html.haml index ef5b41cfb..5ffed7152 100644 --- a/app/views/gardens/show.html.haml +++ b/app/views/gardens/show.html.haml @@ -9,6 +9,11 @@ = tag("meta", property: "og:type", content: "website") = tag("meta", property: "og:url", content: request.original_url) = tag("meta", property: "og:site_name", content: ENV['GROWSTUFF_SITE_NAME']) + +- content_for :scripts do + = javascript_include_tag "charts" + = javascript_include_tag "https://www.gstatic.com/charts/loader.js" + .row .col-md-9 %p.btn-group= render 'gardens/actions', garden: @garden @@ -32,6 +37,10 @@ Why not = link_to 'tell us more.', edit_garden_path(@garden) + %h3 Garden timeline + .row + = timeline garden_timeline_path(@garden), adapter: "google" + %h3 What's planted here? .row - if @current_plantings.size.positive? diff --git a/config/routes.rb b/config/routes.rb index 14c4bd401..cc90a4063 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -27,7 +27,9 @@ Growstuff::Application.routes.draw do get '/plantings/owner/:owner' => 'plantings#index', as: 'plantings_by_owner' get '/plantings/crop/:crop' => 'plantings#index', as: 'plantings_by_crop' - resources :gardens + resources :gardens do + get 'timeline' => 'gardens#timeline' + end get '/gardens/owner/:owner' => 'gardens#index', as: 'gardens_by_owner' resources :seeds From 1a4e0bd48a473ac1b587215bda75cbe19a597b99 Mon Sep 17 00:00:00 2001 From: Awesome Code Date: Wed, 10 Jan 2018 20:18:17 +0000 Subject: [PATCH 2/2] Auto corrected by following Style/RescueStandardError --- app/models/csv_importer.rb | 2 +- db/seeds.rb | 2 +- spec/controllers/photo_associations_controller_spec.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/csv_importer.rb b/app/models/csv_importer.rb index 66297b13c..f95fae8f2 100644 --- a/app/models/csv_importer.rb +++ b/app/models/csv_importer.rb @@ -64,7 +64,7 @@ class CsvImporter def cropbot @cropbot = Member.find_by!(login_name: 'cropbot') unless @cropbot @cropbot - rescue + rescue StandardError raise "cropbot account not found: run rake db:seed" end end diff --git a/db/seeds.rb b/db/seeds.rb index 7df7e0e4c..be885a352 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -65,7 +65,7 @@ def load_test_users # rubocop:disable Metrics/AbcSize source_path = Rails.root.join('db', 'seeds') begin suburb_file = File.open("#{source_path}/suburbs.csv") - rescue + rescue StandardError puts "Warning: unable to open suburbs.csv" end diff --git a/spec/controllers/photo_associations_controller_spec.rb b/spec/controllers/photo_associations_controller_spec.rb index 75a04eedd..f021d5aa8 100644 --- a/spec/controllers/photo_associations_controller_spec.rb +++ b/spec/controllers/photo_associations_controller_spec.rb @@ -31,7 +31,7 @@ describe PhotoAssociationsController do expect do begin delete :destroy, valid_params - rescue + rescue StandardError nil end end.not_to change(photo.harvests, :count)