Class: Backend::NotificationsController

Inherits:
BaseController show all
Defined in:
app/controllers/backend/notifications_controller.rb

Instance Attribute Summary

Attributes inherited from ApplicationController

#current_theme

Instance Method Summary collapse

Methods inherited from BaseController

account_lettering_states_crit, accounts_range_crit, amount_range_crit, crit_params, journal_entries_states_crit, journal_letter_crit, journal_period_crit, journals_crit, search_conditions

Methods inherited from ApplicationController

#after_sign_in_path_for, #authorized?, human_action_name, #human_action_name, #session_controller?

Instance Method Details

#destroyObject


50
51
52
53
54
55
56
57
58
59
# File 'app/controllers/backend/notifications_controller.rb', line 50

def destroy
  if params[:id]
    notification = find_and_check
    return unless notification
    notification.read!
  else
    current_user.unread_notifications.find_each(&:read!)
  end
  redirect_to params[:redirect] || { action: :index }
end

#indexObject


21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/backend/notifications_controller.rb', line 21

def index
  if params[:mode] == 'unread'
    @notifications = current_user.unread_notifications.where('created_at >= ?', Time.now - params[:ago].to_f)
    global_count = current_user.unread_notifications.count
    response = {
      count: global_count,
      status: :x_notifications.tl(count: global_count),
      new_messages: @notifications.collect(&:human_message)
    }
    render json: response.to_json
  else
    @notifications = current_user.unread_notifications.order(created_at: :desc)
  end
end

#showObject


36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/backend/notifications_controller.rb', line 36

def show
  notification = find_and_check
  return unless notification
  notification.read!
  if notification.target_url
    redirect_to notification.target_url
  elsif notification.target
    target = notification.target
    redirect_to(controller: target.class.model_name.plural, action: :show, id: target.id)
  else
    redirect_to action: :index
  end
end