Class: Spree::Admin::FeaturedTripsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/spree/admin/featured_trips_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/spree/admin/featured_trips_controller.rb', line 21

def create
  trip = SpreeCmCommissioner::Trip.find(params[:trip_id])
  featured_until = parse_featured_until(params[:featured_until])

  if featured_until.present? && featured_until > Time.current && trip.update(featured_until: featured_until)
    flash[:success] = 'Trip was added to featured trips.'
  else
    flash[:error] = 'Featured until must be a future date and time.'
  end

  redirect_to spree.admin_featured_trips_path
end

#indexObject



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/spree/admin/featured_trips_controller.rb', line 7

def index
  @status = filter_status
  @query = params[:q].to_s.strip
  @vendor_id = params[:vendor_id].presence
  @origin_place_id = params[:origin_place_id].presence
  @destination_place_id = params[:destination_place_id].presence
  @vendors = Spree::Vendor.order(:name)
  @places = SpreeCmCommissioner::Place.order(:name)
  @active_count = SpreeCmCommissioner::Trip.currently_featured.count
  @expired_count = SpreeCmCommissioner::Trip.where.not(featured_until: nil).where('featured_until < ?', Time.current).count
  @featured_trips = filtered_featured_trips
  @available_trips = available_trips
end

#updateObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/spree/admin/featured_trips_controller.rb', line 34

def update
  trip = SpreeCmCommissioner::Trip.find(params[:id])

  if ActiveModel::Type::Boolean.new.cast(params[:remove])
    trip.update(featured_until: nil)
    flash[:success] = 'Trip was removed from featured trips.'
  else
    update_featured_until(trip)
  end

  redirect_to spree.admin_featured_trips_path(
    status: params[:status],
    vendor_id: params[:vendor_id],
    origin_place_id: params[:origin_place_id],
    destination_place_id: params[:destination_place_id],
    q: params[:q]
  )
end