mirror of
https://github.com/Growstuff/growstuff.git
synced 2025-12-31 13:37:49 -05:00
* 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
89 lines
1.8 KiB
Ruby
89 lines
1.8 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class ActivitiesController < DataController
|
|
def index
|
|
@show_all = params[:all] == '1'
|
|
|
|
where = {}
|
|
where['active'] = true unless @show_all
|
|
|
|
if params[:member_slug]
|
|
@owner = Member.find_by(slug: params[:member_slug])
|
|
where['owner_id'] = @owner.id unless @owner.nil?
|
|
end
|
|
|
|
@activities = Activity.search(
|
|
where:,
|
|
page: params[:page],
|
|
limit: 30,
|
|
boost_by: [:created_at],
|
|
load: false
|
|
)
|
|
@filename = "Growstuff-#{specifics}Activities-#{Time.zone.now.to_fs(:number)}.csv"
|
|
respond_with(@activities)
|
|
end
|
|
|
|
def show
|
|
respond_with @activity
|
|
end
|
|
|
|
def new
|
|
@activity = Activity.new(
|
|
owner: current_member
|
|
)
|
|
if params[:garden_id]
|
|
@activity.garden = Garden.find_by(
|
|
owner: current_member,
|
|
id: params[:garden_id]
|
|
)
|
|
end
|
|
|
|
if params[:planting_id]
|
|
@activity.planting = Planting.find_by(
|
|
owner: current_member,
|
|
id: params[:planting_id]
|
|
)
|
|
end
|
|
|
|
respond_with @activity
|
|
end
|
|
|
|
def edit
|
|
# the following are needed to display the form but aren't used
|
|
@gardens = @activity.owner.gardens.active.order_by_name
|
|
@plantings = @activity.owner.plantings.active
|
|
end
|
|
|
|
def create
|
|
@activity = Activity.new(activity_params)
|
|
@activity.owner = current_member
|
|
@activity.save
|
|
respond_with @activity
|
|
end
|
|
|
|
def update
|
|
@activity.update(activity_params)
|
|
respond_with @activity
|
|
end
|
|
|
|
def destroy
|
|
@activity.destroy
|
|
respond_with @activity, location: @activity.garden
|
|
end
|
|
|
|
private
|
|
|
|
def activity_params
|
|
params.require(:activity).permit(
|
|
:name, :description, :category, :finished,
|
|
:garden_id, :planting_id, :due_date
|
|
)
|
|
end
|
|
|
|
def specifics
|
|
if @owner.present?
|
|
"#{@owner.to_param}-"
|
|
end
|
|
end
|
|
end
|