2024-02-25 12:15:55 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2011-06-12 16:41:23 -04:00
|
|
|
class PoolElementsController < ApplicationController
|
2019-11-26 17:03:43 -05:00
|
|
|
respond_to :html, :json, :js
|
2018-04-02 13:51:26 -04:00
|
|
|
before_action :member_only
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2011-01-20 18:30:36 -05:00
|
|
|
def create
|
2013-02-17 15:10:58 -05:00
|
|
|
@pool = Pool.find_by_name(params[:pool_name]) || Pool.find_by_id(params[:pool_id])
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2022-07-11 16:52:26 -04:00
|
|
|
if @pool.present?
|
2013-02-17 23:39:43 -05:00
|
|
|
@post = Post.find(params[:post_id])
|
2020-04-18 20:40:04 -04:00
|
|
|
@pool.with_lock do
|
|
|
|
@pool.add(@post.id)
|
|
|
|
@pool.save
|
|
|
|
end
|
2013-02-17 23:39:43 -05:00
|
|
|
append_pool_to_session(@pool)
|
2015-11-03 23:31:19 -05:00
|
|
|
else
|
|
|
|
@error = "That pool does not exist"
|
2013-02-17 15:10:58 -05:00
|
|
|
end
|
2011-01-20 18:30:36 -05:00
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2011-01-20 18:30:36 -05:00
|
|
|
def destroy
|
|
|
|
@pool = Pool.find(params[:pool_id])
|
2011-03-04 18:50:38 -05:00
|
|
|
@post = Post.find(params[:post_id])
|
2020-04-18 20:40:04 -04:00
|
|
|
@pool.with_lock do
|
2022-02-10 11:53:51 -05:00
|
|
|
@pool.remove!(@post)
|
2020-04-18 20:40:04 -04:00
|
|
|
@pool.save
|
|
|
|
end
|
2013-02-17 15:10:58 -05:00
|
|
|
respond_with(@pool, :location => post_path(@post))
|
2011-01-20 18:30:36 -05:00
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2021-07-18 11:50:57 -04:00
|
|
|
private
|
|
|
|
|
2011-03-04 18:50:38 -05:00
|
|
|
def append_pool_to_session(pool)
|
|
|
|
recent_pool_ids = session[:recent_pool_ids].to_s.scan(/\d+/)
|
|
|
|
recent_pool_ids << pool.id.to_s
|
|
|
|
recent_pool_ids = recent_pool_ids.slice(1, 5) if recent_pool_ids.size > 5
|
|
|
|
session[:recent_pool_ids] = recent_pool_ids.uniq.join(",")
|
|
|
|
end
|
2011-01-20 18:30:36 -05:00
|
|
|
end
|