Class: Admin::NotificationsController

Inherits:
ResourceController
  • Object
show all
Defined in:
app/controllers/spree/admin/notifications_controller.rb

Overview

Class NotificationController

Instance Method Summary collapse

Instance Method Details

#_date_time_string(notification) ⇒ Object



59
60
61
62
63
64
# File 'app/controllers/spree/admin/notifications_controller.rb', line 59

def _date_time_string(notification)
  notification.start_date =
    notification.start_date.strftime('%Y-%m-%d %H:%M') if notification.start_date?
  notification.end_date =
    notification.end_date.strftime('%Y-%m-%d %H:%M') if notification.end_date?
end

#_set_notification(params) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/spree/admin/notifications_controller.rb', line 46

def _set_notification(params)
  @notification = {}
  @start_date = params[:notification][:start_date]
  @start_date = Time.zone.parse(params[:notification][:start_date]).getutc unless @start_date.blank?

  @end_date = params[:notification][:end_date]
  @end_date = Time.zone.parse(params[:notification][:end_date]).getutc unless @end_date.blank?
  @message = params[:notification][:notification]
  @notification = { notification: @message,
                    start_date: @start_date,
                    end_date: @end_date }
end

#createObject



16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/spree/admin/notifications_controller.rb', line 16

def create
  @notification_params = _set_notification(params)
  @spree_notification = Spree::Notification.new(@notification_params)
  if @spree_notification.save
    redirect_to admin_notifications_path,
                notice: 'Notification has been created Succefully.'
  else
    _date_time_string(@spree_notification)
    render :new
  end
end

#editObject



28
29
30
31
# File 'app/controllers/spree/admin/notifications_controller.rb', line 28

def edit
  @spree_notification = Spree::Notification.find(params[:id])
  _date_time_string(@spree_notification)
end

#indexObject



6
7
8
9
10
# File 'app/controllers/spree/admin/notifications_controller.rb', line 6

def index
  @notifications =
    Spree::Notification.order('created_at desc')
    .page(params[:page]).per(Spree::Config[:orders_per_page])
end

#newObject



12
13
14
# File 'app/controllers/spree/admin/notifications_controller.rb', line 12

def new
  @spree_notification = Spree::Notification.new
end

#updateObject



33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/spree/admin/notifications_controller.rb', line 33

def update
  @spree_notification = Spree::Notification.find(params[:id])
  @notification_params = _set_notification(params)

  if @spree_notification.update_attributes(@notification_params)
    redirect_to admin_notifications_path,
                notice: 'Notification has been updated Successfully'
  else
    _date_time_string(@spree_notification)
    render :edit
  end
end