Class: Kenui::EmailNotificationsController

Inherits:
EngineController
  • Object
show all
Defined in:
app/controllers/kenui/email_notifications_controller.rb

Instance Method Summary collapse

Methods inherited from EngineController

#current_tenant_user, #get_layout, #options_for_klient

Instance Method Details

#configurationObject



56
57
58
59
60
61
62
63
# File 'app/controllers/kenui/email_notifications_controller.rb', line 56

def configuration
   = params.require(:account_id)
  data = Kenui::EmailNotificationService.(,options_for_klient)

  respond_to do |format|
    format.json { render json: { data: data} }
  end
end

#events_to_considerObject



48
49
50
51
52
53
54
# File 'app/controllers/kenui/email_notifications_controller.rb', line 48

def events_to_consider
  data = Kenui::EmailNotificationService.get_events_to_consider(options_for_klient)

  respond_to do |format|
    format.json { render json: { data: data} }
  end
end

#indexObject



4
5
6
# File 'app/controllers/kenui/email_notifications_controller.rb', line 4

def index
  @record_total = (KillBillClient::Model::Account.find_in_batches(nil,nil,false,false,options_for_klient) || []).size
end

#paginationObject

get account list, no sorting



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/kenui/email_notifications_controller.rb', line 9

def pagination
  search_key = (params[:search] || {})[:value].presence
  offset = (params[:start] || 0).to_i
  limit = (params[:length] || 50).to_i
  record_total = (params[:record_total] || 100).to_i
  data = []

  if search_key.present?
    rows = KillBillClient::Model::Account.find_in_batches_by_search_key(search_key, offset, limit, false, false, options_for_klient)
  else
    rows = KillBillClient::Model::Account.find_in_batches(offset, limit, false, false, options_for_klient)
  end

   = rows.map { || . }
  email_notifications_configuration = Kenui::EmailNotificationService.get_configurations(, options_for_klient)

  rows.each do |row|
    events = ''
    unless email_notifications_configuration.first.is_a?(FalseClass)
      configuration = email_notifications_configuration.select { |event| event[:kbAccountId] == row. }
      events = configuration.map { |event| event[:eventType] }.join(', ')
    end

    data << [
      row.name,
      view_context.link_to(row., "/accounts/#{row.}"),
      events,
      view_context.link_to('<i class="fa fa-cog" aria-hidden="true"></i>'.html_safe,
                           '#configureEmailNotification',
                           data: { name: row.name, account_id: row.,
                                   events: events, toggle: 'modal', target: '#configureEmailNotification'})
    ]
  end

  respond_to do |format|
    format.json { render json: { data: data, recordsTotal: record_total, recordsFiltered: record_total} }
  end
end

#set_configurationObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/controllers/kenui/email_notifications_controller.rb', line 65

def set_configuration
  configuration = params.require(:configuration)

  is_success, message = Kenui::EmailNotificationService.(configuration[:account_id],
                                                                                      configuration[:event_types],
                                                                                      'kenui', nil, nil,
                                                                                      options_for_klient )

  if is_success
    flash[:notice] = message
  else
    flash[:error] = message
  end
  redirect_to email_notifications_path
end