mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-09-28 17:04:57 -04:00
Rename the past gardens page to inactive gardens throughout (label, route, action, view, styles). Move its link on the gardens page to below the member's card, with a line saying what it holds, and add an explanation to the page itself. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
94 lines
3.1 KiB
Ruby
94 lines
3.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class GardensController < DataController
|
|
# Anyone can look at a member's inactive gardens, as they can their current ones.
|
|
skip_before_action :authenticate_member!, only: :inactive
|
|
skip_load_and_authorize_resource only: :inactive
|
|
|
|
def index
|
|
@owner = Member.find_by!(slug: params[:member_slug]) if params[:member_slug].present?
|
|
@show_jump_to = params[:member_slug].present? || false
|
|
|
|
@gardens = @gardens.includes(:owner)
|
|
@gardens = @gardens.active
|
|
if @owner.present?
|
|
@gardens = @gardens.left_joins(:garden_collaborators)
|
|
@gardens = @gardens.where(owner: @owner).or(@gardens.where(garden_collaborators: { member: @owner }))
|
|
end
|
|
@gardens = @gardens.where.not(members: { confirmed_at: nil })
|
|
.order(:name).paginate(page: params[:page])
|
|
respond_with(@gardens)
|
|
end
|
|
|
|
# A member's gardens that are no longer active, as a gallery of what they grew.
|
|
def inactive
|
|
@owner = Member.confirmed.find_by!(slug: params[:member_slug])
|
|
owned = Garden.inactive.where(owner: @owner)
|
|
collaborating = Garden.inactive.where(id: GardenCollaborator.where(member: @owner).select(:garden_id))
|
|
@gardens = owned.or(collaborating)
|
|
.includes(:owner, plantings: { crop: { parent: :parent } })
|
|
.order(updated_at: :desc)
|
|
.paginate(page: params[:page], per_page: 12)
|
|
end
|
|
|
|
def show
|
|
@current_plantings = @garden.plantings.current.where.not(failed: true).includes(:crop, :owner).order(planted_at: :desc)
|
|
@current_activities = @garden.activities.current.includes(:owner).order(created_at: :desc)
|
|
@finished_activities = @garden.activities.finished.includes(:owner).order(created_at: :desc)
|
|
@finished_plantings = @garden.plantings.finished.includes(:crop)
|
|
@suggested_companions = Crop.approved.where(
|
|
id: CropCompanion.where(crop_a_id: @current_plantings.select(:crop_id)).select(:crop_b_id)
|
|
).order(:name)
|
|
respond_with(@garden)
|
|
end
|
|
|
|
def new
|
|
@garden = Garden.new
|
|
respond_with(@garden)
|
|
end
|
|
|
|
def edit
|
|
respond_with(@garden)
|
|
end
|
|
|
|
def create
|
|
@garden.owner_id = current_member.id
|
|
if @garden.save
|
|
link = new_activity_path(name: 'Weed the garden bed', garden_id: @garden.id, due_date: 2.weeks.from_now.to_date)
|
|
flash[:notice] = t('gardens.created_prompt_html', link: link).html_safe
|
|
end
|
|
respond_with(@garden)
|
|
end
|
|
|
|
def update
|
|
flash[:notice] = I18n.t('gardens.updated') if @garden.update(garden_params)
|
|
respond_with(@garden)
|
|
end
|
|
|
|
def destroy
|
|
@garden.destroy
|
|
flash[:notice] = I18n.t('gardens.deleted')
|
|
redirect_to(member_gardens_path(@garden.owner))
|
|
end
|
|
|
|
def fetch_wikidata
|
|
if @garden.populate_wikidata_info
|
|
@garden.save
|
|
flash[:notice] = "Wikidata information updated."
|
|
else
|
|
flash[:alert] = "Could not find Wikidata information for this location."
|
|
end
|
|
redirect_to @garden
|
|
end
|
|
|
|
private
|
|
|
|
def garden_params
|
|
params.require(:garden).permit(
|
|
:name, :slug, :description, :active,
|
|
:location, :latitude, :longitude, :area, :area_unit, :garden_type_id,
|
|
:location_wikidata_id, :lowest_temp_c, :highest_temp_c
|
|
)
|
|
end
|
|
end
|