Class: ActivityNotification::NotificationsController

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

Overview

Controller to manage notifications.

Constant Summary

Constants included from CommonController

CommonController::DEFAULT_VIEW_DIRECTORY

Instance Method Summary collapse

Instance Method Details

#destroy(params) ⇒ Response

Deletes a notification.

DELETE /:target_type/:target_id/notifications/:id

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

Parameters:

  • params (Hash)

    Request parameters

Options Hash (params):

  • :filter (String) — default: nil

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

  • :limit (String) — default: nil

    Maximum number of notifications to return

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

    Whether notification index will include group members

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

    Whether notification index will include group members

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

    Whether notification index will be reloaded

Returns:

  • (Response)

    JavaScript view for ajax request or redirects to back as default



73
74
75
76
# File 'app/controllers/activity_notification/notifications_controller.rb', line 73

def destroy
  @notification.destroy
  return_back_or_ajax
end

#index(params) ⇒ Response

Shows notification index of the target.

GET /:target_type/:target_id/notifications

Returns HTML view of notification index.

Parameters:

  • params (Hash)

    Request parameter options for notification index

Options Hash (params):

  • :filter (String) — default: nil

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

  • :limit (String) — default: nil

    Maximum number of notifications to return

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

    Whether notification index will be ordered as earliest first

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

    Whether notification index will include group members

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

    Whether notification index will include group members

  • :filtered_by_type (String) — default: nil

    Notifiable type to filter notification index

  • :filtered_by_group_type (String) — default: nil

    Group type to filter notification index, valid with :filtered_by_group_id

  • :filtered_by_group_id (String) — default: nil

    Group instance ID to filter notification index, valid with :filtered_by_group_type

  • :filtered_by_key (String) — default: nil

    Key of notifications to filter notification index

  • :later_than (String) — default: nil

    ISO 8601 format time to filter notification index later than specified time

  • :earlier_than (String) — default: nil

    ISO 8601 format time to filter notification index earlier than specified time

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

    Whether notification index will be reloaded

Returns:

  • (Response)

    HTML view of notification index



26
27
28
29
# File 'app/controllers/activity_notification/notifications_controller.rb', line 26

def index
  set_index_options
  load_index if params[:reload].to_s.to_boolean(true)
end

#open(params) ⇒ Response

Moves to notifiable_path of the notification.

GET /:target_type/:target_id/notifications/:id/move

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

Parameters:

  • params (Hash)

    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 by their status (Nothing as auto, ‘opened’ or ‘unopened’)

  • :limit (String) — default: nil

    Maximum number of notifications to return

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

    Whether notification index will include group members

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

    Whether notification index will include group members

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

    Whether notification index will be reloaded

Returns:

  • (Response)

    JavaScript view for ajax request or redirects to back as default



108
109
110
111
112
# File 'app/controllers/activity_notification/notifications_controller.rb', line 108

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

#open(params) ⇒ Response

Opens a notification.

PUT /:target_type/:target_id/notifications/:id/open

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

Parameters:

  • params (Hash)

    Request parameters

Options Hash (params):

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

    Whether it redirects to notifiable_path after the notification is opened

  • :filter (String) — default: nil

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

  • :limit (String) — default: nil

    Maximum number of notifications to return

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

    Whether notification index will include group members

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

    Whether notification index will include group members

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

    Whether notification index will be reloaded

Returns:

  • (Response)

    JavaScript view for ajax request or redirects to back as default



90
91
92
93
94
# File 'app/controllers/activity_notification/notifications_controller.rb', line 90

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

#open_all(params) ⇒ Response

Opens all notifications of the target.

POST /:target_type/:target_id/notifications/open_all

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

Parameters:

  • params (Hash)

    Request parameters

Options Hash (params):

  • :filter (String) — default: nil

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

  • :limit (String) — default: nil

    Maximum number of notifications to return

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

    Whether notification index will include group members

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

    Whether notification index will include group members

  • :filtered_by_type (String) — default: nil

    Notifiable type to filter notification index

  • :filtered_by_group_type (String) — default: nil

    Group type to filter notification index, valid with :filtered_by_group_id

  • :filtered_by_group_id (String) — default: nil

    Group instance ID to filter notification index, valid with :filtered_by_group_type

  • :filtered_by_key (String) — default: nil

    Key of notifications to filter notification index

  • :later_than (String) — default: nil

    ISO 8601 format time to filter notification index later than specified time

  • :earlier_than (String) — default: nil

    ISO 8601 format time to filter notification index earlier than specified time

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

    Whether notification index will be reloaded

Returns:

  • (Response)

    JavaScript view for ajax request or redirects to back as default



48
49
50
51
# File 'app/controllers/activity_notification/notifications_controller.rb', line 48

def open_all
  @opened_notifications = @target.open_all_notifications(params)
  return_back_or_ajax
end

#show(params) ⇒ Response

Shows a notification.

GET /:target_type/:target_id/notifications/:id

Returns HTML view as default.

Parameters:

  • params (Hash)

    Request parameters

Returns:

  • (Response)

    HTML view as default



59
60
# File 'app/controllers/activity_notification/notifications_controller.rb', line 59

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.



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

def target_view_path
  super
end