Class: ActivityNotification::NotificationsController

Inherits:
Object
  • Object
show all
Includes:
PolymorphicHelpers, StoreController
Defined in:
app/controllers/activity_notification/notifications_controller.rb

Overview

Controller to manage notifications.

Direct Known Subclasses

NotificationsWithDeviseController

Constant Summary collapse

DEFAULT_VIEW_DIRECTORY =
"default"

Instance Method Summary collapse

Methods included from StoreController

#store_controller_for_activity_notification

Instance Method Details

#controller_pathString

Returns controller path. This method has no action routing and is called from target_view_path method. This method can be overriden.

Returns:

  • “activity_notification/notifications” as controller path



124
125
126
# File 'app/controllers/activity_notification/notifications_controller.rb', line 124

def controller_path
  "activity_notification/notifications"
end

#destroy(params) ⇒ Responce

Deletes a notification.

DELETE /:target_type/:target_id/notifcations/:id

Returns JavaScript view for ajax request or redirects to back as default.

Parameters:

  • Request parameters

Options Hash (params):

  • :filter (String) — default: nil

    Filter option to load notification index (Nothing as auto, ‘opened’ or ‘unopened’)

  • :limit (String) — default: nil

    Limit to query for notifications

  • :reload (String) — default: 'true'

    Whether notification index will be reloaded

  • :without_grouping (String) — default: 'false'

    If notification index will include group members

  • :with_group_members (String) — default: 'false'

    If notification index will include group members

Returns:

  • JavaScript view for ajax request or redirects to back as default



80
81
82
83
# File 'app/controllers/activity_notification/notifications_controller.rb', line 80

def destroy
  @notification.destroy
  return_back_or_ajax
end

#index(params) ⇒ Responce

Shows notification index of the target.

GET /:target_type/:target_id/notifcations

Returns HTML view as default or JSON of notification index with json format parameter.

Parameters:

  • Request parameter options for notification index

Options Hash (params):

  • :filter (String) — default: nil

    Filter option to load notification index (Nothing as auto, ‘opened’ or ‘unopened’)

  • :limit (String) — default: nil

    Limit to query for notifications

  • :reverse (String) — default: 'false'

    If notification index will be ordered as earliest first

  • :without_grouping (String) — default: 'false'

    If notification index will include group members

  • :with_group_members (String) — default: 'false'

    If notification index will include group members

  • :filtered_by_type (String) — default: nil

    Notifiable type for filter

  • :filtered_by_group_type (String) — default: nil

    Group type for filter, valid with :filtered_by_group_id

  • :filtered_by_group_id (String) — default: nil

    Group instance id for filter, valid with :filtered_by_group_type

  • :filtered_by_key (String) — default: nil

    Key of the notification for filter

  • :reload (String) — default: 'true'

    Whether notification index will be reloaded

Returns:

  • HTML view as default or JSON of notification index with json format parameter



30
31
32
33
34
35
36
37
# File 'app/controllers/activity_notification/notifications_controller.rb', line 30

def index
  set_index_options
  @notifications = load_notification_index(@index_options) if params[:reload].to_s.to_boolean(true)
  respond_to do |format|
    format.html # index.html.erb
    format.json { render json: @notifications.to_json(include: [:target, :notifiable, :group]) }
  end
end

#open(params) ⇒ Responce

Moves to notifiable_path of the notification.

GET /:target_type/:target_id/notifcations/:id/move

Returns JavaScript view for ajax request or redirects to back as default.

Parameters:

  • Request parameters

Options Hash (params):

  • :open (String) — default: 'false'

    Whether the notification will be opened

  • :filter (String) — default: nil

    Filter option to load notification index (Nothing as auto, ‘opened’ or ‘unopened’)

  • :limit (String) — default: nil

    Limit to query for notifications

  • :reload (String) — default: 'true'

    Whether notification index will be reloaded

Returns:

  • JavaScript view for ajax request or redirects to back as default



115
116
117
118
# File 'app/controllers/activity_notification/notifications_controller.rb', line 115

def move
  @notification.open! if params[:open].to_s.to_boolean(false)
  redirect_to @notification.notifiable_path
end

#open(params) ⇒ Responce

Opens a notification.

POST /:target_type/:target_id/notifcations/:id/open

Returns JavaScript view for ajax request or redirects to back as default.

Parameters:

  • Request parameters

Options Hash (params):

  • :move (String) — default: 'false'

    Whether redirects to notifiable_path after the notification is opened

  • :filter (String) — default: nil

    Filter option to load notification index (Nothing as auto, ‘opened’ or ‘unopened’)

  • :limit (String) — default: nil

    Limit to query for notifications

  • :reload (String) — default: 'true'

    Whether notification index will be reloaded

  • :without_grouping (String) — default: 'false'

    If notification index will include group members

  • :with_group_members (String) — default: 'false'

    If notification index will include group members

Returns:

  • JavaScript view for ajax request or redirects to back as default



97
98
99
100
101
102
103
# File 'app/controllers/activity_notification/notifications_controller.rb', line 97

def open
  with_members = !(params[:with_group_members].to_s.to_boolean(false) || params[:without_grouping].to_s.to_boolean(false))
  @notification.open!(with_members: with_members)
  params[:move].to_s.to_boolean(false) ? 
    move : 
    return_back_or_ajax
end

#open_all(params) ⇒ Responce

Opens all notifications of the target.

POST /:target_type/:target_id/notifcations/open_all

Returns JavaScript view for ajax request or redirects to back as default.

Parameters:

  • Request parameters

Options Hash (params):

  • :filter (String) — default: nil

    Filter option to load notification index (Nothing as auto, ‘opened’ or ‘unopened’)

  • :limit (String) — default: nil

    Limit to query for notifications

  • :reload (String) — default: 'true'

    Whether notification index will be reloaded

  • :without_grouping (String) — default: 'false'

    If notification index will include group members

  • :with_group_members (String) — default: 'false'

    If notification index will include group members

  • :filtered_by_type (String) — default: nil

    Notifiable type for filter

  • :filtered_by_group_type (String) — default: nil

    Group type for filter, valid only :filtered_by_group_id

  • :filtered_by_group_id (String) — default: nil

    Group instance id for filter, valid only :filtered_by_group_type

  • :filtered_by_key (String) — default: nil

    Key of the notification for filter

Returns:

  • JavaScript view for ajax request or redirects to back as default



54
55
56
57
# File 'app/controllers/activity_notification/notifications_controller.rb', line 54

def open_all
  @target.open_all_notifications(params)
  return_back_or_ajax
end

#show(params) ⇒ Responce

Shows a notification.

GET /:target_type/:target_id/notifcations/:id

Returns HTML view as default.

Parameters:

  • Request parameters

Returns:

  • HTML view as default



65
66
# File 'app/controllers/activity_notification/notifications_controller.rb', line 65

def show
end

#target_view_pathObject

Returns path of the target view templates. This method has no action routing and needs to be public since it is called from view helper.



130
131
132
133
134
135
136
# File 'app/controllers/activity_notification/notifications_controller.rb', line 130

def target_view_path
  target_type = @target.to_resources_name
  view_path = [controller_path, target_type].join('/')
  lookup_context.exists?(action_name, view_path) ?
    view_path :
    [controller_path, DEFAULT_VIEW_DIRECTORY].join('/')
end