Class: Kenui::EmailNotificationsController
- Inherits:
-
EngineController
- Object
- ApplicationController
- EngineController
- Kenui::EmailNotificationsController
- Defined in:
- app/controllers/kenui/email_notifications_controller.rb
Instance Method Summary collapse
- #configuration ⇒ Object
- #events_to_consider ⇒ Object
- #index ⇒ Object
-
#pagination ⇒ Object
get account list, no sorting.
- #set_configuration ⇒ Object
Methods inherited from EngineController
#current_tenant_user, #get_layout, #options_for_klient
Instance Method Details
#configuration ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'app/controllers/kenui/email_notifications_controller.rb', line 57 def configuration account_id = params.require(:account_id) data = Kenui::EmailNotificationService.get_configuration_per_account(account_id, ) respond_to do |format| format.json { render json: { data: data } } end end |
#events_to_consider ⇒ Object
49 50 51 52 53 54 55 |
# File 'app/controllers/kenui/email_notifications_controller.rb', line 49 def events_to_consider data = Kenui::EmailNotificationService.get_events_to_consider() respond_to do |format| format.json { render json: { data: data } } end end |
#index ⇒ Object
5 6 7 |
# File 'app/controllers/kenui/email_notifications_controller.rb', line 5 def index @record_total = (KillBillClient::Model::Account.find_in_batches(nil, nil, false, false, ) || []).size end |
#pagination ⇒ Object
get account list, no sorting
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 47 |
# File 'app/controllers/kenui/email_notifications_controller.rb', line 10 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 = [] rows = if search_key.present? KillBillClient::Model::Account.find_in_batches_by_search_key(search_key, offset, limit, false, false, ) else KillBillClient::Model::Account.find_in_batches(offset, limit, false, false, ) end account_ids = rows.map(&:account_id) email_notifications_configuration = Kenui::EmailNotificationService.get_configurations(account_ids, ) rows.each do |row| events = '' unless email_notifications_configuration.first.is_a?(FalseClass) configuration = email_notifications_configuration.select { |event| event[:kbAccountId] == row.account_id } events = configuration.map { |event| event[:eventType] }.join(', ') end data << [ row.name, view_context.link_to(row.account_id, "/accounts/#{row.account_id}"), events, view_context.link_to('<i class="fa fa-cog" aria-hidden="true"></i>'.html_safe, '#configureEmailNotification', data: { name: row.name, account_id: row.account_id, 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_configuration ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/controllers/kenui/email_notifications_controller.rb', line 66 def set_configuration configuration = params.require(:configuration) is_success, = Kenui::EmailNotificationService.set_configuration_per_account(configuration[:account_id], configuration[:event_types], 'kenui', nil, nil, ) if is_success flash[:notice] = else flash[:error] = end redirect_to email_notifications_path end |