Files
growstuff/app/controllers/gardens_controller.rb
Daniel O'Connor 5be0153c74 Activities (#3646)
* Implement activities

* Add activities to timeline

* Add factory

* Add coverage

* Fix misc issues

* Activities display

* Add activities to garden and plantings

* Add activities to garden and plantings

* Add planting

* Add to planting, harvest show

* More CRUD

* More CRUD

* index

* index

* Extract card view

* Permissions

* Add edit

* Remove workaround fro vs code

* Fix title

* CSV

* CSV

* Add RSS, ical

* Extend ical slightly

* Cleanup

* Rubocop

* Remove doubled form

* Change icon

* Fix short description

* Add menus

* Put homepage widget in

* Add activity icon - MIT licenced - https://www.svgrepo.com/svg/336823/plan

* Naming

* Missing files

* Revert VS Code lag induced change

* Update app/views/home/_harvests.html.haml

* Update activities_controller.rb

* Update activities_controller.rb

* Update app/controllers/activities_controller.rb

* Update index.html.haml

* Apply suggestions from code review

* Apply suggestions from code review

* Typo

* Translation

* Apply suggestions from code review

* Update app/views/plantings/index.ics.erb

* Update app/models/activity.rb

* Update plantings_spec.rb

* Update plantings_spec.rb

* We are now rendering an extra event, so check the next one for the old behaviour
2024-03-10 11:36:24 +10:30

62 lines
1.7 KiB
Ruby

# frozen_string_literal: true
class GardensController < DataController
def index
@owner = Member.find_by(slug: params[:member_slug])
@show_all = params[:all] == '1'
@show_jump_to = params[:member_slug].present? ? true : false
@gardens = @gardens.includes(:owner)
@gardens = @gardens.active unless @show_all
@gardens = @gardens.where(owner: @owner) if @owner.present?
@gardens = @gardens.where.not(members: { confirmed_at: nil })
.order(:name).paginate(page: params[:page])
respond_with(@gardens)
end
def show
@current_plantings = @garden.plantings.current.includes(:crop, :owner).order(planted_at: :desc)
@current_activities = @garden.activities.current.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
flash[:notice] = I18n.t('gardens.created') if @garden.save
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
private
def garden_params
params.require(:garden).permit(
:name, :slug, :description, :active,
:location, :latitude, :longitude, :area, :area_unit, :garden_type_id
)
end
end