Added Harvested for chart

This commit is contained in:
Brenda Wallace committed 2018-01-11 09:03:13 +13:00
1 parent 4af36f68b4
commit 390282f9f2
3 files changed
+19 -9

No files matched your search

+15 -9
View File
@@ -103,23 +103,29 @@ class CropsController < ApplicationController
end
def sunniness
@crop = Crop.find(params[:crop_id])
render json: Planting.where(crop: @crop)
.where.not(sunniness: nil)
.where.not(sunniness: '')
.group(:sunniness).count(:id)
pie_chart_query 'sunniness'
end
def planted_from
pie_chart_query 'planted_from'
end
def harvested_for
@crop = Crop.find(params[:crop_id])
render json: Planting.where(crop: @crop)
.where.not(planted_from: nil)
.where.not(planted_from: '')
.group(:planted_from).count(:id)
render json: Harvest.joins(:plant_part).where(crop: @crop)
.group("plant_parts.name").count(:id)
end
private
def pie_chart_query(field)
@crop = Crop.find(params[:crop_id])
render json: Planting.where(crop: @crop)
.where.not(field.to_sym => nil)
.where.not(field.to_sym => '')
.group(field.to_sym).count(:id)
end
def notifier
case @crop.approval_status
when "approved"
+3
View File
@@ -56,6 +56,9 @@
.col-md-3
%h2 Planted from
= pie_chart crop_planted_from_path(@crop), legend: "bottom"
.col-md-3
%h2 Harvested for
= pie_chart crop_harvested_for_path(@crop), legend: "bottom"
.row
.col-md-12
+1
View File
@@ -52,6 +52,7 @@ Growstuff::Application.routes.draw do
get 'photos' => 'photos#index'
get 'sunniness' => 'crops#sunniness'
get 'planted_from' => 'crops#planted_from'
get 'harvested_for' => 'crops#harvested_for'
end
resources :comments