added modal window

This commit is contained in:
olegphenomenon 2022-04-12 14:28:09 +03:00
parent 2aa1100305
commit 77249629bb
6 changed files with 102 additions and 30 deletions

View file

@ -6,6 +6,7 @@ module Admin
params[:q] ||= {}
@auctions = Auction.with_status(params[:statuses_contains])
@auction = Auction.new
normalize_search_parameters do
@q = @auctions.ransack(PartialSearchFormatter.format(params[:q]))
@ -14,16 +15,47 @@ module Admin
@auctions = @auctions.per(params[:results_per_page]) if params[:results_per_page].to_i.positive?
domains = ReservedDomain.all.order(:name)
q = domains.ransack(PartialSearchFormatter.format(params[:q]))
@domains = q.result.page(params[:page])
@domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i.positive?
render_by_format('admin/auctions/index', 'auctions')
end
def update
def create
auction = Auction.new(domain: params[:domain], status: Auction.statuses[:started])
if auction.save
remove_from_reserved(auction)
flash[:notice] = "Auction #{params[:domain]} created"
else
flash[:alert] = "Something goes wrong"
end
redirect_to admin_auctions_path
end
def upload_spreadsheet
table = CSV.parse(File.read(params[:q][:file]), headers: true)
table.each do |row|
record = row.to_h
auction = Auction.new(domain: record['name'], status: Auction.statuses[:started])
remove_from_reserved(auction) if auction.save!
end
redirect_to admin_auctions_path
end
private
def remove_from_reserved(auction)
domain = ReservedDomain.find_by(name: auction.domain)
domain.destroy if domain.present?
end
def normalize_search_parameters
ca_cache = params[:q][:valid_to_lteq]
begin